-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuseTx.ts
42 lines (38 loc) · 1.21 KB
/
useTx.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { useChain } from '@interchain-kit/react';
import { defaultContext, useQuery } from '@tanstack/react-query';
import { DEFAULT_SIGNING_CLIENT_QUERY_KEY } from 'injective-react/react-query';
import { WalletState } from '@interchain-kit/core';
export enum TxStatus {
Failed = 'Transaction Failed',
Successful = 'Transaction Successful',
Broadcasting = 'Transaction Broadcasting',
}
/**
* Get the signing client for the chain
* This is a hook that returns the signing client for the chain
* @param chainName - The name of the chain
* @param options - The options for the signing client
* @param options.walletStatus - The current status of the wallet, only connected wallets are enabled
* @returns The signing client for the chain
*/
export const useSigningClient = (
chainName: string,
options: {
walletStatus?: WalletState;
}
) => {
const { getSigningClient } = useChain(chainName);
return useQuery(
[DEFAULT_SIGNING_CLIENT_QUERY_KEY, chainName],
async () => {
const client = await getSigningClient();
return client;
},
{
enabled:
!!chainName &&
(!options || options?.walletStatus === WalletState.Connected),
context: defaultContext,
}
);
};