Match selected denom and fetch open edition factory parameters
This commit is contained in:
parent
717fd88e74
commit
d2d06dffae
@ -4,6 +4,9 @@ import { FormControl } from 'components/FormControl'
|
||||
import { FormGroup } from 'components/FormGroup'
|
||||
import { useInputState, useNumberInputState } from 'components/forms/FormInput.hooks'
|
||||
import { InputDateTime } from 'components/InputDateTime'
|
||||
import { openEditionMinterList } from 'config/minter'
|
||||
import type { TokenInfo } from 'config/token'
|
||||
import { stars, tokensList } from 'config/token'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { resolveAddress } from 'utils/resolveAddress'
|
||||
|
||||
@ -15,6 +18,7 @@ interface MintingDetailsProps {
|
||||
onChange: (data: MintingDetailsDataProps) => void
|
||||
uploadMethod: UploadMethod
|
||||
minimumMintPrice: number
|
||||
mintTokenFromFactory?: TokenInfo | undefined
|
||||
}
|
||||
|
||||
export interface MintingDetailsDataProps {
|
||||
@ -23,19 +27,28 @@ export interface MintingDetailsDataProps {
|
||||
startTime: string
|
||||
endTime: string
|
||||
paymentAddress?: string
|
||||
selectedMintToken?: TokenInfo
|
||||
}
|
||||
|
||||
export const MintingDetails = ({ onChange, uploadMethod, minimumMintPrice }: MintingDetailsProps) => {
|
||||
export const MintingDetails = ({
|
||||
onChange,
|
||||
uploadMethod,
|
||||
minimumMintPrice,
|
||||
mintTokenFromFactory,
|
||||
}: MintingDetailsProps) => {
|
||||
const wallet = useWallet()
|
||||
|
||||
const [timestamp, setTimestamp] = useState<Date | undefined>()
|
||||
const [endTimestamp, setEndTimestamp] = useState<Date | undefined>()
|
||||
const [selectedMintToken, setSelectedMintToken] = useState<TokenInfo | undefined>(stars)
|
||||
|
||||
const unitPriceState = useNumberInputState({
|
||||
id: 'unitPrice',
|
||||
name: 'unitPrice',
|
||||
title: 'Unit Price',
|
||||
subtitle: `Price of each token (min. ${minimumMintPrice} STARS)`,
|
||||
title: 'Mint Price',
|
||||
subtitle: `Price of each token (min. ${minimumMintPrice} ${
|
||||
mintTokenFromFactory ? mintTokenFromFactory.displayName : 'STARS'
|
||||
})`,
|
||||
placeholder: '50',
|
||||
})
|
||||
|
||||
@ -76,15 +89,38 @@ export const MintingDetails = ({ onChange, uploadMethod, minimumMintPrice }: Min
|
||||
startTime: timestamp ? (timestamp.getTime() * 1_000_000).toString() : '',
|
||||
endTime: endTimestamp ? (endTimestamp.getTime() * 1_000_000).toString() : '',
|
||||
paymentAddress: paymentAddressState.value.trim(),
|
||||
selectedMintToken,
|
||||
}
|
||||
onChange(data)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [unitPriceState.value, perAddressLimitState.value, timestamp, endTimestamp, paymentAddressState.value])
|
||||
}, [
|
||||
unitPriceState.value,
|
||||
perAddressLimitState.value,
|
||||
timestamp,
|
||||
endTimestamp,
|
||||
paymentAddressState.value,
|
||||
selectedMintToken,
|
||||
])
|
||||
|
||||
return (
|
||||
<div className="border-l-[1px] border-gray-500 border-opacity-20">
|
||||
<FormGroup subtitle="Information about your minting settings" title="Minting Details">
|
||||
<NumberInput {...unitPriceState} isRequired />
|
||||
<div className="flex flex-row items-center">
|
||||
<NumberInput {...unitPriceState} isRequired />
|
||||
<select
|
||||
className="py-[9px] px-4 mt-14 ml-4 placeholder:text-white/50 bg-white/10 rounded border-2 border-white/20 focus:ring focus:ring-plumbus-20"
|
||||
onChange={(e) => setSelectedMintToken(tokensList.find((t) => t.displayName === e.target.value))}
|
||||
>
|
||||
{openEditionMinterList
|
||||
.filter((minter) => minter.factoryAddress !== undefined && minter.updatable === false)
|
||||
.map((minter) => (
|
||||
<option key={minter.id} className="bg-black" value={minter.supportedToken.displayName}>
|
||||
{minter.supportedToken.displayName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<NumberInput {...perAddressLimitState} isRequired />
|
||||
<FormControl htmlId="timestamp" isRequired subtitle="Minting start time (local)" title="Start Time">
|
||||
<InputDateTime minDate={new Date()} onChange={(date) => setTimestamp(date)} value={timestamp} />
|
||||
|
@ -27,7 +27,7 @@ export const openEditionStarsMinter: MinterInfo = {
|
||||
}
|
||||
|
||||
export const openEditionUpdatableStarsMinter: MinterInfo = {
|
||||
id: 'open-edition-stars-minter',
|
||||
id: 'open-edition-updatable-stars-minter',
|
||||
factoryAddress: OPEN_EDITION_UPDATABLE_FACTORY_ADDRESS,
|
||||
supportedToken: stars,
|
||||
updatable: true,
|
||||
@ -41,7 +41,7 @@ export const openEditionIbcAtomMinter: MinterInfo = {
|
||||
}
|
||||
|
||||
export const openEditionUpdatableIbcAtomMinter: MinterInfo = {
|
||||
id: 'open-edition-ibc-atom-minter',
|
||||
id: 'open-edition-updatable-ibc-atom-minter',
|
||||
factoryAddress: OPEN_EDITION_UPDATABLE_IBC_ATOM_FACTORY_ADDRESS,
|
||||
supportedToken: ibcAtom,
|
||||
updatable: true,
|
||||
@ -55,7 +55,7 @@ export const openEditionIbcUsdcMinter: MinterInfo = {
|
||||
}
|
||||
|
||||
export const openEditionUpdatableIbcUsdcMinter: MinterInfo = {
|
||||
id: 'open-edition-ibc-usdc-minter',
|
||||
id: 'open-edition-updatable-ibc-usdc-minter',
|
||||
factoryAddress: OPEN_EDITION_UPDATABLE_IBC_USDC_FACTORY_ADDRESS,
|
||||
supportedToken: ibcUsdc,
|
||||
updatable: false,
|
||||
@ -69,10 +69,19 @@ export const openEditionIbcFrenzMinter: MinterInfo = {
|
||||
}
|
||||
|
||||
export const openEditionUpdatableIbcFrenzMinter: MinterInfo = {
|
||||
id: 'open-edition-ibc-frenz-minter',
|
||||
id: 'open-edition-updatable-ibc-frenz-minter',
|
||||
factoryAddress: OPEN_EDITION_UPDATABLE_IBC_FRENZ_FACTORY_ADDRESS,
|
||||
supportedToken: ibcFrenz,
|
||||
updatable: true,
|
||||
}
|
||||
|
||||
export const openEditionMinterList = [openEditionStarsMinter, openEditionIbcAtomMinter, openEditionIbcFrenzMinter]
|
||||
export const openEditionMinterList = [
|
||||
openEditionStarsMinter,
|
||||
openEditionUpdatableStarsMinter,
|
||||
openEditionUpdatableIbcAtomMinter,
|
||||
openEditionIbcAtomMinter,
|
||||
openEditionIbcFrenzMinter,
|
||||
openEditionUpdatableIbcFrenzMinter,
|
||||
openEditionIbcUsdcMinter,
|
||||
openEditionUpdatableIbcUsdcMinter,
|
||||
]
|
||||
|
@ -33,6 +33,8 @@ import { Conditional } from 'components/Conditional'
|
||||
import { LoadingModal } from 'components/LoadingModal'
|
||||
import type { OpenEditionMinterCreatorDataProps } from 'components/openEdition/OpenEditionMinterCreator'
|
||||
import { OpenEditionMinterCreator } from 'components/openEdition/OpenEditionMinterCreator'
|
||||
import { openEditionMinterList } from 'config/minter'
|
||||
import type { TokenInfo } from 'config/token'
|
||||
import { useContracts } from 'contexts/contracts'
|
||||
import { addLogItem } from 'contexts/log'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
@ -71,6 +73,8 @@ import { uid } from 'utils/random'
|
||||
import type { MinterType } from '../../components/collections/actions/Combobox'
|
||||
import type { UploadMethod } from '../../components/collections/creation/UploadDetails'
|
||||
import { ConfirmationModal } from '../../components/ConfirmationModal'
|
||||
import type { OpenEditionMinterDetailsDataProps } from '../../components/openEdition/OpenEditionMinterCreator'
|
||||
import { tokensList } from '../../config/token'
|
||||
import { getAssetType } from '../../utils/getAssetType'
|
||||
import { isValidAddress } from '../../utils/isValidAddress'
|
||||
|
||||
@ -99,7 +103,9 @@ const CollectionCreationPage: NextPage = () => {
|
||||
const [uploadDetails, setUploadDetails] = useState<UploadDetailsDataProps | null>(null)
|
||||
const [collectionDetails, setCollectionDetails] = useState<CollectionDetailsDataProps | null>(null)
|
||||
const [baseMinterDetails, setBaseMinterDetails] = useState<BaseMinterDetailsDataProps | null>(null)
|
||||
const [openEditionMinterDetails, setOpenEditionMinterDetails] = useState<OpenEditionMinterCreatorDataProps | null>(
|
||||
const [openEditionMinterCreatorData, setOpenEditionMinterCreatorData] =
|
||||
useState<OpenEditionMinterCreatorDataProps | null>(null)
|
||||
const [openEditionMinterDetails, setOpenEditionMinterDetails] = useState<OpenEditionMinterDetailsDataProps | null>(
|
||||
null,
|
||||
)
|
||||
const [mintingDetails, setMintingDetails] = useState<MintingDetailsDataProps | null>(null)
|
||||
@ -122,6 +128,10 @@ const CollectionCreationPage: NextPage = () => {
|
||||
const [minimumOpenEditionUpdatableMintPrice, setMinimumOpenEditionUpdatableMintPrice] = useState<string | null>('0')
|
||||
const [minimumFlexMintPrice, setMinimumFlexMintPrice] = useState<string | null>('0')
|
||||
|
||||
const [mintTokenFromOpenEditionFactory, setMintTokenFromOpenEditionFactory] = useState<TokenInfo | undefined>(
|
||||
undefined,
|
||||
)
|
||||
|
||||
const [uploading, setUploading] = useState(false)
|
||||
const [isMintingComplete, setIsMintingComplete] = useState(false)
|
||||
const [creatingCollection, setCreatingCollection] = useState(false)
|
||||
@ -1043,7 +1053,7 @@ const CollectionCreationPage: NextPage = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const fetchFactoryParameters = async () => {
|
||||
const fetchInitialFactoryParameters = async () => {
|
||||
const client = wallet.client
|
||||
if (!client) return
|
||||
if (BASE_FACTORY_ADDRESS) {
|
||||
@ -1100,6 +1110,7 @@ const CollectionCreationPage: NextPage = () => {
|
||||
setVendingMinterFlexCreationFee(vendingFactoryFlexParameters?.params?.creation_fee?.amount)
|
||||
setMinimumFlexMintPrice(vendingFactoryFlexParameters?.params?.min_mint_price?.amount)
|
||||
}
|
||||
|
||||
if (OPEN_EDITION_FACTORY_ADDRESS) {
|
||||
const openEditionFactoryParameters = await client
|
||||
.queryContractSmart(OPEN_EDITION_FACTORY_ADDRESS, { params: {} })
|
||||
@ -1122,6 +1133,59 @@ const CollectionCreationPage: NextPage = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const fetchOpenEditionFactoryParameters = useCallback(async () => {
|
||||
const client = wallet.client
|
||||
if (!client) return
|
||||
const factoryForSelectedDenom = openEditionMinterList.find(
|
||||
(minter) =>
|
||||
minter.supportedToken === openEditionMinterDetails?.mintingDetails?.selectedMintToken &&
|
||||
minter.updatable === false,
|
||||
)
|
||||
const updatableFactoryForSelectedDenom = openEditionMinterList.find(
|
||||
(minter) =>
|
||||
minter.supportedToken === openEditionMinterDetails?.mintingDetails?.selectedMintToken &&
|
||||
minter.updatable === true,
|
||||
)
|
||||
if (factoryForSelectedDenom?.factoryAddress) {
|
||||
const openEditionFactoryParameters = await client
|
||||
.queryContractSmart(factoryForSelectedDenom.factoryAddress, { params: {} })
|
||||
.catch((error) => {
|
||||
toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
|
||||
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
|
||||
})
|
||||
setOpenEditionMinterCreationFee(openEditionFactoryParameters?.params?.creation_fee?.amount)
|
||||
if (!openEditionMinterDetails?.collectionDetails?.updatable) {
|
||||
setMinimumOpenEditionMintPrice(openEditionFactoryParameters?.params?.min_mint_price?.amount)
|
||||
setMintTokenFromOpenEditionFactory(
|
||||
tokensList.find((token) => token.denom === openEditionFactoryParameters?.params?.min_mint_price?.denom),
|
||||
)
|
||||
}
|
||||
console.log('Selected OE Factory: ', factoryForSelectedDenom)
|
||||
console.log('Selected Updatable OE Factory: ', updatableFactoryForSelectedDenom)
|
||||
}
|
||||
if (updatableFactoryForSelectedDenom?.factoryAddress) {
|
||||
const openEditionUpdatableFactoryParameters = await client
|
||||
.queryContractSmart(updatableFactoryForSelectedDenom.factoryAddress, { params: {} })
|
||||
.catch((error) => {
|
||||
toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
|
||||
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
|
||||
})
|
||||
setOpenEditionMinterUpdatableCreationFee(openEditionUpdatableFactoryParameters?.params?.creation_fee?.amount)
|
||||
if (openEditionMinterDetails?.collectionDetails?.updatable) {
|
||||
setMinimumOpenEditionMintPrice(openEditionUpdatableFactoryParameters?.params?.min_mint_price?.amount)
|
||||
setMintTokenFromOpenEditionFactory(
|
||||
tokensList.find(
|
||||
(token) => token.denom === openEditionUpdatableFactoryParameters?.params?.min_mint_price?.denom,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}, [
|
||||
openEditionMinterDetails?.mintingDetails?.selectedMintToken,
|
||||
openEditionMinterDetails?.collectionDetails?.updatable,
|
||||
wallet.client,
|
||||
])
|
||||
|
||||
const checkwalletBalance = async () => {
|
||||
const walletBalance = await wallet.client?.getBalance(wallet.address, 'ustars').then((balance) => {
|
||||
if (minterType === 'vending' && whitelistDetails?.whitelistState === 'new' && whitelistDetails.memberLimit) {
|
||||
@ -1161,25 +1225,25 @@ const CollectionCreationPage: NextPage = () => {
|
||||
|
||||
const syncCollections = useCallback(async () => {
|
||||
const collectionAddress =
|
||||
minterType === 'openEdition' ? openEditionMinterDetails?.sg721ContractAddress : sg721ContractAddress
|
||||
minterType === 'openEdition' ? openEditionMinterCreatorData?.sg721ContractAddress : sg721ContractAddress
|
||||
if (collectionAddress && SYNC_COLLECTIONS_API_URL) {
|
||||
await axios.get(`${SYNC_COLLECTIONS_API_URL}/${collectionAddress}`).catch((error) => {
|
||||
console.error('Sync collections: ', error)
|
||||
})
|
||||
}
|
||||
}, [minterType, openEditionMinterDetails?.sg721ContractAddress, sg721ContractAddress])
|
||||
}, [minterType, openEditionMinterCreatorData?.sg721ContractAddress, sg721ContractAddress])
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
vendingMinterContractAddress !== null ||
|
||||
openEditionMinterDetails?.openEditionMinterContractAddress ||
|
||||
openEditionMinterCreatorData?.openEditionMinterContractAddress ||
|
||||
isMintingComplete
|
||||
) {
|
||||
scrollRef.current?.scrollIntoView({ behavior: 'smooth' })
|
||||
}
|
||||
if (
|
||||
(minterType === 'vending' && vendingMinterContractAddress !== null) ||
|
||||
(minterType === 'openEdition' && openEditionMinterDetails?.openEditionMinterContractAddress) ||
|
||||
(minterType === 'openEdition' && openEditionMinterCreatorData?.openEditionMinterContractAddress) ||
|
||||
(minterType === 'base' && vendingMinterContractAddress !== null && isMintingComplete)
|
||||
) {
|
||||
void syncCollections()
|
||||
@ -1192,7 +1256,7 @@ const CollectionCreationPage: NextPage = () => {
|
||||
}
|
||||
}, [
|
||||
vendingMinterContractAddress,
|
||||
openEditionMinterDetails?.openEditionMinterContractAddress,
|
||||
openEditionMinterCreatorData?.openEditionMinterContractAddress,
|
||||
isMintingComplete,
|
||||
minterType,
|
||||
syncCollections,
|
||||
@ -1210,9 +1274,13 @@ const CollectionCreationPage: NextPage = () => {
|
||||
}, [minterType, baseMinterDetails?.baseMinterAcquisitionMethod, uploadDetails?.uploadMethod])
|
||||
|
||||
useEffect(() => {
|
||||
void fetchFactoryParameters()
|
||||
void fetchInitialFactoryParameters()
|
||||
}, [wallet.client])
|
||||
|
||||
useEffect(() => {
|
||||
void fetchOpenEditionFactoryParameters()
|
||||
}, [fetchOpenEditionFactoryParameters])
|
||||
|
||||
return (
|
||||
<div>
|
||||
<NextSeo
|
||||
@ -1244,7 +1312,7 @@ const CollectionCreationPage: NextPage = () => {
|
||||
</div>
|
||||
<div className="mx-10" ref={scrollRef}>
|
||||
<Conditional
|
||||
test={minterType === 'openEdition' && openEditionMinterDetails?.openEditionMinterContractAddress !== null}
|
||||
test={minterType === 'openEdition' && openEditionMinterCreatorData?.openEditionMinterContractAddress !== null}
|
||||
>
|
||||
<Alert className="mt-5" type="info">
|
||||
<div>
|
||||
@ -1253,10 +1321,10 @@ const CollectionCreationPage: NextPage = () => {
|
||||
className="text-stargaze hover:underline"
|
||||
external
|
||||
href={`/contracts/openEditionMinter/query/?contractAddress=${
|
||||
openEditionMinterDetails?.openEditionMinterContractAddress as string
|
||||
openEditionMinterCreatorData?.openEditionMinterContractAddress as string
|
||||
}`}
|
||||
>
|
||||
{openEditionMinterDetails?.openEditionMinterContractAddress as string}
|
||||
{openEditionMinterCreatorData?.openEditionMinterContractAddress as string}
|
||||
</Anchor>
|
||||
<br />
|
||||
SG721 Contract Address:{' '}
|
||||
@ -1264,10 +1332,10 @@ const CollectionCreationPage: NextPage = () => {
|
||||
className="text-stargaze hover:underline"
|
||||
external
|
||||
href={`/contracts/sg721/query/?contractAddress=${
|
||||
openEditionMinterDetails?.sg721ContractAddress as string
|
||||
openEditionMinterCreatorData?.sg721ContractAddress as string
|
||||
}`}
|
||||
>
|
||||
{openEditionMinterDetails?.sg721ContractAddress as string}
|
||||
{openEditionMinterCreatorData?.sg721ContractAddress as string}
|
||||
</Anchor>
|
||||
<br />
|
||||
Transaction Hash: {' '}
|
||||
@ -1275,18 +1343,18 @@ const CollectionCreationPage: NextPage = () => {
|
||||
<Anchor
|
||||
className="text-stargaze hover:underline"
|
||||
external
|
||||
href={`${BLOCK_EXPLORER_URL}/tx/${openEditionMinterDetails?.transactionHash as string}`}
|
||||
href={`${BLOCK_EXPLORER_URL}/tx/${openEditionMinterCreatorData?.transactionHash as string}`}
|
||||
>
|
||||
{openEditionMinterDetails?.transactionHash}
|
||||
{openEditionMinterCreatorData?.transactionHash}
|
||||
</Anchor>
|
||||
</Conditional>
|
||||
<Conditional test={NETWORK === 'mainnet'}>
|
||||
<Anchor
|
||||
className="text-stargaze hover:underline"
|
||||
external
|
||||
href={`${BLOCK_EXPLORER_URL}/txs/${openEditionMinterDetails?.transactionHash as string}`}
|
||||
href={`${BLOCK_EXPLORER_URL}/txs/${openEditionMinterCreatorData?.transactionHash as string}`}
|
||||
>
|
||||
{openEditionMinterDetails?.transactionHash}
|
||||
{openEditionMinterCreatorData?.transactionHash}
|
||||
</Anchor>
|
||||
</Conditional>
|
||||
<br />
|
||||
@ -1295,7 +1363,7 @@ const CollectionCreationPage: NextPage = () => {
|
||||
className="text-white"
|
||||
external
|
||||
href={`${STARGAZE_URL}/launchpad/${
|
||||
openEditionMinterDetails?.openEditionMinterContractAddress as string
|
||||
openEditionMinterCreatorData?.openEditionMinterContractAddress as string
|
||||
}`}
|
||||
>
|
||||
View on Launchpad
|
||||
@ -1563,8 +1631,10 @@ const CollectionCreationPage: NextPage = () => {
|
||||
<OpenEditionMinterCreator
|
||||
minimumMintPrice={minimumOpenEditionMintPrice as string}
|
||||
minimumUpdatableMintPrice={minimumOpenEditionUpdatableMintPrice as string}
|
||||
mintTokenFromFactory={mintTokenFromOpenEditionFactory}
|
||||
minterType={minterType}
|
||||
onChange={setOpenEditionMinterDetails}
|
||||
onChange={setOpenEditionMinterCreatorData}
|
||||
onDetailsChange={setOpenEditionMinterDetails}
|
||||
openEditionMinterCreationFee={openEditionMinterCreationFee as string}
|
||||
openEditionMinterUpdatableCreationFee={openEditionMinterUpdatableCreationFee as string}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user