Added the flag backupNeeded

This commit is contained in:
Matias Pando 2014-11-20 18:13:11 -03:00
parent b3b0d7903e
commit 3f65288dca
3 changed files with 64 additions and 11 deletions

View File

@ -62,6 +62,8 @@ function Identity(opts) {
this.walletIds = opts.walletIds || {};
this.wallets = opts.wallets || {};
this.focusedTimestamps = opts.focusedTimestamps || {};
this.backupNeeded = opts.backupNeeded || false;
};
@ -91,7 +93,9 @@ Identity.prototype.getName = function() {
* @return {undefined}
*/
Identity.create = function(opts, cb) {
opts = _.extend({}, opts);
opts = _.extend({
backupNeeded: true
}, opts);
var iden = new Identity(opts);
iden.store(_.extend(opts, {
@ -265,11 +269,12 @@ Identity.prototype.toObj = function() {
return _.extend({
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) {
var crypto = opts.cryptoUtil || cryptoUtil;
this.backupNeeded = false;
return crypto.encrypt(this.password, this.exportWithWalletInfo(opts));
};
@ -279,7 +284,7 @@ Identity.prototype.exportWithWalletInfo = function(opts) {
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
*/
Identity.prototype.store = function(opts, cb) {
log.debug('Storing profile');
var self = this;
opts = opts || {};
opts.backupNeeded = false;
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);
cb();
});
}, function (err) {
}, function(err) {
if (err) return cb(err);
self.storage.removeItem(self.getId(), function(err) {
if (err) return cb(err);
self.emitAndKeepAlive('closed');
@ -552,13 +556,16 @@ Identity.prototype.createWallet = function(opts, cb) {
var self = this;
var w = new walletClass(opts);
self.bindWallet(w);
self.updateFocusedTimestamp(w.getId());
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({
noWallets: true
noWallets: true,
}, function(err) {
return cb(err, w);
});

View File

@ -111,7 +111,14 @@ describe('Identity model', function() {
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() {
it('returns an identity', function() {
var iden = new Identity(getDefaultParams());
@ -124,7 +131,6 @@ describe('Identity model', function() {
it('should create and store identity', function() {
var args = createIdentity();
args.blockchain.on = sinon.stub();
sinon.stub(Identity.prototype, 'store').yields(null);
Identity.create(args.params, function(err, iden) {
should.not.exist(err);
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();
});
});
});
});
});

View File

@ -5,6 +5,9 @@
<a class="text-gray" ng-click="refresh()" ng-if="!$root.updatingBalance">
<i class="fi-refresh"></i>
</a>
<span ng-if="$root.iden.backupNeeded">
BACKUP!
</span>
<span ng-if="$root.updatingBalance">
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
</span>