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

fix: problem with endless loading of balances and names #5296

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

alter-eggo
Copy link
Contributor

@alter-eggo alter-eggo commented Apr 23, 2024

Try out Leather build f69c12dExtension build, Test report, Storybook, Chromatic

This pr fixes "endless" loading of balances and names in only stacks/btc mode, since part of requests are not enabled and useQuery always returns isLoading: true, I changed it to isFetching

Copy link
Collaborator

@kyranjamie kyranjamie left a comment

Choose a reason for hiding this comment

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

isFetching fires more often than isLoading right, as fetching is always new regardless of if it has data.

So doesn't fetching show the loader more often?

src/app/common/hooks/account/use-account-names.ts Outdated Show resolved Hide resolved
@@ -18,6 +19,7 @@ export function useNativeSegwitBalance(address: string) {
btcBalance: wrappedBalance,
isInitialLoading,
isLoading,
isFetching,
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one could also be a single query being returned with a select

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it couldn't... actually not that easy. the query useGetUtxosByAddressQuery is wrapped several times before this exact hook

@kyranjamie
Copy link
Collaborator

Do we show the shimmer or the skeleton?

@alter-eggo
Copy link
Contributor Author

isFetching fires more often than isLoading right, as fetching is always new regardless of if it has data.

So doesn't fetching show the loader more often?

hm, wonder if it's critical to show shimmer animation every time we fetching? otherwise we need to add something like
isInitialFetching: query.isLoading && query.fetchStatus !== "idle"

@alter-eggo
Copy link
Contributor Author

Do we show the shimmer or the skeleton?

for this change we show shimmer

@kyranjamie
Copy link
Collaborator

since part of requests are not enabled

can you explain this a little more? Why is part of the request not enabled?

Questioning this just because the changes don't map to my understanding of these props. isLoading = initial load only. isFetching = all refetches.

So, if we have a problem with it showing loading state too often, how does changing it to a property that is true more often, fix this problem?

@alter-eggo
Copy link
Contributor Author

alter-eggo commented Apr 23, 2024

can you explain this a little more? Why is part of the request not enabled?

e.g. in ledger mode, when we don't have stx address => we set enabled property of stx queries (balance, bns name etc.) to false (enabled: !!stxAddress). in useQuery when enabled is false => it always returns isLoading: true

@fbwoolf
Copy link
Contributor

fbwoolf commented Apr 23, 2024

e.g. in ledger mode, when we don't have stx address => we set enabled property of stx queries (balance, bns name etc.) to false (enabled: !!stxAddress). in useQuery when enabled is false => it always returns isLoading: true

This is actually surprising to me ...shouldn't that disable the query entirely, so isLoading would be false?

@alter-eggo alter-eggo force-pushed the fix/loader-balance branch 2 times, most recently from 1d6680e to 3f625ed Compare April 23, 2024 15:34
Comment on lines 23 to +34
export function useAccountDisplayName({ address, index }: { index: number; address: string }) {
const { data: names = [], isLoading } = useGetAccountNamesByAddressQuery(address);
return useMemo(() => {
const name = names[0] || getAutogeneratedAccountDisplayName(index);
return {
name,
isLoading,
};
}, [names, index, isLoading]);
const query = useGetBnsNamesOwnedByAddress(address, {
select: resp => {
const names = resp.names ?? [];
return names[0] || getAutogeneratedAccountDisplayName(index);
},
});

return {
...query,
data: query.data || getAutogeneratedAccountDisplayName(index),
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

We only need one of these two techniques right? select or replacing data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

problem here is again in ledger mode, when query is not enabled, select doesn't work

Copy link
Collaborator

Choose a reason for hiding this comment

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

but if you do it on the data prop, it works for both cases, and the select isn't needed?

Copy link
Contributor Author

@alter-eggo alter-eggo Apr 24, 2024

Choose a reason for hiding this comment

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

you mean remove select and
data: (query.data?.names ?? [])[0] || getAutogeneratedAccountDisplayName(index) ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It just seems strange to me you're repeating the logic twice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you can try it in ledger bitcoin only mode

@alter-eggo alter-eggo added this pull request to the merge queue Apr 24, 2024
Merged via the queue into dev with commit 15202f4 Apr 24, 2024
28 checks passed
@alter-eggo alter-eggo deleted the fix/loader-balance branch April 24, 2024 07:47
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