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: ignore error when getTokenStandardAndDetails fails #28030

Conversation

sahar-fehri
Copy link
Contributor

@sahar-fehri sahar-fehri commented Oct 22, 2024

Description

Fixes Sentry issue when we are not able to determine token contract standard.

Open in GitHub Codespaces

Related issues

Fixes: #17287

Manual testing steps

(I was not able to repro with my NFTs but to simulate, we can go to the core fct getTokenStandardAndDetails and add
throw new Error('Unable to determine contract standard'); at the start of the fct;

  1. Go NFT page
  2. Click on any NFT
  3. Click Send
  4. You should be able to send the NFT

Screenshots/Recordings

Before

Screen.Recording.2024-10-23.at.02.24.34.mov

After

Screen.Recording.2024-10-23.at.02.44.38.mov

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

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.

@metamaskbot
Copy link
Collaborator

Builds ready [ddb4ae2]
Page Load Metrics (1901 ± 79 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16952393191016881
domContentLoaded16852321187715373
load16962391190116579
domInteractive17182563316
backgroundConnect86822188
firstReactRender48176993316
getState459192010
initialActions01000
loadScripts12071890140215072
setupStore1072272411
uiStartup18942569212419393
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: -7 Bytes (-0.00%)

// prevent infinite stuck loading state
dispatch(hideLoadingIndication());
throw error;
})),
Copy link
Contributor Author

@sahar-fehri sahar-fehri Oct 22, 2024

Choose a reason for hiding this comment

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

This change wont affect native transfers;
It also wont affect ERC20 transfers because for ERC20 transfers tokenCanBeTreatedAsAnERC20 here should be true making details defined and skipping the call to getTokenStandardAndDetails.
This should only affect NFT assets;

This is throwing because the code detects that there is a missing property which is symbol in the case of the nfts i have tested with (here) and because the providedDetails has standard property it will go into the else and call getTokenStandardAndDetails. (still not sure why getTokenStandardAndDetails would throw for so many contracts, it might be good to add the contract address and tokenId in the error log)

The code is detecting that the symbol is missing because the nftDetails symbol is inside providedDetails.collection,
but this piece of code
is expecting the symbol inside the providedDetails object;

The properties that it is checking for an NFT are basically "name, symbol, tokenId" i dnt think tokenId can be undefined for an NFT.
Looking at the number of users affected by this; i would expect that most of them had missingProperty= symbol

Adding sth similar to this;

let missingProperty = STANDARD_TO_REQUIRED_PROPERTIES[ providedDetails.standard ]?.find((property) => { if (providedDetails.collection && property === 'symbol') { return providedDetails.collection[property] === undefined; } return providedDetails[property] === undefined; });
Would make the code go into this if statement
and not make the call to getTokenStandardAndDetails.

However, the symbol inside collection is not always defined either, there will be cases where our third party provider did not return it.

In the case; the code will go into else and call getTokenStandardAndDetails;
For that i have also removed the "throw error"; I don't see why it is necessary to throw when this call fails; I have also tested this and my transactions are going through with the call to getTokenStandardAndDetails failing

@sahar-fehri sahar-fehri force-pushed the fix/add-catch-send-nft-when-getTokenStandardAndDetails-fails branch from 3fcf5a6 to c84f198 Compare October 23, 2024 00:17
@sahar-fehri
Copy link
Contributor Author

There are other places in codebase that call getTokenStandardAndDetails; all of them are either within a try/catch or called using useAsyncResult which should also catch the error

@metamaskbot
Copy link
Collaborator

Builds ready [c84f198]
Page Load Metrics (1957 ± 222 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint160033751961447215
domContentLoaded155733551910416200
load159533681957462222
domInteractive25181553416
backgroundConnect6303498139
firstReactRender44176933818
getState5142243618
initialActions01000
loadScripts110826261400332159
setupStore10134313617
uiStartup173839532214635305
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 48 Bytes (0.00%)

@sahar-fehri sahar-fehri marked this pull request as ready for review October 23, 2024 08:20
@sahar-fehri sahar-fehri requested a review from a team as a code owner October 23, 2024 08:20
@salimtb
Copy link
Contributor

salimtb commented Oct 23, 2024

can you add a unit test for this ?

Copy link
Contributor

@gambinish gambinish left a comment

Choose a reason for hiding this comment

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

I wonder if we should still log the error that gets caught to make future troubleshooting easier? Do we have a logger setup for this kind of thing?

Otherwise lgtm 👍

@sahar-fehri sahar-fehri added the needs-assets-ux-review A shared label between the Assets and UX team to flag PRs ready for consolidated team review. label Oct 23, 2024
@sahar-fehri sahar-fehri added this pull request to the merge queue Oct 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 28, 2024
@sahar-fehri sahar-fehri added this pull request to the merge queue Oct 28, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 28, 2024
@sahar-fehri sahar-fehri added this pull request to the merge queue Oct 31, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 31, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [eb405c4]
Page Load Metrics (2739 ± 584 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1599520127511225588
domContentLoaded1583513327101210581
load1597515227391215584
domInteractive27245836431
backgroundConnect97333199
firstReactRender4635514810048
getState595262411
initialActions01000
loadScripts114638791989892429
setupStore1192402411
uiStartup1761565130771400672
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 48 Bytes (0.00%)

@sahar-fehri sahar-fehri added this pull request to the merge queue Nov 4, 2024
Merged via the queue into develop with commit aaee4e7 Nov 4, 2024
76 checks passed
@sahar-fehri sahar-fehri deleted the fix/add-catch-send-nft-when-getTokenStandardAndDetails-fails branch November 4, 2024 18:03
@github-actions github-actions bot locked and limited conversation to collaborators Nov 4, 2024
@metamaskbot metamaskbot added the release-12.8.0 Issue or pull request that will be included in release 12.8.0 label Nov 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-assets-ux-review A shared label between the Assets and UX team to flag PRs ready for consolidated team review. release-12.8.0 Issue or pull request that will be included in release 12.8.0 team-assets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Sentry] Error: Unable to determine contract standard
6 participants