refactor
This commit is contained in:
parent
a4e3cbe463
commit
b4a5c9212f
4 changed files with 73 additions and 110 deletions
|
|
@ -11,7 +11,7 @@
|
|||
</section>
|
||||
|
||||
<section class="right-small">
|
||||
<a class="p10" ng-click="backTo()">
|
||||
<a class="p10" ng-click="goBack()">
|
||||
<span class="text-close">
|
||||
<i class="fi-x size-24"></i>
|
||||
</span>
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
<div class="content preferences text-center">
|
||||
<div ng-show="step == 1">
|
||||
<div ng-show="mnemonicWords || (credentialsEncrypted && !deleted)" class="row">
|
||||
<div ng-show="mnemonicWords || (!credentialsEncrypted && !deleted)" class="row">
|
||||
<h5 class="text-center" translate>Write your wallet recovery phrase</h5>
|
||||
<div class="size-14 text-gray columns" ng-show="(index.n>1 && index.m != index.n )">
|
||||
<span translate>
|
||||
|
|
@ -62,20 +62,12 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div ng-show="mnemonicWords || (credentialsEncrypted && !deleted)">
|
||||
<div ng-show="mnemonicWords || (!credentialsEncrypted && !deleted)">
|
||||
<p class="text-center columns text-gray" ng-show="index.n==1 && step == 1">
|
||||
<span translate>
|
||||
You need the wallet recovery phrase to restore this personal wallet. Write it down and keep them somewhere safe.
|
||||
</span>
|
||||
</p>
|
||||
<div class="row" ng-show="credentialsEncrypted">
|
||||
<div class="m10t columns">
|
||||
<a class="button outline light-gray expand tiny" ng-click="toggle()">
|
||||
<i class="fi-widget m3r"></i>
|
||||
<span translate ng-hide="show">Show Wallet Recovery Phrase</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" ng-show="!credentialsEncrypted">
|
||||
<div class="columns">
|
||||
<div class="panel" ng-class="{'enable_text_select': index.network == 'testnet'}">
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
ng-init="titleSection='Export Wallet'; goBackToState = 'preferencesAdvanced'">
|
||||
</div>
|
||||
|
||||
<div class="content preferences" ng-controller="exportController" ng-init="init()">
|
||||
<div class="content preferences" ng-controller="exportController" ng-init="init(index.prevState)">
|
||||
<h4></h4>
|
||||
<div ng-show="!backupWalletPlainText">
|
||||
<div class="text-warning size-14 m20b" ng-show="error">
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<form>
|
||||
<form ng-hide="touchidEnabled && !touchidSuccess">
|
||||
<div class="row">
|
||||
<div class="columns">
|
||||
<label for="password" translate>Set up a password </label>
|
||||
|
|
|
|||
|
|
@ -7,47 +7,59 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
var prevState;
|
||||
$scope.customWords = [];
|
||||
$scope.walletName = fc.credentials.walletName;
|
||||
$scope.credentialsEncrypted = fc.isPrivKeyEncrypted;
|
||||
|
||||
var handleEncryptedWallet = function(client, cb) {
|
||||
if (!walletService.isEncrypted(client)) return cb();
|
||||
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
|
||||
if (err) return cb(err);
|
||||
return cb(walletService.unlock(client, password));
|
||||
$scope.init = function(state) {
|
||||
prevState = state || 'walletHome';
|
||||
$scope.step = 1;
|
||||
$scope.deleted = isDeletedSeed();
|
||||
if ($scope.deleted) return;
|
||||
|
||||
fingerprintService.check(fc, function(err) {
|
||||
if (err) {
|
||||
go.path(prevState);
|
||||
return;
|
||||
}
|
||||
|
||||
handleEncryptedWallet(fc, function(err) {
|
||||
if (err) {
|
||||
$scope.error = bwsError.msg(err, gettext('Could not decrypt'));
|
||||
$log.warn('Error decrypting credentials:', $scope.error);
|
||||
return;
|
||||
}
|
||||
$scope.credentialsEncrypted = false;
|
||||
$scope.initFlow();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (fc.isPrivKeyEncrypted() && !isDeletedSeed()) {
|
||||
$scope.credentialsEncrypted = true;
|
||||
passwordRequest();
|
||||
} else {
|
||||
if (!isDeletedSeed())
|
||||
initWords();
|
||||
}
|
||||
function shuffledWords(words) {
|
||||
var sort = lodash.sortBy(words);
|
||||
|
||||
$scope.init = function(state) {
|
||||
prevState = state;
|
||||
$scope.passphrase = '';
|
||||
return lodash.map(sort, function(w) {
|
||||
return {
|
||||
word: w,
|
||||
selected: false
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
$scope.initFlow = function() {
|
||||
var words = fc.getMnemonic();
|
||||
$scope.xPrivKey = fc.credentials.xPrivKey;
|
||||
$scope.mnemonicWords = words.split(/[\u3000\s]+/);
|
||||
$scope.shuffledMnemonicWords = shuffledWords($scope.mnemonicWords);
|
||||
$scope.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||
$scope.useIdeograms = words.indexOf("\u3000") >= 0;
|
||||
$scope.passphrase = '';
|
||||
$scope.customWords = [];
|
||||
$scope.step = 1;
|
||||
$scope.deleted = isDeletedSeed();
|
||||
$scope.credentialsEncrypted = false;
|
||||
$scope.selectComplete = false;
|
||||
$scope.backupError = false;
|
||||
|
||||
if (!platformInfo.isCordova) return;
|
||||
if (isDeletedSeed()) return;
|
||||
|
||||
var config = configService.getSync();
|
||||
var touchidAvailable = fingerprintService.isAvailable();
|
||||
var touchidEnabled = config.touchIdFor ? config.touchIdFor[fc.credentials.walletId] : null;
|
||||
|
||||
if (!touchidAvailable || !touchidEnabled) return;
|
||||
|
||||
fingerprintService.check(fc, function(err) {
|
||||
if (err)
|
||||
go.path(prevState);
|
||||
});
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
};
|
||||
|
||||
function isDeletedSeed() {
|
||||
|
|
@ -56,13 +68,14 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
return false;
|
||||
};
|
||||
|
||||
$scope.backTo = function() {
|
||||
go.path(prevState);
|
||||
$scope.goBack = function() {
|
||||
walletService.lock(fc);
|
||||
go.path(prevState || 'walletHome');
|
||||
};
|
||||
|
||||
$scope.goToStep = function(n) {
|
||||
if (n == 1)
|
||||
$scope.init();
|
||||
$scope.initFlow();
|
||||
if (n == 2)
|
||||
$scope.step = 2;
|
||||
if (n == 3) {
|
||||
|
|
@ -89,66 +102,6 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
};
|
||||
};
|
||||
|
||||
function initWords() {
|
||||
var words = fc.getMnemonic();
|
||||
$scope.xPrivKey = fc.credentials.xPrivKey;
|
||||
walletService.lock(fc);
|
||||
$scope.mnemonicWords = words.split(/[\u3000\s]+/);
|
||||
$scope.shuffledMnemonicWords = shuffledWords($scope.mnemonicWords);
|
||||
$scope.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||
$scope.useIdeograms = words.indexOf("\u3000") >= 0;
|
||||
};
|
||||
|
||||
function shuffledWords(words) {
|
||||
var sort = lodash.sortBy(words);
|
||||
|
||||
return lodash.map(sort, function(w) {
|
||||
return {
|
||||
word: w,
|
||||
selected: false
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
$scope.toggle = function() {
|
||||
$scope.error = "";
|
||||
|
||||
if ($scope.credentialsEncrypted)
|
||||
passwordRequest();
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
};
|
||||
|
||||
function passwordRequest() {
|
||||
try {
|
||||
initWords();
|
||||
} catch (e) {
|
||||
if (e.message && e.message.match(/encrypted/) && fc.isPrivKeyEncrypted()) {
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
|
||||
handleEncryptedWallet(fc, function(err) {
|
||||
if (err) {
|
||||
$scope.error = bwsError.msg(err, gettext('Could not decrypt'));
|
||||
$log.warn('Error decrypting credentials:', $scope.error); //TODO
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.credentialsEncrypted = false;
|
||||
initWords();
|
||||
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.addButton = function(index, item) {
|
||||
var newWord = {
|
||||
word: item.word,
|
||||
|
|
@ -209,6 +162,18 @@ angular.module('copayApp.controllers').controller('backupController',
|
|||
}, 1);
|
||||
};
|
||||
|
||||
function handleEncryptedWallet(client, cb) {
|
||||
if (!walletService.isEncrypted(client)) {
|
||||
$scope.credentialsEncrypted = false;
|
||||
return cb();
|
||||
}
|
||||
|
||||
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
|
||||
if (err) return cb(err);
|
||||
return cb(walletService.unlock(client, password));
|
||||
});
|
||||
};
|
||||
|
||||
function backupError(err) {
|
||||
ongoingProcess.set('validatingWords', false);
|
||||
$log.debug('Failed to verify backup: ', err);
|
||||
|
|
|
|||
|
|
@ -7,21 +7,27 @@ angular.module('copayApp.controllers').controller('exportController',
|
|||
var isCordova = platformInfo.isCordova;
|
||||
var fc = profileService.focusedClient;
|
||||
$scope.isEncrypted = fc.isPrivKeyEncrypted();
|
||||
$scope.touchidSuccess = null;
|
||||
$scope.touchidEnabled = null;
|
||||
$scope.error = null;
|
||||
$scope.success = null;
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.init = function(state) {
|
||||
if (!isCordova) return;
|
||||
|
||||
var config = configService.getSync();
|
||||
var touchidAvailable = fingerprintService.isAvailable();
|
||||
var touchidEnabled = config.touchIdFor ? config.touchIdFor[fc.credentials.walletId] : null;
|
||||
var touchidEnabled = $scope.touchidEnabled = config.touchIdFor ? config.touchIdFor[fc.credentials.walletId] : null;
|
||||
|
||||
if (!touchidAvailable || !touchidEnabled) return;
|
||||
|
||||
fingerprintService.check(fc, function(err) {
|
||||
if (err)
|
||||
go.path($scope.goBackToState);
|
||||
go.path(state || 'walletHome');
|
||||
|
||||
$scope.touchidSuccess = true;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
}, 10);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue