diff --git a/src/js/controllers/import.js b/src/js/controllers/import.js index be7dcba92..a12b6f0dc 100644 --- a/src/js/controllers/import.js +++ b/src/js/controllers/import.js @@ -49,13 +49,11 @@ angular.module('copayApp.controllers').controller('importController', } self.loading = true; + opts.compressed = null; + opts.password = null; $timeout(function() { - profileService.importWallet(str2, { - compressed: null, - password: null, - bwsurl: $scope.bwsurl - }, function(err, walletId) { + profileService.importWallet(str2, opts, function(err, walletId) { self.loading = false; if (err) { self.error = err; @@ -69,11 +67,11 @@ angular.module('copayApp.controllers').controller('importController', }, 100); }; - var _importExtendedPrivateKey = function(xPrivKey) { + var _importExtendedPrivateKey = function(xPrivKey, opts) { self.loading = true; $timeout(function() { - profileService.importExtendedPrivateKey(xPrivKey, function(err, walletId) { + profileService.importExtendedPrivateKey(xPrivKey, opts, function(err, walletId) { self.loading = false; if (err) { self.error = err; @@ -114,7 +112,9 @@ angular.module('copayApp.controllers').controller('importController', // If we use onloadend, we need to check the readyState. reader.onloadend = function(evt) { if (evt.target.readyState == FileReader.DONE) { // DONE == 2 - _importBlob(evt.target.result); + var opts = {}; + opts.bwsurl = $scope.bwsurl; + _importBlob(evt.target.result, opts); } } }; @@ -145,7 +145,9 @@ angular.module('copayApp.controllers').controller('importController', if (backupFile) { reader.readAsBinaryString(backupFile); } else { - _importBlob(backupText); + var opts = {}; + opts.bwsurl = $scope.bwsurl; + _importBlob(backupText, opts); } }; @@ -160,6 +162,8 @@ angular.module('copayApp.controllers').controller('importController', } var opts = {}; + if ($scope.bwsurl) + opts.bwsurl = $scope.bwsurl; var passphrase = form.passphrase.$modelValue; var words = form.words.$modelValue; @@ -168,7 +172,7 @@ angular.module('copayApp.controllers').controller('importController', if (!words) { this.error = gettext('Please enter the seed words'); } else if (words.indexOf('xprv') == 0 || words.indexOf('tprv') == 0) { - return _importExtendedPrivateKey(words) + return _importExtendedPrivateKey(words, opts); } else { var wordList = words.split(/[\u3000\s]+/); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 5b01f3d6d..f5647ab0a 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -265,10 +265,7 @@ angular.module('copayApp.services') root.setWalletClients(); root.setAndStoreFocus(walletId, function() { - storageService.storeProfile(root.profile, function(err) { - if (err) return cb(err); - return cb(null); - }); + storageService.storeProfile(root.profile, cb); }); }); } @@ -298,11 +295,7 @@ angular.module('copayApp.services') walletClient.joinWallet(opts.secret, opts.myName || 'me', {}, function(err) { if (err) return bwsError.cb(err, gettext('Could not join wallet'), cb); - - root.storeData(walletClient, opts.bwsurl, function(err) { - if (err) return cb(err); - return cb(null); - }); + root.storeData(walletClient, opts.bwsurl, cb); }); }); }; @@ -334,7 +327,7 @@ angular.module('copayApp.services') }); }; - root._addWalletClient = function(walletClient, cb) { + root._addWalletClient = function(walletClient, opts, cb) { var walletId = walletClient.credentials.walletId; // check if exist @@ -344,16 +337,7 @@ angular.module('copayApp.services') if (w) { return cb(gettext('Wallet already in Copay' + ": ") + w.walletName); } - - root.profile.credentials.push(JSON.parse(walletClient.export())); - root.setWalletClients(); - - root.setAndStoreFocus(walletId, function() { - storageService.storeProfile(root.profile, function(err) { - return cb(null, walletId); - }); - }); - + root.storeData(walletClient, opts.bwsurl, cb); }; root.importWallet = function(str, opts, cb) { @@ -371,10 +355,13 @@ angular.module('copayApp.services') } catch (err) { return cb(gettext('Could not import. Check input file and password')); } - root._addWalletClient(walletClient, cb); + root._addWalletClient(walletClient, opts, cb); }; - root.importExtendedPrivateKey = function(xPrivKey, cb) { + root.importExtendedPrivateKey = function(xPrivKey, opts, cb) { + if (opts.bwsurl) + bwcService.setBaseUrl(opts.bwsurl); + var walletClient = bwcService.getClient(); $log.debug('Importing Wallet xPrivKey'); @@ -382,7 +369,7 @@ angular.module('copayApp.services') if (err) return bwsError.cb(err, gettext('Could not import'), cb); - root._addWalletClient(walletClient, cb); + root._addWalletClient(walletClient, opts, cb); }); }; @@ -394,6 +381,9 @@ angular.module('copayApp.services') }; root.importMnemonic = function(words, opts, cb) { + if (opts.bwsurl) + bwcService.setBaseUrl(opts.bwsurl); + var walletClient = bwcService.getClient(); $log.debug('Importing Wallet Mnemonic'); @@ -406,11 +396,14 @@ angular.module('copayApp.services') if (err) return bwsError.cb(err, gettext('Could not import'), cb); - root._addWalletClient(walletClient, cb); + root._addWalletClient(walletClient, opts, cb); }); }; root.importExtendedPublicKey = function(opts, cb) { + if (opts.bwsurl) + bwcService.setBaseUrl(opts.bwsurl); + var walletClient = bwcService.getClient(); $log.debug('Importing Wallet XPubKey'); @@ -424,7 +417,7 @@ angular.module('copayApp.services') return bwsError.cb(err, gettext('Could not import'), cb); } - root._addWalletClient(walletClient, cb); + root._addWalletClient(walletClient, opts, cb); }); }; @@ -444,6 +437,9 @@ angular.module('copayApp.services') }; root.importLegacyWallet = function(username, password, blob, cb) { + if (opts.bwsurl) + bwcService.setBaseUrl(opts.bwsurl); + var walletClient = bwcService.getClient(); walletClient.createWalletFromOldCopay(username, password, blob, function(err, existed) {