From 72c5cc329840726f59f34e65fae8c41aaaf2583f Mon Sep 17 00:00:00 2001 From: Jack Clancy Date: Wed, 9 Oct 2024 18:30:25 +0100 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20trying=20to=20access=20an=20undefine?= =?UTF-8?q?d=20object=20in=20swaps=20review=20quote=20compo=E2=80=A6=20(#2?= =?UTF-8?q?7708)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Fixes the two errors with trade and decimals being undefined that have been causing crashes starting around the 12.1/12.2 release. I was unable to find the root cause of this issue. Variables in the redux store seem to return as undefined, which leads me to think it might be some sort of redux race condition. The lowest common denominator of this error seems to be that `getUsedQuote` selector in the `ReviewQuote` component. I have added an additional condition to the render guard in the parent component `prepare-swaps-page` to prevent these errors [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27708?quickstart=1) ## **Related issues** [MMS-1569](https://consensyssoftware.atlassian.net/jira/software/projects/MMS/boards/447/backlog?assignee=5ae37c7e42b8a62c4e15d92a&selectedIssue=MMS-1569) ## **Manual testing steps** 1. Open Swaps Page 2. Enter swap amount 3. Edit to token and amount rapidly multiple times 4. Page should not crash ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. [MMS-1569]: https://consensyssoftware.atlassian.net/browse/MMS-1569?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --- ui/pages/swaps/prepare-swap-page/prepare-swap-page.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js index 98bb6933d0c3..45120d9f6a6b 100644 --- a/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js +++ b/ui/pages/swaps/prepare-swap-page/prepare-swap-page.js @@ -52,6 +52,7 @@ import { getTransactionSettingsOpened, setTransactionSettingsOpened, getLatestAddedTokenTo, + getUsedQuote, } from '../../../ducks/swaps/swaps'; import { getSwapsDefaultToken, @@ -190,9 +191,10 @@ export default function PrepareSwapPage({ const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider, shallowEqual); const tokenList = useSelector(getTokenList, isEqual); const quotes = useSelector(getQuotes, isEqual); + const usedQuote = useSelector(getUsedQuote, isEqual); const latestAddedTokenTo = useSelector(getLatestAddedTokenTo, isEqual); const numberOfQuotes = Object.keys(quotes).length; - const areQuotesPresent = numberOfQuotes > 0; + const areQuotesPresent = numberOfQuotes > 0 && usedQuote; const swapsErrorKey = useSelector(getSwapsErrorKey); const aggregatorMetadata = useSelector(getAggregatorMetadata, shallowEqual); const transactionSettingsOpened = useSelector( From 5cff8b536b536945922fe83b378919a8ed733ec8 Mon Sep 17 00:00:00 2001 From: Jack Clancy Date: Thu, 10 Oct 2024 12:50:09 +0100 Subject: [PATCH 2/3] chore: update changelog for rc12.4.1 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cae12b166c2..642ac243803a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ## [12.4.1] +### Fixed +- Fixed try to access an undefined object in swaps review quote component([27708](https://github.com/MetaMask/metamask-extension/pull/27708)) ## [12.4.0] ### Added From 3889c9b78ace210723681515e3817e1c7e85813a Mon Sep 17 00:00:00 2001 From: Jack Clancy Date: Thu, 10 Oct 2024 14:00:58 +0100 Subject: [PATCH 3/3] chore: clarify changeog message Co-authored-by: Mark Stacey --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 642ac243803a..d69b3b7c6fb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [12.4.1] ### Fixed -- Fixed try to access an undefined object in swaps review quote component([27708](https://github.com/MetaMask/metamask-extension/pull/27708)) +- Fix crash on swaps review page ([27708](https://github.com/MetaMask/metamask-extension/pull/27708)) ## [12.4.0] ### Added