Merge pull request #1908 from isocolsky/delete_profile

Delete profile
This commit is contained in:
Matias Alejo Garcia 2014-12-02 03:15:05 -03:00
commit b3c3af5277
5 changed files with 147 additions and 0 deletions

View File

@ -4,6 +4,7 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
$rootScope.title = 'Profile';
$scope.hideAdv = true;
$scope.downloadProfileBackup = function() {
backupService.profileDownload($rootScope.iden);
@ -53,4 +54,17 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
});
};
$scope.deleteProfile = function () {
identityService.deleteProfile(function (err, res) {
if (err) {
log.warn(err);
notification.error('Error', 'Could not delete profile');
return;
}
$location.path('/');
setTimeout(function () {
notification.error('Success', 'Profile successfully deleted');
}, 1);
});
};
});

View File

@ -307,6 +307,33 @@ Identity.prototype.store = function(opts, cb) {
});
};
/**
* @param {Object} opts
* @param {Function} cb
*/
Identity.prototype.remove = function(opts, cb) {
log.debug('Deleting profile');
var self = this;
opts = opts || {};
async.each(_.values(self.wallets), function(w, cb) {
w.close();
self.storage.removeItem(Wallet.getStorageKey(w.getId()), function(err) {
if (err) return cb(err);
cb();
});
}, function (err) {
if (err) return cb(err);
self.storage.removeItem(self.getId(), function(err) {
if (err) return cb(err);
self.emitAndKeepAlive('closed');
return cb();
});
});
};
Identity.prototype._cleanUp = function() {
// NOP
};

View File

@ -87,6 +87,10 @@ angular.module('copayApp.services')
});
};
root.deleteProfile = function (cb) {
$rootScope.iden.remove(null, cb);
};
root.deleteWallet = function(w, cb) {
$rootScope.iden.deleteWallet(w.id, cb);
};

View File

@ -158,6 +158,76 @@ describe('Identity model', function() {
});
});
describe('#remove', function(done) {
it('should remove empty profile', function (done) {
var storage = sinon.stub();
storage.setCredentials = sinon.stub();
storage.removeItem = sinon.stub().yields(null);
var opts = {
email: 'test@test.com',
password: '123',
network: {
testnet: {
url: 'https://test-insight.bitpay.com:443'
},
livenet: {
url: 'https://insight.bitpay.com:443'
},
},
storage: storage,
};
var iden = new Identity(opts);
iden.remove(null, function (err, res) {
should.not.exist(err);
storage.removeItem.calledOnce.should.be.true;
storage.removeItem.getCall(0).args[0].should.equal(iden.getId());
done();
});
});
it('should remove profile and wallets', function(done) {
var storage = sinon.stub();
storage.setCredentials = sinon.stub();
storage.removeItem = sinon.stub().yields(null);
var opts = {
email: 'test@test.com',
password: '123',
network: {
testnet: {
url: 'https://test-insight.bitpay.com:443'
},
livenet: {
url: 'https://insight.bitpay.com:443'
},
},
storage: storage,
};
var iden = new Identity(opts);
_.each(_.range(3), function(i) {
var w = {
on: sinon.stub().yields(null),
getId: sinon.stub().returns('wallet' + i),
getName: sinon.stub().returns('wallet' + i),
close: sinon.stub(),
};
iden.wallets[w.getId()] = w;
});
iden.remove(null, function(err, res) {
should.not.exist(err);
storage.removeItem.callCount.should.equal(4);
storage.removeItem.getCall(0).args[0].should.equal(Wallet.getStorageKey('wallet0'));
storage.removeItem.getCall(3).args[0].should.equal(iden.getId());
done();
});
});
});
describe.skip('#storeWallet', function() {
// TODO test storeWallet
});

View File

@ -37,6 +37,7 @@
</div>
</div>
</div>
<div class="line-dashed-h m20b"></div>
<div class="row" ng-init="getWallets()">
@ -94,4 +95,35 @@
</table>
</div>
</div>
<div class="line-dashed-h m20b"></div>
<div class="m20b row">
<div class="large-12 columns">
<a class="size-12" ng-click="hideAdv=!hideAdv">
<i class="fi-widget m3r"></i>
<span translate ng-hide="!hideAdv">Show</span>
<span translate ng-hide="hideAdv">Hide</span>
<span translate>advanced options</span>
<i ng-if="hideAdv" class="icon-arrow-down4"></i>
<i ng-if="!hideAdv" class="icon-arrow-up4"></i>
</a>
</div>
</div>
<div ng-hide="hideAdv" class="row">
<div class="row">
<div class="large-12 columns">
<div class="panel">
<h2><i class="fi-minus-circle m10r"></i>
<span translate>Delete Profile</span>
</h2>
<p translate class="text-gray">Permanently delete this profile and all its wallets. WARNING: this action cannot be reversed.</p>
<a translate class="button warning m0" ng-really-message="{{'Are you sure you want to delete this profile?' | translate}}"
ng-really-click="deleteProfile()">Delete Profile
</a>
</div>
</div>
</div>
</div>
</div>