From af1f6a1af493bb885f6e92f21fc751db4b8c22d0 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 2 Jul 2020 22:56:09 -0300 Subject: [PATCH 1/9] Fix `dapp` script in `package.json` (#8900) This script is relied upon by our e2e tests. It was broken in #8888, because `@metamask/test-dapp` was updated to a version with a different directory structure. The website is now in the `dist` directory instead of the `website` directory. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 48bf624c7..1680de795 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "benchmark:firefox": "SELENIUM_BROWSER=firefox node test/e2e/benchmark.js", "build:test": "yarn build test", "test": "yarn test:unit && yarn lint", - "dapp": "node development/static-server.js node_modules/@metamask/test-dapp/website --port 8080", + "dapp": "node development/static-server.js node_modules/@metamask/test-dapp/dist --port 8080", "dapp-chain": "GANACHE_ARGS='-b 2' concurrently -k -n ganache,dapp -p '[{time}][{name}]' 'yarn ganache:start' 'sleep 5 && yarn dapp'", "forwarder": "node ./development/static-server.js ./node_modules/@metamask/forwarder/dist/ --port 9010", "dapp-forwarder": "concurrently -k -n forwarder,dapp -p '[{time}][{name}]' 'yarn forwarder' 'yarn dapp'", From b10986ddaaa02e390989ac70cfae9957b6ca7a46 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 2 Jul 2020 23:33:55 -0300 Subject: [PATCH 2/9] Exit with non-zero exit code upon failure (#8901) The `static-server` script now exits with a code of `1` upon failure. Previously it would print the error to the console but exit with a code of `0`, indicating success. --- development/static-server.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/development/static-server.js b/development/static-server.js index d8f22cabe..e07c2e33f 100644 --- a/development/static-server.js +++ b/development/static-server.js @@ -89,4 +89,7 @@ const main = async () => { } main() - .catch(console.error) + .catch((error) => { + console.error(error) + process.exit(1) + }) From 564f76584bf1b3ec853576879e550d148440de97 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 3 Jul 2020 13:02:35 -0300 Subject: [PATCH 3/9] Tolerate missing or falsey substitutions (#8907) Previously the `getMessage` function would throw if a substitution was falsey. Now it will accept any substitution, including `undefined`. A substitution of `null` or `undefined` will still be reported to Sentry and printed to the console as an error, but it will not interrupt execution. Any `null` or `undefined` substitutions will be rendered as empty strings. Ideally we'd never pass in `null` or `undefined` as a substitution, but in practice this sometimes just occurs breifly between renders, which isn't a severe enough problem to justify crashing the UI. The detection of React component substitutions has been updated as well, to ensure that `null` values aren't counted as React substitutions. --- ui/app/helpers/utils/i18n-helper.js | 10 ++++++---- ui/app/helpers/utils/i18n-helper.test.js | 16 ++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ui/app/helpers/utils/i18n-helper.js b/ui/app/helpers/utils/i18n-helper.js index 01a369229..a32120b4f 100644 --- a/ui/app/helpers/utils/i18n-helper.js +++ b/ui/app/helpers/utils/i18n-helper.js @@ -43,7 +43,7 @@ export const getMessage = (localeCode, localeMessages, key, substitutions) => { const hasSubstitutions = Boolean(substitutions && substitutions.length) const hasReactSubstitutions = hasSubstitutions && - substitutions.some((element) => typeof element === 'function' || typeof element === 'object') + substitutions.some((element) => element !== null && (typeof element === 'function' || typeof element === 'object')) // perform substitutions if (hasSubstitutions) { @@ -55,10 +55,12 @@ export const getMessage = (localeCode, localeMessages, key, substitutions) => { return part } const substituteIndex = Number(subMatch[1]) - 1 - if (substitutions[substituteIndex]) { - return substitutions[substituteIndex] + if (substitutions[substituteIndex] == null) { + const error = new Error(`Insufficient number of substitutions for message: '${phrase}'`) + log.error(error) + Sentry.captureException(error) } - throw new Error(`Insufficient number of substitutions for message: '${phrase}'`) + return substitutions[substituteIndex] }) phrase = hasReactSubstitutions diff --git a/ui/app/helpers/utils/i18n-helper.test.js b/ui/app/helpers/utils/i18n-helper.test.js index 2832022e6..4531865ab 100644 --- a/ui/app/helpers/utils/i18n-helper.test.js +++ b/ui/app/helpers/utils/i18n-helper.test.js @@ -132,14 +132,14 @@ describe('i18n helper', function () { assert.equal(result, `${TEST_SUBSTITUTION_1} - ${TEST_SUBSTITUTION_2} - ${TEST_SUBSTITUTION_3} - ${TEST_SUBSTITUTION_4} - ${TEST_SUBSTITUTION_5}`) }) - it('should throw an error when not passed as many substitutions as a message requires', function () { - assert.throws( - () => { - t(TEST_KEY_5, [ TEST_SUBSTITUTION_1, TEST_SUBSTITUTION_2 ]) - }, - Error, - `Insufficient number of substitutions for message: '$1 - $2 - $3'` - ) + it('should correctly render falsey substitutions', function () { + const result = t(TEST_KEY_4, [ 0, -0, '', false, NaN ]) + assert.equal(result, '0 - 0 - - false - NaN') + }) + + it('should render nothing for "null" and "undefined" substitutions', function () { + const result = t(TEST_KEY_5, [ null, TEST_SUBSTITUTION_2 ]) + assert.equal(result, ` - ${TEST_SUBSTITUTION_2} - `) }) it('should return the correct message when a single react substitution is made', function () { From 4a989c339a58c8de2b385736651de0f951c52551 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 3 Jul 2020 13:03:13 -0300 Subject: [PATCH 4/9] Fix activity log inline buttons (#8908) The inline speedup and speedup cancellation buttons in the activity log were broken. An exception would be thrown upon either button being clicked, and nothing would happen from the user's perspective. Both handlers were being passed a transaction id, which was a holdover from before the transaction list redesign. The handlers passed for these two actions now have the transaction id embedded, so it doesn't need to be passed in anymore. They expect the click event to be passed through instead. The handlers passed also didn't handle closing the transaction details modal when clicked. After fixing the first problem, they still didn't work because the speedup/cancel dialog was shown behind the transaction details modal. Both issues are now fixed. Both buttons now close the transaction details modal, and trigger the appropriate action. --- .../transaction-activity-log.component.js | 14 ++++++-------- .../transaction-list-item-details.component.js | 6 ++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js b/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js index b5618b83b..4a9a9791e 100644 --- a/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js +++ b/ui/app/components/app/transaction-activity-log/transaction-activity-log.component.js @@ -36,34 +36,32 @@ export default class TransactionActivityLog extends PureComponent { global.platform.openTab({ url: etherscanUrl }) } - renderInlineRetry (index, activity) { + renderInlineRetry (index) { const { t } = this.context const { inlineRetryIndex, primaryTransaction = {}, onRetry, isEarliestNonce } = this.props const { status } = primaryTransaction - const { id } = activity return isEarliestNonce && status !== CONFIRMED_STATUS && index === inlineRetryIndex ? (
onRetry(id)} + onClick={onRetry} > { t('speedUpTransaction') }
) : null } - renderInlineCancel (index, activity) { + renderInlineCancel (index) { const { t } = this.context const { inlineCancelIndex, primaryTransaction = {}, onCancel, isEarliestNonce } = this.props const { status } = primaryTransaction - const { id } = activity return isEarliestNonce && status !== CONFIRMED_STATUS && index === inlineCancelIndex ? (
onCancel(id)} + onClick={onCancel} > { t('speedUpCancellation') }
@@ -107,8 +105,8 @@ export default class TransactionActivityLog extends PureComponent { > { activityText } - { this.renderInlineRetry(index, activity) } - { this.renderInlineCancel(index, activity) } + { this.renderInlineRetry(index) } + { this.renderInlineCancel(index) } ) diff --git a/ui/app/components/app/transaction-list-item-details/transaction-list-item-details.component.js b/ui/app/components/app/transaction-list-item-details/transaction-list-item-details.component.js index b0ea259db..cc5418860 100644 --- a/ui/app/components/app/transaction-list-item-details/transaction-list-item-details.component.js +++ b/ui/app/components/app/transaction-list-item-details/transaction-list-item-details.component.js @@ -145,8 +145,6 @@ export default class TransactionListItemDetails extends PureComponent { transactionGroup, showSpeedUp, showRetry, - onCancel, - onRetry, recipientEns, recipientAddress, rpcPrefs: { blockExplorerUrl } = {}, @@ -253,8 +251,8 @@ export default class TransactionListItemDetails extends PureComponent { From a4e7cff36ef6296fd5e11f6fb60a83d1154fe48a Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 3 Jul 2020 13:03:47 -0300 Subject: [PATCH 5/9] Prevent confirming blank suggested token (#8909) The "confirm suggested token" page allowed the confirm button to be pressed even when there were no tokens to confirm. This can happen sometimes when the page is in the process of redirecting. --- .../confirm-add-suggested-token.component.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/app/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js b/ui/app/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js index f6c47f894..cf4594024 100644 --- a/ui/app/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js +++ b/ui/app/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js @@ -122,6 +122,7 @@ export default class ConfirmAddSuggestedToken extends Component { type="secondary" large className="page-container__footer-button" + disabled={pendingTokens.length === 0} onClick={() => { addToken(pendingToken) .then(() => removeSuggestedTokens()) From b0014a9b357b995a834289a3816c1c50b5d7e5ef Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 3 Jul 2020 13:16:31 -0300 Subject: [PATCH 6/9] Handle suggested token resolved elsewhere (#8910) When a suggested token was resolved in a different window, the popup or notification UI could get stuck with an empty suggested token list, where either action would throw an error. This case is now handled by either redirecting or closing the window, in the popup and notification cases respectively. This check is performed on both component mount and update. --- .../confirm-add-suggested-token.component.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ui/app/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js b/ui/app/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js index cf4594024..876fbd761 100644 --- a/ui/app/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js +++ b/ui/app/pages/confirm-add-suggested-token/confirm-add-suggested-token.component.js @@ -3,6 +3,8 @@ import PropTypes from 'prop-types' import Button from '../../components/ui/button' import Identicon from '../../components/ui/identicon' import TokenBalance from '../../components/ui/token-balance' +import { getEnvironmentType } from '../../../../app/scripts/lib/util' +import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../app/scripts/lib/enums' export default class ConfirmAddSuggestedToken extends Component { static contextTypes = { @@ -19,9 +21,23 @@ export default class ConfirmAddSuggestedToken extends Component { } componentDidMount () { + this._checkPendingTokens() + } + + componentDidUpdate () { + this._checkPendingTokens() + } + + _checkPendingTokens () { const { mostRecentOverviewPage, pendingTokens = {}, history } = this.props - if (Object.keys(pendingTokens).length === 0) { + if (Object.keys(pendingTokens).length > 0) { + return + } + + if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) { + global.platform.closeCurrentWindow() + } else { history.push(mostRecentOverviewPage) } } From f97f95cc8670351670031eb45a81a1ae37459b42 Mon Sep 17 00:00:00 2001 From: Erik Marks <25517051+rekmarks@users.noreply.github.com> Date: Fri, 3 Jul 2020 10:14:43 -0700 Subject: [PATCH 7/9] Fix kovan chain ID constant (#8913) --- app/scripts/controllers/network/enums.js | 2 +- test/unit/app/controllers/network/network-controller-test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/controllers/network/enums.js b/app/scripts/controllers/network/enums.js index e2a7deab3..13bdbbe1a 100644 --- a/app/scripts/controllers/network/enums.js +++ b/app/scripts/controllers/network/enums.js @@ -15,7 +15,7 @@ export const MAINNET_CHAIN_ID = '0x1' export const ROPSTEN_CHAIN_ID = '0x3' export const RINKEBY_CHAIN_ID = '0x4' export const GOERLI_CHAIN_ID = '0x5' -export const KOVAN_CHAIN_ID = '0x42' +export const KOVAN_CHAIN_ID = '0x2a' export const ROPSTEN_DISPLAY_NAME = 'Ropsten' export const RINKEBY_DISPLAY_NAME = 'Rinkeby' diff --git a/test/unit/app/controllers/network/network-controller-test.js b/test/unit/app/controllers/network/network-controller-test.js index e081204be..14d3bf31f 100644 --- a/test/unit/app/controllers/network/network-controller-test.js +++ b/test/unit/app/controllers/network/network-controller-test.js @@ -82,7 +82,7 @@ describe('NetworkController', function () { input: '0x4', expected: 'Rinkeby', }, { - input: '0x42', + input: '0x2a', expected: 'Kovan', }, { input: 'ropsten', From e0c32772876c0931e69a5c2d7e79c179a9d81618 Mon Sep 17 00:00:00 2001 From: MetaMask Bot Date: Fri, 3 Jul 2020 15:52:46 +0000 Subject: [PATCH 8/9] Version v8.0.2 --- CHANGELOG.md | 2 ++ app/manifest/_base.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c80389505..548c75ff1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Develop Branch +## 8.0.2 Fri Jul 03 2020 + ## 8.0.1 Thu Jul 02 2020 - [#8874](https://github.com/MetaMask/metamask-extension/pull/8874): Fx overflow behaviour of add token list - [#8885](https://github.com/MetaMask/metamask-extension/pull/8885): Show `origin` in connect flow rather than site name diff --git a/app/manifest/_base.json b/app/manifest/_base.json index 1d567a273..6f054b6db 100644 --- a/app/manifest/_base.json +++ b/app/manifest/_base.json @@ -1,7 +1,7 @@ { "name": "__MSG_appName__", "short_name": "__MSG_appName__", - "version": "8.0.1", + "version": "8.0.2", "manifest_version": 2, "author": "https://metamask.io", "description": "__MSG_appDescription__", From 042bcc8fe92e699c221a0c7ccb26e770e68b7484 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 3 Jul 2020 14:28:44 -0300 Subject: [PATCH 9/9] Update changelog for v8.0.2 (#8912) --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 548c75ff1..5b8c56d71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ ## Current Develop Branch ## 8.0.2 Fri Jul 03 2020 +- [#8907](https://github.com/MetaMask/metamask-extension/pull/8907): Tolerate missing or falsey substitutions +- [#8908](https://github.com/MetaMask/metamask-extension/pull/8908): Fix activity log inline buttons +- [#8909](https://github.com/MetaMask/metamask-extension/pull/8909): Prevent confirming blank suggested token +- [#8910](https://github.com/MetaMask/metamask-extension/pull/8910): Handle suggested token resolved elsewhere +- [#8913](https://github.com/MetaMask/metamask-extension/pull/8913): Fix Kovan chain ID constant ## 8.0.1 Thu Jul 02 2020 - [#8874](https://github.com/MetaMask/metamask-extension/pull/8874): Fx overflow behaviour of add token list