Add freeze_collection_info() to collection actions

This commit is contained in:
Serkan Reis 2022-10-24 15:20:12 +03:00
parent 8a07a182e5
commit 7a2e35a859
3 changed files with 62 additions and 8 deletions

View File

@ -32,6 +32,8 @@ interface CollectionActionsProps {
minterMessages: MinterInstance | undefined
}
type ExplicitContentType = true | false | undefined
export const CollectionActions = ({
sg721ContractAddress,
sg721Messages,
@ -45,7 +47,7 @@ export const CollectionActions = ({
const [airdropAllocationArray, setAirdropAllocationArray] = useState<AirdropAllocation[]>([])
const [airdropArray, setAirdropArray] = useState<string[]>([])
const [collectionInfo, setCollectionInfo] = useState<CollectionInfo>()
const [explicitContent, setExplicitContent] = useState(false)
const [explicitContent, setExplicitContent] = useState<ExplicitContentType>(undefined)
const actionComboboxState = useActionsComboboxState()
const type = actionComboboxState.value?.id
@ -125,6 +127,7 @@ export const CollectionActions = ({
name: 'royaltyPaymentAddress',
title: 'Royalty Payment Address',
subtitle: 'Address to receive royalties.',
placeholder: 'stars1234567890abcdefghijklmnopqrstuvwxyz...',
})
const royaltyShareState = useInputState({
@ -217,10 +220,16 @@ export const CollectionActions = ({
throw new Error('Please enter minter and sg721 contract addresses!')
}
if (type === 'update_mint_price' && priceState.value < 50) {
console.log('here')
throw new Error('Mint price must be at least 50 STARS')
}
if (
type === 'update_collection_info' &&
(royaltyShareState.value ? !royaltyPaymentAddressState.value : royaltyPaymentAddressState.value)
) {
throw new Error('Royalty payment address and share percentage are both required')
}
const txHash = await toast.promise(dispatchExecute(payload), {
error: `${type.charAt(0).toUpperCase() + type.slice(1)} execute failed!`,
loading: 'Executing message...',
@ -239,7 +248,6 @@ export const CollectionActions = ({
const airdropFileOnChange = (data: AirdropAllocation[]) => {
setAirdropAllocationArray(data)
console.log(data)
}
return (
@ -258,10 +266,10 @@ export const CollectionActions = ({
{showImageField && <TextInput className="mb-2" {...imageState} />}
{showExternalLinkField && <TextInput className="mb-2" {...externalLinkState} />}
{showRoyaltyRelatedFields && (
<>
<div className="p-2 my-4 rounded border-2 border-gray-500/50">
<TextInput className="mb-2" {...royaltyPaymentAddressState} />
<NumberInput className="mb-2" {...royaltyShareState} />
</>
</div>
)}
{showExplicitContentField && (
<div className="flex flex-col space-y-2">
@ -272,7 +280,7 @@ export const CollectionActions = ({
</span>
<div className="ml-2 font-bold form-check form-check-inline">
<input
checked={explicitContent}
checked={explicitContent === true}
className="peer sr-only"
id="explicitRadio1"
name="explicitRadioOptions1"
@ -290,7 +298,7 @@ export const CollectionActions = ({
</div>
<div className="ml-2 font-bold form-check form-check-inline">
<input
checked={!explicitContent}
checked={explicitContent === false}
className="peer sr-only"
id="explicitRadio2"
name="explicitRadioOptions2"

View File

@ -17,6 +17,7 @@ export const ACTION_TYPES = [
'update_start_trading_time',
'update_per_address_limit',
'update_collection_info',
'freeze_collection_info',
'withdraw',
'transfer',
'batch_transfer',
@ -89,6 +90,11 @@ export const ACTION_LIST: ActionListItem[] = [
name: 'Update Collection Info',
description: `Update Collection Info`,
},
{
id: 'freeze_collection_info',
name: 'Freeze Collection Info',
description: `Freeze collection info to prevent further updates`,
},
{
id: 'withdraw',
name: 'Withdraw Tokens',
@ -166,6 +172,7 @@ export type DispatchExecuteArgs = {
| { type: Select<'airdrop'>; recipients: string[] }
| { type: Select<'burn_remaining'> }
| { type: Select<'update_collection_info'>; collectionInfo: CollectionInfo | undefined }
| { type: Select<'freeze_collection_info'> }
)
export const dispatchExecute = async (args: DispatchExecuteArgs) => {
@ -207,6 +214,9 @@ export const dispatchExecute = async (args: DispatchExecuteArgs) => {
case 'update_collection_info': {
return sg721Messages.updateCollectionInfo(args.collectionInfo as CollectionInfo)
}
case 'freeze_collection_info': {
return sg721Messages.freezeCollectionInfo()
}
case 'shuffle': {
return minterMessages.shuffle(txSigner)
}
@ -277,6 +287,9 @@ export const previewExecutePayload = (args: DispatchExecuteArgs) => {
case 'update_collection_info': {
return sg721Messages(sg721Contract)?.updateCollectionInfo(args.collectionInfo as CollectionInfo)
}
case 'freeze_collection_info': {
return sg721Messages(sg721Contract)?.freezeCollectionInfo()
}
case 'shuffle': {
return minterMessages(minterContract)?.shuffle()
}

View File

@ -76,6 +76,7 @@ export interface SG721Instance {
/// Mint a new NFT, can only be called by the contract minter
mint: (tokenId: string, owner: string, tokenURI?: string) => Promise<string> //MintMsg<T>
updateCollectionInfo: (collectionInfo: CollectionInfo) => Promise<string>
freezeCollectionInfo: () => Promise<string>
/// Burn an NFT the sender has access to
burn: (tokenId: string) => Promise<string>
batchBurn: (tokenIds: string) => Promise<string>
@ -94,6 +95,7 @@ export interface Sg721Messages {
batchBurn: (tokenIds: string) => BatchBurnMessage
batchTransfer: (recipient: string, tokenIds: string) => BatchTransferMessage
updateCollectionInfo: (collectionInfo: CollectionInfo) => UpdateCollectionInfoMessage
freezeCollectionInfo: () => FreezeCollectionInfoMessage
}
export interface TransferNFTMessage {
@ -219,6 +221,13 @@ export interface UpdateCollectionInfoMessage {
funds: Coin[]
}
export interface FreezeCollectionInfoMessage {
sender: string
contract: string
msg: { freeze_collection_info: Record<string, never> }
funds: Coin[]
}
export interface SG721Contract {
instantiate: (
senderAddress: string,
@ -537,7 +546,6 @@ export const SG721 = (client: SigningCosmWasmClient, txSigner: string): SG721Con
// eslint-disable-next-line @typescript-eslint/no-shadow
const updateCollectionInfo = async (collectionInfo: CollectionInfo): Promise<string> => {
console.log(collectionInfo)
const res = await client.execute(
txSigner,
contractAddress,
@ -550,6 +558,19 @@ export const SG721 = (client: SigningCosmWasmClient, txSigner: string): SG721Con
return res.transactionHash
}
const freezeCollectionInfo = async (): Promise<string> => {
const res = await client.execute(
txSigner,
contractAddress,
{
freeze_collection_info: {},
},
'auto',
'',
)
return res.transactionHash
}
return {
contractAddress,
ownerOf,
@ -575,6 +596,7 @@ export const SG721 = (client: SigningCosmWasmClient, txSigner: string): SG721Con
batchBurn,
batchTransfer,
updateCollectionInfo,
freezeCollectionInfo,
}
}
@ -767,6 +789,16 @@ export const SG721 = (client: SigningCosmWasmClient, txSigner: string): SG721Con
funds: [],
}
}
const freezeCollectionInfo = () => {
return {
sender: txSigner,
contract: contractAddress,
msg: {
freeze_collection_info: {},
},
funds: [],
}
}
return {
transferNft,
@ -780,6 +812,7 @@ export const SG721 = (client: SigningCosmWasmClient, txSigner: string): SG721Con
batchBurn,
batchTransfer,
updateCollectionInfo,
freezeCollectionInfo,
}
}