mirror of https://github.com/BTCPrivate/copay.git
Save last opened wallet
This commit is contained in:
parent
698bd3f616
commit
9b1708b88e
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -19,6 +19,13 @@ FakeStorage.prototype.getGlobal = function(id) {
|
|||
return this.storage[id];
|
||||
};
|
||||
|
||||
FakeStorage.prototype.setLastOpened = function(val) {
|
||||
this.storage['lastOpened'] = val;
|
||||
};
|
||||
|
||||
FakeStorage.prototype.getLastOpened = function() {
|
||||
return this.storage['lastOpened'];
|
||||
};
|
||||
|
||||
FakeStorage.prototype.removeGlobal = function(id) {
|
||||
delete this.storage[id];
|
||||
|
|
|
@ -317,6 +317,20 @@ describe('WalletFactory model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should clean lastOpened on delete wallet', function(done) {
|
||||
var wf = new WalletFactory(config, '0.0.1');
|
||||
var w = wf.create({
|
||||
name: 'test wallet'
|
||||
});
|
||||
|
||||
wf.storage.setLastOpened(w.id);
|
||||
wf.delete(w.id, function() {
|
||||
var last = wf.storage.getLastOpened();
|
||||
should.equal(last, undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if wallet does not exist', function() {
|
||||
var opts = {
|
||||
'requiredCopayers': 2,
|
||||
|
@ -343,6 +357,23 @@ describe('WalletFactory model', function() {
|
|||
wf.read.calledWith(walletId).should.be.true;
|
||||
});
|
||||
|
||||
it('should save lastOpened on create/open a wallet', function() {
|
||||
var opts = {
|
||||
'requiredCopayers': 2,
|
||||
'totalCopayers': 3
|
||||
};
|
||||
var wf = new WalletFactory(config, '0.0.1');
|
||||
var w = wf.create(opts);
|
||||
var last = wf.storage.getLastOpened();
|
||||
should.equal(last, w.id);
|
||||
|
||||
wf.storage.setLastOpened('other_id');
|
||||
|
||||
var wo = wf.open(w.id, opts);
|
||||
last = wf.storage.getLastOpened();
|
||||
should.equal(last, w.id);
|
||||
});
|
||||
|
||||
it('should return error if network are differents', function() {
|
||||
var opts = {
|
||||
'requiredCopayers': 2,
|
||||
|
|
|
@ -148,6 +148,18 @@ describe('Storage/LocalEncrypted model', function() {
|
|||
s.getName(1).should.equal('hola');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLastOpened #setLastOpened', function() {
|
||||
it('should get/set names', function() {
|
||||
var s = new LocalEncrypted({
|
||||
localStorage: localMock,
|
||||
password: 'password'
|
||||
});
|
||||
s.setLastOpened('hey');
|
||||
s.getLastOpened().should.equal('hey');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getWallets', function() {
|
||||
it('should retreive wallets from storage', function() {
|
||||
var s = new LocalEncrypted({
|
||||
|
|
Loading…
Reference in New Issue