Merge pull request #230 from public-awesome/royalty-registry-update

Royalty registry update
This commit is contained in:
Serkan Reis 2023-10-10 14:21:40 +03:00 committed by GitHub
commit 8fc3f71413
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 267 additions and 44 deletions

View File

@ -1,4 +1,4 @@
APP_VERSION=0.7.10
APP_VERSION=0.7.11
NEXT_PUBLIC_PINATA_ENDPOINT_URL=https://api.pinata.cloud/pinning/pinFileToIPFS
NEXT_PUBLIC_SG721_CODE_ID=2595
@ -40,6 +40,7 @@ NEXT_PUBLIC_OPEN_EDITION_UPDATABLE_IBC_FRNZ_FACTORY_ADDRESS="stars1tc09vlgdg8rqy
NEXT_PUBLIC_SG721_NAME_ADDRESS="stars1fx74nkqkw2748av8j7ew7r3xt9cgjqduwn8m0ur5lhe49uhlsasszc5fhr"
NEXT_PUBLIC_ROYALTY_REGISTRY_ADDRESS="stars1crgx0f70fzksa57hq87wtl8f04h0qyk5la0hk0fu8dyhl67ju80qaxzr5z"
NEXT_PUBLIC_INFINITY_SWAP_PROTOCOL_ADDRESS="stars136yp6fl9h66m0cwv8weu4w4aawveuz40992ty0atj5ecjd8z0thqv9xpy5"
NEXT_PUBLIC_WHITELIST_CODE_ID=2602
NEXT_PUBLIC_WHITELIST_FLEX_CODE_ID=2603
NEXT_PUBLIC_BADGE_HUB_CODE_ID=1336

View File

@ -1,6 +1,7 @@
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable no-nested-ternary */
import { toUtf8 } from '@cosmjs/encoding'
import clsx from 'clsx'
import { AirdropUpload } from 'components/AirdropUpload'
import { Button } from 'components/Button'
import type { DispatchExecuteArgs } from 'components/collections/actions/actions'
@ -20,6 +21,7 @@ import { useGlobalSettings } from 'contexts/globalSettings'
import { useWallet } from 'contexts/wallet'
import type { BaseMinterInstance } from 'contracts/baseMinter'
import type { OpenEditionMinterInstance } from 'contracts/openEditionMinter'
import type { RoyaltyRegistryInstance } from 'contracts/royaltyRegistry'
import type { SG721Instance } from 'contracts/sg721'
import type { VendingMinterInstance } from 'contracts/vendingMinter'
import type { FormEvent } from 'react'
@ -27,6 +29,7 @@ import { useEffect, useState } from 'react'
import { toast } from 'react-hot-toast'
import { FaArrowRight } from 'react-icons/fa'
import { useMutation } from 'react-query'
import { ROYALTY_REGISTRY_ADDRESS } from 'utils/constants'
import type { AirdropAllocation } from 'utils/isValidAccountsFile'
import { resolveAddress } from 'utils/resolveAddress'
@ -41,6 +44,7 @@ interface CollectionActionsProps {
vendingMinterMessages: VendingMinterInstance | undefined
baseMinterMessages: BaseMinterInstance | undefined
openEditionMinterMessages: OpenEditionMinterInstance | undefined
royaltyRegistryMessages: RoyaltyRegistryInstance | undefined
minterType: MinterType
sg721Type: Sg721Type
}
@ -54,6 +58,7 @@ export const CollectionActions = ({
vendingMinterMessages,
baseMinterMessages,
openEditionMinterMessages,
royaltyRegistryMessages,
minterType,
sg721Type,
}: CollectionActionsProps) => {
@ -69,6 +74,7 @@ export const CollectionActions = ({
const [explicitContent, setExplicitContent] = useState<ExplicitContentType>(undefined)
const [resolvedRecipientAddress, setResolvedRecipientAddress] = useState<string>('')
const [jsonExtensions, setJsonExtensions] = useState<boolean>(false)
const [decrement, setDecrement] = useState<boolean>(false)
const actionComboboxState = useActionsComboboxState()
const type = actionComboboxState.value?.id
@ -170,8 +176,11 @@ export const CollectionActions = ({
const royaltyShareState = useInputState({
id: 'royalty-share',
name: 'royaltyShare',
title: 'Share Percentage',
subtitle: 'Percentage of royalties to be paid',
title: type !== 'update_royalties_for_infinity_swap' ? 'Share Percentage' : 'Share Delta',
subtitle:
type !== 'update_royalties_for_infinity_swap'
? 'Percentage of royalties to be paid'
: 'Change in share percentage',
placeholder: '5%',
})
@ -208,7 +217,10 @@ export const CollectionActions = ({
const showDescriptionField = type === 'update_collection_info'
const showImageField = type === 'update_collection_info'
const showExternalLinkField = type === 'update_collection_info'
const showRoyaltyRelatedFields = type === 'update_collection_info'
const showRoyaltyRelatedFields =
type === 'update_collection_info' ||
type === 'set_royalties_for_infinity_swap' ||
type === 'update_royalties_for_infinity_swap'
const showExplicitContentField = type === 'update_collection_info'
const showBaseUriField = type === 'batch_update_token_metadata'
@ -219,6 +231,7 @@ export const CollectionActions = ({
limit: limitState.value,
minterContract: minterContractAddress,
sg721Contract: sg721ContractAddress,
royaltyRegistryContract: ROYALTY_REGISTRY_ADDRESS,
tokenId: tokenIdState.value,
tokenIds: tokenIdListState.value,
tokenUri: tokenURIState.value.trim().endsWith('/')
@ -229,6 +242,7 @@ export const CollectionActions = ({
baseMinterMessages,
openEditionMinterMessages,
sg721Messages,
royaltyRegistryMessages,
recipient: resolvedRecipientAddress,
recipients: airdropArray,
tokenRecipients: airdropAllocationArray,
@ -240,6 +254,7 @@ export const CollectionActions = ({
: baseURIState.value.trim(),
collectionInfo,
jsonExtensions,
decrement,
}
const resolveRecipientAddress = async () => {
await resolveAddress(recipientState.value.trim(), wallet).then((resolvedAddress) => {
@ -448,6 +463,24 @@ export const CollectionActions = ({
<div className="p-2 my-4 rounded border-2 border-gray-500/50">
<TextInput className="mb-2" {...royaltyPaymentAddressState} />
<NumberInput className="mb-2" {...royaltyShareState} />
<Conditional test={type === 'update_royalties_for_infinity_swap'}>
<div className="flex flex-row space-y-2 w-1/4">
<div className={clsx('flex flex-col space-y-2 w-full form-control')}>
<label className="justify-start cursor-pointer label">
<div className="flex flex-col">
<span className="mr-4 font-bold">Increment</span>
</div>
<input
checked={decrement}
className={`toggle ${decrement ? `bg-stargaze` : `bg-gray-600`}`}
onClick={() => setDecrement(!decrement)}
type="checkbox"
/>
</label>
</div>
<span className="mx-4 font-bold">Decrement</span>
</div>
</Conditional>
</div>
)}
{showExplicitContentField && (

View File

@ -1,10 +1,13 @@
/* eslint-disable eslint-comments/disable-enable-pair */
import { useBaseMinterContract } from 'contracts/baseMinter'
import { useOpenEditionMinterContract } from 'contracts/openEditionMinter'
import type { RoyaltyRegistryInstance } from 'contracts/royaltyRegistry'
import { useRoyaltyRegistryContract } from 'contracts/royaltyRegistry'
import type { CollectionInfo, SG721Instance } from 'contracts/sg721'
import { useSG721Contract } from 'contracts/sg721'
import type { VendingMinterInstance } from 'contracts/vendingMinter'
import { useVendingMinterContract } from 'contracts/vendingMinter'
import { INFINITY_SWAP_PROTOCOL_ADDRESS } from 'utils/constants'
import type { AirdropAllocation } from 'utils/isValidAccountsFile'
import type { BaseMinterInstance } from '../../../contracts/baseMinter/contract'
@ -29,6 +32,8 @@ export const ACTION_TYPES = [
'update_per_address_limit',
'update_collection_info',
'freeze_collection_info',
'set_royalties_for_infinity_swap',
'update_royalties_for_infinity_swap',
'transfer',
'batch_transfer',
'batch_transfer_multi_address',
@ -73,6 +78,16 @@ export const BASE_ACTION_LIST: ActionListItem[] = [
name: 'Freeze Collection Info',
description: `Freeze collection info to prevent further updates`,
},
{
id: 'set_royalties_for_infinity_swap',
name: 'Set Royalty Details for Infinity Swap',
description: `Set royalty details for Infinity Swap`,
},
{
id: 'update_royalties_for_infinity_swap',
name: 'Update Royalty Details for Infinity Swap',
description: `Update royalty details for Infinity Swap`,
},
{
id: 'transfer',
name: 'Transfer Tokens',
@ -166,6 +181,16 @@ export const VENDING_ACTION_LIST: ActionListItem[] = [
name: 'Freeze Collection Info',
description: `Freeze collection info to prevent further updates`,
},
{
id: 'set_royalties_for_infinity_swap',
name: 'Set Royalty Details for Infinity Swap',
description: `Set royalty details for Infinity Swap`,
},
{
id: 'update_royalties_for_infinity_swap',
name: 'Update Royalty Details for Infinity Swap',
description: `Update royalty details for Infinity Swap`,
},
{
id: 'transfer',
name: 'Transfer Tokens',
@ -259,6 +284,16 @@ export const OPEN_EDITION_ACTION_LIST: ActionListItem[] = [
name: 'Freeze Collection Info',
description: `Freeze collection info to prevent further updates`,
},
{
id: 'set_royalties_for_infinity_swap',
name: 'Set Royalty Details for Infinity Swap',
description: `Set royalty details for Infinity Swap`,
},
{
id: 'update_royalties_for_infinity_swap',
name: 'Update Royalty Details for Infinity Swap',
description: `Update royalty details for Infinity Swap`,
},
{
id: 'transfer',
name: 'Transfer Tokens',
@ -323,10 +358,12 @@ export interface DispatchExecuteProps {
export interface DispatchExecuteArgs {
minterContract: string
sg721Contract: string
royaltyRegistryContract: string
vendingMinterMessages?: VendingMinterInstance
baseMinterMessages?: BaseMinterInstance
openEditionMinterMessages?: OpenEditionMinterInstance
sg721Messages?: SG721Instance
royaltyRegistryMessages?: RoyaltyRegistryInstance
txSigner: string
type: string | undefined
tokenUri: string
@ -344,11 +381,25 @@ export interface DispatchExecuteArgs {
collectionInfo: CollectionInfo | undefined
baseUri: string
jsonExtensions: boolean
decrement: boolean
}
export const dispatchExecute = async (args: DispatchExecuteArgs) => {
const { vendingMinterMessages, baseMinterMessages, openEditionMinterMessages, sg721Messages, txSigner } = args
if (!vendingMinterMessages || !baseMinterMessages || !openEditionMinterMessages || !sg721Messages) {
const {
vendingMinterMessages,
baseMinterMessages,
openEditionMinterMessages,
sg721Messages,
royaltyRegistryMessages,
txSigner,
} = args
if (
!vendingMinterMessages ||
!baseMinterMessages ||
!openEditionMinterMessages ||
!sg721Messages ||
!royaltyRegistryMessages
) {
throw new Error('Cannot execute actions')
}
switch (args.type) {
@ -415,6 +466,23 @@ export const dispatchExecute = async (args: DispatchExecuteArgs) => {
case 'shuffle': {
return vendingMinterMessages.shuffle(txSigner)
}
case 'set_royalties_for_infinity_swap': {
return royaltyRegistryMessages.setCollectionRoyaltyProtocol(
args.sg721Contract,
INFINITY_SWAP_PROTOCOL_ADDRESS,
args.collectionInfo?.royalty_info?.payment_address as string,
Number(args.collectionInfo?.royalty_info?.share) * 100,
)
}
case 'update_royalties_for_infinity_swap': {
return royaltyRegistryMessages.updateCollectionRoyaltyProtocol(
args.sg721Contract,
INFINITY_SWAP_PROTOCOL_ADDRESS,
args.collectionInfo?.royalty_info?.payment_address as string,
Number(args.collectionInfo?.royalty_info?.share) * 100,
args.decrement,
)
}
case 'transfer': {
return sg721Messages.transferNft(args.recipient, args.tokenId.toString())
}
@ -460,7 +528,10 @@ export const previewExecutePayload = (args: DispatchExecuteArgs) => {
const { messages: baseMinterMessages } = useBaseMinterContract()
// eslint-disable-next-line react-hooks/rules-of-hooks
const { messages: openEditionMinterMessages } = useOpenEditionMinterContract()
const { minterContract, sg721Contract } = args
// eslint-disable-next-line react-hooks/rules-of-hooks
const { messages: royaltyRegistryMessages } = useRoyaltyRegistryContract()
const { minterContract, sg721Contract, royaltyRegistryContract } = args
switch (args.type) {
case 'mint_token_uri': {
return baseMinterMessages(minterContract)?.mint(args.tokenUri)
@ -525,6 +596,23 @@ export const previewExecutePayload = (args: DispatchExecuteArgs) => {
case 'shuffle': {
return vendingMinterMessages(minterContract)?.shuffle()
}
case 'set_royalties_for_infinity_swap': {
return royaltyRegistryMessages(royaltyRegistryContract)?.setCollectionRoyaltyProtocol(
args.sg721Contract,
INFINITY_SWAP_PROTOCOL_ADDRESS,
args.collectionInfo?.royalty_info?.payment_address as string,
Number(args.collectionInfo?.royalty_info?.share) * 100,
)
}
case 'update_royalties_for_infinity_swap': {
return royaltyRegistryMessages(royaltyRegistryContract)?.updateCollectionRoyaltyProtocol(
args.sg721Contract,
INFINITY_SWAP_PROTOCOL_ADDRESS,
args.collectionInfo?.royalty_info?.payment_address as string,
Number(args.collectionInfo?.royalty_info?.share) * 100,
args.decrement,
)
}
case 'transfer': {
return sg721Messages(sg721Contract)?.transferNft(args.recipient, args.tokenId.toString())
}

View File

@ -7,6 +7,7 @@ import { useInputState } from 'components/forms/FormInput.hooks'
import { JsonPreview } from 'components/JsonPreview'
import type { BaseMinterInstance } from 'contracts/baseMinter'
import type { OpenEditionMinterInstance } from 'contracts/openEditionMinter'
import type { RoyaltyRegistryInstance } from 'contracts/royaltyRegistry'
import type { SG721Instance } from 'contracts/sg721'
import type { VendingMinterInstance } from 'contracts/vendingMinter'
import { toast } from 'react-hot-toast'
@ -19,10 +20,12 @@ import type { MinterType } from '../actions/Combobox'
interface CollectionQueriesProps {
minterContractAddress: string
sg721ContractAddress: string
royaltyRegistryContractAddress: string
sg721Messages: SG721Instance | undefined
vendingMinterMessages: VendingMinterInstance | undefined
baseMinterMessages: BaseMinterInstance | undefined
openEditionMinterMessages: OpenEditionMinterInstance | undefined
royaltyRegistryMessages: RoyaltyRegistryInstance | undefined
minterType: MinterType
}
export const CollectionQueries = ({
@ -33,6 +36,7 @@ export const CollectionQueries = ({
openEditionMinterMessages,
baseMinterMessages,
minterType,
royaltyRegistryMessages,
}: CollectionQueriesProps) => {
const wallet = useWallet()
@ -65,9 +69,11 @@ export const CollectionQueries = ({
baseMinterMessages,
vendingMinterMessages,
openEditionMinterMessages,
royaltyRegistryMessages,
type,
tokenId,
address,
sg721ContractAddress,
] as const,
async ({ queryKey }) => {
const [
@ -75,9 +81,11 @@ export const CollectionQueries = ({
_baseMinterMessages_,
_vendingMinterMessages,
_openEditionMinterMessages,
_royaltyRegistryMessages,
_type,
_tokenId,
_address,
_sg721ContractAddress,
] = queryKey
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const res = await resolveAddress(_address, wallet).then(async (resolvedAddress) => {
@ -88,8 +96,10 @@ export const CollectionQueries = ({
baseMinterMessages: _baseMinterMessages_,
openEditionMinterMessages: _openEditionMinterMessages,
sg721Messages: _sg721Messages,
royaltyRegistryMessages: _royaltyRegistryMessages,
address: resolvedAddress,
type: _type,
sg721ContractAddress: _sg721ContractAddress,
})
return result
})
@ -102,7 +112,9 @@ export const CollectionQueries = ({
toast.error(error.message, { style: { maxWidth: 'none' } })
}
},
enabled: Boolean(sg721ContractAddress && minterContractAddress && type),
enabled:
Boolean(type && type === 'infinity_swap_royalties' && sg721ContractAddress) ||
Boolean(sg721ContractAddress && minterContractAddress && type),
retry: false,
},
)

View File

@ -1,7 +1,9 @@
import type { BaseMinterInstance } from 'contracts/baseMinter'
import type { OpenEditionMinterInstance } from 'contracts/openEditionMinter/contract'
import type { RoyaltyRegistryInstance } from 'contracts/royaltyRegistry'
import type { SG721Instance } from 'contracts/sg721'
import type { VendingMinterInstance } from 'contracts/vendingMinter'
import { INFINITY_SWAP_PROTOCOL_ADDRESS } from 'utils/constants'
export type QueryType = typeof QUERY_TYPES[number]
@ -13,6 +15,7 @@ export const QUERY_TYPES = [
'total_mint_count',
'tokens',
// 'token_owners',
'infinity_swap_royalties',
'token_info',
'config',
'status',
@ -35,6 +38,11 @@ export const VENDING_QUERY_LIST: QueryListItem[] = [
name: 'Mint Price',
description: `Get the price of minting a token.`,
},
{
id: 'infinity_swap_royalties',
name: 'Infinity Swap Royalty Details',
description: `Get the collection's royalty details for Infinity Swap`,
},
{
id: 'num_tokens',
name: 'Mintable Number of Tokens',
@ -77,6 +85,11 @@ export const BASE_QUERY_LIST: QueryListItem[] = [
name: 'Tokens Minted to User',
description: `Get the number of tokens minted in the collection to a user.`,
},
{
id: 'infinity_swap_royalties',
name: 'Infinity Swap Royalty Details',
description: `Get the collection's royalty details for Infinity Swap`,
},
{
id: 'token_info',
name: 'Token Info',
@ -104,6 +117,11 @@ export const OPEN_EDITION_QUERY_LIST: QueryListItem[] = [
name: 'Mint Price',
description: `Get the price of minting a token.`,
},
{
id: 'infinity_swap_royalties',
name: 'Infinity Swap Royalty Details',
description: `Get the collection's royalty details for Infinity Swap`,
},
{
id: 'tokens_minted_to_user',
name: 'Tokens Minted to User',
@ -148,6 +166,8 @@ export type DispatchQueryArgs = {
vendingMinterMessages?: VendingMinterInstance
openEditionMinterMessages?: OpenEditionMinterInstance
sg721Messages?: SG721Instance
royaltyRegistryMessages?: RoyaltyRegistryInstance
sg721ContractAddress?: string
} & (
| { type: undefined }
| { type: Select<'collection_info'> }
@ -156,6 +176,7 @@ export type DispatchQueryArgs = {
| { type: Select<'tokens_minted_to_user'>; address: string }
| { type: Select<'total_mint_count'> }
| { type: Select<'tokens'>; address: string }
| { type: Select<'infinity_swap_royalties'> }
// | { type: Select<'token_owners'> }
| { type: Select<'token_info'>; tokenId: string }
| { type: Select<'config'> }
@ -163,7 +184,13 @@ export type DispatchQueryArgs = {
)
export const dispatchQuery = async (args: DispatchQueryArgs) => {
const { baseMinterMessages, vendingMinterMessages, openEditionMinterMessages, sg721Messages } = args
const {
baseMinterMessages,
vendingMinterMessages,
openEditionMinterMessages,
sg721Messages,
royaltyRegistryMessages,
} = args
if (!baseMinterMessages || !vendingMinterMessages || !openEditionMinterMessages || !sg721Messages) {
throw new Error('Cannot execute actions')
}
@ -189,6 +216,12 @@ export const dispatchQuery = async (args: DispatchQueryArgs) => {
// case 'token_owners': {
// return vendingMinterMessages.updateStartTime(txSigner, args.startTime)
// }
case 'infinity_swap_royalties': {
return royaltyRegistryMessages?.collectionRoyaltyProtocol(
args.sg721ContractAddress as string,
INFINITY_SWAP_PROTOCOL_ADDRESS,
)
}
case 'token_info': {
if (!args.tokenId) return
return sg721Messages.allNftInfo(args.tokenId)

View File

@ -25,23 +25,23 @@ export const EXECUTE_LIST: ExecuteListItem[] = [
},
{
id: 'set_collection_royalty_default',
name: 'Set Collection Royalty Default',
description: 'Set collection royalty default',
name: 'Set Default Collection Royalty',
description: 'Set default collection royalty for unknown protocols',
},
{
id: 'update_collection_royalty_default',
name: 'Update Collection Royalty Default',
description: 'Update collection royalty default',
name: 'Update Default Collection Royalty',
description: 'Update default collection royalty for unknown protocols',
},
{
id: 'set_collection_royalty_protocol',
name: 'Set Collection Royalty Protocol',
description: 'Set collection royalty protocol',
name: 'Set Protocol Collection Royalty',
description: 'Set collection royalty for a specific protocol',
},
{
id: 'update_collection_royalty_protocol',
name: 'Update Collection Royalty Protocol',
description: 'Update collection royalty protocol',
name: 'Update Protocol Collection Royalty',
description: 'Update collection royalty for a specific protocol',
},
]

1
env.d.ts vendored
View File

@ -47,6 +47,7 @@ declare namespace NodeJS {
readonly NEXT_PUBLIC_BASE_FACTORY_UPDATABLE_ADDRESS: string
readonly NEXT_PUBLIC_SG721_NAME_ADDRESS: string
readonly NEXT_PUBLIC_ROYALTY_REGISTRY_ADDRESS: string
readonly NEXT_PUBLIC_INFINITY_SWAP_PROTOCOL_ADDRESS: string
readonly NEXT_PUBLIC_BASE_MINTER_CODE_ID: string
readonly NEXT_PUBLIC_BADGE_HUB_CODE_ID: string
readonly NEXT_PUBLIC_BADGE_HUB_ADDRESS: string

View File

@ -1,6 +1,6 @@
{
"name": "stargaze-studio",
"version": "0.7.10",
"version": "0.7.11",
"workspaces": [
"packages/*"
],

View File

@ -12,6 +12,7 @@ import { useRouter } from 'next/router'
import { NextSeo } from 'next-seo'
import { useEffect, useMemo, useState } from 'react'
import toast from 'react-hot-toast'
import { ROYALTY_REGISTRY_ADDRESS } from 'utils/constants'
import { useDebounce } from 'utils/debounce'
import { withMetadata } from 'utils/layout'
import { links } from 'utils/links'
@ -24,6 +25,7 @@ const CollectionActionsPage: NextPage = () => {
vendingMinter: vendingMinterContract,
openEditionMinter: openEditionMinterContract,
sg721: sg721Contract,
royaltyRegistry: royaltyRegistryContract,
} = useContracts()
const wallet = useWallet()
@ -66,6 +68,11 @@ const CollectionActionsPage: NextPage = () => {
[sg721Contract, sg721ContractState.value],
)
const royaltyRegistryMessages = useMemo(
() => royaltyRegistryContract?.use(ROYALTY_REGISTRY_ADDRESS),
[royaltyRegistryContract],
)
const sg721ContractAddress = sg721ContractState.value
const minterContractAddress = minterContractState.value
@ -227,6 +234,7 @@ const CollectionActionsPage: NextPage = () => {
minterContractAddress={minterContractState.value}
minterType={minterType}
openEditionMinterMessages={openEditionMinterMessages}
royaltyRegistryMessages={royaltyRegistryMessages}
sg721ContractAddress={sg721ContractState.value}
sg721Messages={sg721Messages}
sg721Type={sg721Type}
@ -238,6 +246,8 @@ const CollectionActionsPage: NextPage = () => {
minterContractAddress={minterContractState.value}
minterType={minterType}
openEditionMinterMessages={openEditionMinterMessages}
royaltyRegistryContractAddress={ROYALTY_REGISTRY_ADDRESS}
royaltyRegistryMessages={royaltyRegistryMessages}
sg721ContractAddress={sg721ContractState.value}
sg721Messages={sg721Messages}
vendingMinterMessages={vendingMinterMessages}

View File

@ -23,15 +23,18 @@ import { useEffect, useMemo, useState } from 'react'
import { toast } from 'react-hot-toast'
import { FaArrowRight } from 'react-icons/fa'
import { useMutation } from 'react-query'
import { ROYALTY_REGISTRY_ADDRESS } from 'utils/constants'
import { INFINITY_SWAP_PROTOCOL_ADDRESS, ROYALTY_REGISTRY_ADDRESS } from 'utils/constants'
import { withMetadata } from 'utils/layout'
import { links } from 'utils/links'
export const protocolList = [{ name: 'Infinity Swap', address: INFINITY_SWAP_PROTOCOL_ADDRESS }]
const RoyaltyRegistryExecutePage: NextPage = () => {
const { royaltyRegistry: contract } = useContracts()
const wallet = useWallet()
const [lastTx, setLastTx] = useState('')
const [manualProtocolInput, setManualProtocolInput] = useState(false)
const comboboxState = useExecuteComboboxState()
const type = comboboxState.value?.id
@ -52,11 +55,14 @@ const RoyaltyRegistryExecutePage: NextPage = () => {
subtitle: 'Address of the collection',
})
const collectionAddress = collectionAddressState.value
const protocolAddressState = useInputState({
id: 'protocol-address',
name: 'protocol-address',
title: 'Protocol Address',
subtitle: 'Address of the protocol',
defaultValue: INFINITY_SWAP_PROTOCOL_ADDRESS,
})
const recipientAddressState = useInputState({
@ -131,14 +137,14 @@ const RoyaltyRegistryExecutePage: NextPage = () => {
const router = useRouter()
useEffect(() => {
if (contractAddress.length > 0) {
void router.replace({ query: { contractAddress } })
if (collectionAddress.length > 0) {
void router.replace({ query: { collectionAddress } })
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [contractAddress])
}, [collectionAddress])
useEffect(() => {
const initial = new URL(document.URL).searchParams.get('contractAddress')
if (initial && initial.length > 0) contractState.onChange(initial)
const initial = new URL(document.URL).searchParams.get('collectionAddress')
if (initial && initial.length > 0) collectionAddressState.onChange(initial)
}, [])
return (
@ -153,13 +159,34 @@ const RoyaltyRegistryExecutePage: NextPage = () => {
<form className="grid grid-cols-2 p-4 space-x-8" onSubmit={mutate}>
<div className="space-y-8">
<AddressInput {...contractState} />
<ExecuteCombobox {...comboboxState} />
<AddressInput {...collectionAddressState} />
<ExecuteCombobox {...comboboxState} />
<Conditional
test={isEitherType(type, ['set_collection_royalty_protocol', 'update_collection_royalty_protocol'])}
>
<AddressInput {...protocolAddressState} />
<span className="mr-4 font-bold">Selected Protocol</span>
<select
className="py-2 px-4 placeholder:text-white/50 bg-white/10 rounded border-2 border-white/20 focus:ring focus:ring-plumbus-20"
onChange={(e) => {
if (e.target.value) {
protocolAddressState.onChange(e.target.value)
setManualProtocolInput(false)
} else {
protocolAddressState.onChange('')
setManualProtocolInput(true)
}
}}
>
{protocolList.map((protocol) => (
<option key={protocol.address} value={protocol.address}>
{protocol.name}
</option>
))}
<option value="">Manual Input</option>
</select>
<Conditional test={manualProtocolInput}>
<AddressInput {...protocolAddressState} />
</Conditional>
</Conditional>
<Conditional test={showRecipientAddress}>
<AddressInput {...recipientAddressState} />

View File

@ -17,11 +17,13 @@ import { NextSeo } from 'next-seo'
import { useEffect, useState } from 'react'
import { toast } from 'react-hot-toast'
import { useQuery } from 'react-query'
import { ROYALTY_REGISTRY_ADDRESS } from 'utils/constants'
import { INFINITY_SWAP_PROTOCOL_ADDRESS, ROYALTY_REGISTRY_ADDRESS } from 'utils/constants'
import { withMetadata } from 'utils/layout'
import { links } from 'utils/links'
import { resolveAddress } from 'utils/resolveAddress'
import { protocolList } from './execute'
const RoyaltyRegistryQueryPage: NextPage = () => {
const { royaltyRegistry: contract } = useContracts()
const wallet = useWallet()
@ -47,12 +49,14 @@ const RoyaltyRegistryQueryPage: NextPage = () => {
name: 'protocol-address',
title: 'Protocol Address',
subtitle: 'Address of the protocol',
defaultValue: INFINITY_SWAP_PROTOCOL_ADDRESS,
})
const collectionAddress = collectionAddressState.value
const protocolAddress = protocolAddressState.value
const [type, setType] = useState<QueryType>('config')
const [manualProtocolInput, setManualProtocolInput] = useState(false)
const { data: response } = useQuery(
[contractAddress, type, contract, wallet, collectionAddress, protocolAddress] as const,
@ -82,14 +86,14 @@ const RoyaltyRegistryQueryPage: NextPage = () => {
const router = useRouter()
useEffect(() => {
if (contractAddress.length > 0) {
void router.replace({ query: { contractAddress } })
if (collectionAddress.length > 0) {
void router.replace({ query: { collectionAddress } })
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [contractAddress])
}, [collectionAddress])
useEffect(() => {
const initial = new URL(document.URL).searchParams.get('contractAddress')
if (initial && initial.length > 0) contractState.onChange(initial)
const initial = new URL(document.URL).searchParams.get('collectionAddress')
if (initial && initial.length > 0) collectionAddressState.onChange(initial)
}, [])
return (
@ -104,7 +108,7 @@ const RoyaltyRegistryQueryPage: NextPage = () => {
<div className="grid grid-cols-2 p-4 space-x-8">
<div className="space-y-8">
<AddressInput {...contractState} />
<AddressInput {...collectionAddressState} />
<FormControl htmlId="contract-query-type" subtitle="Type of query to be dispatched" title="Query Type">
<select
className={clsx(
@ -124,17 +128,30 @@ const RoyaltyRegistryQueryPage: NextPage = () => {
))}
</select>
</FormControl>
<Conditional
test={
type === 'collection_royalty_default' ||
type === 'royalty_payment' ||
type === 'collection_royalty_protocol'
}
>
<AddressInput {...collectionAddressState} />
</Conditional>
<Conditional test={type === 'collection_royalty_protocol' || type === 'royalty_payment'}>
<AddressInput {...protocolAddressState} />
<span className="mr-4 font-bold">Selected Protocol</span>
<select
className="py-2 px-4 placeholder:text-white/50 bg-white/10 rounded border-2 border-white/20 focus:ring focus:ring-plumbus-20"
onChange={(e) => {
if (e.target.value) {
protocolAddressState.onChange(e.target.value)
setManualProtocolInput(false)
} else {
protocolAddressState.onChange('')
setManualProtocolInput(true)
}
}}
>
{protocolList.map((protocol) => (
<option key={protocol.address} value={protocol.address}>
{protocol.name}
</option>
))}
<option value="">Manual Input</option>
</select>
<Conditional test={manualProtocolInput}>
<AddressInput {...protocolAddressState} />
</Conditional>
</Conditional>
</div>
<JsonPreview content={contractAddress ? { type, response } : null} title="Query Response" />

View File

@ -41,6 +41,7 @@ export const OPEN_EDITION_UPDATABLE_IBC_FRNZ_FACTORY_ADDRESS =
export const OPEN_EDITION_MINTER_CODE_ID = parseInt(process.env.NEXT_PUBLIC_OPEN_EDITION_MINTER_CODE_ID, 10)
export const SG721_NAME_ADDRESS = process.env.NEXT_PUBLIC_SG721_NAME_ADDRESS
export const ROYALTY_REGISTRY_ADDRESS = process.env.NEXT_PUBLIC_ROYALTY_REGISTRY_ADDRESS
export const INFINITY_SWAP_PROTOCOL_ADDRESS = process.env.NEXT_PUBLIC_INFINITY_SWAP_PROTOCOL_ADDRESS
export const BASE_MINTER_CODE_ID = parseInt(process.env.NEXT_PUBLIC_VENDING_MINTER_CODE_ID, 10)
export const BADGE_HUB_CODE_ID = parseInt(process.env.NEXT_PUBLIC_BADGE_HUB_CODE_ID, 10)
export const BADGE_HUB_ADDRESS = process.env.NEXT_PUBLIC_BADGE_HUB_ADDRESS