Save last opened wallet

This commit is contained in:
Yemel Jardi 2014-08-04 15:10:01 -03:00
commit 9b1708b88e
6 changed files with 62 additions and 1 deletions

View file

@ -9,7 +9,7 @@ angular.module('copayApp.controllers').controller('OpenController',
};
$scope.loading = false;
$scope.wallets = walletFactory.getWallets().sort(cmp);
$scope.selectedWalletId = $scope.wallets.length ? $scope.wallets[0].id : null;
$scope.selectedWalletId = walletFactory.storage.getLastOpened() || ($scope.wallets[0] && $scope.wallets[0].id);
$scope.openPassword = '';
$scope.open = function(form) {

View file

@ -143,6 +143,7 @@ WalletFactory.prototype.create = function(opts) {
opts.version = opts.version || this.version;
var w = new Wallet(opts);
w.store();
this.storage.setLastOpened(w.id);
return w;
};
@ -179,6 +180,8 @@ WalletFactory.prototype.open = function(walletId, opts) {
if (w) {
w.store();
}
this.storage.setLastOpened(walletId);
return w;
};
@ -194,6 +197,7 @@ WalletFactory.prototype.delete = function(walletId, cb) {
var s = this.storage;
this.log('## DELETING WALLET ID:' + walletId); //TODO
s.deleteWallet(walletId);
s.setLastOpened(undefined);
return cb();
};

View file

@ -172,6 +172,13 @@ Storage.prototype.deleteWallet = function(walletId) {
}
};
Storage.prototype.setLastOpened = function(walletId) {
this.setGlobal('lastOpened', walletId);
}
Storage.prototype.getLastOpened = function() {
return this.getGlobal('lastOpened');
}
//obj contains keys to be set
Storage.prototype.setFromObj = function(walletId, obj) {