From 14379b3c63ad571a5a5c7955fe116f0eef8474d8 Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 30 May 2016 13:37:15 -0300 Subject: [PATCH] replace scope variables - rename shuffle words function --- public/views/backup.html | 2 +- src/js/controllers/backup.js | 45 ++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/public/views/backup.html b/public/views/backup.html index 6b314fb76..e7990c779 100644 --- a/public/views/backup.html +++ b/public/views/backup.html @@ -117,7 +117,7 @@ Please tap the words in order to confirm your backup phrase is correctly written.

- +
diff --git a/src/js/controllers/backup.js b/src/js/controllers/backup.js index 623af695f..cb81c905a 100644 --- a/src/js/controllers/backup.js +++ b/src/js/controllers/backup.js @@ -5,7 +5,7 @@ angular.module('copayApp.controllers').controller('backupController', var self = this; var fc = profileService.focusedClient; - $scope.customWords = []; + self.customWords = []; self.walletName = fc.credentials.walletName; var handleEncryptedWallet = function(client, cb) { @@ -16,19 +16,6 @@ angular.module('copayApp.controllers').controller('backupController', }); }; - function init() { - $scope.passphrase = ''; - _shuffleWords(); - $scope.customWords = []; - self.step = 1; - self.deleted = false; - self.credentialsEncrypted = false; - self.selectComplete = false; - self.backupError = false; - }; - - init(); - if (fc.credentials && !fc.credentials.mnemonicEncrypted && !fc.credentials.mnemonic) self.deleted = true; @@ -40,6 +27,19 @@ angular.module('copayApp.controllers').controller('backupController', initWords(); } + init(); + + function init() { + $scope.passphrase = ''; + self.shuffledMnemonicWords = shuffledWords(self.mnemonicWords); + self.customWords = []; + self.step = 1; + self.deleted = false; + self.credentialsEncrypted = false; + self.selectComplete = false; + self.backupError = false; + }; + self.goToStep = function(n) { self.step = n; if (self.step == 1) @@ -56,14 +56,15 @@ angular.module('copayApp.controllers').controller('backupController', self.xPrivKey = fc.credentials.xPrivKey; walletService.lock(fc); self.mnemonicWords = words.split(/[\u3000\s]+/); - _shuffleWords(); + self.shuffledMnemonicWords = shuffledWords(self.mnemonicWords); self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase(); self.useIdeograms = words.indexOf("\u3000") >= 0; }; - function _shuffleWords() { - var sort = lodash.sortBy(self.mnemonicWords); - self.shuffledMnemonicWords = lodash.map(sort, function(w) { + function shuffledWords(words) { + var sort = lodash.sortBy(words); + + return lodash.map(sort, function(w) { return { word: w, selected: false @@ -115,19 +116,19 @@ angular.module('copayApp.controllers').controller('backupController', word: item.word, prevIndex: index }; - $scope.customWords.push(newWord); + self.customWords.push(newWord); self.shuffledMnemonicWords[index].selected = true; self.shouldContinue(); }; $scope.removeButton = function(index, item) { - $scope.customWords.splice(index, 1); + self.customWords.splice(index, 1); self.shuffledMnemonicWords[item.prevIndex].selected = false; self.shouldContinue(); }; self.shouldContinue = function() { - if ($scope.customWords.length == 12) + if (self.customWords.length == 12) self.selectComplete = true; else self.selectComplete = false; @@ -138,7 +139,7 @@ angular.module('copayApp.controllers').controller('backupController', var walletClient = bwcService.getClient(); var separator = self.useIdeograms ? '\u3000' : ' '; - var customSentence = lodash.pluck($scope.customWords, 'word').join(separator); + var customSentence = lodash.pluck(self.customWords, 'word').join(separator); var passphrase = $scope.passphrase || ''; try {