Skip to content

Commit 05bbc8f

Browse files
committed
refactor: update KarmaButton to use useKarmaBalance hook and adjust queryKey for balance fetching
1 parent dbe75d6 commit 05bbc8f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

apps/hub/src/app/_components/karma-button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Image from 'next/image'
66

77
import { formatKarma } from '~utils/currency'
88

9-
import { useKarmaRewardsDistributor } from '../_hooks/useKarmaRewardsDistributor'
9+
import { useKarmaBalance } from '../_hooks/useKarmaBalance'
1010

1111
import type { ComponentProps } from 'react'
1212

@@ -17,7 +17,7 @@ type Props = {
1717

1818
const KarmaButton = (props: Props) => {
1919
const { size = '32', className, ...rest } = props
20-
const { data } = useKarmaRewardsDistributor()
20+
const { data } = useKarmaBalance()
2121

2222
const amount = formatKarma(data?.balance ?? BigInt(0), {
2323
compact: size === '32' ? false : true,

apps/hub/src/app/_hooks/useKarmaBalance.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useQuery, type UseQueryResult } from '@tanstack/react-query'
33
import { type Address } from 'viem'
44
import { useAccount, useChainId, useConfig } from 'wagmi'
55
import { readContract } from 'wagmi/actions'
6+
import { statusSepolia } from 'wagmi/chains'
67

78
import { CACHE_CONFIG, KARMA } from '~constants/index'
89

@@ -161,16 +162,21 @@ export function useKarmaBalance(
161162

162163
// Use provided address or fall back to connected address
163164
const targetAddress = queryAddress ?? connectedAddress
165+
const isStatusNetworkSepolia = chainId === statusSepolia.id
164166

165167
return useQuery<KarmaBalanceData>({
166-
queryKey: [QUERY_KEY_PREFIX, targetAddress, chainId] as const,
168+
queryKey: [QUERY_KEY_PREFIX, targetAddress, statusSepolia.id] as const,
167169
queryFn: async (): Promise<KarmaBalanceData> => {
168170
if (!targetAddress) {
169171
throw new Error('No address provided')
170172
}
171173

172174
try {
173-
const balance = await fetchKarmaBalance(config, chainId, targetAddress)
175+
const balance = await fetchKarmaBalance(
176+
config,
177+
statusSepolia.id,
178+
targetAddress
179+
)
174180

175181
return {
176182
balance,
@@ -183,7 +189,7 @@ export function useKarmaBalance(
183189
throw error
184190
}
185191
},
186-
enabled: enabled && !!targetAddress,
192+
enabled: enabled && !!targetAddress && isStatusNetworkSepolia,
187193
staleTime,
188194
refetchInterval,
189195
retry: 3,

0 commit comments

Comments
 (0)