fixes when deleting wallets

This commit is contained in:
Matias Alejo Garcia 2014-12-02 16:53:24 -03:00
commit 394a5b474a
4 changed files with 29 additions and 11 deletions

View file

@ -1,5 +1,5 @@
'use strict'; '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.username = $rootScope.iden.getName();
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; $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() { $scope.init = function() {
if ($rootScope.quotaPerItem) { if ($rootScope.quotaPerItem) {
$scope.perItem = $filter('noFractionNumber')($rootScope.quotaPerItem / 1000, 1); $scope.perItem = $filter('noFractionNumber')($rootScope.quotaPerItem / 1000, 1);
$scope.nrWallets = parseInt($rootScope.quotaItems) - 1; $scope.nrWallets = parseInt($rootScope.quotaItems) - 1;
} }
// no need to add event handlers here. Wallet deletion is handle by callback.
}; };
$scope.setWallets = function() { $scope.setWallets = function() {
@ -46,8 +48,10 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
w.usage = $filter('noFractionNumber')(bits / max * 100, 0); w.usage = $filter('noFractionNumber')(bits / max * 100, 0);
} }
}); });
$scope.wallets = wallets; $scope.wallets = wallets;
$timeout(function(){
$scope.$digest();
})
}; };
$scope.downloadWalletBackup = function(w) { $scope.downloadWalletBackup = function(w) {

View file

@ -63,7 +63,19 @@ angular.module('copayApp.controllers').controller('SidebarController', function(
$scope.walletSelection = false; $scope.walletSelection = false;
$scope.setWallets(); $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.walletSelection = false;
$scope.setWallets(); $scope.setWallets();
}); });

View file

@ -645,7 +645,7 @@ Identity.prototype.deleteWallet = function(walletId, cb) {
this.storage.removeItem(Wallet.getStorageKey(walletId), function(err) { this.storage.removeItem(Wallet.getStorageKey(walletId), function(err) {
if (err) return cb(err); if (err) return cb(err);
self.emitAndKeepAlive('deletedWallet', walletId); self.emitAndKeepAlive('walletDeleted', walletId);
self.store(null, cb); self.store(null, cb);
return cb(); return cb();
}); });

View file

@ -126,6 +126,13 @@ angular.module('copayApp.services')
$location.path('/send'); $location.path('/send');
}; };
root.noFocusedWallet = function() {
$rootScope.wallet = null;
$timeout(function() {
$rootScope.$digest();
})
};
root.setFocusedWallet = function(w, dontUpdateIt) { root.setFocusedWallet = function(w, dontUpdateIt) {
if (!_.isObject(w)) if (!_.isObject(w))
w = $rootScope.iden.getWalletById(w); w = $rootScope.iden.getWalletById(w);
@ -280,13 +287,8 @@ angular.module('copayApp.services')
$rootScope.$digest() $rootScope.$digest()
}); });
iden.on('deletedWallet', function(wid) { iden.on('walletDeleted', function(wid) {
notification.info('Wallet deleted', $filter('translate')('This wallet was deleted')); // do nothing. this is handled 'on sync' on controller.
if ($rootScope.wallet.id === wid) {
$rootScope.wallet = null;
var lastFocused = iden.getLastFocusedWalletId();
root.setFocusedWallet(lastFocused);
}
}); });
iden.on('closed', function() { iden.on('closed', function() {