Update open edition factory contract helpers
This commit is contained in:
parent
434f2e5926
commit
d527f65512
2
contracts/openEditionFactory/index.ts
Normal file
2
contracts/openEditionFactory/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export * from './contract'
|
||||||
|
export * from './useContract'
|
31
contracts/openEditionFactory/messages/execute.ts
Normal file
31
contracts/openEditionFactory/messages/execute.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* eslint-disable eslint-comments/disable-enable-pair */
|
||||||
|
|
||||||
|
import type { Coin } from '@cosmjs/proto-signing'
|
||||||
|
|
||||||
|
import type { OpenEditionFactoryInstance } from '../index'
|
||||||
|
import { useOpenEditionFactoryContract } from '../index'
|
||||||
|
|
||||||
|
/** @see {@link OpenEditionFactoryInstance} */
|
||||||
|
export interface DispatchExecuteArgs {
|
||||||
|
contract: string
|
||||||
|
messages?: OpenEditionFactoryInstance
|
||||||
|
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.createOpenEditionMinter(txSigner, args.msg, args.funds, args.updatable)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const previewExecutePayload = (args: DispatchExecuteArgs) => {
|
||||||
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
|
const { messages } = useOpenEditionFactoryContract()
|
||||||
|
const { contract } = args
|
||||||
|
return messages(contract)?.createOpenEditionMinter(args.msg, args.funds, args.updatable)
|
||||||
|
}
|
76
contracts/openEditionFactory/useContract.ts
Normal file
76
contracts/openEditionFactory/useContract.ts
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import type { logs } from '@cosmjs/stargate'
|
||||||
|
import { useWallet } from 'contexts/wallet'
|
||||||
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
import type { OpenEditionFactoryContract, OpenEditionFactoryInstance, OpenEditionFactoryMessages } from './contract'
|
||||||
|
import { openEditionFactory as initContract } from './contract'
|
||||||
|
|
||||||
|
/*export interface InstantiateResponse {
|
||||||
|
/** The address of the newly instantiated contract *-/
|
||||||
|
readonly contractAddress: string
|
||||||
|
readonly logs: readonly logs.Log[]
|
||||||
|
/** Block height in which the transaction is included *-/
|
||||||
|
readonly height: number
|
||||||
|
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex *-/
|
||||||
|
readonly transactionHash: string
|
||||||
|
readonly gasWanted: number
|
||||||
|
readonly gasUsed: number
|
||||||
|
}*/
|
||||||
|
|
||||||
|
interface InstantiateResponse {
|
||||||
|
readonly contractAddress: string
|
||||||
|
readonly transactionHash: string
|
||||||
|
readonly logs: readonly logs.Log[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UseOpenEditionFactoryContractProps {
|
||||||
|
use: (customAddress: string) => OpenEditionFactoryInstance | undefined
|
||||||
|
updateContractAddress: (contractAddress: string) => void
|
||||||
|
getContractAddress: () => string | undefined
|
||||||
|
messages: (contractAddress: string) => OpenEditionFactoryMessages | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useOpenEditionFactoryContract(): UseOpenEditionFactoryContractProps {
|
||||||
|
const wallet = useWallet()
|
||||||
|
|
||||||
|
const [address, setAddress] = useState<string>('')
|
||||||
|
const [openEditionFactory, setOpenEditionFactory] = useState<OpenEditionFactoryContract>()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setAddress(localStorage.getItem('contract_address') || '')
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const OpenEditionFactoryBaseContract = initContract(wallet.getClient(), wallet.address)
|
||||||
|
setOpenEditionFactory(OpenEditionFactoryBaseContract)
|
||||||
|
}, [wallet])
|
||||||
|
|
||||||
|
const updateContractAddress = (contractAddress: string) => {
|
||||||
|
setAddress(contractAddress)
|
||||||
|
}
|
||||||
|
|
||||||
|
const use = useCallback(
|
||||||
|
(customAddress = ''): OpenEditionFactoryInstance | undefined => {
|
||||||
|
return openEditionFactory?.use(address || customAddress)
|
||||||
|
},
|
||||||
|
[openEditionFactory, address],
|
||||||
|
)
|
||||||
|
|
||||||
|
const getContractAddress = (): string | undefined => {
|
||||||
|
return address
|
||||||
|
}
|
||||||
|
|
||||||
|
const messages = useCallback(
|
||||||
|
(customAddress = ''): OpenEditionFactoryMessages | undefined => {
|
||||||
|
return openEditionFactory?.messages(address || customAddress)
|
||||||
|
},
|
||||||
|
[openEditionFactory, address],
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
use,
|
||||||
|
updateContractAddress,
|
||||||
|
getContractAddress,
|
||||||
|
messages,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user