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>
|
||||||
|
|
||||||
<section class="right-small">
|
<section class="right-small">
|
||||||
<a class="p10" ng-click="backTo()">
|
<a class="p10" ng-click="goBack()">
|
||||||
<span class="text-close">
|
<span class="text-close">
|
||||||
<i class="fi-x size-24"></i>
|
<i class="fi-x size-24"></i>
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
<div class="content preferences text-center">
|
<div class="content preferences text-center">
|
||||||
<div ng-show="step == 1">
|
<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>
|
<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 )">
|
<div class="size-14 text-gray columns" ng-show="(index.n>1 && index.m != index.n )">
|
||||||
<span translate>
|
<span translate>
|
||||||
|
|
@ -62,20 +62,12 @@
|
||||||
</div>
|
</div>
|
||||||
</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">
|
<p class="text-center columns text-gray" ng-show="index.n==1 && step == 1">
|
||||||
<span translate>
|
<span translate>
|
||||||
You need the wallet recovery phrase to restore this personal wallet. Write it down and keep them somewhere safe.
|
You need the wallet recovery phrase to restore this personal wallet. Write it down and keep them somewhere safe.
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</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="row" ng-show="!credentialsEncrypted">
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="panel" ng-class="{'enable_text_select': index.network == 'testnet'}">
|
<div class="panel" ng-class="{'enable_text_select': index.network == 'testnet'}">
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
ng-init="titleSection='Export Wallet'; goBackToState = 'preferencesAdvanced'">
|
ng-init="titleSection='Export Wallet'; goBackToState = 'preferencesAdvanced'">
|
||||||
</div>
|
</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>
|
<h4></h4>
|
||||||
<div ng-show="!backupWalletPlainText">
|
<div ng-show="!backupWalletPlainText">
|
||||||
<div class="text-warning size-14 m20b" ng-show="error">
|
<div class="text-warning size-14 m20b" ng-show="error">
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form>
|
<form ng-hide="touchidEnabled && !touchidSuccess">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<label for="password" translate>Set up a password </label>
|
<label for="password" translate>Set up a password </label>
|
||||||
|
|
|
||||||
|
|
@ -7,47 +7,59 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
var prevState;
|
var prevState;
|
||||||
$scope.customWords = [];
|
$scope.customWords = [];
|
||||||
$scope.walletName = fc.credentials.walletName;
|
$scope.walletName = fc.credentials.walletName;
|
||||||
|
$scope.credentialsEncrypted = fc.isPrivKeyEncrypted;
|
||||||
|
|
||||||
var handleEncryptedWallet = function(client, cb) {
|
$scope.init = function(state) {
|
||||||
if (!walletService.isEncrypted(client)) return cb();
|
prevState = state || 'walletHome';
|
||||||
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
|
$scope.step = 1;
|
||||||
if (err) return cb(err);
|
$scope.deleted = isDeletedSeed();
|
||||||
return cb(walletService.unlock(client, password));
|
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()) {
|
function shuffledWords(words) {
|
||||||
$scope.credentialsEncrypted = true;
|
var sort = lodash.sortBy(words);
|
||||||
passwordRequest();
|
|
||||||
} else {
|
|
||||||
if (!isDeletedSeed())
|
|
||||||
initWords();
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.init = function(state) {
|
return lodash.map(sort, function(w) {
|
||||||
prevState = state;
|
return {
|
||||||
$scope.passphrase = '';
|
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.shuffledMnemonicWords = shuffledWords($scope.mnemonicWords);
|
||||||
|
$scope.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||||
|
$scope.useIdeograms = words.indexOf("\u3000") >= 0;
|
||||||
|
$scope.passphrase = '';
|
||||||
$scope.customWords = [];
|
$scope.customWords = [];
|
||||||
$scope.step = 1;
|
$scope.step = 1;
|
||||||
$scope.deleted = isDeletedSeed();
|
|
||||||
$scope.credentialsEncrypted = false;
|
|
||||||
$scope.selectComplete = false;
|
$scope.selectComplete = false;
|
||||||
$scope.backupError = false;
|
$scope.backupError = false;
|
||||||
|
|
||||||
if (!platformInfo.isCordova) return;
|
$timeout(function() {
|
||||||
if (isDeletedSeed()) return;
|
$scope.$apply();
|
||||||
|
}, 10);
|
||||||
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);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function isDeletedSeed() {
|
function isDeletedSeed() {
|
||||||
|
|
@ -56,13 +68,14 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.backTo = function() {
|
$scope.goBack = function() {
|
||||||
go.path(prevState);
|
walletService.lock(fc);
|
||||||
|
go.path(prevState || 'walletHome');
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.goToStep = function(n) {
|
$scope.goToStep = function(n) {
|
||||||
if (n == 1)
|
if (n == 1)
|
||||||
$scope.init();
|
$scope.initFlow();
|
||||||
if (n == 2)
|
if (n == 2)
|
||||||
$scope.step = 2;
|
$scope.step = 2;
|
||||||
if (n == 3) {
|
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) {
|
$scope.addButton = function(index, item) {
|
||||||
var newWord = {
|
var newWord = {
|
||||||
word: item.word,
|
word: item.word,
|
||||||
|
|
@ -209,6 +162,18 @@ angular.module('copayApp.controllers').controller('backupController',
|
||||||
}, 1);
|
}, 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) {
|
function backupError(err) {
|
||||||
ongoingProcess.set('validatingWords', false);
|
ongoingProcess.set('validatingWords', false);
|
||||||
$log.debug('Failed to verify backup: ', err);
|
$log.debug('Failed to verify backup: ', err);
|
||||||
|
|
|
||||||
|
|
@ -7,21 +7,27 @@ angular.module('copayApp.controllers').controller('exportController',
|
||||||
var isCordova = platformInfo.isCordova;
|
var isCordova = platformInfo.isCordova;
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
$scope.isEncrypted = fc.isPrivKeyEncrypted();
|
$scope.isEncrypted = fc.isPrivKeyEncrypted();
|
||||||
|
$scope.touchidSuccess = null;
|
||||||
|
$scope.touchidEnabled = null;
|
||||||
$scope.error = null;
|
$scope.error = null;
|
||||||
$scope.success = null;
|
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function(state) {
|
||||||
if (!isCordova) return;
|
if (!isCordova) return;
|
||||||
|
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
var touchidAvailable = fingerprintService.isAvailable();
|
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;
|
if (!touchidAvailable || !touchidEnabled) return;
|
||||||
|
|
||||||
fingerprintService.check(fc, function(err) {
|
fingerprintService.check(fc, function(err) {
|
||||||
if (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