Files
nym/explorer-nextjs/app/hooks/useNymClient.tsx
T
Fouad e5f41731ae Explorer NextJS Rebuild (#4534)
* bootstrap next app + add overview page

* fix AssetList type

* fix up nav stuff

* Refactor Nav component and add network components pages

* Refactor WorldMap component and update TelegramIcon, GitHubIcon, NymVpnIcon, DiscordIcon, and TwitterIcon components

* add service providers page

* mixnodes page

* delegations page + use material react table for all tables

* nodes map page

* Refactor StyledLink component and remove unnecessary console.log statements

* Refactor ESLint configuration, remove unused dependencies, and update component imports

* update deps

* Refactor imports and update dependencies

* fix dark mode

* build single mixnode page

* build single gateway page

* Refactor handleOnDelegate function to use useCallback in mixnodes page.tsx

* Add defaults for constants

---------

Co-authored-by: Mark Sinclair <mmsinclair@users.noreply.github.com>
2024-05-16 16:12:06 +01:00

45 lines
1.3 KiB
TypeScript

'use client'
import { useEffect, useState } from 'react'
import { useChain } from '@cosmos-kit/react'
import { contracts } from '@nymproject/contract-clients'
import {
MixnetClient,
MixnetQueryClient,
} from '@nymproject/contract-clients/Mixnet.client'
import { COSMOS_KIT_USE_CHAIN, NYM_MIXNET_CONTRACT } from '@/app/api/constants'
export const useNymClient = (address?: string) => {
const [nymClient, setNymClient] = useState<MixnetClient>()
const [nymQueryClient, setNymQueryClient] = useState<MixnetQueryClient>()
const { getCosmWasmClient, getSigningCosmWasmClient } =
useChain(COSMOS_KIT_USE_CHAIN)
useEffect(() => {
if (address) {
const init = async () => {
const cosmWasmSigningClient = await getSigningCosmWasmClient()
const cosmWasmClient = await getCosmWasmClient()
const client = new contracts.Mixnet.MixnetClient(
cosmWasmSigningClient as any,
address,
NYM_MIXNET_CONTRACT
)
const queryClient = new contracts.Mixnet.MixnetQueryClient(
cosmWasmClient as any,
NYM_MIXNET_CONTRACT
)
setNymClient(client)
setNymQueryClient(queryClient)
}
init()
}
}, [address, getCosmWasmClient, getSigningCosmWasmClient])
return { nymClient, nymQueryClient }
}