1- import { useState } from "react" ;
1+ import { useEffect , useState } from "react" ;
22import { Hex , parseEther } from "viem" ;
3+ import { useQueryClient } from "@tanstack/react-query" ;
34import { PendingIcon } from "../icons/PendingIcon" ;
45import { Button } from "../ui/Button" ;
56import { Balance } from "../ui/Balance" ;
@@ -11,6 +12,7 @@ import { RelayChains, StepContentProps } from "./common";
1112import { TruncatedHex } from "../ui/TruncatedHex" ;
1213import { useShowMutationError } from "../errors/useShowMutationError" ;
1314import { useShowQueryError } from "../errors/useShowQueryError" ;
15+ import { usePrevious } from "../errors/usePrevious" ;
1416import { CopyIcon } from "../icons/CopyIcon" ;
1517import { CheckIcon } from "../icons/CheckIcon" ;
1618
@@ -19,10 +21,12 @@ export type Props = StepContentProps & {
1921} ;
2022
2123export function GasBalance ( { isActive, isExpanded, sessionAddress } : Props ) {
24+ const queryClient = useQueryClient ( ) ;
2225 const { chain } = useEntryKitConfig ( ) ;
2326 const [ copied , setCopied ] = useState ( false ) ;
2427
2528 const balance = useShowQueryError ( useBalance ( { chainId : chain . id , address : sessionAddress } ) ) ;
29+ const prevBalance = usePrevious ( balance . data ) ;
2630 useWatchBlockNumber ( { onBlockNumber : ( ) => balance . refetch ( ) } ) ;
2731
2832 const setBalance = useShowMutationError ( useSetBalance ( ) ) ;
@@ -35,6 +39,12 @@ export function GasBalance({ isActive, isExpanded, sessionAddress }: Props) {
3539 setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
3640 } ;
3741
42+ useEffect ( ( ) => {
43+ if ( balance . data != null && prevBalance ?. value === 0n && balance . data . value > 0n ) {
44+ queryClient . invalidateQueries ( { queryKey : [ "getPrerequisites" ] } ) ;
45+ }
46+ } , [ balance . data , prevBalance , setBalance , sessionAddress , queryClient ] ) ;
47+
3848 return (
3949 < div className = "flex flex-col gap-4" >
4050 < div className = "flex justify-between gap-4" >
0 commit comments