diff --git a/public/views/import.html b/public/views/import.html index 8f1eb7261..aa6d916a2 100644 --- a/public/views/import.html +++ b/public/views/import.html @@ -1,4 +1,4 @@ - + {{'Import Wallet' | translate}} @@ -6,7 +6,7 @@ - +
Recovery phrase @@ -24,18 +24,3 @@
- - - diff --git a/public/views/onboarding/welcome.html b/public/views/onboarding/welcome.html index 1c97d5274..f71e8a053 100644 --- a/public/views/onboarding/welcome.html +++ b/public/views/onboarding/welcome.html @@ -14,7 +14,7 @@
- +
diff --git a/public/views/tab-import-hardware.html b/public/views/tab-import-hardware.html index 5f0b7c1b6..18996d0da 100644 --- a/public/views/tab-import-hardware.html +++ b/public/views/tab-import-hardware.html @@ -11,21 +11,16 @@
Wallet Type
- + + -
diff --git a/src/js/controllers/import.js b/src/js/controllers/import.js index 8206ed56b..01d452c6b 100644 --- a/src/js/controllers/import.js +++ b/src/js/controllers/import.js @@ -1,23 +1,26 @@ 'use strict'; 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 isDevel = platformInfo.isDevel; var reader = new FileReader(); var defaults = configService.getDefaults(); 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 = []; if (isChromeApp) { @@ -38,6 +41,7 @@ angular.module('copayApp.controllers').controller('importController', $scope.processWalletInfo = function(code) { if (!code) return; + $scope.importErr = false; var parsedCode = code.split('|'); @@ -58,19 +62,12 @@ angular.module('copayApp.controllers').controller('importController', if (info.type == 1 && info.hasPassphrase) popupService.showAlert(gettextCatalog.getString('Password required. Make sure to enter your password in advanced options')); - $scope.derivationPath = info.derivationPath; - $scope.testnetEnabled = info.network == 'testnet' ? true : false; + $scope.formData.derivationPath = info.derivationPath; + $scope.formData.testnetEnabled = info.network == 'testnet' ? true : false; $timeout(function() { - $scope.words = info.data; - $rootScope.$apply(); - }, 1); - }; - - $scope.setType = function(type) { - $scope.type = type; - $timeout(function() { - $rootScope.$apply(); + $scope.formData.words = info.data; + $scope.$apply(); }, 1); }; @@ -85,9 +82,6 @@ angular.module('copayApp.controllers').controller('importController', if (err) { popupService.showAlert(gettextCatalog.getString('Error'), err); - $timeout(function() { - $rootScope.$apply(); - }); return; } @@ -179,7 +173,7 @@ angular.module('copayApp.controllers').controller('importController', }; $scope.setDerivationPath = function() { - derivationPath = $scope.formData.testnetEnabled ? derivationPathHelper.defaultTestnet : derivationPathHelper.default; + $scope.formData.derivationPath = $scope.formData.testnetEnabled ? derivationPathHelper.defaultTestnet : derivationPathHelper.default; }; $scope.getFile = function() { @@ -228,7 +222,8 @@ angular.module('copayApp.controllers').controller('importController', if ($scope.formData.bwsurl) opts.bwsurl = $scope.formData.bwsurl; - var pathData = derivationPathHelper.parse(derivationPath); + var pathData = derivationPathHelper.parse($scope.formData.derivationPath); + if (!pathData) { popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Invalid derivation path')); return; @@ -268,7 +263,7 @@ angular.module('copayApp.controllers').controller('importController', } lopts.externalSource = 'trezor'; - lopts.bwsurl = $scope.bwsurl; + lopts.bwsurl = $scope.formData.bwsurl; ongoingProcess.set('importingWallet', true); $log.debug('Import opts', lopts); @@ -284,45 +279,37 @@ angular.module('copayApp.controllers').controller('importController', }; $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')); return; } + $scope.importErr = false; - var account = +$scope.account; + var account = $scope.formData.ccount; - if ($scope.seedSourceId == 'trezor') { + if ($scope.seedSource.id == 'trezor') { if (account < 1) { - $scope.error = gettext('Invalid account number'); + popupService.showAlert(gettextCatalog.getString('Invalid account number')); return; } account = account - 1; } - switch ($scope.seedSourceId) { + switch ($scope.seedSource.id) { case ('ledger'): ongoingProcess.set('connectingledger', true); $scope.importLedger(account); break; case ('trezor'): ongoingProcess.set('connectingtrezor', true); - $scope.importTrezor(account, $scope.isMultisig); + $scope.importTrezor(account, $scope.formData.isMultisig); break; default: 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) { ledger.getInfoForNewWallet(true, account, function(err, lopts) { ongoingProcess.clear(); @@ -332,7 +319,7 @@ angular.module('copayApp.controllers').controller('importController', } lopts.externalSource = 'ledger'; - lopts.bwsurl = $scope.bwsurl; + lopts.bwsurl = $scope.formData.bwsurl; ongoingProcess.set('importingWallet', true); $log.debug('Import opts', lopts); @@ -348,7 +335,6 @@ angular.module('copayApp.controllers').controller('importController', }; var finish = function(wallet) { - walletService.updateRemotePreferences(wallet, {}, function() { $log.debug('Remote preferences saved for:' + wallet.credentials.walletId) }); @@ -361,8 +347,4 @@ angular.module('copayApp.controllers').controller('importController', } $state.go('tabs.home'); }; - - updateSeedSourceSelect(); - $scope.setSeedSource(); - if ($stateParams.code) $scope.processWalletInfo($stateParams.code); }); diff --git a/src/js/controllers/onboarding/welcomeController.js b/src/js/controllers/onboarding/welcomeController.js index f08a5b5eb..bb74b9206 100644 --- a/src/js/controllers/onboarding/welcomeController.js +++ b/src/js/controllers/onboarding/welcomeController.js @@ -3,7 +3,7 @@ angular.module('copayApp.controllers').controller('welcomeController', function($scope, $state, $timeout, $log, $ionicPopup, profileService) { $scope.goImport = function(code) { - $state.go('onboarding.import.phrase', { + $state.go('onboarding.import', { fromOnboarding: true, code: code });