-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
// If API fails or chainsToDetectUsingRpc still has items, add chains to RPC detection | ||
this.#addChainsToRpcDetection( |
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.
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(...)
}
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.
Let me know if either of these fixes makes sense to you @salimtb
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.
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 ?
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.
I updated it to keep the RPC fallback if the account API request fails.
!tokenBalancesByChain || | ||
Object.keys(tokenBalancesByChain).length === 0 | ||
) { | ||
if (tokenBalancesByChain === null) { |
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.
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
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
@metamask/package-b
Checklist