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

TW-687 Reduce balances loading from chain #1064

Conversation

keshan3262
Copy link
Collaborator

No description provided.

lendihop
lendihop previously approved these changes Jan 29, 2024
src/lib/balances/hooks.ts Show resolved Hide resolved
src/lib/balances/hooks.ts Outdated Show resolved Hide resolved
src/app/templates/OperationStatus.tsx Outdated Show resolved Hide resolved
src/lib/temple/operation.ts Outdated Show resolved Hide resolved
lendihop
lendihop previously approved these changes Feb 2, 2024
Comment on lines +149 to +151
// 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);
Copy link
Collaborator

@alex-tsx alex-tsx Feb 6, 2024

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.

  1. FA-2 Tokens

https://tzip.tezosagora.org/proposal/tzip-12/#token-metadata

image Screenshot 2024-02-06 at 14 41 25
  1. FA-1.2 tokens

https://tzip.tezosagora.org/proposal/tzip-7#metadata

https://tzip.tezosagora.org/proposal/tzip-7#token-metadata

Copy link
Collaborator Author

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.

Copy link
Collaborator

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) => {
Copy link
Collaborator

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 });
Copy link
Collaborator

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

Copy link
Collaborator

@alex-tsx alex-tsx left a 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.

@alex-tsx alex-tsx marked this pull request as draft February 11, 2024 22:59
@keshan3262 keshan3262 closed this Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants