refactors to UX
This commit is contained in:
parent
508a8bfc3c
commit
70d306242e
5 changed files with 41 additions and 22 deletions
|
|
@ -11,6 +11,7 @@ var version = require('../../version').version;
|
|||
var PluginManager = require('./PluginManager');
|
||||
var Profile = require('./Profile');
|
||||
var Insight = module.exports.Insight = require('./Insight');
|
||||
var Async = module.exports.Async = require('./Async');
|
||||
var preconditions = require('preconditions').singleton();
|
||||
var Storage = module.exports.Storage = require('./Storage');
|
||||
|
||||
|
|
@ -44,8 +45,8 @@ function Identity(email, password, opts) {
|
|||
this.storage = Identity._newStorage(storageOpts);
|
||||
|
||||
this.networks = {
|
||||
'livenet': Identity._newInsight(opts.network.livenet),
|
||||
'testnet': Identity._newInsight(opts.network.testnet),
|
||||
'livenet': Identity._newAsync(opts.network.livenet),
|
||||
'testnet': Identity._newAsync(opts.network.testnet),
|
||||
};
|
||||
this.blockchains = {
|
||||
'livenet': Identity._newInsight(opts.network.livenet),
|
||||
|
|
@ -69,6 +70,12 @@ Identity._newInsight = function(opts) {
|
|||
return new Insight(opts);
|
||||
};
|
||||
|
||||
Identity._newAsync = function(opts) {
|
||||
return new Async(opts);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Identity._newStorage = function(opts) {
|
||||
return new Storage(opts);
|
||||
};
|
||||
|
|
@ -89,13 +96,6 @@ Identity._walletDelete = function(id, cb) {
|
|||
return Wallet.delete(id, cb);
|
||||
};
|
||||
|
||||
Identity._profileOpen = function(e, p, s, cb) {
|
||||
Profile.create(e, p, s, cb);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* creates and Identity
|
||||
*
|
||||
|
|
@ -113,18 +113,18 @@ Identity.create = function(email, password, opts, cb) {
|
|||
Identity._createProfile(email, password, iden.storage, function(err, profile) {
|
||||
if (err) return cb(err);
|
||||
iden.profile = profile;
|
||||
console.log('[Identity.js.115:profile:]',profile); //TODO
|
||||
|
||||
if (opts.noWallets)
|
||||
cb(null, iden);
|
||||
|
||||
// default wallet
|
||||
var wopts = {
|
||||
var wopts = _.extend(opts.walletDefaults,{
|
||||
nickname: email,
|
||||
networkName: opts.networkName,
|
||||
requiredCopayers: 1,
|
||||
totalCopayers: 1,
|
||||
};
|
||||
|
||||
});
|
||||
iden.createWallet(wopts, function(err, w) {
|
||||
return cb(null, iden, w);
|
||||
});
|
||||
|
|
@ -158,10 +158,9 @@ Identity.prototype.validate = function(authcode, cb) {
|
|||
Identity.open = function(email, password, opts, cb) {
|
||||
var iden = new Identity(email, password, opts);
|
||||
|
||||
Identity._profileOpen(email, password, iden.storage, function(err, profile) {
|
||||
Identity._createProfile(email, password, iden.storage, function(err, profile) {
|
||||
if (err) return cb(err);
|
||||
iden.profile = profile;
|
||||
|
||||
return cb(null, iden);
|
||||
});
|
||||
};
|
||||
|
|
@ -254,6 +253,7 @@ Identity.prototype.importWallet = function(base64, passphrase, skipFields, cb) {
|
|||
*/
|
||||
Identity.prototype.createWallet = function(opts, cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
preconditions.checkState(this.profile);
|
||||
|
||||
opts = opts || {};
|
||||
opts.networkName = opts.networkName || 'testnet';
|
||||
|
|
@ -318,6 +318,7 @@ Identity.prototype.addWallet = function(wallet, cb) {
|
|||
preconditions.checkArgument(wallet);
|
||||
preconditions.checkArgument(wallet.getId);
|
||||
preconditions.checkArgument(cb);
|
||||
preconditions.checkState(this.profile);
|
||||
|
||||
var self = this;
|
||||
self.profile.addWallet(wallet.id, function(err) {
|
||||
|
|
|
|||
|
|
@ -30,11 +30,17 @@ Profile.key = function(hash) {
|
|||
|
||||
Profile.create = function(email, password, storage, cb) {
|
||||
preconditions.checkArgument(cb);
|
||||
preconditions.checkArgument(storage.setPassphrase);
|
||||
|
||||
preconditions.checkState(storage.hasPassphrase());
|
||||
|
||||
var p = new Profile({
|
||||
email: email,
|
||||
hash: Profile.hash(email,password),
|
||||
}, storage);
|
||||
p.store({}, cb);
|
||||
p.store({}, function(err) {
|
||||
return cb(err,p);
|
||||
});
|
||||
};
|
||||
|
||||
Profile.open = function(email, password, storage, cb) {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@ Storage.prototype._getPassphrase = function() {
|
|||
return pps[this.__uniqueid];
|
||||
}
|
||||
|
||||
|
||||
Storage.prototype.hasPassphrase = function() {
|
||||
return pps[this.__uniqueid] ? true : false;
|
||||
};
|
||||
|
||||
Storage.prototype.setPassphrase = function(password) {
|
||||
pps[this.__uniqueid] = password;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,8 +79,6 @@ function Wallet(opts) {
|
|||
|
||||
this.publicKeyRing.walletId = this.id;
|
||||
this.txProposals.walletId = this.id;
|
||||
this.network.maxPeers = this.totalCopayers;
|
||||
this.network.secretNumber = this.secretNumber;
|
||||
this.registeredPeerIds = [];
|
||||
this.addressBook = opts.addressBook || {};
|
||||
this.publicKey = this.privateKey.publicHex;
|
||||
|
|
@ -96,6 +94,15 @@ function Wallet(opts) {
|
|||
|
||||
this.paymentRequests = opts.paymentRequests || {};
|
||||
|
||||
|
||||
var networkName = Wallet.obtainNetworkName(this);
|
||||
this.network = _.isArray(this.network)? this.network[networkName] : this.network;
|
||||
this.blockchain = _.isArray(this.blockchain) ? this.blockchain[networkName] : this.blockchain;
|
||||
|
||||
|
||||
this.network.maxPeers = this.totalCopayers;
|
||||
this.network.secretNumber = this.secretNumber;
|
||||
|
||||
//network nonces are 8 byte buffers, representing a big endian number
|
||||
//one nonce for oneself, and then one nonce for each copayer
|
||||
this.network.setHexNonce(opts.networkNonce);
|
||||
|
|
@ -1064,8 +1071,8 @@ Wallet.fromObj = function(o, storage, network, blockchain, skipFields) {
|
|||
opts.lastTimestamp = o.lastTimestamp;
|
||||
|
||||
opts.storage = storage;
|
||||
opts.network = _.isArray(network)? network[networkName] : network;
|
||||
opts.blockchain = _.isArray(blockchain) ? blockchain[networkName] : blockchain;
|
||||
opts.network = network;
|
||||
opts.blockchain = blockchain;
|
||||
opts.isImported = true;
|
||||
|
||||
return new Wallet(opts);
|
||||
|
|
|
|||
|
|
@ -127,14 +127,14 @@ describe('Identity model', function() {
|
|||
|
||||
describe('#open', function(done) {
|
||||
beforeEach(function() {
|
||||
Identity._profileOpen = sinon.stub().callsArgWith(3, null, 'kk');
|
||||
Identity._createProfile = sinon.stub().callsArgWith(3, null, 'kk');
|
||||
});
|
||||
|
||||
it('should call ._profileOpen', function(done) {
|
||||
it('should call ._createProfile', function(done) {
|
||||
Identity.open(email, password, config, function(err, iden) {
|
||||
should.not.exist(err);
|
||||
iden.profile.should.equal('kk');
|
||||
Identity._profileOpen.calledOnce.should.equal(true);
|
||||
Identity._createProfile.calledOnce.should.equal(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue