Update vending factory contract helpers

This commit is contained in:
Serkan Reis 2023-04-27 20:16:40 +03:00
parent 5cdcc66611
commit 0945bcf927
2 changed files with 16 additions and 5 deletions

View File

@ -1,7 +1,9 @@
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable no-nested-ternary */
import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import type { Coin } from '@cosmjs/proto-signing'
import type { logs } from '@cosmjs/stargate'
import { VENDING_FACTORY_ADDRESS } from 'utils/constants'
import { VENDING_FACTORY_ADDRESS, VENDING_FACTORY_FLEX_ADDRESS } from 'utils/constants'
import { VENDING_FACTORY_UPDATABLE_ADDRESS } from '../../utils/constants'
@ -23,11 +25,17 @@ export interface VendingFactoryInstance {
msg: Record<string, unknown>,
funds: Coin[],
updatable?: boolean,
flex?: boolean,
) => Promise<CreateVendingMinterResponse>
}
export interface VendingFactoryMessages {
createVendingMinter: (msg: Record<string, unknown>, funds: Coin[], updatable?: boolean) => CreateVendingMinterMessage
createVendingMinter: (
msg: Record<string, unknown>,
funds: Coin[],
updatable?: boolean,
flex?: boolean,
) => CreateVendingMinterMessage
}
export interface CreateVendingMinterMessage {
@ -53,10 +61,11 @@ export const vendingFactory = (client: SigningCosmWasmClient, txSigner: string):
msg: Record<string, unknown>,
funds: Coin[],
updatable?: boolean,
flex?: boolean,
): Promise<CreateVendingMinterResponse> => {
const result = await client.execute(
senderAddress,
updatable ? VENDING_FACTORY_UPDATABLE_ADDRESS : VENDING_FACTORY_ADDRESS,
flex ? VENDING_FACTORY_FLEX_ADDRESS : updatable ? VENDING_FACTORY_UPDATABLE_ADDRESS : VENDING_FACTORY_ADDRESS,
msg,
'auto',
'',
@ -82,6 +91,7 @@ export const vendingFactory = (client: SigningCosmWasmClient, txSigner: string):
msg: Record<string, unknown>,
funds: Coin[],
updatable?: boolean,
flex?: boolean,
): CreateVendingMinterMessage => {
return {
sender: txSigner,

View File

@ -11,6 +11,7 @@ export interface DispatchExecuteArgs {
msg: Record<string, unknown>
funds: Coin[]
updatable?: boolean
flex?: boolean
}
export const dispatchExecute = async (args: DispatchExecuteArgs) => {
@ -18,12 +19,12 @@ export const dispatchExecute = async (args: DispatchExecuteArgs) => {
if (!messages) {
throw new Error('cannot dispatch execute, messages is not defined')
}
return messages.createVendingMinter(txSigner, args.msg, args.funds, args.updatable)
return messages.createVendingMinter(txSigner, args.msg, args.funds, args.updatable, args.flex)
}
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.funds, args.updatable)
return messages(contract)?.createVendingMinter(args.msg, args.funds, args.updatable, args.flex)
}