useTransaction.ts raw
1 import useSWR, { SWRConfiguration } from "swr";
2
3 import { Transaction } from "src/types";
4 import { swrFetcher } from "src/utils/swr";
5
6 const pollConfiguration: SWRConfiguration = {
7 refreshInterval: 3000,
8 };
9
10 export function useTransaction(paymentHash: string, poll = false) {
11 return useSWR<Transaction>(
12 paymentHash && `/api/transactions/${paymentHash}`,
13 swrFetcher,
14 poll ? pollConfiguration : undefined
15 );
16 }
17