Merge pull request #4244 from JDonadio/fix/backup-controller
Fix backup controller
This commit is contained in:
commit
a77e730e48
2 changed files with 53 additions and 66 deletions
|
|
@ -116,13 +116,16 @@
|
||||||
<p class="text-gray m0" translate>
|
<p class="text-gray m0" translate>
|
||||||
Please tap the words in order to confirm your backup phrase is correctly written.
|
Please tap the words in order to confirm your backup phrase is correctly written.
|
||||||
</p>
|
</p>
|
||||||
<div class="panel words text-left" ng-class="{'enable_text_select': index.network == 'testnet'}">
|
<div class="panel words text-left">
|
||||||
<div id="addWord"></div>
|
<span ng-repeat="cword in wordsC.customWords track by $index" ng-show="wordsC.customWords[$index]">
|
||||||
|
<button class="button radius tiny words" ng-click="removeButton($index, cword)">{{cword.word}}</button>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-left" ng-class="{'enable_text_select': index.network == 'testnet'}" id="buttons">
|
<div class="text-left">
|
||||||
<span ng-repeat="word in wordsC.shuffledMnemonicWords track by $index">
|
<span ng-repeat="shuffledWord in wordsC.shuffledMnemonicWords track by $index">
|
||||||
<button class="button radius tiny words" ng-if="$index > 9" ng-click="wordsC.disableButton($index, word)" id="{{$index + word}}">{{word}}</button>
|
<button class="button radius tiny words" ng-click="addButton($index, shuffledWord)"
|
||||||
<button class="button radius tiny words" ng-if="$index <= 9" ng-click="wordsC.disableButton('0' + $index, word)" id="{{'0' + $index + word}}">{{word}}</button>
|
ng-disabled="shuffledWord.selected">{{shuffledWord.word}}
|
||||||
|
</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('backupController',
|
angular.module('copayApp.controllers').controller('backupController',
|
||||||
function($rootScope, $scope, $timeout, $document, $log, $state, $compile, go, lodash, profileService, gettext, bwcService, bwsError, walletService) {
|
function($rootScope, $scope, $timeout, $log, lodash, profileService, gettext, bwcService, bwsError, walletService) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
var customWords = [];
|
self.customWords = [];
|
||||||
self.walletName = fc.credentials.walletName;
|
self.walletName = fc.credentials.walletName;
|
||||||
|
|
||||||
var handleEncryptedWallet = function(client, cb) {
|
var handleEncryptedWallet = function(client, cb) {
|
||||||
|
|
@ -16,19 +16,6 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function init() {
|
|
||||||
$scope.passphrase = '';
|
|
||||||
resetAllButtons();
|
|
||||||
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)
|
if (fc.credentials && !fc.credentials.mnemonicEncrypted && !fc.credentials.mnemonic)
|
||||||
self.deleted = true;
|
self.deleted = true;
|
||||||
|
|
||||||
|
|
@ -40,6 +27,19 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
initWords();
|
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.goToStep = function(n) {
|
||||||
self.step = n;
|
self.step = n;
|
||||||
if (self.step == 1)
|
if (self.step == 1)
|
||||||
|
|
@ -49,18 +49,29 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
if (self.step == 4) {
|
if (self.step == 4) {
|
||||||
confirm();
|
confirm();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function initWords() {
|
function initWords() {
|
||||||
var words = fc.getMnemonic();
|
var words = fc.getMnemonic();
|
||||||
self.xPrivKey = fc.credentials.xPrivKey;
|
self.xPrivKey = fc.credentials.xPrivKey;
|
||||||
walletService.lock(fc);
|
walletService.lock(fc);
|
||||||
self.mnemonicWords = words.split(/[\u3000\s]+/);
|
self.mnemonicWords = words.split(/[\u3000\s]+/);
|
||||||
self.shuffledMnemonicWords = lodash.sortBy(self.mnemonicWords);;
|
self.shuffledMnemonicWords = shuffledWords(self.mnemonicWords);
|
||||||
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||||
self.useIdeograms = words.indexOf("\u3000") >= 0;
|
self.useIdeograms = words.indexOf("\u3000") >= 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function shuffledWords(words) {
|
||||||
|
var sort = lodash.sortBy(words);
|
||||||
|
|
||||||
|
return lodash.map(sort, function(w) {
|
||||||
|
return {
|
||||||
|
word: w,
|
||||||
|
selected: false
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
self.toggle = function() {
|
self.toggle = function() {
|
||||||
self.error = "";
|
self.error = "";
|
||||||
|
|
||||||
|
|
@ -98,64 +109,37 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function resetAllButtons() {
|
$scope.addButton = function(index, item) {
|
||||||
$document.getElementById('addWord').innerHTML = '';
|
var newWord = {
|
||||||
var nodes = $document.getElementById("buttons").getElementsByTagName('button');
|
word: item.word,
|
||||||
lodash.each(nodes, function(n) {
|
prevIndex: index
|
||||||
$document.getElementById(n.id).disabled = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
self.enableButton = function(word) {
|
|
||||||
$document.getElementById(word).disabled = false;
|
|
||||||
lodash.remove(customWords, function(v) {
|
|
||||||
return v == word;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
self.disableButton = function(index, word) {
|
|
||||||
var element = {
|
|
||||||
index: index,
|
|
||||||
word: word
|
|
||||||
};
|
};
|
||||||
$document.getElementById(index + word).disabled = true;
|
self.customWords.push(newWord);
|
||||||
customWords.push(element);
|
self.shuffledMnemonicWords[index].selected = true;
|
||||||
self.addButton(index, word);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.addButton = function(index, word) {
|
|
||||||
var btnhtml = '<button class="button radius tiny words" ng-disabled="wordsC.disableButtons"' +
|
|
||||||
'data-ng-click="wordsC.removeButton($event)" id="_' + index + word + '" > ' + word + ' </button>';
|
|
||||||
var temp = $compile(btnhtml)($scope);
|
|
||||||
angular.element($document.getElementById('addWord')).append(temp);
|
|
||||||
self.shouldContinue();
|
self.shouldContinue();
|
||||||
}
|
};
|
||||||
|
|
||||||
self.removeButton = function(event) {
|
$scope.removeButton = function(index, item) {
|
||||||
var id = (event.target.id);
|
self.customWords.splice(index, 1);
|
||||||
$document.getElementById(id).remove();
|
self.shuffledMnemonicWords[item.prevIndex].selected = false;
|
||||||
self.enableButton(id.substring(1));
|
|
||||||
lodash.remove(customWords, function(d) {
|
|
||||||
return d.index == id.substring(1, 3);
|
|
||||||
});
|
|
||||||
self.shouldContinue();
|
self.shouldContinue();
|
||||||
}
|
};
|
||||||
|
|
||||||
self.shouldContinue = function() {
|
self.shouldContinue = function() {
|
||||||
if (customWords.length == 12)
|
if (self.customWords.length == 12)
|
||||||
self.selectComplete = true;
|
self.selectComplete = true;
|
||||||
else
|
else
|
||||||
self.selectComplete = false;
|
self.selectComplete = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
function confirm() {
|
function confirm() {
|
||||||
self.backupError = false;
|
self.backupError = false;
|
||||||
|
|
||||||
var walletClient = bwcService.getClient();
|
var walletClient = bwcService.getClient();
|
||||||
var separator = self.useIdeograms ? '\u3000' : ' ';
|
var separator = self.useIdeograms ? '\u3000' : ' ';
|
||||||
var customSentence = lodash.pluck(customWords, 'word').join(separator);
|
var customSentence = lodash.pluck(self.customWords, 'word').join(separator);
|
||||||
var passphrase = $scope.passphrase || '';
|
var passphrase = $scope.passphrase || '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -173,7 +157,7 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
}
|
}
|
||||||
|
|
||||||
$rootScope.$emit('Local/BackupDone');
|
$rootScope.$emit('Local/BackupDone');
|
||||||
}
|
};
|
||||||
|
|
||||||
function backupError(err) {
|
function backupError(err) {
|
||||||
$log.debug('Failed to verify backup: ', err);
|
$log.debug('Failed to verify backup: ', err);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue