Update the list of actions for SG721 Dashboard > Execute

This commit is contained in:
Serkan Reis 2023-02-26 13:45:18 +03:00
parent d27d22367e
commit 14983047cf
3 changed files with 38 additions and 4 deletions

View File

@ -45,7 +45,7 @@ export const ConfirmationModal = (props: ConfirmationModalProps) => {
<div className="flex justify-end w-full">
<Button className="px-0 mt-4 mr-5 mb-4 max-h-12 bg-gray-600 hover:bg-gray-600">
<label
className="w-full h-full text-white bg-gray-600 hover:bg-gray-600 border-0 btn modal-button"
className="w-full h-full text-white bg-gray-600 hover:bg-gray-600 rounded border-0 btn modal-button"
htmlFor="my-modal-2"
>
Go Back

View File

@ -12,6 +12,8 @@ export const EXECUTE_TYPES = [
'revoke_all',
'mint',
'burn',
'update_token_metadata',
'freeze_token_metadata',
] as const
export interface ExecuteListItem {
@ -61,6 +63,16 @@ export const EXECUTE_LIST: ExecuteListItem[] = [
name: 'Burn',
description: `Burn a token transaction sender has access to`,
},
{
id: 'update_token_metadata',
name: 'Update Token Metadata',
description: `Update the metadata URI for a token`,
},
{
id: 'freeze_token_metadata',
name: 'Freeze Token Metadata',
description: `Render the metadata for tokens no longer updatable`,
},
]
export interface DispatchExecuteProps {
@ -84,6 +96,8 @@ export type DispatchExecuteArgs = {
| { type: Select<'revoke_all'>; operator: string }
| { type: Select<'mint'>; recipient: string; tokenId: string; tokenURI?: string }
| { type: Select<'burn'>; tokenId: string }
| { type: Select<'update_token_metadata'>; tokenId: string; tokenURI: string }
| { type: Select<'freeze_token_metadata'> }
)
export const dispatchExecute = async (args: DispatchExecuteArgs) => {
@ -116,6 +130,12 @@ export const dispatchExecute = async (args: DispatchExecuteArgs) => {
case 'burn': {
return messages.burn(args.tokenId)
}
case 'update_token_metadata': {
return messages.updateTokenMetadata(args.tokenId, args.tokenURI)
}
case 'freeze_token_metadata': {
return messages.freezeTokenMetadata()
}
default: {
throw new Error('unknown execute type')
}
@ -151,6 +171,12 @@ export const previewExecutePayload = (args: DispatchExecuteArgs) => {
case 'burn': {
return messages(contract)?.burn(args.tokenId)
}
case 'update_token_metadata': {
return messages(contract)?.updateTokenMetadata(args.tokenId, args.tokenURI)
}
case 'freeze_token_metadata': {
return messages(contract)?.freezeTokenMetadata()
}
default: {
return {}
}

View File

@ -85,11 +85,19 @@ const Sg721ExecutePage: NextPage = () => {
placeholder: 'ipfs://xyz...',
})
const showTokenIdField = isEitherType(type, ['transfer_nft', 'send_nft', 'approve', 'revoke', 'mint', 'burn'])
const showTokenIdField = isEitherType(type, [
'transfer_nft',
'send_nft',
'approve',
'revoke',
'mint',
'burn',
'update_token_metadata',
])
const showRecipientField = isEitherType(type, ['transfer_nft', 'send_nft', 'approve', 'revoke', 'mint'])
const showOperatorField = isEitherType(type, ['approve_all', 'revoke_all'])
const showMessageField = type === 'send_nft'
const showTokenURIField = type === 'mint'
const showTokenURIField = isEitherType(type, ['mint', 'update_token_metadata'])
const messages = useMemo(() => contract?.use(contractState.value), [contract, contractState.value])
const payload: DispatchExecuteArgs = {
@ -99,7 +107,7 @@ const Sg721ExecutePage: NextPage = () => {
recipient: resolvedRecipientAddress,
operator: resolvedOperatorAddress,
type,
tokenURI: tokenURIState.value,
tokenURI: tokenURIState.value.trim(),
msg: parseJson(messageState.value) || {},
}
const { isLoading, mutate } = useMutation(