Merge pull request #4331 from JDonadio/backup-spinner

Add spinner - backup flow
This commit is contained in:
Javier Donadío 2016-06-09 16:41:02 -03:00
commit 8e8d17de6a
2 changed files with 60 additions and 29 deletions

View file

@ -19,6 +19,13 @@
</section> </section>
</nav> </nav>
<div class="onGoingProcess" ng-show="wordsC.loading">
<div class="onGoingProcess-content" ng-style="{'background-color':index.backgroundColor}">
<ion-spinner class="spinner-stable" icon="lines"></ion-spinner>
<span translate>Validating recovery phrase...</span>
</div>
</div>
<div class="box-notification" ng-show="wordsC.error"> <div class="box-notification" ng-show="wordsC.error">
<span class="text-warning"> <span class="text-warning">
{{wordsC.error|translate}} {{wordsC.error|translate}}

View file

@ -5,6 +5,7 @@ angular.module('copayApp.controllers').controller('backupController',
var self = this; var self = this;
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
self.loading = false;
self.customWords = []; self.customWords = [];
self.walletName = fc.credentials.walletName; self.walletName = fc.credentials.walletName;
@ -44,14 +45,32 @@ angular.module('copayApp.controllers').controller('backupController',
}; };
self.goToStep = function(n) { self.goToStep = function(n) {
self.step = n; if (n == 1)
if (self.step == 1)
init(); init();
if (self.step == 3 && !self.mnemonicHasPassphrase) if (n == 2)
self.step++; self.step = 2;
if (self.step == 4) { if (n == 3) {
confirm(); 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() { function initWords() {
@ -125,6 +144,7 @@ angular.module('copayApp.controllers').controller('backupController',
}; };
$scope.removeButton = function(index, item) { $scope.removeButton = function(index, item) {
if (self.loading) return;
self.customWords.splice(index, 1); self.customWords.splice(index, 1);
self.shuffledMnemonicWords[item.prevIndex].selected = false; self.shuffledMnemonicWords[item.prevIndex].selected = false;
self.shouldContinue(); self.shouldContinue();
@ -137,15 +157,16 @@ angular.module('copayApp.controllers').controller('backupController',
self.selectComplete = false; self.selectComplete = false;
}; };
function confirm() { function confirm(cb) {
self.backupError = false; self.backupError = false;
var customWordList = lodash.pluck(self.customWords, 'word'); var customWordList = lodash.pluck(self.customWords, 'word');
if (!lodash.isEqual(self.mnemonicWords, customWordList)) { if (!lodash.isEqual(self.mnemonicWords, customWordList)) {
return backupError('Mnemonic string mismatch') return cb('Mnemonic string mismatch');
} }
$timeout(function() {
if (self.mnemonicHasPassphrase) { if (self.mnemonicHasPassphrase) {
var walletClient = bwcService.getClient(); var walletClient = bwcService.getClient();
var separator = self.useIdeograms ? '\u3000' : ' '; var separator = self.useIdeograms ? '\u3000' : ' ';
@ -157,20 +178,23 @@ angular.module('copayApp.controllers').controller('backupController',
network: fc.credentials.network, network: fc.credentials.network,
passphrase: passphrase, passphrase: passphrase,
account: fc.credentials.account account: fc.credentials.account
}) });
} catch (err) { } catch (err) {
return backupError(err); return cb(err);
} }
if (walletClient.credentials.xPrivKey != self.xPrivKey) { if (walletClient.credentials.xPrivKey != self.xPrivKey) {
return backupError('Private key mismatch'); return cb('Private key mismatch');
} }
} }
$rootScope.$emit('Local/BackupDone'); $rootScope.$emit('Local/BackupDone');
return cb();
}, 1);
}; };
function backupError(err) { function backupError(err) {
self.loading = false;
$log.debug('Failed to verify backup: ', err); $log.debug('Failed to verify backup: ', err);
self.backupError = true; self.backupError = true;