Merge pull request #1471 from isocolsky/fix/last_opened

Added lastOpened to list of all wallets
This commit is contained in:
Matias Alejo Garcia 2014-09-25 09:07:59 -03:00
commit 45d532abfc
3 changed files with 45 additions and 13 deletions

View File

@ -23,17 +23,14 @@ angular.module('copayApp.controllers').controller('OpenController', function($sc
} else {
$scope.retreiving = false;
$scope.wallets = wallets.sort(cmp);
walletFactory.storage.getLastOpened(function(ret) {
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);
var lastOpened = _.findWhere($scope.wallets, {
lastOpened: true
});
$scope.selectedWalletId = lastOpened ? lastOpened.id : ($scope.wallets[0] && $scope.wallets[0].id);
setTimeout(function() {
$rootScope.$digest();
}, 0);
}
});

View File

@ -368,11 +368,19 @@ WalletFactory.prototype.open = function(walletId, passphrase, cb) {
};
WalletFactory.prototype.getWallets = function(cb) {
this.storage.getWallets(function(ret) {
ret.forEach(function(i) {
var self = this;
this.storage.getWallets(function(wallets) {
wallets.forEach(function(i) {
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);
})
});
};

View File

@ -189,6 +189,7 @@ describe('WalletFactory model', function() {
describe('#getWallets', function() {
it('should return empty array if no wallets', function(done) {
wf.storage.getWallets = sinon.stub().yields([]);
wf.storage.getLastOpened = sinon.stub().yields(null);
wf.getWallets(function(err, ws) {
should.not.exist(err);
@ -205,6 +206,7 @@ describe('WalletFactory model', function() {
name: 'w',
id: 'id2',
}]);
wf.storage.getLastOpened = sinon.stub().yields(null);
wf.getWallets(function(err, ws) {
should.not.exist(err);
@ -220,6 +222,31 @@ describe('WalletFactory model', function() {
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() {