-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuseStargateClient.ts
29 lines (28 loc) · 1.07 KB
/
useStargateClient.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
import { Ref, computed, ref, watch } from 'vue'
import { ExtensionWallet } from '@interchain-kit/core'
import { useChain, useWalletManager } from '@interchain-kit/vue'
import { SigningClient as SigningStargateClient } from '@interchainjs/cosmos/signing-client';
export const useStargateClient = (chainName: Ref<string>) => {
const { rpcEndpoint, chain } = useChain(chainName)
const stargazeClient = ref()
const wm = useWalletManager()
const signer = computed(() => {
if (!chain.value.chainId) {
return
}
const wallet = wm.getCurrentWallet() as unknown as ExtensionWallet
return wallet.getOfflineSigner(chain.value.chainId, 'direct') // cosmoshub-4
})
const _fetchClient = async (rpcEndpoint: string, signer: any) => {
if (!rpcEndpoint || !signer) {
return
}
let res = await SigningStargateClient.connectWithSigner(rpcEndpoint, signer)
stargazeClient.value = res
}
watch([rpcEndpoint, signer], ([rpc, sn]) => {
_fetchClient(rpc as string, sn)
})
_fetchClient(rpcEndpoint.value as string, signer.value)
return stargazeClient
}