diff --git a/public/views/backup.html b/public/views/backup.html index c39c20c69..a3452e40c 100644 --- a/public/views/backup.html +++ b/public/views/backup.html @@ -19,6 +19,13 @@ +
+
You need the wallet recovery phrase to restore this personal wallet. Write it down and keep them somewhere safe. diff --git a/src/js/controllers/backup.js b/src/js/controllers/backup.js index 0e5bc2601..d06c85aaa 100644 --- a/src/js/controllers/backup.js +++ b/src/js/controllers/backup.js @@ -5,6 +5,7 @@ angular.module('copayApp.controllers').controller('backupController', var self = this; var fc = profileService.focusedClient; + self.loading = false; self.customWords = []; self.walletName = fc.credentials.walletName; @@ -44,14 +45,32 @@ angular.module('copayApp.controllers').controller('backupController', }; self.goToStep = function(n) { - self.step = n; - if (self.step == 1) + if (n == 1) init(); - if (self.step == 3 && !self.mnemonicHasPassphrase) - self.step++; - if (self.step == 4) { - confirm(); + if (n == 2) + self.step = 2; + if (n == 3) { + if (!self.mnemonicHasPassphrase) + finalStep(); + else + self.step = 3; } + if (n == 4) + finalStep(); + + function finalStep() { + self.loading = true; + confirm(function(err) { + self.loading = false; + if (err) { + backupError(err); + } + $timeout(function() { + self.step = 4; + return; + }, 1); + }); + }; }; function initWords() { @@ -125,6 +144,7 @@ angular.module('copayApp.controllers').controller('backupController', }; $scope.removeButton = function(index, item) { + if (self.loading) return; self.customWords.splice(index, 1); self.shuffledMnemonicWords[item.prevIndex].selected = false; self.shouldContinue(); @@ -137,40 +157,44 @@ angular.module('copayApp.controllers').controller('backupController', self.selectComplete = false; }; - function confirm() { + function confirm(cb) { self.backupError = false; var customWordList = lodash.pluck(self.customWords, 'word'); if (!lodash.isEqual(self.mnemonicWords, customWordList)) { - return backupError('Mnemonic string mismatch') + return cb('Mnemonic string mismatch'); } - if (self.mnemonicHasPassphrase) { - var walletClient = bwcService.getClient(); - var separator = self.useIdeograms ? '\u3000' : ' '; - var customSentence = customWordList.join(separator); - var passphrase = $scope.passphrase || ''; + $timeout(function() { + if (self.mnemonicHasPassphrase) { + var walletClient = bwcService.getClient(); + var separator = self.useIdeograms ? '\u3000' : ' '; + var customSentence = customWordList.join(separator); + var passphrase = $scope.passphrase || ''; - try { - walletClient.seedFromMnemonic(customSentence, { - network: fc.credentials.network, - passphrase: passphrase, - account: fc.credentials.account - }) - } catch (err) { - return backupError(err); + try { + walletClient.seedFromMnemonic(customSentence, { + network: fc.credentials.network, + passphrase: passphrase, + account: fc.credentials.account + }); + } catch (err) { + return cb(err); + } + + if (walletClient.credentials.xPrivKey != self.xPrivKey) { + return cb('Private key mismatch'); + } } - if (walletClient.credentials.xPrivKey != self.xPrivKey) { - return backupError('Private key mismatch'); - } - } - - $rootScope.$emit('Local/BackupDone'); + $rootScope.$emit('Local/BackupDone'); + return cb(); + }, 1); }; function backupError(err) { + self.loading = false; $log.debug('Failed to verify backup: ', err); self.backupError = true;