diff --git a/js/controllers/copayers.js b/js/controllers/copayers.js index a988ad048..c424741a8 100644 --- a/js/controllers/copayers.js +++ b/js/controllers/copayers.js @@ -1,9 +1,9 @@ 'use strict'; angular.module('copayApp.controllers').controller('CopayersController', - function($scope, $rootScope, $timeout, go) { + function($scope, $rootScope, $timeout, go, identityService, notification) { + var w = $rootScope.wallet; $scope.init = function() { - var w = $rootScope.wallet; $rootScope.title = 'Share this secret with your copayers'; $scope.loading = false; $scope.secret = $rootScope.wallet.getSecret(); @@ -27,4 +27,25 @@ angular.module('copayApp.controllers').controller('CopayersController', $rootScope.$digest(); }, 1); }; + + $scope.deleteWallet = function() { + $scope.loading = true; + identityService.deleteWallet(w, function(err) { + if (err) { + $scope.loading = null; + $scope.error = err.message || err; + copay.logger.warn(err); + $timeout(function () { $scope.$digest(); }); + } else { + $scope.loading = false; + if ($rootScope.wallet) { + go.walletHome(); + } + $timeout(function() { + notification.success('Success', 'The wallet "' + (w.name || w.id) + '" was deleted'); + }); + } + }); + }; + }); diff --git a/js/controllers/more.js b/js/controllers/more.js index f3068922a..36f8e5159 100644 --- a/js/controllers/more.js +++ b/js/controllers/more.js @@ -1,9 +1,20 @@ 'use strict'; angular.module('copayApp.controllers').controller('MoreController', - function($scope, $rootScope, $location, $filter, balanceService, notification, rateService) { + function($scope, $rootScope, $location, $filter, $timeout, balanceService, notification, rateService, backupService, identityService, isMobile, isCordova, go) { var w = $rootScope.wallet; - $scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; + var max = $rootScope.quotaPerItem; + $scope.isSafari = isMobile.Safari(); + $scope.isCordova = isCordova; + $scope.wallet = w; + $scope.error = null; + $scope.success = null; + + var bits = w.sizes().total; + w.kb = $filter('noFractionNumber')(bits / 1000, 1); + if (max) { + w.usage = $filter('noFractionNumber')(bits / max * 100, 0); + } $rootScope.title = 'Settings'; @@ -105,4 +116,34 @@ angular.module('copayApp.controllers').controller('MoreController', }, true); }); }; + + $scope.deleteWallet = function() { + $scope.loading = true; + identityService.deleteWallet(w, function(err) { + if (err) { + $scope.loading = null; + $scope.error = err.message || err; + copay.logger.warn(err); + $timeout(function () { $scope.$digest(); }); + } else { + $scope.loading = false; + if ($rootScope.wallet) { + go.walletHome(); + } + $timeout(function() { + notification.success('Success', 'The wallet "' + (w.name || w.id) + '" was deleted'); + }); + } + }); + }; + + $scope.downloadWalletBackup = function() { + backupService.walletDownload(w); + }; + + $scope.viewWalletBackup = function() { + $scope.backupWalletPlainText = backupService.walletEncrypted(w); + }; + + }); diff --git a/js/controllers/profile.js b/js/controllers/profile.js index 8bebdfeae..94cc7c6d8 100644 --- a/js/controllers/profile.js +++ b/js/controllers/profile.js @@ -25,25 +25,6 @@ angular.module('copayApp.controllers').controller('ProfileController', function( // no need to add event handlers here. Wallet deletion is handle by callback. }; - $scope.setWallets = function() { - if (!$rootScope.iden) return; - - var wallets = $rootScope.iden.getWallets(); - var max = $rootScope.quotaPerItem; - - _.each(wallets, function(w) { - var bits = w.sizes().total; - w.kb = $filter('noFractionNumber')(bits / 1000, 1); - if (max) { - w.usage = $filter('noFractionNumber')(bits / max * 100, 0); - } - }); - $scope.wallets = wallets; - $timeout(function(){ - $scope.$digest(); - }) - }; - $scope.deleteProfile = function() { identityService.deleteProfile(function(err, res) { if (err) { @@ -57,54 +38,4 @@ angular.module('copayApp.controllers').controller('ProfileController', function( }); }); }; - - $scope.showWalletInfo = function(w) { - var ModalInstanceCtrl = function($scope, $modalInstance) { - if (!w) return; - $scope.isSafari = isMobile.Safari(); - $scope.isCordova = isCordova; - $scope.item = w; - $scope.error = null; - $scope.success = null; - - $scope.deleteWallet = function() { - - $scope.loading = true; - identityService.deleteWallet($scope.item, function(err) { - if (err) { - $scope.loading = null; - $scope.error = err.message || err; - copay.logger.warn(err); - $timeout(function () { $scope.$digest(); }); - } else { - $modalInstance.close($scope.item.name || $scope.item.id); - } - }); - }; - - $scope.downloadWalletBackup = function() { - backupService.walletDownload($scope.item); - }; - - $scope.viewWalletBackup = function() { - $scope.backupWalletPlainText = backupService.walletEncrypted($scope.item); - }; - - $scope.close = function() { - $modalInstance.dismiss('cancel'); - }; - }; - - var modalInstance = $modal.open({ - templateUrl: 'views/modals/wallet-info.html', - windowClass: 'medium', - controller: ModalInstanceCtrl - }); - - modalInstance.result.then(function(walletName) { - $scope.loading = false; - $scope.success = 'The wallet "' + walletName + '" was deleted'; - $scope.setWallets(); - }); - }; }); diff --git a/js/models/Identity.js b/js/models/Identity.js index 289f205bf..ee74ad469 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -218,6 +218,9 @@ Identity.prototype.deleteWallet = function(walletId, cb) { self.storage.removeItem(Wallet.getStorageKey(walletId), function(err) { if (err) return cb(err); self.emitAndKeepAlive('walletDeleted', walletId); + if (!self.walletIds.length) { + self.emitAndKeepAlive('noWallets') + } self.store({ noWallets: true }, cb); diff --git a/views/copayers.html b/views/copayers.html index 9ca0fdcd3..14db0f488 100644 --- a/views/copayers.html +++ b/views/copayers.html @@ -49,6 +49,32 @@ +
| Name | -Type | - - - -
|---|---|
| - - - {{item.name || item.id }} - - | -{{item.requiredCopayers}} of {{item.totalCopayers}} - {{networkName}} | - - - -