replaced last opened with last focused wallet

This commit is contained in:
Ivan Socolsky 2014-10-20 18:33:21 -03:00 committed by Matias Alejo Garcia
commit 37526b554e
7 changed files with 46 additions and 38 deletions

View file

@ -25,13 +25,13 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
networkName: config.networkName,
walletDefaults: config.wallet,
passphraseConfig: config.passphraseConfig,
}, function(err, iden, firstWallet) {
}, function(err, iden, lastFocusedWallet) {
if (err && !iden) {
console.log('Error:' + err)
controllerUtils.onErrorDigest(
$scope, (err.toString() || '').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error');
} else {
controllerUtils.bindProfile($scope, iden, firstWallet);
controllerUtils.bindProfile($scope, iden, lastFocusedWallet);
}
});
}

View file

@ -207,10 +207,8 @@ Identity.open = function(email, password, opts, cb) {
wallets.push(w);
}
if (--remaining == 0) {
var firstWallet = _.findWhere(wallets, {
id: wids[0]
});
return cb(err, iden, firstWallet);
var lastFocused = iden.profile.getLastFocusedWallet();
return cb(err, iden, lastFocused);
}
})
});
@ -350,7 +348,7 @@ Identity.prototype.toEncryptedObj = function() {
ret.iterations = this.storage.iterations;
ret.wallets = {};
_.each(this.openWallets, function(w){
_.each(this.openWallets, function(w) {
ret.wallets[w.getId()] = w.toEncryptedObj();
});
@ -437,11 +435,8 @@ Identity.prototype.createWallet = function(opts, cb) {
this.addWallet(w, function(err) {
if (err) return cb(err);
self.openWallets.push(w);
self.profile.setLastOpenedTs(w.id, function(err) {
w.netStart();
return cb(err, w);
});
w.netStart();
return cb(err, w);
});
};
@ -511,10 +506,8 @@ Identity.prototype.openWallet = function(walletId, cb) {
self.openWallets.push(w);
w.store(function(err) {
self.profile.setLastOpenedTs(walletId, function() {
w.netStart();
return cb(err, w);
});
w.netStart();
return cb(err, w);
});
});
// });

View file

@ -76,7 +76,7 @@ Profile.prototype.getWallet = function(walletId, cb) {
Profile.prototype.listWallets = function() {
return _.sortBy(this.walletInfos, function(winfo) {
return -winfo.lastOpenedTs || -winfo.createdTs;
return winfo.createdTs;
});
};
@ -121,12 +121,21 @@ Profile.prototype.addWallet = function(walletId, info, cb) {
};
Profile.prototype.setLastOpenedTs = function(walletId, cb) {
Profile.prototype.setLastFocusedTs = function(walletId, cb) {
return this.addToWallet(walletId, {
lastOpenedTs: Date.now()
lastFocusedTs: Date.now()
}, cb);
};
Profile.prototype.getLastFocusedWallet = function() {
var self = this;
var maxTs = _.max(_.pluck(self.walletInfos, 'lastFocusedTs'));
var last = _.findWhere(_.values(self.walletInfos), {
lastFocusedTs: maxTs
});
return last ? last.id : null;
};
Profile.prototype.store = function(opts, cb) {
var self = this;
var val = self.toObj();

View file

@ -25,7 +25,6 @@ function TxProposal(opts) {
this.version = opts.version;
this.builder = opts.builder;
this.createdTs = opts.createdTs;
this.createdTs = opts.createdTs;
this._inputSigners = [];
// CopayerIds

View file

@ -209,10 +209,12 @@ angular.module('copayApp.services')
preconditions.checkState(w && _.isObject(w));
$rootScope.wallet = w;
root.redirIfLogged();
root.updateBalance(w, function() {
$rootScope.$digest();
})
$rootScope.iden.profile.setLastFocusedTs(w.id, function() {
root.redirIfLogged();
root.updateBalance(w, function() {
$rootScope.$digest();
})
});
};
root.bindProfile = function($scope, iden, w) {