moved default wallet creation to controller
This commit is contained in:
parent
25ba346489
commit
240b48eee3
3 changed files with 45 additions and 68 deletions
|
|
@ -77,42 +77,12 @@ Identity.prototype.getName = function() {
|
||||||
* @param cb
|
* @param cb
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
Identity.create = function(opts, cb) {
|
Identity.create = function(opts) {
|
||||||
opts = _.extend({}, opts);
|
opts = _.extend({}, opts);
|
||||||
|
|
||||||
var iden = new Identity(opts);
|
return new Identity(opts);
|
||||||
if (opts.noWallets) {
|
|
||||||
return cb(null, iden);
|
|
||||||
} else {
|
|
||||||
return iden.createDefaultWallet(opts, cb);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a wallet, 1-of-1 named general
|
|
||||||
*
|
|
||||||
* @param {Object} opts
|
|
||||||
* @param {Object} opts.walletDefaults
|
|
||||||
* @param {string} opts.walletDefaults.networkName
|
|
||||||
*/
|
|
||||||
Identity.prototype.createDefaultWallet = function(opts, callback) {
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
var walletOptions = _.extend(opts.walletDefaults, {
|
|
||||||
nickname: this.fullName || this.email,
|
|
||||||
networkName: opts.networkName,
|
|
||||||
requiredCopayers: 1,
|
|
||||||
totalCopayers: 1,
|
|
||||||
password: this.password,
|
|
||||||
name: 'general'
|
|
||||||
});
|
|
||||||
this.createWallet(walletOptions, function(err, wallet) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
return callback(null, self);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open an Identity from the given storage
|
* Open an Identity from the given storage
|
||||||
|
|
@ -124,7 +94,6 @@ Identity.prototype.createDefaultWallet = function(opts, callback) {
|
||||||
* @param {Function} cb
|
* @param {Function} cb
|
||||||
*/
|
*/
|
||||||
Identity.open = function(opts, cb) {
|
Identity.open = function(opts, cb) {
|
||||||
|
|
||||||
var storage = opts.storage || opts.pluginManager.get('DB');
|
var storage = opts.storage || opts.pluginManager.get('DB');
|
||||||
storage.setCredentials(opts.email, opts.password, opts);
|
storage.setCredentials(opts.email, opts.password, opts);
|
||||||
storage.getItem(Identity.getKeyForEmail(opts.email), function(err, data) {
|
storage.getItem(Identity.getKeyForEmail(opts.email), function(err, data) {
|
||||||
|
|
@ -444,7 +413,7 @@ Identity.prototype.createWallet = function(opts, cb) {
|
||||||
opts.txProposals = opts.txProposals || new TxProposals({
|
opts.txProposals = opts.txProposals || new TxProposals({
|
||||||
networkName: opts.networkName,
|
networkName: opts.networkName,
|
||||||
});
|
});
|
||||||
var walletClass = opts.walletClass || Wallet;
|
var walletClass = opts.walletClass || Wallet;
|
||||||
|
|
||||||
log.debug('\t### TxProposals Initialized');
|
log.debug('\t### TxProposals Initialized');
|
||||||
|
|
||||||
|
|
@ -465,8 +434,10 @@ 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({noWallets:true},function(err){
|
self.store({
|
||||||
return cb(err,w);
|
noWallets: true
|
||||||
|
}, function(err) {
|
||||||
|
return cb(err, w);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ angular.module('copayApp.services')
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
root.create = function(scope, form) {
|
root.create = function(scope, form) {
|
||||||
copay.Identity.create({
|
var iden = copay.Identity.create({
|
||||||
email: form.email.$modelValue,
|
email: form.email.$modelValue,
|
||||||
password: form.password.$modelValue,
|
password: form.password.$modelValue,
|
||||||
pluginManager: pluginManager,
|
pluginManager: pluginManager,
|
||||||
|
|
@ -13,9 +13,24 @@ angular.module('copayApp.services')
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
walletDefaults: config.wallet,
|
walletDefaults: config.wallet,
|
||||||
passphraseConfig: config.passphraseConfig,
|
passphraseConfig: config.passphraseConfig,
|
||||||
}, function(err, iden) {
|
});
|
||||||
var firstWallet = iden.getLastFocusedWallet();
|
|
||||||
controllerUtils.bindProfile(scope, iden, firstWallet);
|
var walletOptions = {
|
||||||
|
nickname: iden.fullName,
|
||||||
|
networkName: config.networkName,
|
||||||
|
requiredCopayers: 1,
|
||||||
|
totalCopayers: 1,
|
||||||
|
password: iden.password,
|
||||||
|
name: 'My wallet',
|
||||||
|
};
|
||||||
|
iden.createWallet(walletOptions, function(err, wallet) {
|
||||||
|
if (err) {
|
||||||
|
console.log('Error:' + err)
|
||||||
|
controllerUtils.onErrorDigest(
|
||||||
|
scope, 'Could not create default wallet');
|
||||||
|
} else {
|
||||||
|
controllerUtils.bindProfile(scope, iden, wallet.id);
|
||||||
|
}
|
||||||
scope.loading = false;
|
scope.loading = false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -123,17 +123,15 @@ describe('Identity model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Identity.create()', function() {
|
describe('Identity.create()', function() {
|
||||||
it('should create', function(done) {
|
it('should create', function() {
|
||||||
var args = createIdentity();
|
var args = createIdentity();
|
||||||
args.blockchain.on = sinon.stub();
|
args.blockchain.on = sinon.stub();
|
||||||
var old = Identity.prototype.createWallet;
|
var old = Identity.prototype.createWallet;
|
||||||
Identity.prototype.createWallet = sinon.stub().yields(null, getNewWallet());
|
Identity.prototype.createWallet = sinon.stub().yields(null, getNewWallet());
|
||||||
Identity.create(args.params, function(err, iden) {
|
var iden = Identity.create(args.params);
|
||||||
should.not.exist(err);
|
should.exist(iden);
|
||||||
should.exist(iden.wallets);
|
should.exist(iden.wallets);
|
||||||
Identity.prototype.createWallet = old;
|
Identity.prototype.createWallet = old;
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -168,16 +166,13 @@ describe('Identity model', function() {
|
||||||
describe('#createWallet', function() {
|
describe('#createWallet', function() {
|
||||||
var iden = null;
|
var iden = null;
|
||||||
var args = null;
|
var args = null;
|
||||||
beforeEach(function(done) {
|
beforeEach(function() {
|
||||||
args = createIdentity();
|
args = createIdentity();
|
||||||
args.params.noWallets = true;
|
args.params.noWallets = true;
|
||||||
var old = Identity.prototype.createWallet;
|
var old = Identity.prototype.createWallet;
|
||||||
Identity.prototype.createWallet = sinon.stub().yields(null, getNewWallet());
|
Identity.prototype.createWallet = sinon.stub().yields(null, getNewWallet());
|
||||||
Identity.create(args.params, function(err, identity) {
|
iden = Identity.create(args.params);
|
||||||
iden = identity;
|
Identity.prototype.createWallet = old;
|
||||||
Identity.prototype.createWallet = old;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
it('should be able to create wallets with given pk', function(done) {
|
it('should be able to create wallets with given pk', function(done) {
|
||||||
var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m';
|
var priv = 'tprv8ZgxMBicQKsPdEqHcA7RjJTayxA3gSSqeRTttS1JjVbgmNDZdSk9EHZK5pc52GY5xFmwcakmUeKWUDzGoMLGAhrfr5b3MovMUZUTPqisL2m';
|
||||||
|
|
@ -234,13 +229,12 @@ describe('Identity model', function() {
|
||||||
importWallet: sinon.stub().returns(getNewWallet()),
|
importWallet: sinon.stub().returns(getNewWallet()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.create(args.params, function(err, iden) {
|
var iden = Identity.create(args.params);
|
||||||
iden.retrieveWalletFromStorage('dummy', opts, function(err, wallet) {
|
iden.retrieveWalletFromStorage('dummy', opts, function(err, wallet) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
opts.importWallet.calledOnce.should.equal(true);
|
opts.importWallet.calledOnce.should.equal(true);
|
||||||
should.exist(wallet);
|
should.exist(wallet);
|
||||||
done();
|
done();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -281,7 +275,7 @@ describe('Identity model', function() {
|
||||||
var args = null;
|
var args = null;
|
||||||
var net = null;
|
var net = null;
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function() {
|
||||||
args = createIdentity();
|
args = createIdentity();
|
||||||
args.params.Async = net = sinon.stub();
|
args.params.Async = net = sinon.stub();
|
||||||
|
|
||||||
|
|
@ -291,11 +285,8 @@ describe('Identity model', function() {
|
||||||
var old = Identity.prototype.createWallet;
|
var old = Identity.prototype.createWallet;
|
||||||
Identity.prototype.createWallet = sinon.stub().yields(null, getNewWallet());
|
Identity.prototype.createWallet = sinon.stub().yields(null, getNewWallet());
|
||||||
|
|
||||||
Identity.create(args.params, function(err, identity) {
|
iden = Identity.create(args.params);
|
||||||
iden = identity;
|
Identity.prototype.createWallet = old;
|
||||||
Identity.prototype.createWallet = old;
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should yield bad network error', function(done) {
|
it('should yield bad network error', function(done) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue