Added the flag backupNeeded
This commit is contained in:
parent
b3b0d7903e
commit
3f65288dca
3 changed files with 64 additions and 11 deletions
|
|
@ -62,6 +62,8 @@ function Identity(opts) {
|
||||||
this.walletIds = opts.walletIds || {};
|
this.walletIds = opts.walletIds || {};
|
||||||
this.wallets = opts.wallets || {};
|
this.wallets = opts.wallets || {};
|
||||||
this.focusedTimestamps = opts.focusedTimestamps || {};
|
this.focusedTimestamps = opts.focusedTimestamps || {};
|
||||||
|
this.backupNeeded = opts.backupNeeded || false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -91,7 +93,9 @@ Identity.prototype.getName = function() {
|
||||||
* @return {undefined}
|
* @return {undefined}
|
||||||
*/
|
*/
|
||||||
Identity.create = function(opts, cb) {
|
Identity.create = function(opts, cb) {
|
||||||
opts = _.extend({}, opts);
|
opts = _.extend({
|
||||||
|
backupNeeded: true
|
||||||
|
}, opts);
|
||||||
|
|
||||||
var iden = new Identity(opts);
|
var iden = new Identity(opts);
|
||||||
iden.store(_.extend(opts, {
|
iden.store(_.extend(opts, {
|
||||||
|
|
@ -265,11 +269,12 @@ Identity.prototype.toObj = function() {
|
||||||
return _.extend({
|
return _.extend({
|
||||||
walletIds: _.isEmpty(this.wallets) ? this.walletsIds : _.keys(this.wallets),
|
walletIds: _.isEmpty(this.wallets) ? this.walletsIds : _.keys(this.wallets),
|
||||||
},
|
},
|
||||||
_.pick(this, 'version', 'fullName', 'password', 'email', 'focusedTimestamps'));
|
_.pick(this, 'version', 'fullName', 'password', 'email', 'backupNeeded', 'focusedTimestamps'));
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.prototype.exportEncryptedWithWalletInfo = function(opts) {
|
Identity.prototype.exportEncryptedWithWalletInfo = function(opts) {
|
||||||
var crypto = opts.cryptoUtil || cryptoUtil;
|
var crypto = opts.cryptoUtil || cryptoUtil;
|
||||||
|
this.backupNeeded = false;
|
||||||
return crypto.encrypt(this.password, this.exportWithWalletInfo(opts));
|
return crypto.encrypt(this.password, this.exportWithWalletInfo(opts));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -279,7 +284,7 @@ Identity.prototype.exportWithWalletInfo = function(opts) {
|
||||||
return wallet.toObj();
|
return wallet.toObj();
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
_.pick(this, 'version', 'fullName', 'password', 'email')
|
_.pick(this, 'version', 'fullName', 'password', 'email', 'backupNeeded')
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -288,10 +293,9 @@ Identity.prototype.exportWithWalletInfo = function(opts) {
|
||||||
* @param {Function} cb
|
* @param {Function} cb
|
||||||
*/
|
*/
|
||||||
Identity.prototype.store = function(opts, cb) {
|
Identity.prototype.store = function(opts, cb) {
|
||||||
log.debug('Storing profile');
|
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
opts.backupNeeded = false;
|
||||||
|
|
||||||
var storeFunction = opts.failIfExists ? self.storage.createItem : self.storage.setItem;
|
var storeFunction = opts.failIfExists ? self.storage.createItem : self.storage.setItem;
|
||||||
|
|
||||||
|
|
@ -323,9 +327,9 @@ Identity.prototype.remove = function(opts, cb) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
}, function (err) {
|
}, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
self.storage.removeItem(self.getId(), function(err) {
|
self.storage.removeItem(self.getId(), function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
self.emitAndKeepAlive('closed');
|
self.emitAndKeepAlive('closed');
|
||||||
|
|
@ -552,13 +556,16 @@ Identity.prototype.createWallet = function(opts, cb) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
||||||
var w = new walletClass(opts);
|
var w = new walletClass(opts);
|
||||||
self.bindWallet(w);
|
self.bindWallet(w);
|
||||||
self.updateFocusedTimestamp(w.getId());
|
self.updateFocusedTimestamp(w.getId());
|
||||||
self.storeWallet(w, function(err) {
|
self.storeWallet(w, function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err); << << << < HEAD === === =
|
||||||
|
|
||||||
|
self.backupNeeded = true; >>> >>> > Added the flag backupNeeded
|
||||||
self.store({
|
self.store({
|
||||||
noWallets: true
|
noWallets: true,
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
return cb(err, w);
|
return cb(err, w);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,14 @@ describe('Identity model', function() {
|
||||||
params: params
|
params: params
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
var orig;
|
||||||
|
beforeEach(function() {
|
||||||
|
orig = Identity.prototype.store;
|
||||||
|
sinon.stub(Identity.prototype, 'store').yields(null);
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
Identity.prototype.store = orig;
|
||||||
|
});
|
||||||
describe('new Identity()', function() {
|
describe('new Identity()', function() {
|
||||||
it('returns an identity', function() {
|
it('returns an identity', function() {
|
||||||
var iden = new Identity(getDefaultParams());
|
var iden = new Identity(getDefaultParams());
|
||||||
|
|
@ -124,7 +131,6 @@ describe('Identity model', function() {
|
||||||
it('should create and store identity', function() {
|
it('should create and store identity', function() {
|
||||||
var args = createIdentity();
|
var args = createIdentity();
|
||||||
args.blockchain.on = sinon.stub();
|
args.blockchain.on = sinon.stub();
|
||||||
sinon.stub(Identity.prototype, 'store').yields(null);
|
|
||||||
Identity.create(args.params, function(err, iden) {
|
Identity.create(args.params, function(err, iden) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
should.exist(iden);
|
should.exist(iden);
|
||||||
|
|
@ -492,4 +498,41 @@ describe('Identity model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Identity backupNeeded', function() {
|
||||||
|
|
||||||
|
it('should create Profile with backupNeeded set to true', function(done) {
|
||||||
|
var args = createIdentity();
|
||||||
|
Identity.create(args.params, function(err, iden) {
|
||||||
|
should.not.exist(err);
|
||||||
|
iden.backupNeeded.should.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('making a backup should set backupNeeded set to false', function(done) {
|
||||||
|
var args = createIdentity();
|
||||||
|
Identity.create(args.params, function(err, iden) {
|
||||||
|
should.not.exist(err);
|
||||||
|
iden.exportEncryptedWithWalletInfo(iden.password)
|
||||||
|
iden.backupNeeded.should.be.false;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adding a wallet should set backupNeeded to true', function(done) {
|
||||||
|
var args = createIdentity();
|
||||||
|
Identity.create(args.params, function(err, iden) {
|
||||||
|
should.not.exist(err);
|
||||||
|
iden.exportEncryptedWithWalletInfo(iden.password);
|
||||||
|
iden.createWallet({
|
||||||
|
walletClass: walletClass,
|
||||||
|
}, function(err, w2) {
|
||||||
|
iden.backupNeeded.should.be.true;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@
|
||||||
<a class="text-gray" ng-click="refresh()" ng-if="!$root.updatingBalance">
|
<a class="text-gray" ng-click="refresh()" ng-if="!$root.updatingBalance">
|
||||||
<i class="fi-refresh"></i>
|
<i class="fi-refresh"></i>
|
||||||
</a>
|
</a>
|
||||||
|
<span ng-if="$root.iden.backupNeeded">
|
||||||
|
BACKUP!
|
||||||
|
</span>
|
||||||
<span ng-if="$root.updatingBalance">
|
<span ng-if="$root.updatingBalance">
|
||||||
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue