complete import process

This commit is contained in:
Javier 2016-09-06 16:40:57 -03:00
commit 9632fe8b64
5 changed files with 41 additions and 80 deletions

View file

@ -1,4 +1,4 @@
<ion-view> <ion-view ng-controller="tabsController" ng-init="importInit()">
<ion-nav-bar class="bar-royal"> <ion-nav-bar class="bar-royal">
<ion-nav-title>{{'Import Wallet' | translate}}</ion-nav-title> <ion-nav-title>{{'Import Wallet' | translate}}</ion-nav-title>
<ion-nav-back-button> <ion-nav-back-button>
@ -6,7 +6,7 @@
</ion-nav-back-button> </ion-nav-back-button>
</ion-nav-bar> </ion-nav-bar>
<ion-content ng-controller="importController" ng-init="phrase = true; importInit()"> <ion-content ng-controller="importController" ng-init="phrase = true; init()">
<div class="row text-center"> <div class="row text-center">
<div class="col" ng-click="phrase = true; file = hardware = false" ng-style="phrase && {'border-bottom': '2px solid'}"> <div class="col" ng-click="phrase = true; file = hardware = false" ng-style="phrase && {'border-bottom': '2px solid'}">
<span translate>Recovery phrase</span> <span translate>Recovery phrase</span>
@ -24,18 +24,3 @@
<div ng-include="'views/tab-import-hardware.html'" ng-if="hardware"></div> <div ng-include="'views/tab-import-hardware.html'" ng-if="hardware"></div>
</ion-content> </ion-content>
</ion-view> </ion-view>
<!-- <ion-view ng-controller="tabsController" ng-init="importInit()">
<ion-tabs class="tabs-striped tabs-color-positive tabs-color-active-positive tabs-top">
<div ng-if="!fromOnboarding">
<div ng-include="'views/tab-import'"></div>
</div>
<div ng-if="fromOnboarding">
<div ng-include="'views/tab-import'"></div>
</div>
</ion-tabs>
</ion-view> -->

View file

@ -14,7 +14,7 @@
<button class="button button-block get-started col col-75" href ui-sref="onboarding.tour" translate>Get started</button> <button class="button button-block get-started col col-75" href ui-sref="onboarding.tour" translate>Get started</button>
</div> </div>
<div class="row"> <div class="row">
<button class="button button-block restore col col-75" translate href ui-sref="onboarding.import.phrase({'fromOnboarding':true})">Restore</button> <button class="button button-block restore col col-75" translate href ui-sref="onboarding.import({'fromOnboarding':true})">Restore</button>
</div> </div>
</ion-content> </ion-content>
</ion-view> </ion-view>

View file

@ -11,21 +11,16 @@
<div class="input-label" translate> <div class="input-label" translate>
Wallet Type Wallet Type
</div> </div>
<select ng-model="seedSource"
ng-options="seed as seed.label for seed in seedOptions" <select ng-model="seedSource" ng-options="seed as seed.label for seed in seedOptions"></select>
ng-change="setSeedSource()">
</select>
</label> </label>
<label class="item item-input item-stacked-label" <label class="item item-input item-stacked-label" ng-show="seedSource.id == 'trezor' || seedSource.id == 'ledger'">
ng-show="seedSourceId == 'trezor' || seedSourceId == 'ledger'">
<span class="input-label" translate>Account Number</span> <span class="input-label" translate>Account Number</span>
<input type="number" id="account" ng-model="account" ignore-mouse-wheel> <input type="number" ng-model="formData.account" ignore-mouse-wheel>
</label> </label>
<ion-toggle ng-show="seedSourceId == 'trezor'" <ion-toggle ng-show="seedSource.id == 'trezor'" ng-model="formData.isMultisig" toggle-class="toggle-positive">
ng-model="isMultisig"
toggle-class="toggle-positive">
<span translate>Shared Wallet</span> <span translate>Shared Wallet</span>
</ion-toggle> </ion-toggle>
@ -37,9 +32,8 @@
<div ng-show="showAdv"> <div ng-show="showAdv">
<label class="item item-input item-stacked-label"> <label class="item item-input item-stacked-label">
<span class="input-label">Wallet Service URL</span> <span class="input-label">Wallet Service URL</span>
<input type="text" id="bwsurl" name="bwsurl" ng-model="bwsurl"> <input type="text" ng-model="formData.bwsurl">
</label> </label>
</div> </div>
</div> </div>

View file

@ -1,23 +1,26 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('importController', angular.module('copayApp.controllers').controller('importController',
function($scope, $rootScope, $timeout, $log, $state, $stateParams, $ionicHistory, profileService, configService, sjcl, gettext, ledger, trezor, derivationPathHelper, platformInfo, bwcService, ongoingProcess, walletService, popupService, gettextCatalog) { function($scope, $timeout, $log, $state, $stateParams, profileService, configService, sjcl, ledger, trezor, derivationPathHelper, platformInfo, bwcService, ongoingProcess, walletService, popupService, gettextCatalog) {
var isChromeApp = platformInfo.isChromeApp; var isChromeApp = platformInfo.isChromeApp;
var isDevel = platformInfo.isDevel; var isDevel = platformInfo.isDevel;
var reader = new FileReader(); var reader = new FileReader();
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
var errors = bwcService.getErrors(); var errors = bwcService.getErrors();
var derivationPath = 'livenet';
$scope.isSafari = platformInfo.isSafari;
$scope.isCordova = platformInfo.isCordova;
$scope.formData = {};
$scope.formData.bwsurl = defaults.bws.url;
$scope.formData.derivationPath = derivationPathHelper.default;
$scope.formData.account = 1;
$scope.importErr = false;
var updateSeedSourceSelect = function() { $scope.init = function() {
$scope.isSafari = platformInfo.isSafari;
$scope.isCordova = platformInfo.isCordova;
$scope.formData = {};
$scope.formData.bwsurl = defaults.bws.url;
$scope.formData.derivationPath = derivationPathHelper.default;
$scope.formData.account = 1;
$scope.importErr = false;
if ($stateParams.code)
$scope.processWalletInfo($stateParams.code);
$scope.seedOptions = []; $scope.seedOptions = [];
if (isChromeApp) { if (isChromeApp) {
@ -38,6 +41,7 @@ angular.module('copayApp.controllers').controller('importController',
$scope.processWalletInfo = function(code) { $scope.processWalletInfo = function(code) {
if (!code) return; if (!code) return;
$scope.importErr = false; $scope.importErr = false;
var parsedCode = code.split('|'); var parsedCode = code.split('|');
@ -58,19 +62,12 @@ angular.module('copayApp.controllers').controller('importController',
if (info.type == 1 && info.hasPassphrase) if (info.type == 1 && info.hasPassphrase)
popupService.showAlert(gettextCatalog.getString('Password required. Make sure to enter your password in advanced options')); popupService.showAlert(gettextCatalog.getString('Password required. Make sure to enter your password in advanced options'));
$scope.derivationPath = info.derivationPath; $scope.formData.derivationPath = info.derivationPath;
$scope.testnetEnabled = info.network == 'testnet' ? true : false; $scope.formData.testnetEnabled = info.network == 'testnet' ? true : false;
$timeout(function() { $timeout(function() {
$scope.words = info.data; $scope.formData.words = info.data;
$rootScope.$apply(); $scope.$apply();
}, 1);
};
$scope.setType = function(type) {
$scope.type = type;
$timeout(function() {
$rootScope.$apply();
}, 1); }, 1);
}; };
@ -85,9 +82,6 @@ angular.module('copayApp.controllers').controller('importController',
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err); popupService.showAlert(gettextCatalog.getString('Error'), err);
$timeout(function() {
$rootScope.$apply();
});
return; return;
} }
@ -179,7 +173,7 @@ angular.module('copayApp.controllers').controller('importController',
}; };
$scope.setDerivationPath = function() { $scope.setDerivationPath = function() {
derivationPath = $scope.formData.testnetEnabled ? derivationPathHelper.defaultTestnet : derivationPathHelper.default; $scope.formData.derivationPath = $scope.formData.testnetEnabled ? derivationPathHelper.defaultTestnet : derivationPathHelper.default;
}; };
$scope.getFile = function() { $scope.getFile = function() {
@ -228,7 +222,8 @@ angular.module('copayApp.controllers').controller('importController',
if ($scope.formData.bwsurl) if ($scope.formData.bwsurl)
opts.bwsurl = $scope.formData.bwsurl; opts.bwsurl = $scope.formData.bwsurl;
var pathData = derivationPathHelper.parse(derivationPath); var pathData = derivationPathHelper.parse($scope.formData.derivationPath);
if (!pathData) { if (!pathData) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Invalid derivation path')); popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Invalid derivation path'));
return; return;
@ -268,7 +263,7 @@ angular.module('copayApp.controllers').controller('importController',
} }
lopts.externalSource = 'trezor'; lopts.externalSource = 'trezor';
lopts.bwsurl = $scope.bwsurl; lopts.bwsurl = $scope.formData.bwsurl;
ongoingProcess.set('importingWallet', true); ongoingProcess.set('importingWallet', true);
$log.debug('Import opts', lopts); $log.debug('Import opts', lopts);
@ -284,45 +279,37 @@ angular.module('copayApp.controllers').controller('importController',
}; };
$scope.importHW = function(form) { $scope.importHW = function(form) {
if (form.$invalid || $scope.account < 0) { if (form.$invalid || $scope.formData.ccount < 0) {
popupService.showAlert(gettextCatalog.getString('There is an error in the form')); popupService.showAlert(gettextCatalog.getString('There is an error in the form'));
return; return;
} }
$scope.importErr = false; $scope.importErr = false;
var account = +$scope.account; var account = $scope.formData.ccount;
if ($scope.seedSourceId == 'trezor') { if ($scope.seedSource.id == 'trezor') {
if (account < 1) { if (account < 1) {
$scope.error = gettext('Invalid account number'); popupService.showAlert(gettextCatalog.getString('Invalid account number'));
return; return;
} }
account = account - 1; account = account - 1;
} }
switch ($scope.seedSourceId) { switch ($scope.seedSource.id) {
case ('ledger'): case ('ledger'):
ongoingProcess.set('connectingledger', true); ongoingProcess.set('connectingledger', true);
$scope.importLedger(account); $scope.importLedger(account);
break; break;
case ('trezor'): case ('trezor'):
ongoingProcess.set('connectingtrezor', true); ongoingProcess.set('connectingtrezor', true);
$scope.importTrezor(account, $scope.isMultisig); $scope.importTrezor(account, $scope.formData.isMultisig);
break; break;
default: default:
throw ('Error: bad source id'); throw ('Error: bad source id');
}; };
}; };
$scope.setSeedSource = function() {
if (!$scope.seedSource) return;
$scope.seedSourceId = $scope.seedSource.id;
$timeout(function() {
$rootScope.$apply();
});
};
$scope.importLedger = function(account) { $scope.importLedger = function(account) {
ledger.getInfoForNewWallet(true, account, function(err, lopts) { ledger.getInfoForNewWallet(true, account, function(err, lopts) {
ongoingProcess.clear(); ongoingProcess.clear();
@ -332,7 +319,7 @@ angular.module('copayApp.controllers').controller('importController',
} }
lopts.externalSource = 'ledger'; lopts.externalSource = 'ledger';
lopts.bwsurl = $scope.bwsurl; lopts.bwsurl = $scope.formData.bwsurl;
ongoingProcess.set('importingWallet', true); ongoingProcess.set('importingWallet', true);
$log.debug('Import opts', lopts); $log.debug('Import opts', lopts);
@ -348,7 +335,6 @@ angular.module('copayApp.controllers').controller('importController',
}; };
var finish = function(wallet) { var finish = function(wallet) {
walletService.updateRemotePreferences(wallet, {}, function() { walletService.updateRemotePreferences(wallet, {}, function() {
$log.debug('Remote preferences saved for:' + wallet.credentials.walletId) $log.debug('Remote preferences saved for:' + wallet.credentials.walletId)
}); });
@ -361,8 +347,4 @@ angular.module('copayApp.controllers').controller('importController',
} }
$state.go('tabs.home'); $state.go('tabs.home');
}; };
updateSeedSourceSelect();
$scope.setSeedSource();
if ($stateParams.code) $scope.processWalletInfo($stateParams.code);
}); });

View file

@ -3,7 +3,7 @@
angular.module('copayApp.controllers').controller('welcomeController', function($scope, $state, $timeout, $log, $ionicPopup, profileService) { angular.module('copayApp.controllers').controller('welcomeController', function($scope, $state, $timeout, $log, $ionicPopup, profileService) {
$scope.goImport = function(code) { $scope.goImport = function(code) {
$state.go('onboarding.import.phrase', { $state.go('onboarding.import', {
fromOnboarding: true, fromOnboarding: true,
code: code code: code
}); });