From d53bb61d4762bf276d2fae68b18cd20efbe2a498 Mon Sep 17 00:00:00 2001 From: Shane Date: Wed, 12 May 2021 15:12:46 -0700 Subject: [PATCH 1/5] return early from metaRPCHandler if stream has ended (#11065) * return early from metaRPCHandler if stream has ended * add write after end guard to handleUpdate --- app/scripts/lib/createMetaRPCHandler.js | 6 ++++ app/scripts/lib/createMetaRPCHandler.test.js | 36 ++++++++++++++++++++ app/scripts/metamask-controller.js | 3 ++ 3 files changed, 45 insertions(+) diff --git a/app/scripts/lib/createMetaRPCHandler.js b/app/scripts/lib/createMetaRPCHandler.js index 24ac0ff6a..9b25c6ce7 100644 --- a/app/scripts/lib/createMetaRPCHandler.js +++ b/app/scripts/lib/createMetaRPCHandler.js @@ -2,6 +2,9 @@ import { ethErrors, serializeError } from 'eth-rpc-errors'; const createMetaRPCHandler = (api, outStream) => { return (data) => { + if (outStream._writableState.ended) { + return; + } if (!api[data.method]) { outStream.write({ jsonrpc: '2.0', @@ -13,6 +16,9 @@ const createMetaRPCHandler = (api, outStream) => { return; } api[data.method](...data.params, (err, result) => { + if (outStream._writableState.ended) { + return; + } if (err) { outStream.write({ jsonrpc: '2.0', diff --git a/app/scripts/lib/createMetaRPCHandler.test.js b/app/scripts/lib/createMetaRPCHandler.test.js index e37985105..c3f644ec8 100644 --- a/app/scripts/lib/createMetaRPCHandler.test.js +++ b/app/scripts/lib/createMetaRPCHandler.test.js @@ -58,4 +58,40 @@ describe('createMetaRPCHandler', function () { done(); }); }); + it('can not throw an error for writing an error after end', function (done) { + const api = { + foo: (param1, cb) => { + assert.strictEqual(param1, 'bar'); + cb(new Error('foo-error')); + }, + }; + const streamTest = createThoughStream(); + const handler = createMetaRPCHandler(api, streamTest); + streamTest.end(); + handler({ + id: 1, + method: 'foo', + params: ['bar'], + }); + done(); + }); + it('can not throw an error for write after end', function (done) { + const api = { + foo: (param1, cb) => { + assert.strictEqual(param1, 'bar'); + cb(undefined, { + foo: 'bar', + }); + }, + }; + const streamTest = createThoughStream(); + const handler = createMetaRPCHandler(api, streamTest); + streamTest.end(); + handler({ + id: 1, + method: 'foo', + params: ['bar'], + }); + done(); + }); }); diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 2ae3c6ef1..00b3115c8 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -2024,6 +2024,9 @@ export default class MetamaskController extends EventEmitter { // set up postStream transport outStream.on('data', createMetaRPCHandler(api, outStream)); const handleUpdate = (update) => { + if (outStream._writableState.ended) { + return; + } // send notification to client-side outStream.write({ jsonrpc: '2.0', From 42a72aa3527585dbfdf998246230961b17c760cc Mon Sep 17 00:00:00 2001 From: Thomas Huang Date: Wed, 12 May 2021 15:25:37 -0700 Subject: [PATCH 2/5] Add isHex check for addresses supplied to icons (#11071) --- ui/app/components/ui/identicon/identicon.component.js | 10 ++++++---- ui/lib/icon-factory.js | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ui/app/components/ui/identicon/identicon.component.js b/ui/app/components/ui/identicon/identicon.component.js index bad826dc9..d52717d05 100644 --- a/ui/app/components/ui/identicon/identicon.component.js +++ b/ui/app/components/ui/identicon/identicon.component.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import classnames from 'classnames'; import contractMap from '@metamask/contract-metadata'; -import { checksumAddress } from '../../../helpers/utils/util'; +import { checksumAddress, isHex } from '../../../helpers/utils/util'; import Jazzicon from '../jazzicon'; import BlockieIdenticon from './blockieIdenticon'; @@ -85,10 +85,12 @@ export default class Identicon extends PureComponent { } if (address) { - const checksummedAddress = checksumAddress(address); + if (isHex(address)) { + const checksummedAddress = checksumAddress(address); - if (contractMap[checksummedAddress]?.logo) { - return this.renderJazzicon(); + if (contractMap[checksummedAddress]?.logo) { + return this.renderJazzicon(); + } } return ( diff --git a/ui/lib/icon-factory.js b/ui/lib/icon-factory.js index c72f5dfd9..503e20fe1 100644 --- a/ui/lib/icon-factory.js +++ b/ui/lib/icon-factory.js @@ -1,5 +1,5 @@ import contractMap from '@metamask/contract-metadata'; -import { isValidAddress, checksumAddress } from '../app/helpers/utils/util'; +import { isValidAddress, checksumAddress, isHex } from '../app/helpers/utils/util'; let iconFactory; @@ -16,7 +16,12 @@ function IconFactory(jazzicon) { } IconFactory.prototype.iconForAddress = function (address, diameter) { - const addr = checksumAddress(address); + let addr = address; + + if (isHex(address)) { + addr = checksumAddress(address); + } + if (iconExistsFor(addr)) { return imageElFor(addr); } From 1bf11afd55082bc0003c446c3daa80ea10d9c2b9 Mon Sep 17 00:00:00 2001 From: MetaMask Bot Date: Wed, 12 May 2021 22:35:26 +0000 Subject: [PATCH 3/5] Version v9.5.2 --- CHANGELOG.md | 8 +++++++- app/manifest/_base.json | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 043a560a8..cea71f752 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [9.5.2] +### Uncategorized +- [#11071](https://github.com/MetaMask/metamask-extension/pull/11071): Add isHex check for addresses supplied to icons +- [#11065](https://github.com/MetaMask/metamask-extension/pull/11065): return early from metaRPCHandler if stream has ended + ## [9.5.1] ### Fixed - [#11048](https://github.com/MetaMask/metamask-extension/pull/11048): Fixed icon on approval screen @@ -2226,7 +2231,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Uncategorized - Added the ability to restore accounts from seed words. -[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v9.5.1...HEAD +[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v9.5.2...HEAD +[9.5.2]: https://github.com/MetaMask/metamask-extension/compare/v9.5.1...v9.5.2 [9.5.1]: https://github.com/MetaMask/metamask-extension/compare/v9.5.0...v9.5.1 [9.5.0]: https://github.com/MetaMask/metamask-extension/compare/v9.4.0...v9.5.0 [9.4.0]: https://github.com/MetaMask/metamask-extension/compare/v9.3.0...v9.4.0 diff --git a/app/manifest/_base.json b/app/manifest/_base.json index 40c975a05..07664ccd7 100644 --- a/app/manifest/_base.json +++ b/app/manifest/_base.json @@ -71,6 +71,6 @@ "notifications" ], "short_name": "__MSG_appName__", - "version": "9.5.1", + "version": "9.5.2", "web_accessible_resources": ["inpage.js", "phishing.html"] } From 1170a250fa0394c8a8f59d39a047d1837c608761 Mon Sep 17 00:00:00 2001 From: ryanml Date: Wed, 12 May 2021 15:44:17 -0700 Subject: [PATCH 4/5] icon-factory.js lint fix --- ui/lib/icon-factory.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ui/lib/icon-factory.js b/ui/lib/icon-factory.js index 503e20fe1..7e8a27aca 100644 --- a/ui/lib/icon-factory.js +++ b/ui/lib/icon-factory.js @@ -1,5 +1,9 @@ import contractMap from '@metamask/contract-metadata'; -import { isValidAddress, checksumAddress, isHex } from '../app/helpers/utils/util'; +import { + isValidAddress, + checksumAddress, + isHex, +} from '../app/helpers/utils/util'; let iconFactory; From 6bd303fa65be64de642af66f4ea1fb409fd9b851 Mon Sep 17 00:00:00 2001 From: ryanml Date: Wed, 12 May 2021 15:56:46 -0700 Subject: [PATCH 5/5] [skip e2e] Update changelog for v9.5.2 (#11074) --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cea71f752..f6d821b36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ## [9.5.2] -### Uncategorized -- [#11071](https://github.com/MetaMask/metamask-extension/pull/11071): Add isHex check for addresses supplied to icons -- [#11065](https://github.com/MetaMask/metamask-extension/pull/11065): return early from metaRPCHandler if stream has ended +### Fixed +- [#11071](https://github.com/MetaMask/metamask-extension/pull/11071): Fixing address entry error when sending a transaction on a custom network ## [9.5.1] ### Fixed