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 token detection fallback #4928

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

fix token detection fallback #4928

wants to merge 4 commits into from

Conversation

bergeron
Copy link
Contributor

@bergeron bergeron commented Nov 14, 2024

Explanation

Even when account API detection succeeded, it was doing an additional, redundant RPC based detection on the same chains.

References

Changelog

@metamask/package-a

  • : Your change here
  • : Your change here

@metamask/package-b

  • : Your change here
  • : Your change here

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
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

}

// If API fails or chainsToDetectUsingRpc still has items, add chains to RPC detection
this.#addChainsToRpcDetection(
Copy link
Contributor Author

@bergeron bergeron Nov 14, 2024

Choose a reason for hiding this comment

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

This seems like it was just adding all the account API chains, so it was doing an additional, redundant RPC based detection even when the account api just succeeded for those chains.

The above condition is not sufficient to short circuit, when you have a mix of chains that do and do not support account api.

If we want to keep an rpc based fallback if the account API fails, we could instead make the condition something like:

if (apiResult?.result === 'failed') {
  this.#addChainsToRpcDetection(...)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if either of these fixes makes sense to you @salimtb

Copy link
Contributor

@salimtb salimtb Nov 14, 2024

Choose a reason for hiding this comment

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

yes, i got the idea and the fix makes sense to me. Just to confirm, given that the unit test is currently failing, with this fix, do we revert to the RPC method if the call to the account API fails or not called ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated it to keep the RPC fallback if the account API request fails.

!tokenBalancesByChain ||
Object.keys(tokenBalancesByChain).length === 0
) {
if (tokenBalancesByChain === null) {
Copy link
Contributor Author

@bergeron bergeron Nov 14, 2024

Choose a reason for hiding this comment

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

This used to return failed if the api response was empty. But that's a valid response if it's an empty account with no tokens. Now it returns failed if the request is not http 200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants