Files
nym/explorer-v2/src/hooks/useNymClient.ts
Fouad dc88650d6d Explorer V2 (#5548)
* remove pnpm lock file (should only be using yarn)

* Add lefthook configuration for pre-commit checks

* Add explorer-v2 to package.json dependencies

* add explorer v2

* update explorer v2 package name

* + basepath
+ redirect to basepath
+ blog icons refactor
+ icons refactor

* Add Getting Started instructions to README

* fix noise graph bug and line graph UI

* Delete unused translations, clean up console logs

* / test image url

* update yarn.lock

---------

Co-authored-by: RadekSabacky <radek@nymtech.net>
Co-authored-by: windy-ux <75579979+windy-ux@users.noreply.github.com>
Co-authored-by: Yana <iana.matrosova@gmail.com>
Co-authored-by: Mark Sinclair <mmsinclair@users.noreply.github.com>
2025-03-13 11:31:59 +00:00

48 lines
1.5 KiB
TypeScript

"use client";
import { useChain } from "@cosmos-kit/react";
import { contracts } from "@nymproject/contract-clients";
import type {
MixnetClient,
MixnetQueryClient,
} from "@nymproject/contract-clients/Mixnet.client";
import { useEffect, useState } from "react";
import { COSMOS_KIT_USE_CHAIN, NYM_MIXNET_CONTRACT } from "../config";
export const useNymClient = () => {
const [nymClient, setNymClient] = useState<MixnetClient>();
const [nymQueryClient, setNymQueryClient] = useState<MixnetQueryClient>();
const { address, 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(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
cosmWasmSigningClient as any,
address,
NYM_MIXNET_CONTRACT,
);
const queryClient = new contracts.Mixnet.MixnetQueryClient(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
cosmWasmClient as any,
NYM_MIXNET_CONTRACT,
);
setNymClient(client);
setNymQueryClient(queryClient);
};
init();
}
}, [address, getCosmWasmClient, getSigningCosmWasmClient]);
return { nymClient, nymQueryClient, address };
};