complete import process - scope only
This commit is contained in:
parent
afc2598d59
commit
dbd78a5ad1
3 changed files with 96 additions and 78 deletions
|
|
@ -4,17 +4,17 @@
|
|||
ng-init="titleSection='Import wallet'; goBackToState = 'add'; noColor = true">
|
||||
</div>
|
||||
|
||||
<div class="content p20b" ng-controller="importController as import" ng-init="type='12'">
|
||||
<div class="content p20b" ng-controller="importController" ng-init="type='12'">
|
||||
<div class="create-tab pr small-only-text-center" ng-hide="create.hideTabs">
|
||||
<div class="row">
|
||||
<div class="tab-container small-4 medium-4 large-4" ng-class="{'selected': type =='12'}">
|
||||
<a href ng-click="import.setType('12')" translate>Recovery Phrase</a>
|
||||
<a href ng-click="setType('12')" translate>Recovery Phrase</a>
|
||||
</div>
|
||||
<div class="tab-container small-4 medium-4 large-4" ng-class="{'selected': type=='file'}">
|
||||
<a href ng-click="import.setType('file')" translate>File/Text Backup</a>
|
||||
<a href ng-click="setType('file')" translate>File/Text Backup</a>
|
||||
</div>
|
||||
<div class="tab-container small-4 medium-4 large-4" ng-class="{'selected': type=='hwWallet'}">
|
||||
<a href ng-click="import.setType('hwWallet')" translate>Hardware Wallet</a>
|
||||
<a href ng-click="setType('hwWallet')" translate>Hardware Wallet</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<div class="box-notification m20b" ng-show="import.importErr">
|
||||
<div ng-show="import.importErr" class="text-warning">
|
||||
<div class="box-notification m20b" ng-show="importErr">
|
||||
<div ng-show="importErr" class="text-warning">
|
||||
<div class="m10 text-bold" translate>Could not access the wallet at the server. Please check:</div>
|
||||
<ul class="size-12">
|
||||
<li translate>The password of the recovery phrase (if set)</li>
|
||||
|
|
@ -37,15 +37,15 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box-notification m20b" ng-show="import.error">
|
||||
<div class="text-warning">{{import.error|translate}}</div>
|
||||
<div class="box-notification m20b" ng-show="error">
|
||||
<div class="text-warning">{{error|translate}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<form name="importForm12" ng-submit="import.importMnemonic(importForm12)" novalidate>
|
||||
<form name="importForm12" ng-submit="importMnemonic(importForm12)" novalidate>
|
||||
<label for="words">
|
||||
<span translate>Type the Recovery Phrase (usually 12 words)</span>:
|
||||
</label>
|
||||
|
|
@ -101,33 +101,33 @@
|
|||
<div ng-show="type == 'file' ">
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<div class="box-notification m20b" ng-show="import.error">
|
||||
<div class="box-notification m20b" ng-show="error">
|
||||
<span class="text-warning size-14">
|
||||
{{import.error|translate}}
|
||||
{{error|translate}}
|
||||
</span>
|
||||
</div>
|
||||
<form name="importForm" ng-submit="import.importBlob(importForm)" novalidate>
|
||||
<form name="importForm" ng-submit="importBlob(importForm)" novalidate>
|
||||
|
||||
<div ng-show="!index.isSafari && !index.isCordova" class="line-b m10b">
|
||||
<label for="backupFile">
|
||||
<span translate>Choose a backup file from your computer</span> <i class="fi-laptop"></i>
|
||||
</label>
|
||||
<input type="file" class="form-control" placeholder="{{'Select a backup file'|translate}}"
|
||||
name="backupFile" ng-model="import.backupFile" ng-file-select>
|
||||
name="backupFile" ng-model="backupFile" ng-file-select>
|
||||
</div>
|
||||
|
||||
<div ng-show="index.isSafari || index.isCordova">
|
||||
<label for="backupText">
|
||||
<span translate>Paste the backup plain text code</span> <i class="fi-clipboard"></i>
|
||||
</label>
|
||||
<textarea class="form-control" name="backupText" ng-model="import.backupText" rows="5"></textarea>
|
||||
<textarea class="form-control" name="backupText" ng-model="backupText" rows="5"></textarea>
|
||||
</div>
|
||||
|
||||
<label for="password"><span translate>Password</span>
|
||||
</label>
|
||||
<div class="input">
|
||||
<input type="password" class="form-control" placeholder="{{'Your password'|translate}}"
|
||||
name="password" ng-model="import.password">
|
||||
name="password" ng-model="password">
|
||||
</div>
|
||||
|
||||
<div class="m10t oh" ng-init="hideAdv=true">
|
||||
|
|
@ -150,7 +150,7 @@
|
|||
</div>
|
||||
|
||||
<button translate type="submit" class="button round expand black"
|
||||
ng-disabled="importForm.$invalid || !import.password ">
|
||||
ng-disabled="importForm.$invalid || !password ">
|
||||
Import backup
|
||||
</button>
|
||||
</form>
|
||||
|
|
@ -161,34 +161,34 @@
|
|||
<div ng-show="type == 'hwWallet'">
|
||||
<div class="row">
|
||||
<div class="large-12 columns">
|
||||
<div class="box-notification m20b" ng-show="import.error">
|
||||
<div class="box-notification m20b" ng-show="error">
|
||||
<span class="text-warning size-14">
|
||||
{{import.error|translate}}
|
||||
{{error|translate}}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<form name="importForm3" ng-submit="import.importHW(importForm3)" novalidate>
|
||||
<div ng-show="!import.seedOptions[0]">
|
||||
<form name="importForm3" ng-submit="importHW(importForm3)" novalidate>
|
||||
<div ng-show="!seedOptions[0]">
|
||||
<span translate>No hardware wallets supported on this device</span>
|
||||
</div>
|
||||
<div ng-show="import.seedOptions[0]">
|
||||
<div ng-show="seedOptions[0]">
|
||||
<div>
|
||||
<label><span translate>Wallet Recovery Phrase</span>
|
||||
<select class="m10t" ng-model="seedSource"
|
||||
ng-options="seed as seed.label for seed in import.seedOptions"
|
||||
ng-change="import.setSeedSource()">
|
||||
ng-options="seed as seed.label for seed in seedOptions"
|
||||
ng-change="setSeedSource()">
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div ng-show="import.seedSourceId == 'trezor' || import.seedSourceId == 'ledger'">
|
||||
<div ng-show="seedSourceId == 'trezor' || seedSourceId == 'ledger'">
|
||||
|
||||
<label class="oh"><span translate>Account Number</span>
|
||||
<input type="number" id="account" ng-model="account">
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="oh" ng-show="import.seedSourceId == 'trezor'">
|
||||
<div class="oh" ng-show="seedSourceId == 'trezor'">
|
||||
<ion-toggle ng-model="isMultisig" toggle-class="toggle-balanced" class="bct">
|
||||
<span class="toggle-label" translate>Shared Wallet</span>
|
||||
</ion-toggle>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ angular.module('copayApp.controllers').controller('exportController',
|
|||
$scope.isCordova = platformInfo.isCordova;
|
||||
$scope.isSafari = platformInfo.isSafari;
|
||||
$scope.error = null;
|
||||
console.log(fc.credentials);
|
||||
|
||||
$scope.init = function(state) {
|
||||
$scope.QROpts = false;
|
||||
|
|
@ -79,7 +80,8 @@ angular.module('copayApp.controllers').controller('exportController',
|
|||
}
|
||||
}
|
||||
|
||||
return info.type + '|' + info.data;
|
||||
var code = info.type + '|' + info.data + '|' + c.network.charAt(0).toLowerCase() + '|' + c.account + '|' + c.derivationStrategy + '|' + (c.mnemonicHasPassphrase);
|
||||
return code;
|
||||
};
|
||||
|
||||
$scope.downloadWalletBackup = function() {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('importController',
|
||||
function($scope, $rootScope, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, lodash, ledger, trezor, derivationPathHelper, platformInfo, bwsError, bwcService, ongoingProcess) {
|
||||
function($scope, $rootScope, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, ledger, trezor, derivationPathHelper, platformInfo, bwcService, ongoingProcess) {
|
||||
|
||||
var isChromeApp = platformInfo.isChromeApp;
|
||||
var isDevel = platformInfo.isDevel;
|
||||
|
||||
var self = this;
|
||||
var reader = new FileReader();
|
||||
var defaults = configService.getDefaults();
|
||||
var errors = bwcService.getErrors();
|
||||
|
|
@ -14,52 +12,70 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
$scope.derivationPath = derivationPathHelper.default;
|
||||
$scope.account = 1;
|
||||
$scope.processingCode = null;
|
||||
self.importErr = false;
|
||||
$scope.importErr = false;
|
||||
|
||||
var updateSeedSourceSelect = function() {
|
||||
self.seedOptions = [];
|
||||
$scope.seedOptions = [];
|
||||
|
||||
if (isChromeApp) {
|
||||
self.seedOptions.push({
|
||||
$scope.seedOptions.push({
|
||||
id: 'ledger',
|
||||
label: 'Ledger Hardware Wallet',
|
||||
});
|
||||
}
|
||||
|
||||
if (isChromeApp || isDevel) {
|
||||
self.seedOptions.push({
|
||||
$scope.seedOptions.push({
|
||||
id: 'trezor',
|
||||
label: 'Trezor Hardware Wallet',
|
||||
});
|
||||
$scope.seedSource = self.seedOptions[0];
|
||||
$scope.seedSource = $scope.seedOptions[0];
|
||||
}
|
||||
};
|
||||
|
||||
$scope.processCode = function(code) {
|
||||
$scope.importErr = false;
|
||||
$scope.error = null;
|
||||
ongoingProcess.set('processingCode', true);
|
||||
self.importErr = false;
|
||||
var parsedCode = code.split('|');
|
||||
|
||||
if (parsedCode.length != 2) {
|
||||
if (parsedCode.length != 6) {
|
||||
ongoingProcess.set('processingCode', false);
|
||||
$log.debug('Missing parameters');
|
||||
return;
|
||||
}
|
||||
|
||||
var info = {
|
||||
type: parsedCode[0],
|
||||
data: parsedCode[1],
|
||||
network: parsedCode[2] == 't' ? 'testnet' : 'livenet',
|
||||
account: parseInt(parsedCode[3]),
|
||||
derivationStrategy: parsedCode[4],
|
||||
mnemonicHasPassphrase: parsedCode[5]
|
||||
};
|
||||
|
||||
var client = bwcService.getClient(null, null);
|
||||
|
||||
if (info.type == 1) {
|
||||
client.seedFromMnemonic(info.data, {});
|
||||
client.seedFromMnemonic(info.data, {
|
||||
network: info.network,
|
||||
account: info.account,
|
||||
derivationStrategy: info.derivationStrategy
|
||||
});
|
||||
}
|
||||
|
||||
if (info.type == 2) {
|
||||
client.seedFromExtendedPrivateKey(info.data, {});
|
||||
client.seedFromExtendedPrivateKey(info.data, {
|
||||
account: info.account,
|
||||
derivationStrategy: info.derivationStrategy
|
||||
});
|
||||
}
|
||||
|
||||
if (info.type == 3) {
|
||||
client.seedFromExtendedPublicKey(info.data, {});
|
||||
client.seedFromExtendedPublicKey(info.data, {
|
||||
account: info.account,
|
||||
derivationStrategy: info.derivationStrategy
|
||||
});
|
||||
}
|
||||
|
||||
$scope.words = info.data;
|
||||
|
|
@ -76,9 +92,9 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
}, 1);
|
||||
};
|
||||
|
||||
this.setType = function(type) {
|
||||
$scope.setType = function(type) {
|
||||
$scope.type = type;
|
||||
this.error = null;
|
||||
$scope.error = null;
|
||||
$timeout(function() {
|
||||
$rootScope.$apply();
|
||||
}, 1);
|
||||
|
|
@ -87,14 +103,14 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
var _importBlob = function(str, opts) {
|
||||
var str2, err;
|
||||
try {
|
||||
str2 = sjcl.decrypt(self.password, str);
|
||||
str2 = sjcl.decrypt($scope.password, str);
|
||||
} catch (e) {
|
||||
err = gettext('Could not decrypt file, check your password');
|
||||
$log.warn(e);
|
||||
};
|
||||
|
||||
if (err) {
|
||||
self.error = err;
|
||||
$scope.error = err;
|
||||
$timeout(function() {
|
||||
$rootScope.$apply();
|
||||
});
|
||||
|
|
@ -109,7 +125,7 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
profileService.importWallet(str2, opts, function(err, walletId) {
|
||||
ongoingProcess.set('importingWallet', false);
|
||||
if (err) {
|
||||
self.error = err;
|
||||
$scope.error = err;
|
||||
} else {
|
||||
$rootScope.$emit('Local/WalletImported', walletId);
|
||||
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
|
||||
|
|
@ -126,9 +142,9 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
ongoingProcess.set('importingWallet', false);
|
||||
if (err) {
|
||||
if (err instanceof errors.NOT_AUTHORIZED) {
|
||||
self.importErr = true;
|
||||
$scope.importErr = true;
|
||||
} else {
|
||||
self.error = err;
|
||||
$scope.error = err;
|
||||
}
|
||||
return $timeout(function() {
|
||||
$scope.$apply();
|
||||
|
|
@ -151,9 +167,9 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
|
||||
if (err) {
|
||||
if (err instanceof errors.NOT_AUTHORIZED) {
|
||||
self.importErr = true;
|
||||
$scope.importErr = true;
|
||||
} else {
|
||||
self.error = err;
|
||||
$scope.error = err;
|
||||
}
|
||||
return $timeout(function() {
|
||||
$scope.$apply();
|
||||
|
|
@ -185,9 +201,9 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
}
|
||||
};
|
||||
|
||||
this.importBlob = function(form) {
|
||||
$scope.importBlob = function(form) {
|
||||
if (form.$invalid) {
|
||||
this.error = gettext('There is an error in the form');
|
||||
$scope.error = gettext('There is an error in the form');
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
|
|
@ -199,7 +215,7 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
var password = form.password.$modelValue;
|
||||
|
||||
if (!backupFile && !backupText) {
|
||||
this.error = gettext('Please, select your backup file');
|
||||
$scope.error = gettext('Please, select your backup file');
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
|
|
@ -216,9 +232,9 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
}
|
||||
};
|
||||
|
||||
this.importMnemonic = function(form) {
|
||||
$scope.importMnemonic = function(form) {
|
||||
if (form.$invalid) {
|
||||
this.error = gettext('There is an error in the form');
|
||||
$scope.error = gettext('There is an error in the form');
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
|
|
@ -232,7 +248,7 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
|
||||
var pathData = derivationPathHelper.parse($scope.derivationPath);
|
||||
if (!pathData) {
|
||||
this.error = gettext('Invalid derivation path');
|
||||
$scope.error = gettext('Invalid derivation path');
|
||||
return;
|
||||
}
|
||||
opts.account = pathData.account;
|
||||
|
|
@ -240,21 +256,21 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
opts.derivationStrategy = pathData.derivationStrategy;
|
||||
|
||||
var words = form.words.$modelValue;
|
||||
this.error = null;
|
||||
$scope.error = null;
|
||||
|
||||
if (!words) {
|
||||
this.error = gettext('Please enter the recovery phrase');
|
||||
$scope.error = gettext('Please enter the recovery phrase');
|
||||
} else if (words.indexOf('xprv') == 0 || words.indexOf('tprv') == 0) {
|
||||
return _importExtendedPrivateKey(words, opts);
|
||||
} else {
|
||||
var wordList = words.split(/[\u3000\s]+/);
|
||||
|
||||
if ((wordList.length % 3) != 0) {
|
||||
this.error = gettext('Wrong number of recovery words:') + wordList.length;
|
||||
$scope.error = gettext('Wrong number of recovery words:') + wordList.length;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.error) {
|
||||
if ($scope.error) {
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
|
|
@ -267,12 +283,12 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
_importMnemonic(words, opts);
|
||||
};
|
||||
|
||||
this.importTrezor = function(account, isMultisig) {
|
||||
var self = this;
|
||||
$scope.importTrezor = function(account, isMultisig) {
|
||||
var $scope = $scope;
|
||||
trezor.getInfoForNewWallet(isMultisig, account, function(err, lopts) {
|
||||
ongoingProcess.clear();
|
||||
if (err) {
|
||||
self.error = err;
|
||||
$scope.error = err;
|
||||
$scope.$apply();
|
||||
return;
|
||||
}
|
||||
|
|
@ -285,7 +301,7 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
profileService.importExtendedPublicKey(lopts, function(err, walletId) {
|
||||
ongoingProcess.set('importingWallet', false);
|
||||
if (err) {
|
||||
self.error = err;
|
||||
$scope.error = err;
|
||||
return $timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
|
|
@ -297,56 +313,56 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
}, 100);
|
||||
};
|
||||
|
||||
this.importHW = function(form) {
|
||||
$scope.importHW = function(form) {
|
||||
if (form.$invalid || $scope.account < 0) {
|
||||
this.error = gettext('There is an error in the form');
|
||||
$scope.error = gettext('There is an error in the form');
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.error = '';
|
||||
this.importErr = false;
|
||||
$scope.error = '';
|
||||
$scope.importErr = false;
|
||||
|
||||
var account = +$scope.account;
|
||||
|
||||
if (self.seedSourceId == 'trezor') {
|
||||
if ($scope.seedSourceId == 'trezor') {
|
||||
if (account < 1) {
|
||||
this.error = gettext('Invalid account number');
|
||||
$scope.error = gettext('Invalid account number');
|
||||
return;
|
||||
}
|
||||
account = account - 1;
|
||||
}
|
||||
|
||||
switch (self.seedSourceId) {
|
||||
switch ($scope.seedSourceId) {
|
||||
case ('ledger'):
|
||||
ongoingProcess.set('connectingledger', true);
|
||||
self.importLedger(account);
|
||||
$scope.importLedger(account);
|
||||
break;
|
||||
case ('trezor'):
|
||||
ongoingProcess.set('connectingtrezor', true);
|
||||
self.importTrezor(account, $scope.isMultisig);
|
||||
$scope.importTrezor(account, $scope.isMultisig);
|
||||
break;
|
||||
default:
|
||||
throw ('Error: bad source id');
|
||||
};
|
||||
};
|
||||
|
||||
this.setSeedSource = function() {
|
||||
$scope.setSeedSource = function() {
|
||||
if (!$scope.seedSource) return;
|
||||
self.seedSourceId = $scope.seedSource.id;
|
||||
$scope.seedSourceId = $scope.seedSource.id;
|
||||
|
||||
$timeout(function() {
|
||||
$rootScope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
this.importLedger = function(account) {
|
||||
var self = this;
|
||||
$scope.importLedger = function(account) {
|
||||
var $scope = $scope;
|
||||
ledger.getInfoForNewWallet(true, account, function(err, lopts) {
|
||||
ongoingProcess.clear();
|
||||
if (err) {
|
||||
self.error = err;
|
||||
$scope.error = err;
|
||||
$scope.$apply();
|
||||
return;
|
||||
}
|
||||
|
|
@ -359,7 +375,7 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
profileService.importExtendedPublicKey(lopts, function(err, walletId) {
|
||||
ongoingProcess.set('importingWallet', false);
|
||||
if (err) {
|
||||
self.error = err;
|
||||
$scope.error = err;
|
||||
return $timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
|
|
@ -372,5 +388,5 @@ angular.module('copayApp.controllers').controller('importController',
|
|||
};
|
||||
|
||||
updateSeedSourceSelect();
|
||||
self.setSeedSource('new');
|
||||
$scope.setSeedSource('new');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue