diff --git a/public/views/add.html b/public/views/add.html index 491830b33..01c54b81c 100644 --- a/public/views/add.html +++ b/public/views/add.html @@ -20,7 +20,7 @@ - +

Import wallet

diff --git a/public/views/import.html b/public/views/import.html index 17e6187aa..aa6d916a2 100644 --- a/public/views/import.html +++ b/public/views/import.html @@ -1,33 +1,26 @@ - + + {{'Import Wallet' | translate}} + + + + -
- - - - - - - - - - - + +
+
+ Recovery phrase +
+
+ File/Text +
+
+ Hardware wallet +
-
- - - - - - - - - - - -
- - +
+
+
+
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-file.html b/public/views/tab-import-file.html index 07cae197b..76946086d 100644 --- a/public/views/tab-import-file.html +++ b/public/views/tab-import-file.html @@ -1,61 +1,40 @@ - - - - - - {{'Import wallet' | translate}} - - - - -
- -
- - - - - - - - - Show advanced options - Hide advanced options - - -
- - - -
+ +
+ - - + - - + + + + Show advanced options + Hide advanced options + + +
+ +
+
+ + + diff --git a/public/views/tab-import-hardware.html b/public/views/tab-import-hardware.html index 835a46328..18996d0da 100644 --- a/public/views/tab-import-hardware.html +++ b/public/views/tab-import-hardware.html @@ -1,69 +1,44 @@ - - - - - - {{'Import wallet' | translate}} - +
+
+
+ No hardware wallets supported on this device +
+
- - - - -
-
- No hardware wallets supported on this device +
+
+ + + + + + Shared Wallet + + + + Show advanced options + Hide advanced options + + +
+
+
-
-
- - - - - - - Shared Wallet - - - - Show advanced options - Hide advanced options - - -
- - - -
-
- - -
- - - - - + +
+ diff --git a/public/views/tab-import-phrase.html b/public/views/tab-import-phrase.html index 0473f6944..91447b758 100644 --- a/public/views/tab-import-phrase.html +++ b/public/views/tab-import-phrase.html @@ -1,84 +1,66 @@ - - - - - - Import wallet - +
+
Could not access the wallet at the server. Please check:
+
    +
  • The password of the recovery phrase (if set)
  • +
  • The derivation path
  • +
  • The wallet service URL
  • +
+
+ NOTE: To import a wallet from a 3rd party software, please go to Add Wallet > Create Wallet, and specify the Recovery Phrase there. +
+
- - -
-
Could not access the wallet at the server. Please check:
-
    -
  • The password of the recovery phrase (if set)
  • -
  • The derivation path
  • -
  • The wallet service URL
  • -
-
- NOTE: To import a wallet from a 3rd party software, please go to Add Wallet > Create Wallet, and specify the Recovery Phrase there. +
+
+
+
+ +
+
+
- -
+ + Show advanced options + Hide advanced options + -
-
- -
-
- -
-
+
+ - - Show advanced options - Hide advanced options - + -
+ - + + Testnet + +
+
- - - - - - Testnet - -
-
- - -
- - + + diff --git a/src/js/controllers/import.js b/src/js/controllers/import.js index 4ba74e011..01d452c6b 100644 --- a/src/js/controllers/import.js +++ b/src/js/controllers/import.js @@ -1,21 +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(); - $scope.isSafari = platformInfo.isSafari; - $scope.isCordova = platformInfo.isCordova; - $scope.bwsurl = defaults.bws.url; - $scope.derivationPath = derivationPathHelper.default; - $scope.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) { @@ -36,6 +41,7 @@ angular.module('copayApp.controllers').controller('importController', $scope.processWalletInfo = function(code) { if (!code) return; + $scope.importErr = false; var parsedCode = code.split('|'); @@ -56,26 +62,19 @@ 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); }; var _importBlob = function(str, opts) { var str2, err; try { - str2 = sjcl.decrypt($scope.password, str); + str2 = sjcl.decrypt($scope.formData.password, str); } catch (e) { err = gettextCatalog.getString('Could not decrypt file, check your password'); $log.warn(e); @@ -83,9 +82,6 @@ angular.module('copayApp.controllers').controller('importController', if (err) { popupService.showAlert(gettextCatalog.getString('Error'), err); - $timeout(function() { - $rootScope.$apply(); - }); return; } @@ -147,7 +143,7 @@ angular.module('copayApp.controllers').controller('importController', if (err) $log.error(err); }); } - + $state.go('tabs.home'); }); }, 100); @@ -176,11 +172,8 @@ angular.module('copayApp.controllers').controller('importController', }, 100); }; - $scope.setDerivationPath = function(testnetEnabled) { - if (testnetEnabled) - $scope.derivationPath = derivationPathHelper.defaultTestnet; - else - $scope.derivationPath = derivationPathHelper.default; + $scope.setDerivationPath = function() { + $scope.formData.derivationPath = $scope.formData.testnetEnabled ? derivationPathHelper.defaultTestnet : derivationPathHelper.default; }; $scope.getFile = function() { @@ -188,7 +181,7 @@ angular.module('copayApp.controllers').controller('importController', reader.onloadend = function(evt) { if (evt.target.readyState == FileReader.DONE) { // DONE == 2 var opts = {}; - opts.bwsurl = $scope.bwsurl; + opts.bwsurl = $scope.formData.bwsurl; _importBlob(evt.target.result, opts); } } @@ -200,9 +193,9 @@ angular.module('copayApp.controllers').controller('importController', return; } - var backupFile = $scope.file; - var backupText = form.backupText.$modelValue; - var password = form.password.$modelValue; + var backupFile = $scope.formData.file; + var backupText = $scope.formData.backupText; + var password = $scope.formData.password; if (!backupFile && !backupText) { popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Please, select your backup file')); @@ -213,7 +206,7 @@ angular.module('copayApp.controllers').controller('importController', reader.readAsBinaryString(backupFile); } else { var opts = {}; - opts.bwsurl = $scope.bwsurl; + opts.bwsurl = $scope.formData.bwsurl; _importBlob(backupText, opts); } }; @@ -225,19 +218,22 @@ angular.module('copayApp.controllers').controller('importController', } var opts = {}; - if ($scope.bwsurl) - opts.bwsurl = $scope.bwsurl; - var pathData = derivationPathHelper.parse($scope.derivationPath); + if ($scope.formData.bwsurl) + opts.bwsurl = $scope.formData.bwsurl; + + var pathData = derivationPathHelper.parse($scope.formData.derivationPath); + if (!pathData) { popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Invalid derivation path')); return; } + opts.account = pathData.account; opts.networkName = pathData.networkName; opts.derivationStrategy = pathData.derivationStrategy; - var words = form.words.$modelValue || null; + var words = $scope.formData.words || null; if (!words) { popupService.showAlert(gettextCatalog.getString('Please enter the recovery phrase')); @@ -254,9 +250,7 @@ angular.module('copayApp.controllers').controller('importController', } } - var passphrase = form.passphrase.$modelValue; - opts.passphrase = form.passphrase.$modelValue || null; - + opts.passphrase = $scope.formData.passphrase || null; _importMnemonic(words, opts); }; @@ -269,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); @@ -285,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(); @@ -333,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); @@ -349,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) }); @@ -362,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 }); diff --git a/src/js/directives/directives.js b/src/js/directives/directives.js index 88458c146..d9bee9bf3 100644 --- a/src/js/directives/directives.js +++ b/src/js/directives/directives.js @@ -107,7 +107,7 @@ angular.module('copayApp.directives') return { link: function($scope, el) { el.bind('change', function(e) { - $scope.file = (e.srcElement || e.target).files[0]; + $scope.formData.file = (e.srcElement || e.target).files[0]; $scope.getFile(); }); } diff --git a/src/js/routes.js b/src/js/routes.js index 1b8f754d0..209627a30 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -276,37 +276,12 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }) .state('tabs.import', { url: '/import', - // abstract: true, views: { 'tab-home': { templateUrl: 'views/import.html' }, }, }) - .state('tabs.import.phrase', { - url: '/tab-import-phrase', - views: { - 'tab-import-phrase': { - templateUrl: 'views/tab-import-phrase.html', - }, - } - }) - .state('tabs.import.file', { - url: '/tab-import-file', - views: { - 'tab-import-file': { - templateUrl: 'views/tab-import-file.html', - }, - } - }) - .state('tabs.import.hardware', { - url: '/tab-import-hardware', - views: { - 'tab-import-hardware': { - templateUrl: 'views/tab-import-hardware.html', - }, - } - }) .state('tabs.create', { url: '/create', views: { @@ -626,7 +601,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }) .state('onboarding.import', { url: '/import', - abstract: true, views: { 'onboarding': { templateUrl: 'views/import.html' @@ -637,30 +611,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr fromOnboarding: null }, }) - .state('onboarding.import.phrase', { - url: '/tab-import-phrase', - views: { - 'tab-import-phrase': { - templateUrl: 'views/tab-import-phrase.html', - }, - } - }) - .state('onboarding.import.file', { - url: '/tab-import-file', - views: { - 'tab-import-file': { - templateUrl: 'views/tab-import-file.html', - }, - } - }) - .state('onboarding.import.hardware', { - url: '/tab-import-hardware', - views: { - 'tab-import-hardware': { - templateUrl: 'views/tab-import-hardware.html', - }, - } - }) /* *