-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathuseChain.ts
More file actions
46 lines (42 loc) · 1.87 KB
/
useChain.ts
File metadata and controls
46 lines (42 loc) · 1.87 KB
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
43
44
45
46
import { computed } from 'vue'
import { useWalletManager } from './useWalletManager'
import { useAccount } from './useAccount'
import { useCurrentWallet } from './useCurrentWallet'
import { useInterchainClient } from './useInterchainClient'
import { useWalletModal } from '../modal'
import { ChainNameNotExist } from '@interchain-kit/core'
import { getChainLogoUrl } from '../utils'
export function useChain(chainName: string) {
const walletManager = useWalletManager()
const currentWallet = useCurrentWallet()
const account = useAccount(chainName, computed(() => currentWallet.value?.option?.name))
const interchainClient = useInterchainClient(chainName, computed(() => currentWallet.value?.option?.name))
const { open, close } = useWalletModal()
const chainToShow = computed(() => walletManager.chains.find(c => c.chainName === chainName))
const assetList = computed(() => walletManager.assetLists.find(a => a.chainName === chainName))
if (!chainToShow.value) {
throw new ChainNameNotExist(chainName)
}
return {
logoUrl: computed(() => getChainLogoUrl(assetList.value)),
chain: chainToShow,
assetList,
address: computed(() => account.value?.address),
wallet: currentWallet,
connect: () => {
if (currentWallet.value) {
return
}
open()
},
openView: open,
closeView: close,
getRpcEndpoint: () => walletManager.getRpcEndpoint(currentWallet.value, chainName),
status: computed(() => currentWallet.value?.walletState),
username: computed(() => account.value?.username),
message: computed(() => currentWallet.value?.errorMessage),
getSigningCosmWasmClient: () => walletManager.getSigningCosmwasmClient(currentWallet.value?.option?.name || '', chainName),
getSigningCosmosClient: () => walletManager.getSigningCosmosClient(currentWallet.value?.option?.name || '', chainName),
...interchainClient
}
}