diff options
-rw-r--r-- | .eslintignore | 1 | ||||
-rw-r--r-- | app/manifest.json | 8 | ||||
-rw-r--r-- | app/scripts/background.js | 8 | ||||
-rw-r--r-- | app/trezor-usb-permissions.html | 33 | ||||
-rw-r--r-- | app/vendor/trezor/content-script.js | 21 | ||||
-rw-r--r-- | app/vendor/trezor/usb-permissions.js | 50 | ||||
-rw-r--r-- | gulpfile.js | 4 | ||||
-rw-r--r-- | package-lock.json | 39 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | test/e2e/beta/from-import-beta-ui.spec.js | 31 | ||||
-rw-r--r-- | ui/app/components/modals/account-details-modal.js | 1 | ||||
-rw-r--r-- | ui/app/components/pages/create-account/connect-hardware/index.js | 7 | ||||
-rw-r--r-- | ui/app/css/itcss/components/new-account.scss | 1 |
13 files changed, 163 insertions, 43 deletions
diff --git a/.eslintignore b/.eslintignore index 6c7f99f40..be8afdd4c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -9,6 +9,7 @@ development/states.js app/scripts/lib/extension-instance.js app/scripts/chromereload.js +app/vendor/** ui/lib/blockies.js diff --git a/app/manifest.json b/app/manifest.json index 3718f5c8a..7793c6e38 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -52,6 +52,14 @@ ], "run_at": "document_start", "all_frames": true + }, + { + "matches": [ + "*://connect.trezor.io/5/popup.html" + ], + "js": [ + "vendor/trezor/content-script.js" + ] } ], "permissions": [ diff --git a/app/scripts/background.js b/app/scripts/background.js index 546fef569..e13d2842a 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -333,6 +333,10 @@ function setupController (initState, initLangCode) { [ENVIRONMENT_TYPE_FULLSCREEN]: true, } + const metamaskBlacklistedPorts = [ + 'trezor-connect', + ] + const isClientOpenStatus = () => { return popupIsOpen || Boolean(Object.keys(openMetamaskTabsIDs).length) || notificationIsOpen } @@ -353,6 +357,10 @@ function setupController (initState, initLangCode) { const processName = remotePort.name const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName] + if (metamaskBlacklistedPorts.includes(remotePort.name)) { + return false + } + if (isMetaMaskInternalProcess) { const portStream = new PortStream(remotePort) // communication with popup diff --git a/app/trezor-usb-permissions.html b/app/trezor-usb-permissions.html new file mode 100644 index 000000000..16f28e5e1 --- /dev/null +++ b/app/trezor-usb-permissions.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8" /> + <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> + <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" /> + <title>TrezorConnect | Trezor</title> + <meta name="description" content="" /> + <meta name="keywords" content="" /> + <meta name="author" content="Trezor info@trezor.io" /> + <meta name="robots" content="noindex, nofollow" /> + <meta name="title" content="Trezor Connect" /> + <meta name="theme-color" content="#ffffff" /> + <meta http-equiv="Pragma" content="no-cache" /> + <meta http-equiv="Expires" content="-1" /> + <style> + * { + margin: 0; + padding: 0; + } + html, body { + position: relative; + width: 100%; + height: 100%; + min-height: 500px; + min-width: 328px; + } + </style> +</head> +<body> + <iframe id="trezor-usb-permissions" src="https://connect.trezor.io/5/extension-permissions.html" allow="usb" frameborder="0" width="100%" height="100%"></iframe> + <script type="text/javascript" src="./vendor/trezor/usb-permissions.js"></script> +</body>
\ No newline at end of file diff --git a/app/vendor/trezor/content-script.js b/app/vendor/trezor/content-script.js new file mode 100644 index 000000000..a21332f46 --- /dev/null +++ b/app/vendor/trezor/content-script.js @@ -0,0 +1,21 @@ +/* +Passing messages from background script to popup +*/ + +let port = chrome.runtime.connect({ name: 'trezor-connect' }); +port.onMessage.addListener(message => { + window.postMessage(message, window.location.origin); +}); +port.onDisconnect.addListener(d => { + port = null; +}); + +/* +Passing messages from popup to background script +*/ + +window.addEventListener('message', event => { + if (port && event.source === window && event.data) { + port.postMessage(event.data); + } +}); diff --git a/app/vendor/trezor/usb-permissions.js b/app/vendor/trezor/usb-permissions.js new file mode 100644 index 000000000..9de47e0a1 --- /dev/null +++ b/app/vendor/trezor/usb-permissions.js @@ -0,0 +1,50 @@ +/* +Handling messages from usb permissions iframe +*/ + +const switchToPopupTab = (event) => { + + window.removeEventListener('beforeunload', switchToPopupTab); + + if (!event) { + // triggered from 'usb-permissions-close' message + // switch tab to previous index and close current + chrome.tabs.query({ + currentWindow: true, + active: true, + }, (current) => { + if (current.length < 0) return; + chrome.tabs.query({ + index: current[0].index - 1 + }, popup => { + if (popup.length < 0) return; + chrome.tabs.update(popup[0].id, { active: true }); + }) + chrome.tabs.remove(current[0].id); + }); + return; + } + + // triggered from 'beforeunload' event + // find tab by popup pattern and switch to it + chrome.tabs.query({ + url: "*://connect.trezor.io/*/popup.html" + }, (tabs) => { + if (tabs.length < 0) return; + chrome.tabs.update(tabs[0].id, { active: true }); + }); +} + +window.addEventListener('message', event => { + if (event.data === 'usb-permissions-init') { + const iframe = document.getElementById('trezor-usb-permissions'); + iframe.contentWindow.postMessage({ + type: 'usb-permissions-init', + extension: chrome.runtime.id, + }, '*'); + } else if (event.data === 'usb-permissions-close') { + switchToPopupTab(); + } +}); + +window.addEventListener('beforeunload', switchToPopupTab);
\ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 480f544d8..920e9f8ae 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -74,6 +74,10 @@ createCopyTasks('fonts', { source: './app/fonts/', destinations: commonPlatforms.map(platform => `./dist/${platform}/fonts`), }) +createCopyTasks('vendor', { + source: './app/vendor/', + destinations: commonPlatforms.map(platform => `./dist/${platform}/vendor`), +}) createCopyTasks('reload', { devOnly: true, source: './app/scripts/', diff --git a/package-lock.json b/package-lock.json index 016e25647..cee8b15ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7658,9 +7658,15 @@ } }, "enzyme-adapter-utils": { +<<<<<<< HEAD + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/enzyme-adapter-utils/-/enzyme-adapter-utils-1.7.0.tgz", + "integrity": "sha512-K5FVpGxMlakvvWS6TkwogAzvMRE4pgve6grPzCuraVHRBzgrmeasGDF1CS2rQc7uKo7OF0FQZxaQm8oJAKXFVw==", +======= "version": "1.8.0", "resolved": "https://registry.npmjs.org/enzyme-adapter-utils/-/enzyme-adapter-utils-1.8.0.tgz", "integrity": "sha512-K9U2RGr1pvWPGEAIRQRVH4UdlqzpfLsKonuHyAK6lxu46yfGsMDVlO3+YvQwQpVjVw8eviEVIOmlFAnMbIhv/w==", +>>>>>>> fdb023381be323bd3198d5e102447e6591e7e73e "dev": true, "requires": { "function.prototype.name": "^1.1.0", @@ -8163,7 +8169,7 @@ } }, "eth-contract-metadata": { - "version": "github:MetaMask/eth-contract-metadata#2da362052a312dc6c72a7eec116abf6284664f50", + "version": "github:MetaMask/eth-contract-metadata#1c0e1c343c3cfb9a15ce9862588f548749001de3", "from": "github:MetaMask/eth-contract-metadata#master" }, "eth-ens-namehash": { @@ -8883,15 +8889,15 @@ } }, "eth-trezor-keyring": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/eth-trezor-keyring/-/eth-trezor-keyring-0.1.0.tgz", - "integrity": "sha512-7ynDXiXGQOh9CslksJSmGGK726lV9fTnIp2QQnjbZJgR4zJIoSUYQYKvT2wXcxLhVrTUl2hLjwKN9QGqDCMVwA==", + "version": "github:MetaMask/eth-trezor-keyring#7bdeb094dc3549c474c83fcebcfb38882f400ae1", + "from": "github:MetaMask/eth-trezor-keyring#trezor-v5", "requires": { "eth-sig-util": "^1.4.2", "ethereumjs-tx": "^1.3.4", "ethereumjs-util": "^5.1.5", "events": "^2.0.0", - "hdkey": "0.8.0" + "hdkey": "0.8.0", + "trezor-connect": "^5.0.31" }, "dependencies": { "ethereum-common": { @@ -8900,9 +8906,9 @@ "integrity": "sha1-L9w1dvIykDNYl26znaeDIT/5Uj8=" }, "ethereumjs-tx": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/ethereumjs-tx/-/ethereumjs-tx-1.3.6.tgz", - "integrity": "sha512-wzsEs0mCSLqdDjqSDg6AWh1hyL8H3R/pyZxehkcCXq5MJEFXWz+eJ2jSv+3yEaLy6tXrNP7dmqS3Kyb3zAONkg==", + "version": "1.3.7", + "resolved": "https://registry.npmjs.org/ethereumjs-tx/-/ethereumjs-tx-1.3.7.tgz", + "integrity": "sha512-wvLMxzt1RPhAQ9Yi3/HKZTn0FZYpnsmQdbKYfUUpi4j1SEIcbkd9tndVjcPrufY3V7j2IebOpC00Zp2P/Ay2kA==", "requires": { "ethereum-common": "^0.0.18", "ethereumjs-util": "^5.0.0" @@ -29587,6 +29593,23 @@ "resolved": "https://registry.npmjs.org/treeify/-/treeify-1.1.0.tgz", "integrity": "sha512-1m4RA7xVAJrSGrrXGs0L3YTwyvBs2S8PbRHaLZAkFw7JR8oIFwYtysxlBZhYIa7xSyiYJKZ3iGrrk55cGA3i9A==" }, + "trezor-connect": { + "version": "5.0.30", + "resolved": "https://registry.npmjs.org/trezor-connect/-/trezor-connect-5.0.30.tgz", + "integrity": "sha512-LX3j8g8UP5qqA4lTnK1CAWBGbYy6mphRBqOruTZvjGP9AxZGe8UuJIt7GhG02seh8JPi2bIKlTDYCqDUefh/BA==", + "requires": { + "babel-runtime": "^6.26.0", + "events": "^1.1.1", + "whatwg-fetch": "^2.0.4" + }, + "dependencies": { + "whatwg-fetch": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz", + "integrity": "sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==" + } + } + }, "trim": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/trim/-/trim-0.0.1.tgz", diff --git a/package.json b/package.json index 0ef2ab6a9..beb122a3c 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "eth-query": "^2.1.2", "eth-sig-util": "^1.4.2", "eth-token-tracker": "^1.1.4", - "eth-trezor-keyring": "^0.1.0", + "eth-trezor-keyring": "github:MetaMask/eth-trezor-keyring#trezor-v5", "ethereumjs-abi": "^0.6.4", "ethereumjs-tx": "^1.3.0", "ethereumjs-util": "github:ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9", diff --git a/test/e2e/beta/from-import-beta-ui.spec.js b/test/e2e/beta/from-import-beta-ui.spec.js index f8a904263..5ee8f0268 100644 --- a/test/e2e/beta/from-import-beta-ui.spec.js +++ b/test/e2e/beta/from-import-beta-ui.spec.js @@ -373,36 +373,7 @@ describe('Using MetaMask with an existing account', function () { await connectButtons[0].click() await delay(regularDelayMs) const allWindows = await driver.getAllWindowHandles() - switch (process.env.SELENIUM_BROWSER) { - case 'chrome': - assert.equal(allWindows.length, 2) - break - default: - assert.equal(allWindows.length, 1) - } - }) - - it('should show the "Browser not supported" screen for non Chrome browsers', async () => { - if (process.env.SELENIUM_BROWSER !== 'chrome') { - const title = await findElements(driver, By.xpath(`//h3[contains(text(), 'Your Browser is not supported...')]`)) - assert.equal(title.length, 1) - - const downloadChromeButtons = await findElements(driver, By.xpath(`//button[contains(text(), 'Download Google Chrome')]`)) - assert.equal(downloadChromeButtons.length, 1) - - await downloadChromeButtons[0].click() - await delay(regularDelayMs) - - const [newUITab, downloadChromeTab] = await driver.getAllWindowHandles() - - await driver.switchTo().window(downloadChromeTab) - await delay(regularDelayMs) - const tabUrl = await driver.getCurrentUrl() - assert.equal(tabUrl, 'https://www.google.com/chrome/') - await driver.close() - await delay(regularDelayMs) - await driver.switchTo().window(newUITab) - } + assert.equal(allWindows.length, 2) }) }) }) diff --git a/ui/app/components/modals/account-details-modal.js b/ui/app/components/modals/account-details-modal.js index bc577fda0..0bbabf38d 100644 --- a/ui/app/components/modals/account-details-modal.js +++ b/ui/app/components/modals/account-details-modal.js @@ -65,6 +65,7 @@ AccountDetailsModal.prototype.render = function () { exportPrivateKeyFeatureEnabled = false } + return h(AccountModalContainer, {}, [ h(EditableLabel, { className: 'account-modal__name', diff --git a/ui/app/components/pages/create-account/connect-hardware/index.js b/ui/app/components/pages/create-account/connect-hardware/index.js index 547df5223..4fe25f629 100644 --- a/ui/app/components/pages/create-account/connect-hardware/index.js +++ b/ui/app/components/pages/create-account/connect-hardware/index.js @@ -50,9 +50,8 @@ class ConnectHardwareForm extends Component { } connectToHardwareWallet = (device) => { - // None of the hardware wallets are supported - // At least for now - if (getPlatform() === PLATFORM_FIREFOX) { + // Ledger hardware wallets are not supported on firefox + if (getPlatform() === PLATFORM_FIREFOX && device === 'ledger') { this.setState({ browserSupported: false, error: null}) return null } @@ -126,7 +125,7 @@ class ConnectHardwareForm extends Component { .catch(e => { if (e === 'Window blocked') { this.setState({ browserSupported: false, error: null}) - } else if (e !== 'Window closed') { + } else if (e !== 'Window closed' && e !== 'Popup closed') { this.setState({ error: e.toString() }) } }) diff --git a/ui/app/css/itcss/components/new-account.scss b/ui/app/css/itcss/components/new-account.scss index e4c7a4e0d..9c639e147 100644 --- a/ui/app/css/itcss/components/new-account.scss +++ b/ui/app/css/itcss/components/new-account.scss @@ -449,6 +449,7 @@ margin-top: 10px; &__button { + background: #fff; height: 19px; display: flex; color: #33a4e7; |