2022-09-22 13:23:16 +00:00
|
|
|
import { QueryCombobox } from 'components/collections/queries/Combobox'
|
|
|
|
import { useQueryComboboxState } from 'components/collections/queries/Combobox.hooks'
|
|
|
|
import { dispatchQuery } from 'components/collections/queries/query'
|
|
|
|
import { FormControl } from 'components/FormControl'
|
|
|
|
import { AddressInput, TextInput } from 'components/forms/FormInput'
|
|
|
|
import { useInputState } from 'components/forms/FormInput.hooks'
|
|
|
|
import { JsonPreview } from 'components/JsonPreview'
|
2022-12-09 18:47:03 +00:00
|
|
|
import type { BaseMinterInstance } from 'contracts/baseMinter'
|
2023-06-17 08:24:39 +00:00
|
|
|
import type { OpenEditionMinterInstance } from 'contracts/openEditionMinter'
|
2023-10-10 11:19:52 +00:00
|
|
|
import type { RoyaltyRegistryInstance } from 'contracts/royaltyRegistry'
|
2022-09-22 14:04:44 +00:00
|
|
|
import type { SG721Instance } from 'contracts/sg721'
|
2022-12-09 18:47:03 +00:00
|
|
|
import type { VendingMinterInstance } from 'contracts/vendingMinter'
|
2022-09-22 13:23:16 +00:00
|
|
|
import { toast } from 'react-hot-toast'
|
|
|
|
import { useQuery } from 'react-query'
|
|
|
|
|
2023-01-12 08:45:57 +00:00
|
|
|
import { useWallet } from '../../../contexts/wallet'
|
|
|
|
import { resolveAddress } from '../../../utils/resolveAddress'
|
2022-12-09 18:47:03 +00:00
|
|
|
import type { MinterType } from '../actions/Combobox'
|
|
|
|
|
2022-09-22 14:04:44 +00:00
|
|
|
interface CollectionQueriesProps {
|
|
|
|
minterContractAddress: string
|
|
|
|
sg721ContractAddress: string
|
2023-10-10 11:19:52 +00:00
|
|
|
royaltyRegistryContractAddress: string
|
2022-09-22 14:04:44 +00:00
|
|
|
sg721Messages: SG721Instance | undefined
|
2022-12-09 18:47:03 +00:00
|
|
|
vendingMinterMessages: VendingMinterInstance | undefined
|
|
|
|
baseMinterMessages: BaseMinterInstance | undefined
|
2023-06-17 08:24:39 +00:00
|
|
|
openEditionMinterMessages: OpenEditionMinterInstance | undefined
|
2023-10-10 11:19:52 +00:00
|
|
|
royaltyRegistryMessages: RoyaltyRegistryInstance | undefined
|
2022-12-09 18:47:03 +00:00
|
|
|
minterType: MinterType
|
2022-09-22 14:04:44 +00:00
|
|
|
}
|
|
|
|
export const CollectionQueries = ({
|
|
|
|
sg721ContractAddress,
|
|
|
|
sg721Messages,
|
|
|
|
minterContractAddress,
|
2022-12-09 18:47:03 +00:00
|
|
|
vendingMinterMessages,
|
2023-06-17 08:24:39 +00:00
|
|
|
openEditionMinterMessages,
|
2022-12-09 18:47:03 +00:00
|
|
|
baseMinterMessages,
|
|
|
|
minterType,
|
2023-10-10 11:19:52 +00:00
|
|
|
royaltyRegistryMessages,
|
2022-09-22 14:04:44 +00:00
|
|
|
}: CollectionQueriesProps) => {
|
2023-01-12 08:45:57 +00:00
|
|
|
const wallet = useWallet()
|
|
|
|
|
2022-09-22 13:23:16 +00:00
|
|
|
const comboboxState = useQueryComboboxState()
|
|
|
|
const type = comboboxState.value?.id
|
|
|
|
|
|
|
|
const tokenIdState = useInputState({
|
|
|
|
id: 'token-id',
|
|
|
|
name: 'tokenId',
|
|
|
|
title: 'Token ID',
|
|
|
|
subtitle: 'Enter the token ID',
|
|
|
|
placeholder: '1',
|
|
|
|
})
|
|
|
|
const tokenId = tokenIdState.value
|
|
|
|
|
|
|
|
const addressState = useInputState({
|
|
|
|
id: 'address',
|
|
|
|
name: 'address',
|
|
|
|
title: 'User Address',
|
|
|
|
subtitle: 'Address of the user',
|
|
|
|
})
|
|
|
|
const address = addressState.value
|
|
|
|
|
|
|
|
const showTokenIdField = type === 'token_info'
|
2022-12-15 11:59:05 +00:00
|
|
|
const showAddressField = type === 'tokens_minted_to_user' || type === 'tokens'
|
2022-09-22 13:23:16 +00:00
|
|
|
|
|
|
|
const { data: response } = useQuery(
|
2023-06-17 08:24:39 +00:00
|
|
|
[
|
|
|
|
sg721Messages,
|
|
|
|
baseMinterMessages,
|
|
|
|
vendingMinterMessages,
|
|
|
|
openEditionMinterMessages,
|
2023-10-10 11:19:52 +00:00
|
|
|
royaltyRegistryMessages,
|
2023-06-17 08:24:39 +00:00
|
|
|
type,
|
|
|
|
tokenId,
|
|
|
|
address,
|
2023-10-10 11:19:52 +00:00
|
|
|
sg721ContractAddress,
|
2023-06-17 08:24:39 +00:00
|
|
|
] as const,
|
2022-09-22 13:23:16 +00:00
|
|
|
async ({ queryKey }) => {
|
2023-06-17 08:24:39 +00:00
|
|
|
const [
|
|
|
|
_sg721Messages,
|
|
|
|
_baseMinterMessages_,
|
|
|
|
_vendingMinterMessages,
|
|
|
|
_openEditionMinterMessages,
|
2023-10-10 11:19:52 +00:00
|
|
|
_royaltyRegistryMessages,
|
2023-06-17 08:24:39 +00:00
|
|
|
_type,
|
|
|
|
_tokenId,
|
|
|
|
_address,
|
2023-10-10 11:19:52 +00:00
|
|
|
_sg721ContractAddress,
|
2023-06-17 08:24:39 +00:00
|
|
|
] = queryKey
|
2022-12-09 18:47:03 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
2023-01-12 08:45:57 +00:00
|
|
|
const res = await resolveAddress(_address, wallet).then(async (resolvedAddress) => {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
|
|
const result = await dispatchQuery({
|
|
|
|
tokenId: _tokenId,
|
|
|
|
vendingMinterMessages: _vendingMinterMessages,
|
|
|
|
baseMinterMessages: _baseMinterMessages_,
|
2023-06-17 08:24:39 +00:00
|
|
|
openEditionMinterMessages: _openEditionMinterMessages,
|
2023-01-12 08:45:57 +00:00
|
|
|
sg721Messages: _sg721Messages,
|
2023-10-10 11:19:52 +00:00
|
|
|
royaltyRegistryMessages: _royaltyRegistryMessages,
|
2023-01-12 08:45:57 +00:00
|
|
|
address: resolvedAddress,
|
|
|
|
type: _type,
|
2023-10-10 11:19:52 +00:00
|
|
|
sg721ContractAddress: _sg721ContractAddress,
|
2023-01-12 08:45:57 +00:00
|
|
|
})
|
|
|
|
return result
|
2022-09-22 13:23:16 +00:00
|
|
|
})
|
2023-01-12 08:45:57 +00:00
|
|
|
return res
|
2022-09-22 13:23:16 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
placeholderData: null,
|
|
|
|
onError: (error: any) => {
|
2023-01-12 08:45:57 +00:00
|
|
|
if (addressState.value.length > 12 && !addressState.value.includes('.')) {
|
|
|
|
toast.error(error.message, { style: { maxWidth: 'none' } })
|
|
|
|
}
|
2022-09-22 13:23:16 +00:00
|
|
|
},
|
2023-10-10 11:19:52 +00:00
|
|
|
enabled:
|
|
|
|
Boolean(type && type === 'infinity_swap_royalties' && sg721ContractAddress) ||
|
|
|
|
Boolean(sg721ContractAddress && minterContractAddress && type),
|
2022-09-22 13:23:16 +00:00
|
|
|
retry: false,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="grid grid-cols-2 mt-4">
|
|
|
|
<div className="mr-2 space-y-8">
|
2022-12-09 18:47:03 +00:00
|
|
|
<QueryCombobox minterType={minterType} {...comboboxState} />
|
2022-09-22 13:23:16 +00:00
|
|
|
{showAddressField && <AddressInput {...addressState} />}
|
|
|
|
{showTokenIdField && <TextInput {...tokenIdState} />}
|
|
|
|
</div>
|
|
|
|
<div className="space-y-8">
|
|
|
|
<FormControl title="Query Response">
|
|
|
|
<JsonPreview content={response || {}} isCopyable />
|
|
|
|
</FormControl>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|