-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/react/src/hooks/account/wallet/use-execute-on-remote-module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |