Skip to content

Commit

Permalink
useExecuteOnRemoteModule
Browse files Browse the repository at this point in the history
  • Loading branch information
adairrr committed Jun 13, 2024
1 parent 04de2a6 commit 5899de2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/react/src/hooks/account/wallet/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './use-deposit'
export * from './use-create-sub-account'
export * from './use-execute-on-remote'
export * from './use-execute-on-remote-module'
export * from './use-create-remote-account'
export * from './use-execute'
export * from './use-upgrade-module'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { AccountId, AccountWalletClient } from '@abstract-money/core'
import { useMutation } from '@tanstack/react-query'
import { useConfig } from '../../../contexts'
import { ExtractArgsFromParameters } from '../../../types/args'
import { UseMutationParameters } from '../../../types/queries'

type ExecuteOnRemoteModuleMutation = ExtractArgsFromParameters<
Parameters<AccountWalletClient['executeOnRemoteModule']>[0]
>

export type UseExecuteOnRemoteModuleParameters = {
accountId: AccountId | undefined
chainName: string | undefined
mutation?: UseMutationParameters<
Awaited<ReturnType<AccountWalletClient['executeOnRemoteModule']>>,
unknown,
ExecuteOnRemoteModuleMutation
>
}

export function useExecuteOnRemoteModule({
accountId,
chainName,
mutation,
}: UseExecuteOnRemoteModuleParameters) {
const config = useConfig()
const walletClient = config.useAccountWalletClient({
accountId,
chainName: chainName,
})

return useMutation(({ args, ...cosmWasmSignOptions }) => {
if (!walletClient) throw new Error('walletClient is not defined')
return walletClient.executeOnRemoteModule({
...cosmWasmSignOptions,
...args,
})
}, mutation)
}

0 comments on commit 5899de2

Please sign in to comment.