From 508a8bfc3cc24b3c326242dbb368b1171a1099f0 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 30 Sep 2014 16:04:17 -0300 Subject: [PATCH] one wallet by default --- config.js | 2 +- js/models/Identity.js | 19 +++++++++++++++++-- js/models/Profile.js | 6 +++--- js/models/Storage.js | 2 +- test/test.Identity.js | 4 ++-- test/test.Profile.js | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/config.js b/config.js index 35e3d9b14..13f6db28e 100644 --- a/config.js +++ b/config.js @@ -3,7 +3,7 @@ var defaultConfig = { defaultLanguage: 'en', // DEFAULT network (livenet or testnet) networkName: 'livenet', - logLevel: 'info', + logLevel: 'debug', // wallet limits diff --git a/js/models/Identity.js b/js/models/Identity.js index f64923079..ebedda4ac 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -106,13 +106,28 @@ Identity._profileOpen = function(e, p, s, cb) { * @return {undefined} */ Identity.create = function(email, password, opts, cb) { + opts = opts || {}; var iden = new Identity(email, password, opts); + Identity._createProfile(email, password, iden.storage, function(err, profile) { if (err) return cb(err); - iden.profile = profile; - return cb(null, iden); + + if (opts.noWallets) + cb(null, iden); + + // default wallet + var wopts = { + nickname: email, + networkName: opts.networkName, + requiredCopayers: 1, + totalCopayers: 1, + }; + + iden.createWallet(wopts, function(err, w) { + return cb(null, iden, w); + }); }); }; diff --git a/js/models/Profile.js b/js/models/Profile.js index 8e20437ac..540149e80 100644 --- a/js/models/Profile.js +++ b/js/models/Profile.js @@ -8,7 +8,7 @@ function Profile(info, storage) { preconditions.checkArgument(info.email); preconditions.checkArgument(info.hash); preconditions.checkArgument(storage); - preconditions.checkArgument(storage.getItem); + preconditions.checkArgument(storage.setPassphrase, 'bad storage'); this.hash = info.hash; this.email = info.email; @@ -34,8 +34,7 @@ Profile.create = function(email, password, storage, cb) { email: email, hash: Profile.hash(email,password), }, storage); - - p.store(cb); + p.store({}, cb); }; Profile.open = function(email, password, storage, cb) { @@ -118,6 +117,7 @@ Profile.prototype.store = function(opts, cb) { var key = self.key; self.storage.get(key, function(val2) { + if (val2 && !opts.overwrite) { if (cb) return cb(new Error('PEXISTS: Profile already exist')) diff --git a/js/models/Storage.js b/js/models/Storage.js index 0f576722f..faf46f1d4 100644 --- a/js/models/Storage.js +++ b/js/models/Storage.js @@ -27,7 +27,7 @@ function Storage(opts) { this.db = opts.db || localStorage; this.sessionStorage = opts.sessionStorage || sessionStorage; } catch (e) { - console.log('Error in storage:', e); //TODO + console.log('Error in storage:', e); }; preconditions.checkState(this.db, 'No db defined'); diff --git a/test/test.Identity.js b/test/test.Identity.js index 0e08da85d..4b361f2ed 100644 --- a/test/test.Identity.js +++ b/test/test.Identity.js @@ -191,7 +191,7 @@ describe('Identity model', function() { iden.createWallet({ privateKeyHex: priv, }, function(err, w) { - Identity._newWallet.getCall(0).args[0].privateKey.toObj().extendedPrivateKeyString.should.equal(priv); + Identity._newWallet.getCall(1).args[0].privateKey.toObj().extendedPrivateKeyString.should.equal(priv); should.not.exist(err); done(); }); @@ -253,7 +253,7 @@ describe('Identity model', function() { iden.openWallet('dummy', 'xxx', function(err, w) { should.not.exist(err); w.store.calledOnce.should.equal(true); - iden.profile.setLastOpenedTs.calledOnce.should.equal(true); + iden.profile.setLastOpenedTs.calledTwice.should.equal(true); iden.migrateWallet.calledOnce.should.equal(true); done(); }); diff --git a/test/test.Profile.js b/test/test.Profile.js index af06fc544..e7f90dd9b 100644 --- a/test/test.Profile.js +++ b/test/test.Profile.js @@ -19,7 +19,7 @@ describe('Profile model', function() { }; beforeEach(function() { - storage.getItem = sinon.stub(); + storage.setPassphrase = sinon.stub(); storage.set = sinon.stub(); storage.set.yields(null); storage.get = sinon.stub().yields(null);