Storing the backup flag

This commit is contained in:
Matias Pando 2014-11-26 12:08:26 -03:00
commit 52fb680658
6 changed files with 34 additions and 98 deletions

View file

@ -28,8 +28,8 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
$scope.init = function() { $scope.init = function() {
if ($rootScope.quotaPerItem) { if ($rootScope.quotaPerItem) {
$scope.perItem = $filter('noFractionNumber')($rootScope.quotaPerItem/1000,1); $scope.perItem = $filter('noFractionNumber')($rootScope.quotaPerItem / 1000, 1);
$scope.nrWallets =parseInt($rootScope.quotaItems) - 1; $scope.nrWallets = parseInt($rootScope.quotaItems) - 1;
} }
}; };
@ -37,13 +37,13 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
if (!$rootScope.iden) return; if (!$rootScope.iden) return;
var wallets = $rootScope.iden.listWallets(); var wallets = $rootScope.iden.listWallets();
var max =$rootScope.quotaPerItem; var max = $rootScope.quotaPerItem;
_.each(wallets, function(w) { _.each(wallets, function(w) {
var bits = w.sizes().total; var bits = w.sizes().total;
w.kb = $filter('noFractionNumber')(bits/1000, 1); w.kb = $filter('noFractionNumber')(bits / 1000, 1);
if (max) { if (max) {
w.usage = $filter('noFractionNumber')(bits/max * 100, 0); w.usage = $filter('noFractionNumber')(bits / max * 100, 0);
} }
}); });
@ -73,15 +73,15 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
}); });
}; };
$scope.deleteProfile = function () { $scope.deleteProfile = function() {
identityService.deleteProfile(function (err, res) { identityService.deleteProfile(function(err, res) {
if (err) { if (err) {
log.warn(err); log.warn(err);
notification.error('Error', 'Could not delete profile'); notification.error('Error', 'Could not delete profile');
return; return;
} }
$location.path('/'); $location.path('/');
setTimeout(function () { setTimeout(function() {
notification.error('Success', 'Profile successfully deleted'); notification.error('Success', 'Profile successfully deleted');
}, 1); }, 1);
}); });

View file

@ -274,10 +274,17 @@ Identity.prototype.toObj = function() {
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));
}; };
Identity.prototype.setBackupDone = function() {
this.backupNeeded = false;
this.store({
noWallets: true
}, function() {});
}
Identity.prototype.exportWithWalletInfo = function(opts) { Identity.prototype.exportWithWalletInfo = function(opts) {
return _.extend({ return _.extend({
wallets: _.map(this.wallets, function(wallet) { wallets: _.map(this.wallets, function(wallet) {
@ -295,12 +302,13 @@ Identity.prototype.exportWithWalletInfo = function(opts) {
Identity.prototype.store = function(opts, cb) { Identity.prototype.store = function(opts, cb) {
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;
storeFunction.call(self.storage, this.getId(), this.toObj(), function(err) { storeFunction.call(self.storage, this.getId(), this.toObj(), function(err) {
if (err) return cb(err); if (err) {
return cb(err);
}
if (opts.noWallets) if (opts.noWallets)
return cb(); return cb();

View file

@ -38,6 +38,7 @@ BackupService.prototype.profileEncrypted = function(iden) {
BackupService.prototype.profileDownload = function(iden) { BackupService.prototype.profileDownload = function(iden) {
var ew = this.profileEncrypted(iden); var ew = this.profileEncrypted(iden);
iden.setBackupDone();
var name = iden.fullName; var name = iden.fullName;
var filename = name + '-profile.json'; var filename = name + '-profile.json';
this._download(ew, name, filename) this._download(ew, name, filename)

View file

@ -48,6 +48,7 @@ angular.module('copayApp.services')
passphraseConfig: config.passphraseConfig, passphraseConfig: config.passphraseConfig,
failIfExists: true, failIfExists: true,
}, function(err, iden) { }, function(err, iden) {
if (err) return cb(err); if (err) return cb(err);
preconditions.checkState(iden); preconditions.checkState(iden);
root.bind(iden); root.bind(iden);
@ -102,7 +103,7 @@ angular.module('copayApp.services')
}); });
}; };
root.deleteProfile = function (cb) { root.deleteProfile = function(cb) {
$rootScope.iden.remove(null, cb); $rootScope.iden.remove(null, cb);
}; };

View file

@ -498,79 +498,4 @@ describe('Identity model', function() {
}); });
}); });
}); });
describe.only('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();
});
});
});
it('joining a wallet should set backupNeeded to true', function(done) {
var args = createIdentity();
var net = null;
var opts = {
secret: '8WtTuiFTkhP5ao7AF2QErSwV39Cbur6pdMebKzQXFqL59RscXM',
nickname: 'test',
password: 'pass'
};
args.params.Async = net = sinon.stub();
net = sinon.stub();
net.on = sinon.stub();
net.start = sinon.stub();
net.start.onFirstCall().callsArg(1);
net.greet = sinon.stub();
Identity.create(args.params, function(err, iden) {
iden.createWallet = sinon.stub();
should.not.exist(err);
iden.exportEncryptedWithWalletInfo(iden.password);
var fakeWallet = {
sendWalletReady: _.noop
};
iden.createWallet.onFirstCall().yields(null, fakeWallet);
opts.privHex = 'tprv8ZgxMBicQKsPf7MCvCjnhnr4uiR2Z2gyNC27vgd9KUu98F9mM1tbaRrWMyddVju36GxLbeyntuSadBAttriwGGMWUkRgVmUUCg5nFioGZsd';
opts.Async = net;
iden.joinWallet(opts, function(err, w) {
console.log('err', err);
console.log('w', w);
console.log('join Wallet');
iden.backupNeeded.should.be.true;
done();
});
});
});
});
}); });

View file

@ -76,6 +76,7 @@ describe("Angular services", function() {
a[Waddr] = 200; a[Waddr] = 200;
w.getBalance = sinon.stub().yields(null, 100000001, a, 90000002, 5); w.getBalance = sinon.stub().yields(null, 100000001, a, 90000002, 5);
//retuns values in DEFAULT UNIT(bits) //retuns values in DEFAULT UNIT(bits)
balanceService.update(w, function() { balanceService.update(w, function() {
var b = w.balanceInfo; var b = w.balanceInfo;
@ -90,7 +91,7 @@ describe("Angular services", function() {
expect(b.balanceByAddr[Waddr]).to.equal(2); expect(b.balanceByAddr[Waddr]).to.equal(2);
expect(b.safeUnspentCount).to.equal(5); expect(b.safeUnspentCount).to.equal(5);
expect(b.topAmount).to.equal(899800.02); expect(b.topAmount).to.equal(899800.02);
},false); }, false);
})); }));
}); });