-
Notifications
You must be signed in to change notification settings - Fork 63
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
TW-687 Reduce balances loading from chain #1064
TW-687 Reduce balances loading from chain #1064
Conversation
// Metadata may really be absent for some assets, see account tz1aSkwEot3L2kmUvcoxzjMomb9mvBNuzFK6 | ||
// in Mainnet for example | ||
return rawBalance == null ? undefined : atomsToTokens(new BigNumber(rawBalance), assetMetadata?.decimals ?? 0); |
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.
It will be safer to never assume decimals === 0
. Our current policy is that absent metadata is metadata that has only failed to load.
Please, refer to the standard specs.
- FA-2 Tokens
https://tzip.tezosagora.org/proposal/tzip-12/#token-metadata
- FA-1.2 tokens
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.
Sorry, in our logic, failure of one token to load means failure of all tokens list to load, which is unacceptable.
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.
useBalance
hook became very very convoluted & large (~200 lines of code) + other new definitions in this file. I think, it should be a rather simple hook, much smaller than this. Please, simplify it.
return new Promise<BigNumber>((res, rej) => { | ||
const unsubscribe = subscribeToActions(action => { | ||
if (shouldUseTzkt) { | ||
suspenseByReduxAction((action, stopSuspense) => { |
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.
Subscriptions to actions is still a very messy mechanism. Why do we need it at all? Can it be a simple throw like this?
if (someReduxStateLoadingFlag && thisFlagIsRelevantToTokenInInterest) throw new Promise(/* implementation here */)
I refer to the way, SWR does this:
export const useCurrentAccountAssetBalance = (slug: string) => { | ||
const { publicKeyHash } = useAccount(); | ||
|
||
const { data: balance } = useBalance(slug, publicKeyHash, { suspense: true }); |
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.
Suspence true
is a change of logic here. Used to be without it
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.
Eliminate suspense
usage thought useBalance
hook everywhere. Handle cases with current suspense: true
gracefully.
No description provided.