Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trying to access an undefined object in swaps review quote compo… #27708

Merged
merged 4 commits into from
Oct 9, 2024

Conversation

jclancy93
Copy link
Contributor

@jclancy93 jclancy93 commented Oct 8, 2024

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

Related issues

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

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • 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.

Copy link
Contributor

github-actions bot commented Oct 8, 2024

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@jclancy93 jclancy93 marked this pull request as ready for review October 9, 2024 13:56
@jclancy93 jclancy93 requested a review from a team as a code owner October 9, 2024 13:56
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Oct 9, 2024
const latestAddedTokenTo = useSelector(getLatestAddedTokenTo, isEqual);
const numberOfQuotes = Object.keys(quotes).length;
const areQuotesPresent = numberOfQuotes > 0;
const areQuotesPresent = numberOfQuotes > 0 && usedQuote;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions, possibly not worth digging into right now but things we could consider trying to straighten out in the future:
(1) What's the reason usedQuote may not exist if numberOfQuotes > 0?
(2) Is numberOfQuotes > 0 adding anything here or would we just want to use the presence/absence of usedQuote?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea for sure, good questions:

1.

This is what I touched on a bit in the PR description usedQuote is derived from getSelectedQuote or getTopQuote, which both use a key to access the quotes object selectedAggId or topAggId. After many changes, there is a single or a couple of render cycles where this is quotes are defined, but usedQuote is not. usedQuote should never be undefined if quotes are defined, but that does not seem to be true always, which is the root cause of this bug. I tried finding out why, but it took me deep into the extension redux setup, which I'm not too familiar with. That's why I opted for a more bandaid fix like this

2.

I think we could probably remove the length check here, but since the checks accomplish similar things to usedQuote and I'd rather minimize the changes required for the PR, I decided to keep it in. If you think it's worth keeping the checks simpler, I can try it out though!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it in for now - no harm in it 🤷

infiniteflower
infiniteflower previously approved these changes Oct 9, 2024
Copy link
Contributor

@infiniteflower infiniteflower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, LGTM

martahj
martahj previously approved these changes Oct 9, 2024
@jclancy93 jclancy93 dismissed stale reviews from martahj and infiniteflower via 7f128cf October 9, 2024 16:28
Copy link

sonarcloud bot commented Oct 9, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [7f128cf]
Page Load Metrics (2095 ± 140 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30125731886571274
domContentLoaded159325652067295142
load164025702095291140
domInteractive23114492412
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 51 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@jclancy93 jclancy93 added this pull request to the merge queue Oct 9, 2024
Merged via the queue into develop with commit b9a24a7 Oct 9, 2024
78 checks passed
@jclancy93 jclancy93 deleted the MMS-1569-swap-quote-crash branch October 9, 2024 18:16
@github-actions github-actions bot locked and limited conversation to collaborators Oct 9, 2024
@metamaskbot metamaskbot added the release-12.7.0 Issue or pull request that will be included in release 12.7.0 label Oct 9, 2024
@jclancy93 jclancy93 removed the release-12.7.0 Issue or pull request that will be included in release 12.7.0 label Oct 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants