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: add support for tokenURI encoded images #4482

Merged
merged 5 commits into from
Jul 2, 2024

Conversation

sahar-fehri
Copy link
Contributor

Explanation

We encountered cases where tokenURI we fetched from the contract is an encoded image:

data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaW5ZTWluIG1lZXQiIHZpZXdCb3g9IjAgMCAzNTAgMzUwIj48c3R5bGU+LmJhc2UgeyBmaWxsOiBibGFjazsgZm9udC1mYW1pbHk6IHNlcmlmOyBmb250LXNpemU6IDE0cHg7fTwvc3R5bGU+PHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0id2hpdGUiIHJ5PSI0MCIgcng9IjQwIiBzdHlsZT0ic3Ryb2tlOiNGRjJGMDA7IHN0cm9rZS13aWR0aDo1OyBvcGFjaXR5OjAuOSIgLz48dGV4dCB4PSI1MCUiIHk9IjIwJSIgY2xhc3M9ImJhc2UiIGRvbWluYW50LWJhc2VsaW5lPSJtaWRkbGUiIHRleHQtYW5jaG9yPSJtaWRkbGUiPkV4YW1wbGUgTkZUPC90ZXh0Pjx0ZXh0IHg9IjUwJSIgeT0iMzAlIiBjbGFzcz0iYmFzZSIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9Im1pZGRsZSI+VG9rZW4gSUQ6IDM8L3RleHQ+PHRleHQgeD0iMS4yJSIgeT0iOTAlIiBjbGFzcz0iYmFzZSIgZG9taW5hbnQtYmFzZWxpbmU9Im1pZGRsZSIgdGV4dC1hbmNob3I9ImxlZnQiIHN0eWxlPSJmb250LXNpemU6MTBweDsiPiBQb3dlcmVkIGJ5IFJBRCBUZWFtPC90ZXh0Pjwvc3ZnPg==

In this case, the code will try to call handleFetch to fetch metadata and fail, and eventually return image: null, which on the client side will result in displaying a default fallback image.

This PR adds a check for this case, and returns the encoded data as the image.

References

Changelog

@metamask/assets-controllers

  • FIXED: Added a check in the function getNftInformationFromTokenURI to see if the fetched tokenURI is an encoded image, in which case, we return it as the image.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@sahar-fehri sahar-fehri requested a review from a team as a code owner June 28, 2024 18:38
bergeron
bergeron previously approved these changes Jun 28, 2024
@sahar-fehri sahar-fehri merged commit 1755534 into main Jul 2, 2024
116 checks passed
@sahar-fehri sahar-fehri deleted the fix/add-support-for-base64-tokenURI-format branch July 2, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants