diff --git a/js/controllers/profile.js b/js/controllers/profile.js index 5eaea7953..ff08185ee 100644 --- a/js/controllers/profile.js +++ b/js/controllers/profile.js @@ -55,6 +55,16 @@ 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); + }); }; }); diff --git a/js/models/Identity.js b/js/models/Identity.js index 23329ca77..0f9fcdad7 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -307,6 +307,31 @@ 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 || {}; + + // HACK (isocolsky): remove notifications while deleting wallets + self.removeAllListeners('deletedWallet'); + + async.each(_.values(self.wallets), function(w, cb) { + self.deleteWallet(w.getId(), 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 }; diff --git a/js/services/identityService.js b/js/services/identityService.js index 6fb1cd0aa..94e6f1653 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -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); };