-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
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.
LGTM! 👍
Issue 1 If I were to remove a token from my wallet then re-add it, the token value shows as “0” to reproduce:
|
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.
sending this guy back. found an issue
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.
🎉 🎉 🎉 🎉
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.
Updates LGTM
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.
@gantunesr Left some comments.
); | ||
}; | ||
|
||
WatchAssetRequest.propTypes = { |
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.
@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.
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.
@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)); |
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.
@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.
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.
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]` |
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.
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.
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.
Fixed, thanks for the reference
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.
cc: @gantunesr
<Text style={styles.infoTitle}>{strings('watch_asset_request.token')}</Text> | ||
</View> | ||
try { | ||
balance = renderFromTokenMinimalUnit(balance, asset.decimals); |
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's move this try catch logic into the renderFromTokenMinimalUnit
function and have it return a fallback balance of 0.
cc: @gantunesr
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.
@gantunesr LGTM
Bug related to a case sensitive match between the keys (address) associated with the token balance.
0x514910771bf9ca656af840dff83e8264ecf123nm != 0x514910771BF9Ca656af840dff83E8264EcF123NM
Fix: Case insensitive key match.