fix escrow handling and fetching
This commit is contained in:
21
app/src/hooks/useEscrow.ts
Normal file
21
app/src/hooks/useEscrow.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useCluster } from '@solana/connector/react'
|
||||
import { createSolanaRpc } from '@solana/kit'
|
||||
import { fetchEscrowAccount } from '@descro/sdk'
|
||||
import type { Address } from '@solana/kit'
|
||||
|
||||
export function useEscrow(pda: Address) {
|
||||
const { cluster } = useCluster()
|
||||
return useQuery({
|
||||
queryKey: ['escrow', pda, cluster?.id],
|
||||
queryFn: () => {
|
||||
const rpc = createSolanaRpc(cluster!.url)
|
||||
return fetchEscrowAccount(
|
||||
rpc as Parameters<typeof fetchEscrowAccount>[0],
|
||||
pda,
|
||||
).catch(() => null)
|
||||
},
|
||||
enabled: !!cluster && !!pda,
|
||||
refetchInterval: 15_000,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user