Add option to Identity#store to fail if it exists
This commit is contained in:
parent
5eade81294
commit
281d66d6e0
2 changed files with 20 additions and 14 deletions
|
|
@ -231,7 +231,9 @@ Identity.prototype.store = function(opts, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
self.storage.setItem(this.getId(), this.toObj(), function(err) {
|
var storeFunction = opts.failIfExists ? self.storage.createItem : self.storage.setItem;
|
||||||
|
|
||||||
|
storeFunction.call(self.storage, this.getId(), this.toObj(), function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
if (opts.noWallets)
|
if (opts.noWallets)
|
||||||
|
|
@ -349,7 +351,7 @@ Identity.importFromFullJson = function(str, password, opts, cb) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
iden.store(function(err) {
|
iden.store(null, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
@ -402,10 +404,8 @@ Identity.prototype.bindWallet = function(w) {
|
||||||
* @param {PublicKeyRing=} opts.publicKeyRing
|
* @param {PublicKeyRing=} opts.publicKeyRing
|
||||||
* @param {string} opts.nickname
|
* @param {string} opts.nickname
|
||||||
* @param {string} opts.password
|
* @param {string} opts.password
|
||||||
* @TODO: Figure out what is this parameter
|
* @param {boolean} opts.spendUnconfirmed this.walletDefaults.spendUnconfirmed
|
||||||
* @param {?} opts.spendUnconfirmed this.walletDefaults.spendUnconfirmed ??
|
* @param {number} opts.reconnectDelay time in milliseconds
|
||||||
* @TODO: Figure out in what unit is this reconnect delay.
|
|
||||||
* @param {number} opts.reconnectDelay milliseconds?
|
|
||||||
* @param {number=} opts.version
|
* @param {number=} opts.version
|
||||||
* @param {callback} opts.version
|
* @param {callback} opts.version
|
||||||
* @return {Wallet}
|
* @return {Wallet}
|
||||||
|
|
@ -467,11 +467,7 @@ Identity.prototype.createWallet = function(opts, cb) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
self.bindWallet(w);
|
self.bindWallet(w);
|
||||||
w.netStart();
|
w.netStart();
|
||||||
self.store({
|
return cb(err, w);
|
||||||
noWallets: true
|
|
||||||
}, function(err) {
|
|
||||||
return cb(err, w);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -539,7 +535,7 @@ Identity.prototype.deleteWallet = function(walletId, cb) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
self.store(cb);
|
self.store(null, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -654,7 +650,11 @@ Identity.prototype.joinWallet = function(opts, cb) {
|
||||||
err = 'walletFull';
|
err = 'walletFull';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cb(err, w);
|
self.store({
|
||||||
|
noWallets: true
|
||||||
|
}, function(err) {
|
||||||
|
return cb(err, w);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,13 @@ angular.module('copayApp.services')
|
||||||
controllerUtils.onErrorDigest(
|
controllerUtils.onErrorDigest(
|
||||||
scope, 'Could not create default wallet');
|
scope, 'Could not create default wallet');
|
||||||
} else {
|
} else {
|
||||||
controllerUtils.bindProfile(scope, iden, wallet.id);
|
iden.store({failIfExists: true}, function(err) {
|
||||||
|
if (err) {
|
||||||
|
controllerUtils.onErrorDigest(scope, 'User already exists!');
|
||||||
|
} else {
|
||||||
|
controllerUtils.bindProfile(scope, iden, wallet.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
scope.loading = false;
|
scope.loading = false;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue