Init open edition minter message list
This commit is contained in:
parent
d9b060a4fb
commit
3065cc35b3
124
contracts/openEditionMinter/messages/execute.ts
Normal file
124
contracts/openEditionMinter/messages/execute.ts
Normal file
@ -0,0 +1,124 @@
|
||||
import type { OpenEditionMinterInstance } from '../index'
|
||||
import { useOpenEditionMinterContract } from '../index'
|
||||
|
||||
export type ExecuteType = typeof EXECUTE_TYPES[number]
|
||||
|
||||
export const EXECUTE_TYPES = [
|
||||
'mint',
|
||||
'update_start_trading_time',
|
||||
'update_per_address_limit',
|
||||
'mint_to',
|
||||
'purge',
|
||||
] as const
|
||||
|
||||
export interface ExecuteListItem {
|
||||
id: ExecuteType
|
||||
name: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
export const EXECUTE_LIST: ExecuteListItem[] = [
|
||||
{
|
||||
id: 'mint',
|
||||
name: 'Mint',
|
||||
description: `Mint a new token`,
|
||||
},
|
||||
{
|
||||
id: 'update_start_trading_time',
|
||||
name: 'Update Start Trading Time',
|
||||
description: `Update start trading time for minting`,
|
||||
},
|
||||
{
|
||||
id: 'update_per_address_limit',
|
||||
name: 'Update Per Address Limit',
|
||||
description: `Update token per address limit`,
|
||||
},
|
||||
{
|
||||
id: 'mint_to',
|
||||
name: 'Mint To',
|
||||
description: `Mint tokens to a given address`,
|
||||
},
|
||||
{
|
||||
id: 'purge',
|
||||
name: 'Purge',
|
||||
description: `Purge`,
|
||||
},
|
||||
]
|
||||
|
||||
export interface DispatchExecuteProps {
|
||||
type: ExecuteType
|
||||
[k: string]: unknown
|
||||
}
|
||||
|
||||
type Select<T extends ExecuteType> = T
|
||||
|
||||
/** @see {@link OpenEditionMinterInstance} */
|
||||
export type DispatchExecuteArgs = {
|
||||
contract: string
|
||||
messages?: OpenEditionMinterInstance
|
||||
txSigner: string
|
||||
} & (
|
||||
| { type: undefined }
|
||||
| { type: Select<'mint'> }
|
||||
| { type: Select<'purge'> }
|
||||
| { type: Select<'update_start_trading_time'>; startTime?: string }
|
||||
| { type: Select<'update_per_address_limit'>; limit: number }
|
||||
| { type: Select<'mint_to'>; recipient: string }
|
||||
)
|
||||
|
||||
export const dispatchExecute = async (args: DispatchExecuteArgs) => {
|
||||
const { messages, txSigner } = args
|
||||
if (!messages) {
|
||||
throw new Error('cannot dispatch execute, messages is not defined')
|
||||
}
|
||||
switch (args.type) {
|
||||
case 'mint': {
|
||||
return messages.mint(txSigner)
|
||||
}
|
||||
case 'purge': {
|
||||
return messages.purge(txSigner)
|
||||
}
|
||||
case 'update_start_trading_time': {
|
||||
return messages.updateStartTradingTime(txSigner, args.startTime)
|
||||
}
|
||||
case 'update_per_address_limit': {
|
||||
return messages.updatePerAddressLimit(txSigner, args.limit)
|
||||
}
|
||||
case 'mint_to': {
|
||||
return messages.mintTo(txSigner, args.recipient)
|
||||
}
|
||||
default: {
|
||||
throw new Error('unknown execute type')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const previewExecutePayload = (args: DispatchExecuteArgs) => {
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
const { messages } = useOpenEditionMinterContract()
|
||||
const { contract } = args
|
||||
switch (args.type) {
|
||||
case 'mint': {
|
||||
return messages(contract)?.mint()
|
||||
}
|
||||
case 'purge': {
|
||||
return messages(contract)?.purge()
|
||||
}
|
||||
case 'update_start_trading_time': {
|
||||
return messages(contract)?.updateStartTradingTime(args.startTime as string)
|
||||
}
|
||||
case 'update_per_address_limit': {
|
||||
return messages(contract)?.updatePerAddressLimit(args.limit)
|
||||
}
|
||||
case 'mint_to': {
|
||||
return messages(contract)?.mintTo(args.recipient)
|
||||
}
|
||||
default: {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const isEitherType = <T extends ExecuteType>(type: unknown, arr: T[]): type is T => {
|
||||
return arr.some((val) => type === val)
|
||||
}
|
||||
53
contracts/openEditionMinter/messages/query.ts
Normal file
53
contracts/openEditionMinter/messages/query.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import type { OpenEditionMinterInstance } from '../contract'
|
||||
|
||||
export type QueryType = typeof QUERY_TYPES[number]
|
||||
|
||||
export const QUERY_TYPES = ['config', 'start_time', 'mint_price', 'mint_count', 'status'] as const
|
||||
|
||||
export interface QueryListItem {
|
||||
id: QueryType
|
||||
name: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
export const QUERY_LIST: QueryListItem[] = [
|
||||
{ id: 'config', name: 'Config', description: 'View current config' },
|
||||
{ id: 'start_time', name: 'Start Time', description: 'View the start time for minting' },
|
||||
{ id: 'mint_price', name: 'Mint Price', description: 'View the mint price' },
|
||||
{
|
||||
id: 'mint_count',
|
||||
name: 'Total Minted Count',
|
||||
description: 'View the total amount of minted tokens for an address',
|
||||
},
|
||||
{ id: 'status', name: 'Status', description: 'View contract status' },
|
||||
]
|
||||
|
||||
export interface DispatchQueryProps {
|
||||
address: string
|
||||
messages: OpenEditionMinterInstance | undefined
|
||||
type: QueryType
|
||||
}
|
||||
|
||||
export const dispatchQuery = (props: DispatchQueryProps) => {
|
||||
const { address, messages, type } = props
|
||||
switch (type) {
|
||||
case 'config': {
|
||||
return messages?.getConfig()
|
||||
}
|
||||
case 'status': {
|
||||
return messages?.getStatus()
|
||||
}
|
||||
case 'start_time': {
|
||||
return messages?.getStartTime()
|
||||
}
|
||||
case 'mint_price': {
|
||||
return messages?.getMintPrice()
|
||||
}
|
||||
case 'mint_count': {
|
||||
return messages?.getMintCount(address)
|
||||
}
|
||||
default: {
|
||||
throw new Error('unknown query type')
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user