diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/_locales/en/messages.json | 24 | ||||
-rw-r--r-- | app/images/connect-icon.svg | 11 | ||||
-rw-r--r-- | app/scripts/lib/util.js | 2 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 68 | ||||
-rw-r--r-- | app/scripts/platforms/extension.js | 7 |
5 files changed, 109 insertions, 3 deletions
diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 46fbdc1a7..f10ba01f3 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -11,6 +11,9 @@ "accountName": { "message": "Account Name" }, + "accountSelectionRequired": { + "message": "You need to select an account!" + }, "address": { "message": "Address" }, @@ -119,6 +122,18 @@ "confirmTransaction": { "message": "Confirm Transaction" }, + "connectHardware": { + "message": "Connect Hardware" + }, + "connect": { + "message": "Connect" + }, + "connecting": { + "message": "Connecting..." + }, + "connectToTrezor": { + "message": "Connect to Trezor" + }, "continue": { "message": "Continue" }, @@ -612,6 +627,9 @@ "popularTokens": { "message": "Popular Tokens" }, + "prev": { + "message": "Prev" + }, "privacyMsg": { "message": "Privacy Policy" }, @@ -787,6 +805,9 @@ "searchTokens": { "message": "Search Tokens" }, + "selectAnAddress": { + "message": "Select an Address" + }, "sendTokensAnywhere": { "message": "Send Tokens to anyone with an Ethereum account" }, @@ -936,6 +957,9 @@ "unknownNetworkId": { "message": "Unknown network ID" }, + "unlock": { + "message": "Unlock" + }, "unlockMessage": { "message": "The decentralized web awaits" }, diff --git a/app/images/connect-icon.svg b/app/images/connect-icon.svg new file mode 100644 index 000000000..84540999a --- /dev/null +++ b/app/images/connect-icon.svg @@ -0,0 +1,11 @@ +<svg width="288" height="288" xmlns="http://www.w3.org/2000/svg"> + + <g> + <title>background</title> + <rect fill="none" id="canvas_background" height="402" width="582" y="-1" x="-1"/> + </g> + <g> + <title>Layer 1</title> + <path fill="#ffffff" id="svg_1" d="m122,25l15,-21c4,-5 10,-5 14,0l16,22c4,5 2,10 -5,10l-12,0l0,118c0,3 3,3 5,1l25,-25c4,-4 6,-10 6,-16l0,-24c-7,0 -12,-5 -12,-12l0,-12c0,-6 5,-12 12,-12l12,0c7,0 12,5 12,12l0,12c0,7 -5,12 -12,12l0,24c0,10 -3,18 -10,25l-31,31c-4,4 -7,6 -7,16l0,49c12,3 21,13 21,26c0,15 -12,27 -27,27s-27,-12 -27,-27c0,-13 9,-23 21,-26l0,-13c0,-10 -3,-13 -7,-17l-31,-31c-6,-6 -10,-14 -10,-24l0,-25c-7,-2 -12,-9 -12,-17c0,-10 8,-18 18,-18s18,8 18,18c0,8 -5,15 -12,17l0,25c0,7 3,12 7,16l25,25c2,2 4,2 4,-1l0,-154l-12,0c-7,0 -9,-5 -4,-11z"/> + </g> +</svg>
\ No newline at end of file diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js index 431d1e59c..51e9036cc 100644 --- a/app/scripts/lib/util.js +++ b/app/scripts/lib/util.js @@ -28,7 +28,7 @@ function getStack () { * */ const getEnvironmentType = (url = window.location.href) => { - if (url.match(/popup.html(?:\?.+)*$/)) { + if (url.match(/popup.html(?:#.*)*$/)) { return ENVIRONMENT_TYPE_POPUP } else if (url.match(/home.html(?:\?.+)*$/) || url.match(/home.html(?:#.*)*$/)) { return ENVIRONMENT_TYPE_FULLSCREEN diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index b4d39031a..6e743d030 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -47,6 +47,7 @@ const percentile = require('percentile') const seedPhraseVerifier = require('./lib/seed-phrase-verifier') const cleanErrorStack = require('./lib/cleanErrorStack') const log = require('loglevel') +const TrezorKeyring = require('eth-trezor-keyring') module.exports = class MetamaskController extends EventEmitter { @@ -124,7 +125,9 @@ module.exports = class MetamaskController extends EventEmitter { }) // key mgmt + const additionalKeyrings = [TrezorKeyring] this.keyringController = new KeyringController({ + keyringTypes: additionalKeyrings, initState: initState.KeyringController, getNetwork: this.networkController.getNetworkState.bind(this.networkController), encryptor: opts.encryptor || undefined, @@ -352,6 +355,10 @@ module.exports = class MetamaskController extends EventEmitter { resetAccount: nodeify(this.resetAccount, this), importAccountWithStrategy: nodeify(this.importAccountWithStrategy, this), + // trezor + connectHardware: nodeify(this.connectHardware, this), + unlockTrezorAccount: nodeify(this.unlockTrezorAccount, this), + // vault management submitPassword: nodeify(this.submitPassword, this), @@ -508,6 +515,67 @@ module.exports = class MetamaskController extends EventEmitter { } // + // Hardware + // + + /** + * Fetch account list from a trezor device. + * + * @returns [] accounts + */ + async connectHardware (deviceName, page) { + + switch (deviceName) { + case 'trezor': + const keyringController = this.keyringController + let keyring = await keyringController.getKeyringsByType( + 'Trezor Hardware' + )[0] + if (!keyring) { + keyring = await this.keyringController.addNewKeyring('Trezor Hardware') + } + + const accounts = page === 1 ? await keyring.getNextPage() : await keyring.getPreviousPage() + this.accountTracker.syncWithAddresses(accounts.map(a => a.address)) + return accounts + + default: + throw new Error('MetamaskController - Unknown device') + } + } + + /** + * Imports an account from a trezor device. + * + * @returns {} keyState + */ + async unlockTrezorAccount (index) { + const keyringController = this.keyringController + const keyring = await keyringController.getKeyringsByType( + 'Trezor Hardware' + )[0] + if (!keyring) { + throw new Error('MetamaskController - No Trezor Hardware Keyring found') + } + + keyring.setAccountToUnlock(index) + const oldAccounts = await keyringController.getAccounts() + const keyState = await keyringController.addNewAccount(keyring) + const newAccounts = await keyringController.getAccounts() + + this.preferencesController.setAddresses(newAccounts) + newAccounts.forEach(address => { + if (!oldAccounts.includes(address)) { + this.preferencesController.setSelectedAddress(address) + } + }) + + const { identities } = this.preferencesController.store.getState() + return { ...keyState, identities } + } + + + // // Account Management // diff --git a/app/scripts/platforms/extension.js b/app/scripts/platforms/extension.js index f5cc255d1..f8dd767dc 100644 --- a/app/scripts/platforms/extension.js +++ b/app/scripts/platforms/extension.js @@ -17,8 +17,11 @@ class ExtensionPlatform { return extension.runtime.getManifest().version } - openExtensionInBrowser () { - const extensionURL = extension.runtime.getURL('home.html') + openExtensionInBrowser (route = null) { + let extensionURL = extension.runtime.getURL('home.html') + if (route) { + extensionURL += `#${route}` + } this.openWindow({ url: extensionURL }) } |