Skip to content

Commit

Permalink
make cosmwasm client not async
Browse files Browse the repository at this point in the history
  • Loading branch information
adairrr committed Oct 8, 2024
1 parent 29085eb commit 8823133
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/actions/public/get-cosm-wasm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type GetCosmWasmClientParameters = {
cosmWasmClient: CosmWasmClient
}

export async function getCosmWasmClient({
export function getCosmWasmClient({
cosmWasmClient,
}: GetCosmWasmClientParameters) {
return cosmWasmClient
Expand Down
22 changes: 19 additions & 3 deletions packages/react/src/utils/use-abstract-module-client.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<TModule>
Expand Down Expand Up @@ -54,7 +62,12 @@ export function useAbstractModuleClient<
query = {},
sender: _sender,
}: UseAbstractModuleClientParameters<TModule>) {
const { useAccountWalletClient } = useConfig()
const { useAccountWalletClient, useAccountPublicClient } = useConfig()

const accountPublicClient = useAccountPublicClient({
accountId,
chainName,
})

const accountWalletClient = useAccountWalletClient({
accountId,
Expand All @@ -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))

Expand Down

0 comments on commit 8823133

Please sign in to comment.