-
-
Notifications
You must be signed in to change notification settings - Fork 201
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 thresshold for update NFT metadata #5134
fix: add thresshold for update NFT metadata #5134
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code itself looks good as it achieves what's stated in the PR description, though I feel like firing 500 eth_call
requests every time users switch selected addresses or preferences are updated sounds still exaggerated.
For instance, is there a reason for requiring updates on NFTs on every preference change?
Thanks @mikesposito ! That's right, i updated the code so it checks before doing the update if at least one of the concerned params has been updated as part of the preference update (ipfsGateway, openSeaEnabled or isIpfsGatewayEnabled) |
if ( | ||
this.#ipfsGateway !== ipfsGateway || | ||
this.#openSeaEnabled !== openSeaEnabled || | ||
this.#isIpfsGatewayEnabled !== isIpfsGatewayEnabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this so that even if this gets triggered for any reason; we do not proceed to update the nftmetadata unless one of the concerned params has changed
82f77b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Co-authored-by: Michele Esposito <[email protected]>
ef12e4f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Explanation
When
onPreferencesControllerStateChange
is triggered inside nftController, it also triggers a check if nfts saved in state needs to be updated.We keep retrying to update NFTs (fetching their metadata) when they have no image, name or description.
Note: When switching newtworks; this line is the trigger for the
onPreferencesControllerStateChange
.While the updateNftUpdateForAccount should be triggered once for NFTs that actually have a (name, description, image)
We will keep retrying for NFTs that don't. (Could be nfts created for testing purposes or some raffle tickets do not have those fields).
We had a user reporting that he is seeing an excessive amount of RPC calls made on one of his accounts on Arbitrum Sepolia. This account holds more than a 1000 NFT. Every time he switches the network to Arbitrum Sepolia, he sees more than a 1000 eth_call made.
That was the result of updateNftUpdateForAccount being triggered everytime the network is switched + The nfts not having (name,image, description)
This PR adds a 500 threshold to avoid sending an excessive amount of RPC calls to fetch nft metadata and adds a check if the triggered onPreferencesControllerStateChange updates any of the concerned params ( ipfsGateway, openseaEnabled, isIpfsGatewayEnabled)
Better improvement:
A better improvement for this would be to add support for BalanceScanner contract, which allows to fetch tokenURI for multiple addresses and tokenIds with fct tokenURIsofTokenIdsForTokens.
We will control how often this is refreshed. For users that have nfts > NFT_UPDATE_THRESHOLD, we save the timestamp of the first update in a mapping chainId => lastTimestamp of updateNftMetadata, and only update after a specific period of time NFT_UPDATE_REFRESH_PERIOD = 48hours.
References
Changelog
@metamask/controller-utils
@metamask/assets-controllers
updateNftUpdateForAccount
Checklist