From 8823133f368d0c791141ae7bafbfc0722c46b7e9 Mon Sep 17 00:00:00 2001 From: adairrr <32375605+adairrr@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:10:29 -0400 Subject: [PATCH] make cosmwasm client not async --- .../actions/public/get-cosm-wasm-client.ts | 2 +- .../src/utils/use-abstract-module-client.ts | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/core/src/actions/public/get-cosm-wasm-client.ts b/packages/core/src/actions/public/get-cosm-wasm-client.ts index 532ea9b7..338bd076 100644 --- a/packages/core/src/actions/public/get-cosm-wasm-client.ts +++ b/packages/core/src/actions/public/get-cosm-wasm-client.ts @@ -4,7 +4,7 @@ export type GetCosmWasmClientParameters = { cosmWasmClient: CosmWasmClient } -export async function getCosmWasmClient({ +export function getCosmWasmClient({ cosmWasmClient, }: GetCosmWasmClientParameters) { return cosmWasmClient diff --git a/packages/react/src/utils/use-abstract-module-client.ts b/packages/react/src/utils/use-abstract-module-client.ts index 7aa6408f..6590a5b2 100644 --- a/packages/react/src/utils/use-abstract-module-client.ts +++ b/packages/react/src/utils/use-abstract-module-client.ts @@ -1,11 +1,16 @@ import * as React from 'react' -import { AccountId, AccountWalletClient } from '@abstract-money/core' +import { + AccountId, + AccountPublicClient, + AccountWalletClient, +} from '@abstract-money/core' import { useConfig } from '../contexts' import { UseQueryParameters, useQuery } from '../types/queries' interface AbstractModuleClientConstructor { new (args: { + accountPublicClient: AccountPublicClient accountWalletClient: AccountWalletClient moduleId: string }): any @@ -14,15 +19,18 @@ interface AbstractModuleClientConstructor { async function getAbstractModuleClient< TModule extends AbstractModuleClientConstructor, >({ + accountPublicClient, accountWalletClient, moduleId, Module, }: { + accountPublicClient: AccountPublicClient accountWalletClient: AccountWalletClient moduleId: string Module: TModule }) { return new Module({ + accountPublicClient: accountPublicClient, accountWalletClient: accountWalletClient, moduleId, }) as InstanceType @@ -54,7 +62,12 @@ export function useAbstractModuleClient< query = {}, sender: _sender, }: UseAbstractModuleClientParameters) { - const { useAccountWalletClient } = useConfig() + const { useAccountWalletClient, useAccountPublicClient } = useConfig() + + const accountPublicClient = useAccountPublicClient({ + accountId, + chainName, + }) const accountWalletClient = useAccountWalletClient({ accountId, @@ -67,15 +80,18 @@ export function useAbstractModuleClient< ) const queryFn = React.useCallback(() => { + if (!accountPublicClient) + throw new Error('accountPublicClient is not defined') if (!accountWalletClient) throw new Error('accountWalletClient is not defined') return getAbstractModuleClient({ + accountPublicClient: accountPublicClient, accountWalletClient: accountWalletClient, moduleId, Module, }) - }, [accountWalletClient, moduleId, Module]) + }, [accountPublicClient, accountWalletClient, moduleId, Module]) const enabled = Boolean(accountWalletClient && (query.enabled ?? true))