File tree Expand file tree Collapse file tree 6 files changed +41
-7
lines changed
web/src/components/receive-tokens-modal Expand file tree Collapse file tree 6 files changed +41
-7
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ export type QueryOptions<T = any> = Pick<
2828 | 'placeholderData'
2929 | 'refetchOnMount'
3030 | 'throwOnError'
31+ | 'refetchInterval'
32+ | 'refetchOnWindowFocus'
3133>
3234
3335export type SelectableQueryOptions < TData , TResult = TData > = Omit <
Original file line number Diff line number Diff line change @@ -57,7 +57,12 @@ export const useTokenBalance = ({
5757 includeConnectedWallets : includeExternalWallets ,
5858 includeStaked
5959 } ,
60- { enabled : isAudio }
60+ {
61+ enabled : isAudio ,
62+ refetchInterval : isPolling ? pollingInterval : undefined ,
63+ refetchOnWindowFocus : ! isPolling ,
64+ ...queryOptions
65+ }
6166 )
6267
6368 // Artist coins query
@@ -95,6 +100,8 @@ export const useTokenBalance = ({
95100 decimals
96101 }
97102 } ,
103+ refetchInterval : isPolling ? pollingInterval : undefined ,
104+ refetchOnWindowFocus : ! isPolling ,
98105 ...queryOptions ,
99106 enabled : ! isUsdc && queryOptions . enabled !== false
100107 }
Original file line number Diff line number Diff line change @@ -26,14 +26,22 @@ type UseFormattedTokenBalanceReturn = {
2626 * Hook to get formatted balance and price information for any supported mint
2727 * @param mint - The mint symbol to get balance and price for
2828 * @param locale - Locale for number formatting (defaults to 'en-US')
29+ * @param isPolling - Whether to enable polling for balance updates
30+ * @param pollingInterval - Interval for polling in milliseconds (defaults to 3000ms)
2931 * @returns Object with formatted balance, price, and loading states
3032 */
3133export const useFormattedTokenBalance = (
3234 mint : string ,
33- locale : string = 'en-US'
35+ locale : string = 'en-US' ,
36+ isPolling ?: boolean ,
37+ pollingInterval ?: number
3438) : UseFormattedTokenBalanceReturn => {
3539 const { data : tokenBalance , isPending : isTokenBalanceLoading } =
36- useTokenBalance ( { mint } )
40+ useTokenBalance ( {
41+ mint,
42+ isPolling,
43+ pollingInterval
44+ } )
3745
3846 const { data, isPending : isTokenPriceLoading } = useArtistCoin ( mint )
3947
Original file line number Diff line number Diff line change @@ -11,10 +11,24 @@ import { TokenIcon } from './TokenIcon'
1111export type BalanceSectionProps = {
1212 /** Mint address for fetching balance */
1313 mint ?: string
14+ /** Whether to enable polling for balance updates */
15+
16+ isPolling ?: boolean
17+ /** Interval for polling in milliseconds */
18+ pollingInterval ?: number
1419}
1520
16- export const BalanceSection = ( { mint } : BalanceSectionProps ) => {
17- const { tokenBalanceFormatted } = useFormattedTokenBalance ( mint ?? '' )
21+ export const BalanceSection = ( {
22+ mint,
23+ isPolling,
24+ pollingInterval
25+ } : BalanceSectionProps ) => {
26+ const { tokenBalanceFormatted } = useFormattedTokenBalance (
27+ mint ?? '' ,
28+ 'en-US' ,
29+ isPolling ,
30+ pollingInterval
31+ )
1832 const { data : coin } = useArtistCoin ( mint )
1933 const tokenInfo = coin ? transformArtistCoinToTokenInfo ( coin ) : undefined
2034
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ export const ReceiveTokensDrawer = () => {
8484 return (
8585 < Drawer isOpen = { isOpen } onClose = { onClose } drawerHeader = { renderHeader } >
8686 < Flex direction = 'column' gap = 'xl' ph = 'xl' >
87- < BalanceSection mint = { mint } />
87+ < BalanceSection mint = { mint } isPolling = { isOpen } pollingInterval = { 3000 } />
8888
8989 { /* QR Code and Explainer Section */ }
9090 < Flex row gap = 'm' alignItems = 'center' >
Original file line number Diff line number Diff line change @@ -37,7 +37,10 @@ export const ReceiveTokensModal = () => {
3737 const { mint } = data ?? { }
3838 const { data : coin } = useArtistCoin ( mint )
3939 const { tokenBalanceFormatted : balance } = useFormattedTokenBalance (
40- mint ?? ''
40+ mint ?? '' ,
41+ 'en-US' ,
42+ isOpen ,
43+ 3000 // Poll every 3 seconds when modal is open
4144 )
4245 const { userBankAddress, loading : userBankLoading } = useUserbank ( mint )
4346 const tokenInfo = coin ? transformArtistCoinToTokenInfo ( coin ) : undefined
You can’t perform that action at this time.
0 commit comments