mirror of https://github.com/BTCPrivate/copay.git
save last five alt currency chosen, remove infinite scroll
This commit is contained in:
parent
58ccac2424
commit
11f063b85d
|
@ -1,38 +1,34 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesAltCurrencyController',
|
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 next = 10;
|
||||||
var completeAlternativeList;
|
var completeAlternativeList;
|
||||||
|
|
||||||
var config = configService.getSync();
|
|
||||||
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
|
|
||||||
$scope.listComplete = false;
|
|
||||||
|
|
||||||
var unusedCurrencyList = [{
|
var unusedCurrencyList = [{
|
||||||
isoCode: 'LTL'
|
isoCode: 'LTL'
|
||||||
}, {
|
}, {
|
||||||
isoCode: 'BTC'
|
isoCode: 'BTC'
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
|
var config = configService.getSync();
|
||||||
|
$scope.currentCurrency = config.wallet.settings.alternativeIsoCode;
|
||||||
|
|
||||||
rateService.whenAvailable(function() {
|
rateService.whenAvailable(function() {
|
||||||
completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
|
storageService.getLastCurrencyUsed(function(err, lastUsedAltCurrency) {
|
||||||
return idx[c.isoCode];
|
|
||||||
});
|
|
||||||
$scope.altCurrencyList = completeAlternativeList.slice(0, next);
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.loadMore = function() {
|
$scope.lastUsedAltCurrencyList = JSON.parse(lastUsedAltCurrency) || [];
|
||||||
$timeout(function() {
|
|
||||||
$scope.altCurrencyList = completeAlternativeList.slice(0, next);
|
var idx = lodash.indexBy(unusedCurrencyList, 'isoCode');
|
||||||
next += 10;
|
var idx2 = lodash.indexBy($scope.lastUsedAltCurrencyList, 'isoCode');
|
||||||
$scope.listComplete = $scope.altCurrencyList.length >= completeAlternativeList.length;
|
|
||||||
$scope.$broadcast('scroll.infiniteScrollComplete');
|
completeAlternativeList = lodash.reject(rateService.listAlternatives(), function(c) {
|
||||||
}, 100);
|
return idx[c.isoCode] || idx2[c.isoCode];
|
||||||
};
|
});
|
||||||
|
$scope.altCurrencyList = completeAlternativeList;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$scope.save = function(newAltCurrency) {
|
$scope.save = function(newAltCurrency) {
|
||||||
var opts = {
|
var opts = {
|
||||||
|
@ -48,9 +44,18 @@ angular.module('copayApp.controllers').controller('preferencesAltCurrencyControl
|
||||||
if (err) $log.warn(err);
|
if (err) $log.warn(err);
|
||||||
|
|
||||||
$ionicHistory.goBack();
|
$ionicHistory.goBack();
|
||||||
|
saveLastUsed(newAltCurrency);
|
||||||
walletService.updateRemotePreferences(profileService.getWallets(), {}, function() {
|
walletService.updateRemotePreferences(profileService.getWallets(), {}, function() {
|
||||||
$log.debug('Remote preferences saved');
|
$log.debug('Remote preferences saved');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function saveLastUsed(newAltCurrency) {
|
||||||
|
$scope.lastUsedAltCurrencyList.unshift(newAltCurrency);
|
||||||
|
$scope.lastUsedAltCurrencyList = $scope.lastUsedAltCurrencyList.slice(0, 5);
|
||||||
|
$scope.lastUsedAltCurrencyList = lodash.uniq($scope.lastUsedAltCurrencyList, 'isoCode');
|
||||||
|
storageService.setLastCurrencyUsed(JSON.stringify($scope.lastUsedAltCurrencyList), function() {});
|
||||||
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -77,25 +77,25 @@ angular.module('copayApp.services')
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// UPGRADING STORAGE
|
// UPGRADING STORAGE
|
||||||
//
|
//
|
||||||
// 1. Write a function to upgrade the desired storage key(s). The function should have the protocol:
|
// 1. Write a function to upgrade the desired storage key(s). The function should have the protocol:
|
||||||
//
|
//
|
||||||
// _upgrade_x(key, network, cb), where:
|
// _upgrade_x(key, network, cb), where:
|
||||||
//
|
//
|
||||||
// `x` is the name of the storage key
|
// `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'
|
// `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
|
// 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
|
// 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
|
// 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.
|
// sortable name. This format is interpreted by the _upgrade() function.
|
||||||
//
|
//
|
||||||
// Upgraders are executed in numerical order per the '##_' object key prefix.
|
// Upgraders are executed in numerical order per the '##_' object key prefix.
|
||||||
//
|
//
|
||||||
var _upgraders = {
|
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) {
|
function _upgrade_bitpayDebitCards(key, network, cb) {
|
||||||
|
@ -375,6 +375,14 @@ angular.module('copayApp.services')
|
||||||
storage.remove('nextStep-' + service, cb);
|
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() {
|
root.checkQuota = function() {
|
||||||
var block = '';
|
var block = '';
|
||||||
// 50MB
|
// 50MB
|
||||||
|
@ -487,12 +495,14 @@ angular.module('copayApp.services')
|
||||||
bitpayAccounts = bitpayAccounts || {};
|
bitpayAccounts = bitpayAccounts || {};
|
||||||
Object.keys(bitpayAccounts).forEach(function(userId) {
|
Object.keys(bitpayAccounts).forEach(function(userId) {
|
||||||
var data = bitpayAccounts[userId]['bitpayDebitCards-' + network];
|
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;
|
data.cards = newCards;
|
||||||
root.setBitpayDebitCards(network, data, function(err) {
|
root.setBitpayDebitCards(network, data, function(err) {
|
||||||
if (err) cb(err);
|
if (err) cb(err);
|
||||||
// If there are no more cards in storage then re-enable the next step entry.
|
// 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 (err) cb(err);
|
||||||
if (cards.length == 0) {
|
if (cards.length == 0) {
|
||||||
root.removeNextStep('BitpayCard', cb);
|
root.removeNextStep('BitpayCard', cb);
|
||||||
|
|
|
@ -7,13 +7,15 @@
|
||||||
</ion-nav-back-button>
|
</ion-nav-back-button>
|
||||||
</ion-nav-bar>
|
</ion-nav-bar>
|
||||||
<ion-content>
|
<ion-content>
|
||||||
<ion-radio ng-repeat="altCurrency in altCurrencyList" ng-value="altCurrency.isoCode" ng-model="currentCurrency"
|
<div class="list" ng-if="lastUsedAltCurrencyList[0]">
|
||||||
ng-click="save(altCurrency)">{{altCurrency.name}}
|
<ion-radio ng-repeat="lastUsedAltCurrency in lastUsedAltCurrencyList" ng-value="lastUsedAltCurrency.isoCode" ng-model="currentCurrency"
|
||||||
</ion-radio>
|
ng-click="save(lastUsedAltCurrency)">{{lastUsedAltCurrency.name}}
|
||||||
<ion-infinite-scroll
|
</ion-radio>
|
||||||
ng-if="!listComplete"
|
</div>
|
||||||
on-infinite="loadMore()"
|
<div class="list">
|
||||||
distance="1%">
|
<ion-radio ng-repeat="altCurrency in altCurrencyList" ng-value="altCurrency.isoCode" ng-model="currentCurrency"
|
||||||
</ion-infinite-scroll>
|
ng-click="save(altCurrency)">{{altCurrency.name}}
|
||||||
|
</ion-radio>
|
||||||
|
</div>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
</ion-view>
|
</ion-view>
|
||||||
|
|
Loading…
Reference in New Issue