-
Notifications
You must be signed in to change notification settings - Fork 866
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
Add use effect on Balance component for the price #856
Conversation
Fix works great! But I think we need to consider rewriting a bit the logic of the
Yes, with that options we can't change mode of let's say group of Also, who remembers why we added that price > 0 condition? Looks like it's redundant |
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 think it's ok to merge it for usdMode fix, but as I said looks like components need updates
Thanks for the review @rin-st !
The USD mode only makes sense when we have a price for the native currency. If it's loading (or if the fetch fails) it doesn't make sense to show the USD mode... since you won't be able to convert to the native currency (which is what we want for any onchain operation / show balance, etc). So I think that was the reason.
This will only work if we ignore my previous comment (the price condition). I agree that
I don't like this one since it'd require people to do their logic for the basic toggle USD / ETH. I'm not sure if these components need a refactor, but like you said, it should probably happen in another PR. I just created this one as a hotfix, to tackle a bug that is currently happening on main (and tried to be consistent with other components) |
Thank you for explanation!
Agree, 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.
Thanks @carletex for the quick fix !! Merging this
For another PR :
Agree on naming that it should be called defaultUdMode
Regarding working, wouldn't it be more intuitive if we had this flow, just thinking out loud :
- Initial state of
price
(global store isundefined
) [denoting we haven't made any request yet for price] - The initial state of
displayUsdMode
should be only derived fromdefaultUdMode
and not the price.const [displayUsdMode, setDisplayUsdMode] = useState(defaultUsdMode);
- We should have an extra global loading state (
isFetchingPrice
) which denotes price is being fetched - The loading skeleton will be shown if
isFetchingPrice || isBalanceInETHLoading ...
are true - An
useEffect
which checks ifprice === 0 && defaultUsdMode
thensetDisplayUsdMode(false)
[With maybe a console.error("Error getting price") ]
I think isFetchingPrice
is good to have in global store since price
is derived from async action and people would love to have it exposed to workaround the flickering / layout shift
Thanks for your answer Shiv, makes sense. But I don't understand how component will work if |
The
usdMode
flag wasn't working on ourBalance
component, since the price takes some time to load and we were always settingdisplayUsdMode
to false on the first render (price > 0 condition)You can test in
page.tsx
This PR adds the missing
useEffect
(as in EtherInput).