Update action list wrt SG721 type on Collection Actions

This commit is contained in:
Serkan Reis 2023-02-25 21:09:43 +03:00
parent 88335ea733
commit a764b96727
4 changed files with 40 additions and 10 deletions

View File

@ -26,7 +26,7 @@ import { resolveAddress } from 'utils/resolveAddress'
import type { CollectionInfo } from '../../../contracts/sg721/contract'
import { TextInput } from '../../forms/FormInput'
import type { MinterType } from './Combobox'
import type { MinterType, Sg721Type } from './Combobox'
interface CollectionActionsProps {
minterContractAddress: string
@ -35,6 +35,7 @@ interface CollectionActionsProps {
vendingMinterMessages: VendingMinterInstance | undefined
baseMinterMessages: BaseMinterInstance | undefined
minterType: MinterType
sg721Type: Sg721Type
}
type ExplicitContentType = true | false | undefined
@ -46,6 +47,7 @@ export const CollectionActions = ({
vendingMinterMessages,
baseMinterMessages,
minterType,
sg721Type,
}: CollectionActionsProps) => {
const wallet = useWallet()
const [lastTx, setLastTx] = useState('')
@ -350,7 +352,7 @@ export const CollectionActions = ({
<form>
<div className="grid grid-cols-2 mt-4">
<div className="mr-2">
<ActionsCombobox minterType={minterType} {...actionComboboxState} />
<ActionsCombobox minterType={minterType} sg721Type={sg721Type} {...actionComboboxState} />
{showRecipientField && <AddressInput {...recipientState} />}
{showTokenUriField && <TextInput className="mt-2" {...tokenURIState} />}
{showWhitelistField && <AddressInput {...whitelistState} />}

View File

@ -6,7 +6,7 @@ import { Fragment, useEffect, useState } from 'react'
import { FaChevronDown, FaInfoCircle } from 'react-icons/fa'
import type { ActionListItem } from './actions'
import { BASE_ACTION_LIST, VENDING_ACTION_LIST } from './actions'
import { BASE_ACTION_LIST, SG721_UPDATABLE_ACTION_LIST, VENDING_ACTION_LIST } from './actions'
export type MinterType = 'base' | 'vending'
export type Sg721Type = 'updatable' | 'base'
@ -15,19 +15,22 @@ export interface ActionsComboboxProps {
value: ActionListItem | null
onChange: (item: ActionListItem) => void
minterType?: MinterType
sg721Type?: Sg721Type
}
export const ActionsCombobox = ({ value, onChange, minterType }: ActionsComboboxProps) => {
export const ActionsCombobox = ({ value, onChange, minterType, sg721Type }: ActionsComboboxProps) => {
const [search, setSearch] = useState('')
const [ACTION_LIST, SET_ACTION_LIST] = useState<ActionListItem[]>(VENDING_ACTION_LIST)
useEffect(() => {
if (minterType === 'base') {
SET_ACTION_LIST(BASE_ACTION_LIST)
} else {
SET_ACTION_LIST(VENDING_ACTION_LIST)
}
}, [minterType])
if (sg721Type === 'updatable') SET_ACTION_LIST(BASE_ACTION_LIST.concat(SG721_UPDATABLE_ACTION_LIST))
else SET_ACTION_LIST(BASE_ACTION_LIST)
} else if (minterType === 'vending') {
if (sg721Type === 'updatable') SET_ACTION_LIST(VENDING_ACTION_LIST.concat(SG721_UPDATABLE_ACTION_LIST))
else SET_ACTION_LIST(VENDING_ACTION_LIST)
} else SET_ACTION_LIST(VENDING_ACTION_LIST.concat(SG721_UPDATABLE_ACTION_LIST))
}, [minterType, sg721Type])
const filtered =
search === '' ? ACTION_LIST : matchSorter(ACTION_LIST, search, { keys: ['id', 'name', 'description'] })

View File

@ -30,6 +30,9 @@ export const ACTION_TYPES = [
'shuffle',
'airdrop',
'burn_remaining',
'update_token_metadata',
'batch_update_token_metadata',
'freeze_metadata',
] as const
export interface ActionListItem {
@ -184,6 +187,24 @@ export const VENDING_ACTION_LIST: ActionListItem[] = [
},
]
export const SG721_UPDATABLE_ACTION_LIST: ActionListItem[] = [
{
id: 'update_token_metadata',
name: 'Update Token Metadata',
description: `Update the metadata URI for a token`,
},
{
id: 'batch_update_token_metadata',
name: 'Batch Update Token Metadata',
description: `Update the metadata URI for a range of tokens`,
},
{
id: 'freeze_metadata',
name: 'Freeze Metadata',
description: `Render the metadata for the collection no longer updatable`,
},
]
export interface DispatchExecuteProps {
type: ActionType
[k: string]: unknown
@ -222,6 +243,9 @@ export type DispatchExecuteArgs = {
| { type: Select<'burn_remaining'> }
| { type: Select<'update_collection_info'>; collectionInfo: CollectionInfo | undefined }
| { type: Select<'freeze_collection_info'> }
| { type: Select<'update_token_metadata'> }
| { type: Select<'batch_update_token_metadata'> }
| { type: Select<'freeze_metadata'> }
)
export const dispatchExecute = async (args: DispatchExecuteArgs) => {

View File

@ -23,7 +23,7 @@ const CollectionActionsPage: NextPage = () => {
const [action, setAction] = useState<boolean>(false)
const [minterType, setMinterType] = useState<MinterType>('vending')
const [sg721Type, setSg721Type] = useState<Sg721Type>('base')
const [sg721Type, setSg721Type] = useState<Sg721Type>('updatable')
const sg721ContractState = useInputState({
id: 'sg721-contract-address',
@ -215,6 +215,7 @@ const CollectionActionsPage: NextPage = () => {
minterType={minterType}
sg721ContractAddress={sg721ContractState.value}
sg721Messages={sg721Messages}
sg721Type={sg721Type}
vendingMinterMessages={vendingMinterMessages}
/>
)) || (