From 5abf35c68cff140f266011c2293802eb30be62c7 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 5 Nov 2015 16:00:38 -0300 Subject: [PATCH] adds trezor support to isDevel --- src/js/controllers/create.js | 16 ++++++++-------- src/js/controllers/import.js | 25 ++++++++++++++----------- src/js/controllers/join.js | 24 ++++++++++++++---------- src/js/services/isDevel.js | 5 +++++ src/js/services/profileService.js | 19 +++++++++++-------- 5 files changed, 52 insertions(+), 37 deletions(-) create mode 100644 src/js/services/isDevel.js diff --git a/src/js/controllers/create.js b/src/js/controllers/create.js index 4c9fd49ca..44a11f67b 100644 --- a/src/js/controllers/create.js +++ b/src/js/controllers/create.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('createController', - function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isCordova, gettext, ledger, trezor, isMobile, isChromeApp) { + function($scope, $rootScope, $location, $timeout, $log, lodash, go, profileService, configService, isCordova, gettext, ledger, trezor, isMobile, isChromeApp, isDevel) { var self = this; var defaults = configService.getDefaults(); @@ -50,19 +50,19 @@ angular.module('copayApp.controllers').controller('createController', label: gettext('Specify Seed...'), }]; $scope.seedSource = self.seedOptions[0]; - if (!isChromeApp) return; - if (n > 1) + if (n > 1 && isChromeApp) self.seedOptions.push({ id: 'ledger', label: gettext('Ledger Hardware Wallet'), }); - self.seedOptions.push({ - id: 'trezor', - label: gettext('Trezor Hardware Wallet'), - }); - + if (isChromeApp || isDevel) { + self.seedOptions.push({ + id: 'trezor', + label: gettext('Trezor Hardware Wallet'), + }); + } }; this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1); diff --git a/src/js/controllers/import.js b/src/js/controllers/import.js index 540e83fb9..8eeec31c4 100644 --- a/src/js/controllers/import.js +++ b/src/js/controllers/import.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('importController', - function($scope, $rootScope, $location, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, lodash, ledger, trezor, isChromeApp) { + function($scope, $rootScope, $location, $timeout, $log, profileService, configService, notification, go, sjcl, gettext, lodash, ledger, trezor, isChromeApp, isDevel) { var self = this; var reader = new FileReader(); @@ -19,18 +19,21 @@ angular.module('copayApp.controllers').controller('importController', var updateSeedSourceSelect = function() { self.seedOptions = []; - if (!isChromeApp) return; - self.seedOptions.push({ - id: 'ledger', - label: gettext('Ledger Hardware Wallet'), - }); + if (isChromeApp) { + self.seedOptions.push({ + id: 'ledger', + label: gettext('Ledger Hardware Wallet'), + }); + } - self.seedOptions.push({ - id: 'trezor', - label: gettext('Trezor Hardware Wallet'), - }); - $scope.seedSource = self.seedOptions[0]; + if (isChromeApp || isDevel) { + self.seedOptions.push({ + id: 'trezor', + label: gettext('Trezor Hardware Wallet'), + }); + $scope.seedSource = self.seedOptions[0]; + } }; diff --git a/src/js/controllers/join.js b/src/js/controllers/join.js index 8fa30f43a..376a60100 100644 --- a/src/js/controllers/join.js +++ b/src/js/controllers/join.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('joinController', - function($scope, $rootScope, $timeout, go, notification, profileService, configService, isCordova, storageService, applicationService, $modal, gettext, lodash, ledger, trezor, isChromeApp) { + function($scope, $rootScope, $timeout, go, notification, profileService, configService, isCordova, storageService, applicationService, $modal, gettext, lodash, ledger, trezor, isChromeApp, isDevel) { var self = this; var defaults = configService.getDefaults(); @@ -25,17 +25,21 @@ angular.module('copayApp.controllers').controller('joinController', label: gettext('Specify Seed...'), }]; $scope.seedSource = self.seedOptions[0]; - if (!isChromeApp) return; - self.seedOptions.push({ - id: 'ledger', - label: gettext('Ledger Hardware Wallet'), - }); - self.seedOptions.push({ - id: 'trezor', - label: gettext('Trezor Hardware Wallet'), - }); + if (isChromeApp) { + self.seedOptions.push({ + id: 'ledger', + label: gettext('Ledger Hardware Wallet'), + }); + } + + if (isChromeApp || isDevel) { + self.seedOptions.push({ + id: 'trezor', + label: gettext('Trezor Hardware Wallet'), + }); + } }; this.setSeedSource = function(src) { diff --git a/src/js/services/isDevel.js b/src/js/services/isDevel.js new file mode 100644 index 000000000..f96ea53e4 --- /dev/null +++ b/src/js/services/isDevel.js @@ -0,0 +1,5 @@ +'use strict'; + +angular.module('copayApp.services').factory('isDevel', function(nodeWebkit, isChromeApp, isMobile) { + return !isMobile.any() && !isChromeApp && !nodeWebkit.isDefined(); +}); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 8382316e6..2def22e4b 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -175,6 +175,13 @@ angular.module('copayApp.services') var walletClient = bwcService.getClient(); var network = opts.networkName || 'livenet'; + // TODO refactor this and use bwc contants? + var derivationStrategy = 'BIP44'; + if (opts.fromHardware && opts.n > 1) { + derivationStrategy = 'BIP48'; + } + + if (opts.mnemonic) { try { opts.mnemonic = root._normalizeMnemonic(opts.mnemonic); @@ -182,14 +189,9 @@ angular.module('copayApp.services') network: network, passphrase: opts.passphrase, account: opts.account || 0, + derivationStrategy: derivationStrategy, }); - // 1) { - //walletClient.credentials.derivationStrategy == - } - // Nasty> - } catch (ex) { $log.info(ex); return cb(gettext('Could not create: Invalid wallet seed')); @@ -204,7 +206,8 @@ angular.module('copayApp.services') } else if (opts.extendedPublicKey) { try { walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, { - account: opts.account || 0, + account: opts.account || 0, + derivationStrategy: derivationStrategy, }); } catch (ex) { $log.warn("Creating wallet from Extended Public Key Arg:", ex, opts); @@ -368,7 +371,7 @@ angular.module('copayApp.services') root.setWalletClients(); root.setAndStoreFocus(walletId, function() { - storageService.storeProfile(root.profile, function(err){ + storageService.storeProfile(root.profile, function(err) { return cb(err, walletId); }); });