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

Refactor useSendAccountBalance. Prefe isLoading to isPending #639

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/app/features/home/screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@
export function HomeScreen() {
const media = useMedia()
const [queryParams] = useRootScreenParams()
const { data: sendAccount, isLoading: sendAccountLoading } = useSendAccount()
const { data: sendAccount, isLoading: isSendAccountLoading } = useSendAccount()
const { search } = queryParams
const { balances } = useSendAccountBalances()
const { balances, isLoading: isBalanceLoading } = useSendAccountBalances()
const usdcBalance = balances?.[0]?.result
const canSend = !!sendAccount && usdcBalance && usdcBalance > 0n

Expand All @@ -169,7 +169,7 @@
<AnimatePresence>
{(() => {
switch (true) {
case sendAccountLoading:
case isSendAccountLoading || isBalanceLoading:
return (
<Stack f={1} h={'100%'} ai={'center'} jc={'center'}>
<Spinner size="large" />
Expand Down Expand Up @@ -249,7 +249,7 @@
fontFamily={'$mono'}
ta="center"
>
Earn rewards, transfer funds, and claim your unique Sendtag before it's gone.

Check warning on line 252 in packages/app/features/home/screen.tsx

View workflow job for this annotation

GitHub Actions / Unit Tests

`'` can be escaped with `&apos;`, `&lsquo;`, `&#39;`, `&rsquo;`
</Paragraph>
</YStack>
<Stack jc="center" ai="center" $gtLg={{ mt: 'auto' }} $lg={{ m: 'auto' }}>
Expand Down
15 changes: 7 additions & 8 deletions packages/app/utils/useSendAccountBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
usdcAbi,
} from '@my/wagmi'
import { useBalance, useReadContracts } from 'wagmi'
import { useSendAccounts } from './send-accounts'
import { useSendAccount } from './send-accounts'
import { useTokenPrices } from './useTokenPrices'

const usdcBaseContract = {
Expand All @@ -23,10 +23,9 @@ const sendBaseContract = {

export const useSendAccountBalances = () => {
const { data: tokenPrices } = useTokenPrices()
const { data: sendAccounts } = useSendAccounts()
const sendAccount = sendAccounts?.[0]
const { data: sendAccount } = useSendAccount()

const { data: tokenBalances, isPending: isPendingTokenBalances } = useReadContracts({
const { data: tokenBalances, isPending: isLoadingTokenBalances } = useReadContracts({
query: { enabled: !!sendAccount },
contracts: [
{
Expand All @@ -42,14 +41,14 @@ export const useSendAccountBalances = () => {
],
})

const { data: ethBalanceOnBase, isPending: isPendingEthBalanceOnBase } = useBalance({
const { data: ethBalanceOnBase, isLoading: isLoadingEthBalanceOnBase } = useBalance({
address: sendAccount?.address,
query: { enabled: !!sendAccount },
chainId: baseMainnet.id,
})

const isPending = isPendingTokenBalances || isPendingEthBalanceOnBase
const balances = isPending
const isLoading = isLoadingTokenBalances || isLoadingEthBalanceOnBase
const balances = isLoading
? undefined
: {
eth: ethBalanceOnBase,
Expand All @@ -66,5 +65,5 @@ export const useSendAccountBalances = () => {
(Number(ethBalanceOnBase?.value ?? 0n) / 10 ** 18) * tokenPrices.ethereum.usd
const totalBalance = usdcBalanceInUsd + sendBalanceInUsd + ethBalanceInUsd

return { balances, totalBalance, isPending }
return { balances, totalBalance, isLoading }
}
Loading