mirror of https://github.com/BTCPrivate/copay.git
fixes when deleting wallets
This commit is contained in:
parent
cac407c827
commit
394a5b474a
|
@ -1,5 +1,5 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, $filter, backupService, identityService) {
|
||||
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, $filter, $timeout, backupService, identityService) {
|
||||
$scope.username = $rootScope.iden.getName();
|
||||
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
|
||||
|
||||
|
@ -26,11 +26,13 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
|
|||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.init = function() {
|
||||
if ($rootScope.quotaPerItem) {
|
||||
$scope.perItem = $filter('noFractionNumber')($rootScope.quotaPerItem / 1000, 1);
|
||||
$scope.nrWallets = parseInt($rootScope.quotaItems) - 1;
|
||||
}
|
||||
// no need to add event handlers here. Wallet deletion is handle by callback.
|
||||
};
|
||||
|
||||
$scope.setWallets = function() {
|
||||
|
@ -46,8 +48,10 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
|
|||
w.usage = $filter('noFractionNumber')(bits / max * 100, 0);
|
||||
}
|
||||
});
|
||||
|
||||
$scope.wallets = wallets;
|
||||
$timeout(function(){
|
||||
$scope.$digest();
|
||||
})
|
||||
};
|
||||
|
||||
$scope.downloadWalletBackup = function(w) {
|
||||
|
|
|
@ -63,7 +63,19 @@ angular.module('copayApp.controllers').controller('SidebarController', function(
|
|||
$scope.walletSelection = false;
|
||||
$scope.setWallets();
|
||||
});
|
||||
iden.on('deleteWallet', function() {
|
||||
iden.on('walletDeleted', function(wid) {
|
||||
if (wid == $rootScope.wallet.id) {
|
||||
copay.logger.debug('Deleted focused wallet:', wid);
|
||||
|
||||
// new focus
|
||||
var newWid = $rootScope.iden.getLastFocusedWalletId();
|
||||
if (newWid && $rootScope.iden.getWalletById(newWid)) {
|
||||
identityService.setFocusedWallet(newWid);
|
||||
} else {
|
||||
copay.logger.debug('No wallets');
|
||||
identityService.noFocusedWallet(newWid);
|
||||
}
|
||||
}
|
||||
$scope.walletSelection = false;
|
||||
$scope.setWallets();
|
||||
});
|
||||
|
|
|
@ -645,7 +645,7 @@ Identity.prototype.deleteWallet = function(walletId, cb) {
|
|||
|
||||
this.storage.removeItem(Wallet.getStorageKey(walletId), function(err) {
|
||||
if (err) return cb(err);
|
||||
self.emitAndKeepAlive('deletedWallet', walletId);
|
||||
self.emitAndKeepAlive('walletDeleted', walletId);
|
||||
self.store(null, cb);
|
||||
return cb();
|
||||
});
|
||||
|
|
|
@ -126,6 +126,13 @@ angular.module('copayApp.services')
|
|||
$location.path('/send');
|
||||
};
|
||||
|
||||
root.noFocusedWallet = function() {
|
||||
$rootScope.wallet = null;
|
||||
$timeout(function() {
|
||||
$rootScope.$digest();
|
||||
})
|
||||
};
|
||||
|
||||
root.setFocusedWallet = function(w, dontUpdateIt) {
|
||||
if (!_.isObject(w))
|
||||
w = $rootScope.iden.getWalletById(w);
|
||||
|
@ -280,13 +287,8 @@ angular.module('copayApp.services')
|
|||
$rootScope.$digest()
|
||||
});
|
||||
|
||||
iden.on('deletedWallet', function(wid) {
|
||||
notification.info('Wallet deleted', $filter('translate')('This wallet was deleted'));
|
||||
if ($rootScope.wallet.id === wid) {
|
||||
$rootScope.wallet = null;
|
||||
var lastFocused = iden.getLastFocusedWalletId();
|
||||
root.setFocusedWallet(lastFocused);
|
||||
}
|
||||
iden.on('walletDeleted', function(wid) {
|
||||
// do nothing. this is handled 'on sync' on controller.
|
||||
});
|
||||
|
||||
iden.on('closed', function() {
|
||||
|
|
Loading…
Reference in New Issue