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

[2847] Bug in token balance #2866

Merged
merged 40 commits into from
Sep 7, 2021
Merged

[2847] Bug in token balance #2866

merged 40 commits into from
Sep 7, 2021

Conversation

gantunesr
Copy link
Member

Bug related to a case sensitive match between the keys (address) associated with the token balance.

0x514910771bf9ca656af840dff83e8264ecf123nm != 0x514910771BF9Ca656af840dff83E8264EcF123NM

Fix: Case insensitive key match.

@gantunesr gantunesr added type-bug Something isn't working needs-qa Any New Features that needs a full manual QA prior to being added to a release. needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) labels Jul 5, 2021
@gantunesr gantunesr requested a review from a team July 5, 2021 16:30
@gantunesr gantunesr self-assigned this Jul 5, 2021
@gantunesr gantunesr changed the title [2847] bug in token correct balance [2847] Bug in token balance Jul 5, 2021
Copy link
Member

@andrepimenta andrepimenta left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@mobularay mobularay removed the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Jul 14, 2021
@cortisiko cortisiko added QA in Progress QA has started on the feature. and removed needs-qa Any New Features that needs a full manual QA prior to being added to a release. labels Aug 4, 2021
@cortisiko
Copy link
Member

Issue 1

If I were to remove a token from my wallet then re-add it, the token value shows as “0”
see on android
see on iOS

to reproduce:

  • delete a saved token from your wallet (i deleted chainlink by long pressing the token then tapping delete)
  • from the browser, go to coingecko.com
  • search for chainlink
  • scroll down a little and then tap on “more information”
  • tap on the fox logo.
  • notice a modal appears with the coin name. notice the coin value is incorrect.

@cortisiko cortisiko added QA'd - Issues Found QA has been complete, however issues have been discovered that need to be addressed and removed QA in Progress QA has started on the feature. labels Aug 10, 2021
@cortisiko cortisiko assigned gantunesr and unassigned cortisiko Aug 10, 2021
Copy link
Member

@cortisiko cortisiko left a comment

Choose a reason for hiding this comment

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

sending this guy back. found an issue

Copy link
Member

@cortisiko cortisiko left a comment

Choose a reason for hiding this comment

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

🎉 🎉 🎉 🎉

@cortisiko cortisiko added QA Passed A successful QA run through has been done and removed QA in Progress QA has started on the feature. labels Aug 31, 2021
@cortisiko cortisiko assigned gantunesr and unassigned cortisiko Aug 31, 2021
Copy link
Contributor

@sethkfman sethkfman left a comment

Choose a reason for hiding this comment

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

Updates LGTM

@sethkfman sethkfman removed the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Sep 2, 2021
Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

@gantunesr Left some comments.

);
};

WatchAssetRequest.propTypes = {
Copy link
Contributor

Choose a reason for hiding this comment

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

@gantunesr Not a blocker, but just wanted to bring up that propTypes here are never exposed when consuming this component because this component is wrapped in a HOC caused by connect(). We'll eventually want to convert this component to TypeScript, which will fix this scenario. Totally up to you if you want to convert it now or leave it for the next person who touches this.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Cal-L I'll open another PR for the next release to convert this component to TS, for the moment I would merged as it is.

<View style={styles.infoTitleWrapper}>
<Text style={styles.infoTitle}>{strings('watch_asset_request.token')}</Text>
</View>
const address = Object.keys(contractBalances).find(key => toLowerCaseEquals(key, asset.address));
Copy link
Contributor

Choose a reason for hiding this comment

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

@gantunesr This will refer to line 129->136: What do you think about ditching contractBalances since based on the logic and what we've observed, it doesn't seem to be a 100% reliable source (Since it's possible for balances to not exist in the object). Based on your implementation, useTokenBalance is already called every time the function is rendered and we can just rely on that for now. This gives us one less condition to check/worry about and it'll clean up the code. The only downside is that we may not be showing existing contract balances right away, but I think that's totally fine. As for what happens if the token balances call fails: It looks like you've exposed a loading and error state in useTokenBalance, which would give us control over the UI.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I was thinking to pass the balance value of contractBalances to the hook and only fetch the new balance if the value was undefined but in a second thought, maybe is better to remove contractBalances as a dependence.

* Hook to handle the balance of ERC20 tokens
* @param {String} tokenAddress Token contract address
* @param {String} userAddress Public address which holds the token
* @returns {Handlers} Handlers `[balance, loading, error]`
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is TypeScript, we could remove the types from the TSDocs.
Ref: https://github.com/microsoft/tsdoc/tree/master/tsdoc

For returns, I wasn't really sure what Handlers meant in this context. We could do something like:
@returns Array that consists of [balance, loading, error] to be more explicit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, thanks for the reference

@gantunesr gantunesr requested a review from Cal-L September 7, 2021 13:23
Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

<Text style={styles.infoTitle}>{strings('watch_asset_request.token')}</Text>
</View>
try {
balance = renderFromTokenMinimalUnit(balance, asset.decimals);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move this try catch logic into the renderFromTokenMinimalUnit function and have it return a fallback balance of 0.

cc: @gantunesr

Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

@gantunesr LGTM

@gantunesr gantunesr merged commit 6fcfe4a into develop Sep 7, 2021
@gantunesr gantunesr deleted the bug/token-correct-balance branch September 7, 2021 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA Passed A successful QA run through has been done type-bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WatchAsset method: "Add suggested token" prompt doesn't show correct balance
6 participants