stargaze-studio/contracts/vendingFactory/messages/execute.ts
2023-02-26 13:08:03 +03:00

30 lines
963 B
TypeScript

import type { Coin } from '@cosmjs/proto-signing'
import type { VendingFactoryInstance } from '../index'
import { useVendingFactoryContract } from '../index'
/** @see {@link VendingFactoryInstance} */
export interface DispatchExecuteArgs {
contract: string
messages?: VendingFactoryInstance
txSigner: string
msg: Record<string, unknown>
funds: Coin[]
updatable?: boolean
}
export const dispatchExecute = async (args: DispatchExecuteArgs) => {
const { messages, txSigner } = args
if (!messages) {
throw new Error('cannot dispatch execute, messages is not defined')
}
return messages.createVendingMinter(txSigner, args.msg, args.funds, args.updatable)
}
export const previewExecutePayload = (args: DispatchExecuteArgs) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const { messages } = useVendingFactoryContract()
const { contract } = args
return messages(contract)?.createVendingMinter(args.msg, args.updatable)
}