on identity open return most recently used wallet

This commit is contained in:
Ivan Socolsky 2014-10-15 10:59:09 -03:00 committed by Matias Alejo Garcia
commit aa9f16a7e9
2 changed files with 60 additions and 18 deletions

View file

@ -197,7 +197,8 @@ Identity.open = function(email, password, opts, cb) {
// Open All wallets from profile
//This could be optional, or opts.onlyOpen = wid
var firstWallet;
var wallets = [];
var remaining = wids.length;
_.each(wids, function(wid) {
iden.openWallet(wid, function(err, w) {
if (err) {
@ -205,13 +206,16 @@ Identity.open = function(email, password, opts, cb) {
iden.profile.deleteWallet(wid, function() {});
} else {
log.info('Open wallet id:' + wid + ' opened');
if (!firstWallet)
firstWallet = w;
wallets.push(w);
}
if (--remaining == 0) {
var firstWallet = _.findWhere(wallets, {
id: wids[0]
});
return cb(err, iden, firstWallet);
}
})
});
return cb(err, iden, firstWallet);
});
};