From 14416a796a7885527bc7a91113fb8251da646c32 Mon Sep 17 00:00:00 2001 From: Brad Decker Date: Tue, 7 Jul 2020 15:15:04 -0500 Subject: [PATCH 1/6] add support for nullish coalescing (#8935) --- babel.config.js | 1 + package.json | 1 + yarn.lock | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/babel.config.js b/babel.config.js index 825b26900a74..26b47fdb9d0e 100644 --- a/babel.config.js +++ b/babel.config.js @@ -20,6 +20,7 @@ module.exports = function (api) { '@babel/plugin-proposal-class-properties', '@babel/plugin-proposal-object-rest-spread', '@babel/plugin-proposal-optional-chaining', + '@babel/plugin-proposal-nullish-coalescing-operator', ], } } diff --git a/package.json b/package.json index e22fb01f3643..6a8b3e46680f 100644 --- a/package.json +++ b/package.json @@ -181,6 +181,7 @@ "devDependencies": { "@babel/core": "^7.5.5", "@babel/plugin-proposal-class-properties": "^7.5.5", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.4", "@babel/plugin-proposal-object-rest-spread": "^7.5.5", "@babel/plugin-proposal-optional-chaining": "^7.8.3", "@babel/plugin-transform-runtime": "^7.5.5", diff --git a/yarn.lock b/yarn.lock index a23a2fa48f2e..ed9acb9176b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -228,6 +228,11 @@ resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250" integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA== +"@babel/helper-plugin-utils@^7.10.4": + version "7.10.4" + resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.10.4.tgz#2f75a831269d4f677de49986dff59927533cf375" + integrity sha512-O4KCvQA6lLiMU9l2eawBPMf1xPP8xPfB3iEQw150hOVTqj/rfXz0ThTb4HEzqQfs2Bmo5Ay8BzxfzVtBrr9dVg== + "@babel/helper-plugin-utils@^7.8.0", "@babel/helper-plugin-utils@^7.8.3": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670" @@ -342,6 +347,14 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-json-strings" "^7.2.0" +"@babel/plugin-proposal-nullish-coalescing-operator@^7.10.4": + version "7.10.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.10.4.tgz#02a7e961fc32e6d5b2db0649e01bf80ddee7e04a" + integrity sha512-wq5n1M3ZUlHl9sqT2ok1T2/MTt6AXE0e1Lz4WzWBr95LsAZ5qDXe4KnFuauYyEyLiohvXFMdbsOTMyLZs91Zlw== + dependencies: + "@babel/helper-plugin-utils" "^7.10.4" + "@babel/plugin-syntax-nullish-coalescing-operator" "^7.8.0" + "@babel/plugin-proposal-object-rest-spread@^7.4.4", "@babel/plugin-proposal-object-rest-spread@^7.5.5", "@babel/plugin-proposal-object-rest-spread@^7.6.2": version "7.8.3" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.8.3.tgz#eb5ae366118ddca67bed583b53d7554cad9951bb" @@ -410,6 +423,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-syntax-nullish-coalescing-operator@^7.8.0": + version "7.8.3" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.8.3.tgz#167ed70368886081f74b5c36c65a88c03b66d1a9" + integrity sha512-aSff4zPII1u2QD7y+F8oDsz19ew4IGEJg9SVW+bqwpwtfFleiQDMdzA/R+UlWDzfnHFCxxleFT0PMIrR36XLNQ== + dependencies: + "@babel/helper-plugin-utils" "^7.8.0" + "@babel/plugin-syntax-object-rest-spread@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz#3b7a3e733510c57e820b9142a6579ac8b0dfad2e" From 15d713f0ee7239d1e1c138c91f12c5c442340aec Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Tue, 7 Jul 2020 15:15:42 -0700 Subject: [PATCH 2/6] Standardize transaction activity conversion's currency to 'ETH' (#8934) --- .../transaction-activity-log.component.js | 6 +++--- 1 file changed, 3 insertions(+), 3 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 4a9a9791e3a1..baa120a8744b 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 @@ -74,14 +74,14 @@ export default class TransactionActivityLog extends PureComponent { const ethValue = index === 0 ? `${getValueFromWeiHex({ value, - fromCurrency: nativeCurrency, - toCurrency: nativeCurrency, + fromCurrency: 'ETH', + toCurrency: 'ETH', conversionRate, numberOfDecimals: 6, })} ${nativeCurrency}` : getEthConversionFromWeiHex({ value, - fromCurrency: nativeCurrency, + fromCurrency: 'ETH', conversionRate, numberOfDecimals: 3, }) From 429af23ea034b627c1236b2f1b113b8354864009 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Tue, 7 Jul 2020 19:16:38 -0300 Subject: [PATCH 3/6] Fix account tracker optimization (#8936) An optimization in `account-tracker.js` was being skipped consistently due to a type error (a number was being compared to a string). The optimization in this case was to update the balances for all accounts with a single request, rather than one request per account. --- app/scripts/lib/account-tracker.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/scripts/lib/account-tracker.js b/app/scripts/lib/account-tracker.js index d1ab1e583544..dd8a2a4799b1 100644 --- a/app/scripts/lib/account-tracker.js +++ b/app/scripts/lib/account-tracker.js @@ -191,19 +191,19 @@ export default class AccountTracker { const currentNetwork = this.network.getNetworkState() switch (currentNetwork) { - case MAINNET_NETWORK_ID: + case MAINNET_NETWORK_ID.toString(): await this._updateAccountsViaBalanceChecker(addresses, SINGLE_CALL_BALANCES_ADDRESS) break - case RINKEBY_NETWORK_ID: + case RINKEBY_NETWORK_ID.toString(): await this._updateAccountsViaBalanceChecker(addresses, SINGLE_CALL_BALANCES_ADDRESS_RINKEBY) break - case ROPSTEN_NETWORK_ID: + case ROPSTEN_NETWORK_ID.toString(): await this._updateAccountsViaBalanceChecker(addresses, SINGLE_CALL_BALANCES_ADDRESS_ROPSTEN) break - case KOVAN_NETWORK_ID: + case KOVAN_NETWORK_ID.toString(): await this._updateAccountsViaBalanceChecker(addresses, SINGLE_CALL_BALANCES_ADDRESS_KOVAN) break From ac525572ebc1a59dd45980b6d70bdafac6a68815 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Tue, 7 Jul 2020 19:48:18 -0230 Subject: [PATCH 4/6] Move checkExistingAddresses to helpers/utils/util and stop its use of ramda (#8868) --- ui/app/helpers/utils/util.js | 20 +++++++++++++ ui/app/helpers/utils/util.test.js | 29 +++++++++++++++++++ ui/app/pages/add-token/add-token.component.js | 2 +- .../token-list/token-list.component.js | 2 +- ui/app/pages/add-token/util.js | 13 --------- .../add-recipient/add-recipient.js | 4 +-- 6 files changed, 52 insertions(+), 18 deletions(-) delete mode 100644 ui/app/pages/add-token/util.js diff --git a/ui/app/helpers/utils/util.js b/ui/app/helpers/utils/util.js index cc1aba75c267..37f852530ff5 100644 --- a/ui/app/helpers/utils/util.js +++ b/ui/app/helpers/utils/util.js @@ -333,3 +333,23 @@ export function isExtensionUrl (urlLike) { } return false } + +/** + * Checks whether an address is in a passed list of objects with address properties. The check is performed on the + * lowercased version of the addresses. + * + * @param {string} address - The hex address to check + * @param {array} list - The array of objects to check + * @returns {boolean} Whether or not the address is in the list + */ +export function checkExistingAddresses (address, list = []) { + if (!address) { + return false + } + + const matchesAddress = (obj) => { + return obj.address.toLowerCase() === address.toLowerCase() + } + + return list.some(matchesAddress) +} diff --git a/ui/app/helpers/utils/util.test.js b/ui/app/helpers/utils/util.test.js index 4647b36522bf..4be1713e9919 100644 --- a/ui/app/helpers/utils/util.test.js +++ b/ui/app/helpers/utils/util.test.js @@ -319,4 +319,33 @@ describe('util', function () { }) }) }) + + describe('checkExistingAddresses', function () { + const tokenList = [ + { address: 'A' }, + { address: 'n' }, + { address: 'Q' }, + { address: 'z' }, + ] + + it('should return true when a lowercase address matches an uppercase address in the passed list', function () { + assert(util.checkExistingAddresses('q', tokenList) === true) + }) + + it('should return true when an uppercase address matches a lowercase address in the passed list', function () { + assert(util.checkExistingAddresses('N', tokenList) === true) + }) + + it('should return true when a lowercase address matches a lowercase address in the passed list', function () { + assert(util.checkExistingAddresses('z', tokenList) === true) + }) + + it('should return true when an uppercase address matches an uppercase address in the passed list', function () { + assert(util.checkExistingAddresses('Q', tokenList) === true) + }) + + it('should return false when the passed address is not in the passed list', function () { + assert(util.checkExistingAddresses('b', tokenList) === false) + }) + }) }) diff --git a/ui/app/pages/add-token/add-token.component.js b/ui/app/pages/add-token/add-token.component.js index f2d0332121a9..158f96a92b65 100644 --- a/ui/app/pages/add-token/add-token.component.js +++ b/ui/app/pages/add-token/add-token.component.js @@ -1,7 +1,7 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import ethUtil from 'ethereumjs-util' -import { checkExistingAddresses } from './util' +import { checkExistingAddresses } from '../../helpers/utils/util' import { tokenInfoGetter } from '../../helpers/utils/token-util' import { CONFIRM_ADD_TOKEN_ROUTE } from '../../helpers/constants/routes' import TextField from '../../components/ui/text-field' diff --git a/ui/app/pages/add-token/token-list/token-list.component.js b/ui/app/pages/add-token/token-list/token-list.component.js index 8843daee5bfd..633ffea9c52c 100644 --- a/ui/app/pages/add-token/token-list/token-list.component.js +++ b/ui/app/pages/add-token/token-list/token-list.component.js @@ -1,7 +1,7 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import classnames from 'classnames' -import { checkExistingAddresses } from '../util' +import { checkExistingAddresses } from '../../../helpers/utils/util' import TokenListPlaceholder from './token-list-placeholder' export default class InfoBox extends Component { diff --git a/ui/app/pages/add-token/util.js b/ui/app/pages/add-token/util.js deleted file mode 100644 index b0f3bbd4c441..000000000000 --- a/ui/app/pages/add-token/util.js +++ /dev/null @@ -1,13 +0,0 @@ -import R from 'ramda' - -export function checkExistingAddresses (address, tokenList = []) { - if (!address) { - return false - } - - const matchesAddress = (existingToken) => { - return existingToken.address.toLowerCase() === address.toLowerCase() - } - - return R.any(matchesAddress)(tokenList) -} diff --git a/ui/app/pages/send/send-content/add-recipient/add-recipient.js b/ui/app/pages/send/send-content/add-recipient/add-recipient.js index b170738e4420..a5407ece02ac 100644 --- a/ui/app/pages/send/send-content/add-recipient/add-recipient.js +++ b/ui/app/pages/send/send-content/add-recipient/add-recipient.js @@ -5,9 +5,7 @@ import { INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR, } from '../../send.constants' -import { isValidAddress, isEthNetwork } from '../../../../helpers/utils/util' -import { checkExistingAddresses } from '../../../add-token/util' - +import { isValidAddress, isEthNetwork, checkExistingAddresses } from '../../../../helpers/utils/util' import ethUtil from 'ethereumjs-util' import contractMap from 'eth-contract-metadata' From 015008c147b941b4b92168e1cb298d39cbcc325e Mon Sep 17 00:00:00 2001 From: MetaMask Bot Date: Tue, 7 Jul 2020 22:29:28 +0000 Subject: [PATCH 5/6] Version v8.0.4 --- CHANGELOG.md | 2 ++ app/manifest/_base.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 739b2cf64de2..18b88533e701 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Develop Branch +## 8.0.4 Tue Jul 07 2020 + ## 8.0.3 Mon Jul 06 2020 - [#8921](https://github.com/MetaMask/metamask-extension/pull/8921): Restore missing 'data' provider event, and fix 'notification' event - [#8923](https://github.com/MetaMask/metamask-extension/pull/8923): Normalize the 'from' parameter for `eth_sendTransaction` diff --git a/app/manifest/_base.json b/app/manifest/_base.json index fa751a2d2040..75c0a2c404a2 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.3", + "version": "8.0.4", "manifest_version": 2, "author": "https://metamask.io", "description": "__MSG_appDescription__", From 5213e9e44d49a5a645b61064e9fd78bf1ebd3e6e Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Tue, 7 Jul 2020 20:57:28 -0300 Subject: [PATCH 6/6] Update changelog for v8.0.4 (#8938) --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18b88533e701..08f5c24cd941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## Current Develop Branch ## 8.0.4 Tue Jul 07 2020 +- [#8934](https://github.com/MetaMask/metamask-extension/pull/8934): Fix transaction activity on custom networks +- [#8936](https://github.com/MetaMask/metamask-extension/pull/8936): Fix account tracker optimization ## 8.0.3 Mon Jul 06 2020 - [#8921](https://github.com/MetaMask/metamask-extension/pull/8921): Restore missing 'data' provider event, and fix 'notification' event