Update factory contract helpers
This commit is contained in:
parent
5f8dea9cc0
commit
d27d22367e
@ -4,6 +4,8 @@ import { coin } from '@cosmjs/proto-signing'
|
||||
import type { logs } from '@cosmjs/stargate'
|
||||
import { BASE_FACTORY_ADDRESS } from 'utils/constants'
|
||||
|
||||
import { BASE_FACTORY_UPDATABLE_ADDRESS } from '../../utils/constants'
|
||||
|
||||
export interface CreateBaseMinterResponse {
|
||||
readonly baseMinterAddress: string
|
||||
readonly sg721Address: string
|
||||
@ -21,11 +23,12 @@ export interface BaseFactoryInstance {
|
||||
senderAddress: string,
|
||||
msg: Record<string, unknown>,
|
||||
funds: Coin[],
|
||||
updatable?: boolean,
|
||||
) => Promise<CreateBaseMinterResponse>
|
||||
}
|
||||
|
||||
export interface BaseFactoryMessages {
|
||||
createBaseMinter: (msg: Record<string, unknown>) => CreateBaseMinterMessage
|
||||
createBaseMinter: (msg: Record<string, unknown>, updatable?: boolean) => CreateBaseMinterMessage
|
||||
}
|
||||
|
||||
export interface CreateBaseMinterMessage {
|
||||
@ -56,8 +59,16 @@ export const baseFactory = (client: SigningCosmWasmClient, txSigner: string): Ba
|
||||
senderAddress: string,
|
||||
msg: Record<string, unknown>,
|
||||
funds: Coin[],
|
||||
updatable?: boolean,
|
||||
): Promise<CreateBaseMinterResponse> => {
|
||||
const result = await client.execute(senderAddress, BASE_FACTORY_ADDRESS, msg, 'auto', '', funds)
|
||||
const result = await client.execute(
|
||||
senderAddress,
|
||||
updatable ? BASE_FACTORY_UPDATABLE_ADDRESS : BASE_FACTORY_ADDRESS,
|
||||
msg,
|
||||
'auto',
|
||||
'',
|
||||
funds,
|
||||
)
|
||||
|
||||
return {
|
||||
baseMinterAddress: result.logs[0].events[5].attributes[0].value,
|
||||
@ -75,12 +86,12 @@ export const baseFactory = (client: SigningCosmWasmClient, txSigner: string): Ba
|
||||
}
|
||||
|
||||
const messages = (contractAddress: string) => {
|
||||
const createBaseMinter = (msg: Record<string, unknown>): CreateBaseMinterMessage => {
|
||||
const createBaseMinter = (msg: Record<string, unknown>, updatable?: boolean): CreateBaseMinterMessage => {
|
||||
return {
|
||||
sender: txSigner,
|
||||
contract: contractAddress,
|
||||
msg,
|
||||
funds: [coin('1000000000', 'ustars')],
|
||||
funds: [coin(updatable ? '3000000000' : '1000000000', 'ustars')],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ export interface DispatchExecuteArgs {
|
||||
txSigner: string
|
||||
msg: Record<string, unknown>
|
||||
funds: Coin[]
|
||||
updatable?: boolean
|
||||
}
|
||||
|
||||
export const dispatchExecute = async (args: DispatchExecuteArgs) => {
|
||||
@ -17,12 +18,12 @@ export const dispatchExecute = async (args: DispatchExecuteArgs) => {
|
||||
if (!messages) {
|
||||
throw new Error('cannot dispatch execute, messages is not defined')
|
||||
}
|
||||
return messages.createBaseMinter(txSigner, args.msg, args.funds)
|
||||
return messages.createBaseMinter(txSigner, args.msg, args.funds, args.updatable)
|
||||
}
|
||||
|
||||
export const previewExecutePayload = (args: DispatchExecuteArgs) => {
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
const { messages } = useBaseFactoryContract()
|
||||
const { contract } = args
|
||||
return messages(contract)?.createBaseMinter(args.msg)
|
||||
return messages(contract)?.createBaseMinter(args.msg, args.updatable)
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import { coin } from '@cosmjs/proto-signing'
|
||||
import type { logs } from '@cosmjs/stargate'
|
||||
import { VENDING_FACTORY_ADDRESS } from 'utils/constants'
|
||||
|
||||
import { VENDING_FACTORY_UPDATABLE_ADDRESS } from '../../utils/constants'
|
||||
|
||||
export interface CreateVendingMinterResponse {
|
||||
readonly vendingMinterAddress: string
|
||||
readonly sg721Address: string
|
||||
@ -21,11 +23,12 @@ export interface VendingFactoryInstance {
|
||||
senderAddress: string,
|
||||
msg: Record<string, unknown>,
|
||||
funds: Coin[],
|
||||
updatable?: boolean,
|
||||
) => Promise<CreateVendingMinterResponse>
|
||||
}
|
||||
|
||||
export interface VendingFactoryMessages {
|
||||
createVendingMinter: (msg: Record<string, unknown>) => CreateVendingMinterMessage
|
||||
createVendingMinter: (msg: Record<string, unknown>, updatable?: boolean) => CreateVendingMinterMessage
|
||||
}
|
||||
|
||||
export interface CreateVendingMinterMessage {
|
||||
@ -50,8 +53,16 @@ export const vendingFactory = (client: SigningCosmWasmClient, txSigner: string):
|
||||
senderAddress: string,
|
||||
msg: Record<string, unknown>,
|
||||
funds: Coin[],
|
||||
updatable?: boolean,
|
||||
): Promise<CreateVendingMinterResponse> => {
|
||||
const result = await client.execute(senderAddress, VENDING_FACTORY_ADDRESS, msg, 'auto', '', funds)
|
||||
const result = await client.execute(
|
||||
senderAddress,
|
||||
updatable ? VENDING_FACTORY_UPDATABLE_ADDRESS : VENDING_FACTORY_ADDRESS,
|
||||
msg,
|
||||
'auto',
|
||||
'',
|
||||
funds,
|
||||
)
|
||||
|
||||
return {
|
||||
vendingMinterAddress: result.logs[0].events[5].attributes[0].value,
|
||||
@ -68,12 +79,12 @@ export const vendingFactory = (client: SigningCosmWasmClient, txSigner: string):
|
||||
}
|
||||
|
||||
const messages = (contractAddress: string) => {
|
||||
const createVendingMinter = (msg: Record<string, unknown>): CreateVendingMinterMessage => {
|
||||
const createVendingMinter = (msg: Record<string, unknown>, updatable?: boolean): CreateVendingMinterMessage => {
|
||||
return {
|
||||
sender: txSigner,
|
||||
contract: contractAddress,
|
||||
msg,
|
||||
funds: [coin('3000000000', 'ustars')],
|
||||
funds: [coin(updatable ? '5000000000' : '3000000000', 'ustars')],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ export interface DispatchExecuteArgs {
|
||||
txSigner: string
|
||||
msg: Record<string, unknown>
|
||||
funds: Coin[]
|
||||
updatable?: boolean
|
||||
}
|
||||
|
||||
export const dispatchExecute = async (args: DispatchExecuteArgs) => {
|
||||
@ -17,12 +18,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)
|
||||
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)
|
||||
return messages(contract)?.createVendingMinter(args.msg, args.updatable)
|
||||
}
|
||||
|
@ -446,6 +446,7 @@ const CollectionCreationPage: NextPage = () => {
|
||||
txSigner: wallet.address,
|
||||
msg,
|
||||
funds: [coin(collectionDetails?.updatable ? '5000000000' : '3000000000', 'ustars')],
|
||||
updatable: collectionDetails?.updatable,
|
||||
}
|
||||
const data = await vendingFactoryDispatchExecute(payload)
|
||||
setTransactionHash(data.transactionHash)
|
||||
@ -496,6 +497,7 @@ const CollectionCreationPage: NextPage = () => {
|
||||
txSigner: wallet.address,
|
||||
msg,
|
||||
funds: [coin(collectionDetails?.updatable ? '3000000000' : '1000000000', 'ustars')],
|
||||
updatable: collectionDetails?.updatable,
|
||||
}
|
||||
await baseFactoryDispatchExecute(payload)
|
||||
.then(async (data) => {
|
||||
|
Loading…
Reference in New Issue
Block a user