import { Box, Button, Center, Spinner, Tab, TabList, TabPanel, TabPanels, Tabs, useColorModeValue, VStack, } from "@chakra-ui/react"; import { GatewayProvider } from "@civic/solana-gateway-react"; import * as anchor from "@project-serum/anchor"; import { useConnection, useWallet } from "@solana/wallet-adapter-react"; import { PublicKey } from "@solana/web3.js"; import { Notification, useTokenBondingFromMint, } from "@strata-foundation/react"; import BN from "bn.js"; import React from "react"; import toast from "react-hot-toast"; import { CANDY_MACHINE_PROGRAM, ICandyMachine, useCandyMachineInfo, useLivePrice } from "../../../hooks"; import { BondingPlot } from "../BondingPlot"; import { Branding } from "../Branding"; import { LbcInfo } from "../LbcInfo"; import { LbcStatus } from "../LbcStatus"; import { IMintArgs, MintButton } from "../MintButton"; import { TransactionHistory } from "../TransactionHistory"; import { mintOneToken } from "./candy-machine"; import { CandyMachineInfo } from "./CandyMachineInfo"; import { MintedNftNotification } from "./MintedNftNotification"; import { toDate } from "./utils"; export interface DynamicPricingCandyMachineProps { candyMachineId?: anchor.web3.PublicKey; onConnectWallet: () => void; onSuccess?: (mint: PublicKey) => void; } export const DynamicPricingCandyMachine = ( props: DynamicPricingCandyMachineProps ) => { const { connection } = useConnection(); const { publicKey, connected, signTransaction, wallet } = useWallet(); const cmState = useCandyMachineInfo(props.candyMachineId); const { candyMachine, isWhitelistUser, isActive, isPresale } = cmState; const mintKey = candyMachine?.tokenMint; const { info: tokenBonding, loading, error, } = useTokenBondingFromMint(mintKey); const { price } = useLivePrice(tokenBonding?.publicKey); const background = useColorModeValue("white", "black.300"); const onMint = async (args: IMintArgs) => { try { document.getElementById("#identity")?.click(); if ( connected && candyMachine?.program && publicKey && props.candyMachineId ) { const mint = await mintOneToken(candyMachine, publicKey, args); if (props.onSuccess) { props.onSuccess(mint) } else { toast.custom( (t) => ( toast.dismiss(t.id)} /> ), { duration: Infinity, } ); } } } catch (error: any) { let message = error.msg || error.toString() || "Minting failed! Please try again!"; let heading = "Transaction Failed"; if (!error.msg) { if (!error.message) { message = "Transaction Timeout! Please try again."; } else if (error.message.indexOf("0x137") != -1) { message = `SOLD OUT!`; } else if (error.message.indexOf("0x135") != -1) { message = `Insufficient funds to mint. Please fund your wallet.`; } } else { if (error.code === 311) { message = `SOLD OUT!`; window.location.reload(); } else if (error.code === 312) { message = `Minting period hasn't started yet.`; } else if (error.code === 6005 || error.code === 6006) { heading = "Transaction Cancelled"; message = "The price moved unfavorably by more than the configured slippage. Change slippage by clicking Advanced Settings"; } else { message = error.toString(); } } console.error(error); toast.custom( (t) => ( toast.dismiss(t.id)} /> ), { duration: 120 * 1000, } ); } }; const selectedProps = { borderBottom: "3px solid #F07733", }; return ( Mint {tokenBonding && ( Transactions )} { typeof window !== "undefined" && } {connected && ( <> {!candyMachine && (
)} {candyMachine && ( {tokenBonding && ( )} {!tokenBonding && } {candyMachine?.isActive && candyMachine?.gatekeeper && publicKey && signTransaction ? ( // @ts-ignore ) : ( )} )} )} {!connected && (
)}
); }; const getCountdownDate = (candyMachine: ICandyMachine): Date | undefined => { if (candyMachine.isActive && candyMachine.endSettings?.endSettingType.date) { return toDate(candyMachine.endSettings.number); } return toDate( candyMachine.goLiveDate ? candyMachine.goLiveDate : candyMachine.isPresale ? new BN(new Date().getTime() / 1000) : undefined ); };