mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #1471 from isocolsky/fix/last_opened
Added lastOpened to list of all wallets
This commit is contained in:
commit
45d532abfc
|
@ -23,17 +23,14 @@ angular.module('copayApp.controllers').controller('OpenController', function($sc
|
||||||
} else {
|
} else {
|
||||||
$scope.retreiving = false;
|
$scope.retreiving = false;
|
||||||
$scope.wallets = wallets.sort(cmp);
|
$scope.wallets = wallets.sort(cmp);
|
||||||
|
var lastOpened = _.findWhere($scope.wallets, {
|
||||||
walletFactory.storage.getLastOpened(function(ret) {
|
lastOpened: true
|
||||||
if (ret && _.indexOf(_.pluck($scope.wallets, 'id')) == -1)
|
|
||||||
ret = null;
|
|
||||||
|
|
||||||
$scope.selectedWalletId = ret || ($scope.wallets[0] && $scope.wallets[0].id);
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
$rootScope.$digest();
|
|
||||||
}, 0);
|
|
||||||
});
|
});
|
||||||
|
$scope.selectedWalletId = lastOpened ? lastOpened.id : ($scope.wallets[0] && $scope.wallets[0].id);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
$rootScope.$digest();
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -368,11 +368,19 @@ WalletFactory.prototype.open = function(walletId, passphrase, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
WalletFactory.prototype.getWallets = function(cb) {
|
WalletFactory.prototype.getWallets = function(cb) {
|
||||||
this.storage.getWallets(function(ret) {
|
var self = this;
|
||||||
ret.forEach(function(i) {
|
this.storage.getWallets(function(wallets) {
|
||||||
|
wallets.forEach(function(i) {
|
||||||
i.show = i.name ? ((i.name + ' <' + i.id + '>')) : i.id;
|
i.show = i.name ? ((i.name + ' <' + i.id + '>')) : i.id;
|
||||||
});
|
});
|
||||||
return cb(null, ret);
|
self.storage.getLastOpened(function(lastId) {
|
||||||
|
var last = _.findWhere(wallets, {
|
||||||
|
id: lastId
|
||||||
|
});
|
||||||
|
if (last)
|
||||||
|
last.lastOpened = true;
|
||||||
|
return cb(null, wallets);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -189,6 +189,7 @@ describe('WalletFactory model', function() {
|
||||||
describe('#getWallets', function() {
|
describe('#getWallets', function() {
|
||||||
it('should return empty array if no wallets', function(done) {
|
it('should return empty array if no wallets', function(done) {
|
||||||
wf.storage.getWallets = sinon.stub().yields([]);
|
wf.storage.getWallets = sinon.stub().yields([]);
|
||||||
|
wf.storage.getLastOpened = sinon.stub().yields(null);
|
||||||
|
|
||||||
wf.getWallets(function(err, ws) {
|
wf.getWallets(function(err, ws) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
|
@ -205,6 +206,7 @@ describe('WalletFactory model', function() {
|
||||||
name: 'w',
|
name: 'w',
|
||||||
id: 'id2',
|
id: 'id2',
|
||||||
}]);
|
}]);
|
||||||
|
wf.storage.getLastOpened = sinon.stub().yields(null);
|
||||||
|
|
||||||
wf.getWallets(function(err, ws) {
|
wf.getWallets(function(err, ws) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
|
@ -220,6 +222,31 @@ describe('WalletFactory model', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('should include last used info', function(done) {
|
||||||
|
wf.storage.getWallets = sinon.stub().yields([{
|
||||||
|
name: 'w1',
|
||||||
|
id: 'id1',
|
||||||
|
}, {
|
||||||
|
name: 'w',
|
||||||
|
id: 'id2',
|
||||||
|
}]);
|
||||||
|
wf.storage.getLastOpened = sinon.stub().yields('id2');
|
||||||
|
|
||||||
|
wf.getWallets(function(err, ws) {
|
||||||
|
should.not.exist(err);
|
||||||
|
ws.should.deep.equal([{
|
||||||
|
name: 'w1',
|
||||||
|
id: 'id1',
|
||||||
|
show: 'w1 <id1>'
|
||||||
|
}, {
|
||||||
|
name: 'w',
|
||||||
|
id: 'id2',
|
||||||
|
lastOpened: true,
|
||||||
|
show: 'w <id2>'
|
||||||
|
}]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#delete', function() {
|
describe('#delete', function() {
|
||||||
|
|
Loading…
Reference in New Issue