mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #5219 from gabrielbazan7/fix/alternativeCurrency
Preferences Alt Currency improves
This commit is contained in:
commit
1cace8ac37
|
@ -1,29 +1,38 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('preferencesAltCurrencyController',
|
||||
function($scope, $log, $timeout, $ionicHistory, configService, rateService, lodash, profileService, walletService) {
|
||||
function($scope, $log, $timeout, $ionicHistory, configService, rateService, lodash, profileService, walletService, storageService) {
|
||||
|
||||
var next = 10;
|
||||
var completeAlternativeList;
|
||||
|
||||
var config = configService.getSync();
|
||||
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
|
||||
$scope.listComplete = false;
|
||||
function init() {
|
||||
var unusedCurrencyList = [{
|
||||
isoCode: 'LTL'
|
||||
}, {
|
||||
isoCode: 'BTC'
|
||||
}];
|
||||
rateService.whenAvailable(function() {
|
||||
|
||||
var unusedCurrencyList = [{
|
||||
isoCode: 'LTL'
|
||||
}, {
|
||||
isoCode: 'BTC'
|
||||
}];
|
||||
$scope.listComplete = false;
|
||||
|
||||
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
|
||||
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
|
||||
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode');
|
||||
|
||||
rateService.whenAvailable(function() {
|
||||
completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
|
||||
return idx[c.isoCode];
|
||||
completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
|
||||
return idx[c.isoCode] || idx2[c.isoCode];
|
||||
});
|
||||
|
||||
completeAlternativeList = completeAlternativeList.sort(function(a, b) {
|
||||
return a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1;
|
||||
});
|
||||
|
||||
$scope.altCurrencyList = completeAlternativeList.slice(0, 10);
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
});
|
||||
$scope.altCurrencyList = completeAlternativeList.slice(0, next);
|
||||
});
|
||||
}
|
||||
|
||||
$scope.loadMore = function() {
|
||||
$timeout(function() {
|
||||
|
@ -34,6 +43,17 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl
|
|||
}, 100);
|
||||
};
|
||||
|
||||
$scope.findCurrency = function(search) {
|
||||
if (!search) init();
|
||||
$scope.altCurrencyList = lodash.filter(completeAlternativeList, function(item) {
|
||||
var val = item.name;
|
||||
return lodash.includes(val.toLowerCase(), search.toLowerCase());
|
||||
});
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.save = function(newAltCurrency) {
|
||||
var opts = {
|
||||
wallet: {
|
||||
|
@ -48,9 +68,26 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl
|
|||
if (err) $log.warn(err);
|
||||
|
||||
$ionicHistory.goBack();
|
||||
saveLastUsed(newAltCurrency);
|
||||
walletService.updateRemotePreferences(profileService.getWallets(), {}, function() {
|
||||
$log.debug('Remote preferences saved');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function saveLastUsed(newAltCurrency) {
|
||||
$scope.lastUsedAltCurrencyList.unshift(newAltCurrency);
|
||||
$scope.lastUsedAltCurrencyList = lodash.uniq($scope.lastUsedAltCurrencyList, 'isoCode');
|
||||
$scope.lastUsedAltCurrencyList = $scope.lastUsedAltCurrencyList.slice(0, 3);
|
||||
storageService.setLastCurrencyUsed(JSON.stringify($scope.lastUsedAltCurrencyList), function() {});
|
||||
};
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
var config = configService.getSync();
|
||||
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
|
||||
storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) {
|
||||
$scope.lastUsedAltCurrencyList = lastUsedAltCurrency ? JSON.parse(lastUsedAltCurrency) : [];
|
||||
init();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -77,25 +77,25 @@ angular.module('copayApp.services')
|
|||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// UPGRADING STORAGE
|
||||
//
|
||||
//
|
||||
// 1. Write a function to upgrade the desired storage key(s). The function should have the protocol:
|
||||
//
|
||||
//
|
||||
// _upgrade_x(key, network, cb), where:
|
||||
//
|
||||
//
|
||||
// `x` is the name of the storage key
|
||||
// `key` is the name of the storage key being upgraded
|
||||
// `key` is the name of the storage key being upgraded
|
||||
// `network` is one of 'livenet', 'testnet'
|
||||
//
|
||||
// 2. Add the storage key to `_upgraders` object using the name of the key as the `_upgrader` object key
|
||||
// with the value being the name of the upgrade function (e.g., _upgrade_x). In order to avoid conflicts
|
||||
// when a storage key is involved in multiple upgraders as well as predicte the order in which upgrades
|
||||
// occur the `_upgrader` object key should be prefixed with '##_' (e.g., '01_') to create a unique and
|
||||
// occur the `_upgrader` object key should be prefixed with '##_' (e.g., '01_') to create a unique and
|
||||
// sortable name. This format is interpreted by the _upgrade() function.
|
||||
//
|
||||
//
|
||||
// Upgraders are executed in numerical order per the '##_' object key prefix.
|
||||
//
|
||||
//
|
||||
var _upgraders = {
|
||||
'00_bitpayDebitCards' : _upgrade_bitpayDebitCards // 2016-11: Upgrade bitpayDebitCards-x to bitpayAccounts-x
|
||||
'00_bitpayDebitCards': _upgrade_bitpayDebitCards // 2016-11: Upgrade bitpayDebitCards-x to bitpayAccounts-x
|
||||
};
|
||||
|
||||
function _upgrade_bitpayDebitCards(key, network, cb) {
|
||||
|
@ -375,6 +375,14 @@ angular.module('copayApp.services')
|
|||
storage.remove('nextStep-' + service, cb);
|
||||
};
|
||||
|
||||
root.setLastCurrencyUsed = function(lastCurrencyUsed, cb) {
|
||||
storage.set('lastCurrencyUsed', lastCurrencyUsed, cb)
|
||||
};
|
||||
|
||||
root.getLastCurrencyUsed = function(cb) {
|
||||
storage.get('lastCurrencyUsed', cb)
|
||||
};
|
||||
|
||||
root.checkQuota = function() {
|
||||
var block = '';
|
||||
// 50MB
|
||||
|
@ -487,12 +495,14 @@ angular.module('copayApp.services')
|
|||
bitpayAccounts = bitpayAccounts || {};
|
||||
Object.keys(bitpayAccounts).forEach(function(userId) {
|
||||
var data = bitpayAccounts[userId]['bitpayDebitCards-' + network];
|
||||
var newCards = lodash.reject(data.cards, {'eid': card.eid});
|
||||
var newCards = lodash.reject(data.cards, {
|
||||
'eid': card.eid
|
||||
});
|
||||
data.cards = newCards;
|
||||
root.setBitpayDebitCards(network, data, function(err) {
|
||||
if (err) cb(err);
|
||||
// If there are no more cards in storage then re-enable the next step entry.
|
||||
root.getBitpayDebitCards(network, function(err, cards){
|
||||
root.getBitpayDebitCards(network, function(err, cards) {
|
||||
if (err) cb(err);
|
||||
if (cards.length == 0) {
|
||||
root.removeNextStep('BitpayCard', cb);
|
||||
|
|
|
@ -7,13 +7,27 @@
|
|||
</ion-nav-back-button>
|
||||
</ion-nav-bar>
|
||||
<ion-content>
|
||||
<ion-radio ng-repeat="altCurrency in altCurrencyList" ng-value="altCurrency.isoCode" ng-model="currentCurrency"
|
||||
ng-click="save(altCurrency)">{{altCurrency.name}}
|
||||
</ion-radio>
|
||||
<div class="bar bar-header item-input-inset m20b">
|
||||
<label class="item-input-wrapper">
|
||||
<i class="icon ion-ios-search placeholder-icon"></i>
|
||||
<input type="search" ng-init="searchedAltCurrency = ''" ng-model="searchedAltCurrency" ng-change="findCurrency(searchedAltCurrency)"
|
||||
placeholder="{{'Search your currency' | translate}}">
|
||||
</label>
|
||||
</div>
|
||||
<div class="list" ng-if="lastUsedAltCurrencyList[0]">
|
||||
<ion-radio ng-repeat="lastUsedAltCurrency in lastUsedAltCurrencyList" ng-value="lastUsedAltCurrency.isoCode" ng-model="currentCurrency"
|
||||
ng-click="save(lastUsedAltCurrency)">{{lastUsedAltCurrency.name}}
|
||||
</ion-radio>
|
||||
</div>
|
||||
<div class="list">
|
||||
<ion-radio ng-repeat="altCurrency in altCurrencyList" ng-value="altCurrency.isoCode" ng-model="currentCurrency"
|
||||
ng-click="save(altCurrency)">{{altCurrency.name}}
|
||||
</ion-radio>
|
||||
</div>
|
||||
<ion-infinite-scroll
|
||||
ng-if="!listComplete"
|
||||
on-infinite="loadMore()"
|
||||
distance="1%">
|
||||
</ion-infinite-scroll>
|
||||
ng-if="!listComplete"
|
||||
on-infinite="loadMore()"
|
||||
distance="50%">
|
||||
</ion-infinite-scroll>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
|
|
Loading…
Reference in New Issue