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

Wrap the getFormattedIpfsUrl call in getAssetImageURL in a try catch,… #21418

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

danjm
Copy link
Contributor

@danjm danjm commented Oct 17, 2023

… so the app doesn't crash on certain ipfs urls

Fixes #21417

Description

See the code comment added in this PR for full details:

    // With v11.1.0, we started seeing errors thrown that included this
    // line in the stack trace. The cause is that the `getIpfsCIDv1AndPath`
    // method within assets-controllers/src/assetsUtil.ts can throw
    // if part of the ipfsUrl, i.e. the `image` variable within this function,
    // contains characters not in the Base58 alphabet. Details on that are
    // here https://digitalbazaar.github.io/base58-spec/#alphabet. This happens
    // with some NFTs, when we attempt to parse part of their IPFS image address
    // with the `CID.parse` function (CID is part of the multiform package)
    //
    // Before v11.1.0 `getFormattedIpfsUrl` was not used in the extension codebase.
    // Its use within assets-controllers always ensures that errors are caught
    // and ignored. So while we were handling NFTs that can cause this error before,
    // we were always catching and ignoring the error. As of PR #20172, we started
    // passing all NFTs image URLs to `getAssetImageURL` from nft-items.js, which is
    // why we started seeing these errors cause crashes for users in v11.1.0
    //
    // For the sake of a quick fix, we are wrapping this call in a try-catch, which
    // the assets-controllers already do in some form in all cases where this function
    // is called. This probably does not affect user experience, as we would not have
    // correctly rendered these NFTs before v11.1.0 either (due to the same error
    // disuccessed in this code comment).
    //
    // In the future, we can look into solving the root cause, which might require
    // no longer using multiform's CID.parse() method within the assets-controller

Manual testing steps

Not sure of an easy way to test.

One way would be:

  1. Add an NFT to your wallet which has an ipfs image url with the character I in it
  2. Go to the NFT tab. That NFT should not be visible, but the app should not crash

Related issues

Related to #18564, but does not fix it.

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained:
    • What problem this PR is solving.
    • How this problem was solved.
    • How reviewers can test my changes.
  • I’ve indicated what issue this PR is linked to: Fixes #???
  • I’ve included tests if applicable.
  • I’ve documented any added code.
  • I’ve applied the right labels on the PR (see labeling guidelines).
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

… so the app doesn't crash on certain ipfs urls
@danjm danjm requested a review from a team as a code owner October 17, 2023 19:35
@github-actions
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 [8fa2db3]
Page Load Metrics (1121 ± 362 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint86143101157
domContentLoaded7013295147
load8218231121753362
domInteractive7013294147
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: -567 Bytes (-0.01%)
  • common: 736 Bytes (0.01%)

@danjm danjm merged commit 5863649 into develop Oct 18, 2023
8 of 9 checks passed
@danjm danjm deleted the fix-nft-error branch October 18, 2023 00:50
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2023
@metamaskbot metamaskbot added the release-11.5.0 Issue or pull request that will be included in release 11.5.0 label Oct 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-11.5.0 Issue or pull request that will be included in release 11.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some NFTs cause Non-base58btc character errors to crash the app on the home screen
5 participants