refactor address management
This commit is contained in:
parent
38b8240341
commit
1323ad48db
5 changed files with 110 additions and 61 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, gettextCatalog, gettext, amMoment) {
|
||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment) {
|
||||
|
||||
var self = this;
|
||||
self.isCordova = isCordova;
|
||||
|
|
@ -464,7 +464,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.alternativeIsoCode = config.alternativeIsoCode;
|
||||
|
||||
// Check address
|
||||
self.checkLastAddress(balance.byAddress);
|
||||
addressService.isUsed(self.walletId, balance.byAddress, function(err, used){
|
||||
if (used) {
|
||||
$log.debug('Address used. Creating new');
|
||||
$rootScope.$emit('Local/NeedNewAddress');
|
||||
}
|
||||
});
|
||||
|
||||
rateService.whenAvailable(function() {
|
||||
|
||||
|
|
@ -488,20 +493,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
}
|
||||
};
|
||||
|
||||
self.checkLastAddress = function(byAddress, cb) {
|
||||
storageService.getLastAddress(self.walletId, function(err, addr) {
|
||||
var used = lodash.find(byAddress, {
|
||||
address: addr
|
||||
});
|
||||
if (used) {
|
||||
$log.debug('Address ' + addr + ' was used. Cleaning Cache.')
|
||||
storageService.clearLastAddress(self.walletId, function(err) {
|
||||
$rootScope.$emit('Local/NeedNewAddress', err);
|
||||
if (cb) return cb();
|
||||
});
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
self.clientError = function(err) {
|
||||
if (isCordova) {
|
||||
|
|
@ -729,7 +720,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
$rootScope.$on('Local/WalletImported', function(event, walletId) {
|
||||
self.needsBackup = false;
|
||||
storageService.setBackupFlag(walletId, function() {
|
||||
storageService.clearLastAddress(walletId, function(err) {
|
||||
addressService.expireAddress(walletId, function(err) {
|
||||
self.startScan(walletId);
|
||||
});
|
||||
});
|
||||
|
|
@ -792,7 +783,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
if (val) {
|
||||
$log.debug('Clear last address cache and Scan');
|
||||
lodash.each(lodash.keys(profileService.walletClients), function(walletId) {
|
||||
storageService.clearLastAddress(walletId, function(err) {
|
||||
addressService.expireAddress(walletId, function(err) {
|
||||
self.startScan(walletId);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue