/* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import type { MintRule } from 'components/badges/creation/ImageUploadDetails' import { BadgeQueries } from 'components/badges/queries/Queries' import { ContractPageHeader } from 'components/ContractPageHeader' import { AddressInput, NumberInput } from 'components/forms/FormInput' import { useInputState } from 'components/forms/FormInput.hooks' import { useContracts } from 'contexts/contracts' import { useWallet } from 'contexts/wallet' import type { NextPage } from 'next' import { useRouter } from 'next/router' import { NextSeo } from 'next-seo' import { useEffect, useMemo, useState } from 'react' import toast from 'react-hot-toast' import { useDebounce } from 'utils/debounce' import { withMetadata } from 'utils/layout' import { links } from 'utils/links' import { BadgeActions } from '../../components/badges/actions/Action' import { useNumberInputState } from '../../components/forms/FormInput.hooks' import { BADGE_HUB_ADDRESS } from '../../utils/constants' const BadgeActionsPage: NextPage = () => { const { badgeHub: badgeHubContract } = useContracts() const wallet = useWallet() const [action, setAction] = useState(false) const [mintRule, setMintRule] = useState('by_key') const badgeHubContractState = useInputState({ id: 'badge-hub-contract-address', name: 'badge-hub-contract-address', title: 'Badge Hub Contract Address', subtitle: 'Address of the Badge Hub contract', defaultValue: BADGE_HUB_ADDRESS, }) const badgeIdState = useNumberInputState({ id: 'badge-id', name: 'badge-id', title: 'Badge ID', subtitle: 'The ID of the badge to interact with', defaultValue: 1, }) const debouncedBadgeHubContractState = useDebounce(badgeHubContractState.value, 300) const debouncedBadgeIdState = useDebounce(badgeIdState.value, 300) const badgeHubMessages = useMemo( () => badgeHubContract?.use(badgeHubContractState.value), [badgeHubContract, badgeHubContractState.value], ) const badgeHubContractAddress = badgeHubContractState.value const badgeId = badgeIdState.value const router = useRouter() useEffect(() => { if (badgeHubContractAddress.length > 0 && badgeId < 1) { void router.replace({ query: { badgeHubContractAddress } }) } if (badgeId > 0 && badgeHubContractAddress.length === 0) { void router.replace({ query: { badgeId } }) } if (badgeId > 0 && badgeHubContractAddress.length > 0) { void router.replace({ query: { badgeHubContractAddress, badgeId } }) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [badgeHubContractAddress, badgeId]) useEffect(() => { const initialBadgeHub = new URL(document.URL).searchParams.get('badgeHubContractAddress') const initialBadgeId = new URL(document.URL).searchParams.get('badgeId') if (initialBadgeHub && initialBadgeHub.length > 0) badgeHubContractState.onChange(initialBadgeHub) if (initialBadgeId && initialBadgeId.length > 0) badgeIdState.onChange(isNaN(parseInt(initialBadgeId)) ? 0 : parseInt(initialBadgeId)) }, []) useEffect(() => { async function getMintRule() { if (wallet.client && debouncedBadgeHubContractState.length > 0 && debouncedBadgeIdState > 0) { const client = wallet.client const data = await toast.promise( client.queryContractSmart(debouncedBadgeHubContractState, { badge: { id: badgeId, }, }), { loading: 'Retrieving Mint Rule...', error: 'Mint Rule retrieval failed.', success: 'Mint Rule retrieved.', }, ) console.log(data) const rule = data.rule console.log(rule) return rule } } void getMintRule() .then((rule) => { if (JSON.stringify(rule).includes('keys')) { setMintRule('by_keys') } else if (JSON.stringify(rule).includes('minter')) { setMintRule('by_minter') } else { setMintRule('by_key') } }) .catch((err) => { console.log(err) setMintRule('by_key') console.log('Unable to retrieve Mint Rule. Defaulting to "by_key".') }) }, [debouncedBadgeHubContractState, debouncedBadgeIdState, wallet.client]) return (
{ setAction(false) }} type="radio" value="false" />
{ setAction(true) }} type="radio" value="true" />
{(action && ( // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition )) || ( )}
) } export default withMetadata(BadgeActionsPage, { center: false })