emitting event

This commit is contained in:
Ivan Socolsky 2014-12-04 17:36:31 -03:00
parent af721f697e
commit 887e5ecd85
1 changed files with 6 additions and 7 deletions

View File

@ -237,6 +237,8 @@ Identity.prototype.retrieveWalletFromStorage = function(walletId, opts, cb) {
* @param {Function} cb * @param {Function} cb
*/ */
Identity.prototype.storeWallet = function(wallet, cb) { Identity.prototype.storeWallet = function(wallet, cb) {
var self = this;
preconditions.checkArgument(wallet && _.isObject(wallet)); preconditions.checkArgument(wallet && _.isObject(wallet));
wallet.setVersion(this.version); wallet.setVersion(this.version);
@ -246,13 +248,13 @@ Identity.prototype.storeWallet = function(wallet, cb) {
this.storage.setItem(key, val, function(err) { this.storage.setItem(key, val, function(err) {
if (err) { if (err) {
log.error('Wallet:' + wallet.getName() + ' couldnt be stored:', err); log.error('Wallet:' + wallet.getName() + ' could not be stored:', err);
log.error('Wallet:' + wallet.getName() + ' Size:', JSON.stringify(wallet.sizes())); log.error('Wallet:' + wallet.getName() + ' Size:', JSON.stringify(wallet.sizes()));
if (err.match('OVERQUOTA')) { if (err.match('OVERQUOTA')) {
self.emitAndKeepAlive('walletStorageError', w.getId(), 'Storage limits on remote server exceeded'); self.emitAndKeepAlive('walletStorageError', wallet.getId(), 'Storage limits on remote server exceeded');
} else { } else {
self.emitAndKeepAlive('walletStorageError', w.getId(), err); self.emitAndKeepAlive('walletStorageError', wallet.getId(), err);
} }
} }
if (cb) if (cb)
@ -582,12 +584,9 @@ Identity.prototype.createWallet = function(opts, cb) {
var self = this; var self = this;
var w = new walletClass(opts); var w = new walletClass(opts);
console.log(_.keys(self.wallets)); if (self.wallets[w.getId()]) {
console.log(w.getId());
if (_.contains(_.keys(self.wallets), w.getId())) {
return cb('walletAlreadyExists'); return cb('walletAlreadyExists');
} }
self.wallets[w.getId()] = w; self.wallets[w.getId()] = w;
self.updateFocusedTimestamp(w.getId()); self.updateFocusedTimestamp(w.getId());
self.bindWallet(w); self.bindWallet(w);