diff --git a/src/components/MintModal.js b/src/components/MintModal.js index 94c635d..ff80286 100644 --- a/src/components/MintModal.js +++ b/src/components/MintModal.js @@ -31,6 +31,8 @@ export const MintModal = (props, ref) => { const [isLoading, setIsLoading] = useState(false) const [step, setStep] = useState(1) const [quantity, setQuantity] = useState(1) + const [mintFunction, setMintfunction] = useState(1) + const [priceFunction, setPriceFunction] = useState(1) const handleClose = () => { setIsOpen(false); @@ -86,6 +88,9 @@ export const MintModal = (props, ref) => { {step === 1 && } @@ -98,10 +103,16 @@ export const MintModal = (props, ref) => { export const modalRef = React.createRef(); -export const showMintModal = (quantity) => { +export const showMintModal = (quantity, mintFunction, priceFunction) => { if (quantity) { modalRef.current?.setQuantity(quantity) } + if (mintFunction) { + modalRef.current?.setMintfunction(mintFunction) + } + if (priceFunction) { + modalRef.current?.setPriceFunction(priceFunction) + } modalRef.current?.setIsOpen(true); } diff --git a/src/components/QuantityModalStep.js b/src/components/QuantityModalStep.js index 8cc05eb..fb01a11 100644 --- a/src/components/QuantityModalStep.js +++ b/src/components/QuantityModalStep.js @@ -15,6 +15,8 @@ import { isEthereumContract } from "../contract"; export const QuantityModalStep = ({ setQuantity, setStep, setIsLoading, setTxHash }) => { const [quantityValue, setQuantityValue] = useState(1) + const [priceFunction, setPriceFunction] = useState() + const [mintFunction, setMintedFunction] = useState() const [maxTokens, setMaxTokens] = useState(getDefaultMaxTokensPerMint()) const [mintPrice, setMintPrice] = useState(undefined) const [mintedNumber, setMintedNumber] = useState() @@ -22,7 +24,7 @@ export const QuantityModalStep = ({ setQuantity, setStep, setIsLoading, setTxHas useEffect(() => { if (isEthereumContract()) { - getMintPrice().then(price => { + getMintPrice(priceFunction).then(price => { if (price !== undefined) { setMintPrice(Number((price) / 1e18)) } @@ -45,7 +47,7 @@ export const QuantityModalStep = ({ setQuantity, setStep, setIsLoading, setTxHas const onSuccess = async () => { setIsLoading(true) - const { tx } = await mint(quantityValue) + const { tx } = await mint(quantityValue, mintFunction, priceFunction) if (tx === undefined) { setIsLoading(false) } diff --git a/src/mint/ui.js b/src/mint/ui.js index 0686290..f8db17c 100644 --- a/src/mint/ui.js +++ b/src/mint/ui.js @@ -16,10 +16,9 @@ export const updateMintButton = () => { const initialBtnText = mintButton.textContent; setButtonText(mintButton, "Loading...") try { - const quantity = getMintQuantity(); const address = await getWalletAddressOrConnect(true) if (address) { - showMintModal(quantity); + showMintModal(getMintQuantity(), getMintFunction(), getPriceFunction()); } } catch (e) { console.log("Error on pressing mint") @@ -56,6 +55,15 @@ const getMintQuantity = () => { const quantity = document.querySelector('#quantity-select')?.value return quantity !== '' && quantity !== undefined ? Number(quantity) : undefined; } +const getMintFunction = (element) => { + const f = element.dataset?.mint; + return f !== '' && f !== undefined ? String(f) : undefined; +} + +const getPriceFunction = (element) => { + const f = element.dataset?.mint; + return f !== '' && f !== undefined ? String(f) : undefined; +} const setButtonText = (btn, text) => { if (btn.childElementCount > 0) { diff --git a/src/mint/web3.js b/src/mint/web3.js index cf56a9e..6ce6cf3 100644 --- a/src/mint/web3.js +++ b/src/mint/web3.js @@ -20,7 +20,9 @@ const getMethodWithCustomName = (methodName) => { return undefined } -const getMintTx = ({ numberOfTokens }) => { +const getMintTx = ({ numberOfTokens, mintFunctionOverride }) => { + const overridingMintMethod = getMethodWithCustomName('mint') + if(overridingMintMethod) return overridingMintMethod(numberOfTokens); const customMintMethod = getMethodWithCustomName('mint') if (customMintMethod) return customMintMethod(numberOfTokens) @@ -50,7 +52,10 @@ const getDefaultMintPrice = () => { return undefined } -export const getMintPrice = async () => { +export const getMintPrice = async (priceFunctionOverride) => { + if(priceFunctionOverride) return getMethodWithCustomName(priceFunctionOverride)(); + if(getMethodWithCustomName('price')) return getMethodWithCustomName('price')(); + const matches = Object.keys(NFTContract.methods).filter(key => !key.includes("()") && (key.toLowerCase().includes('price') || key.toLowerCase().includes('cost')) ) @@ -136,10 +141,11 @@ export const getMaxTokensPerMint = async () => { return getDefaultMaxTokensPerMint() } -export const mint = async (nTokens) => { +export const mint = async (nTokens, mintFunctionOverride, priceFunctionOverride) => { const wallet = await getWalletAddressOrConnect(true); const numberOfTokens = nTokens ?? 1; - const mintPrice = await getMintPrice(); + console.log("in mint function, priceFunctionOverride: ", priceFunctionOverride, " mintFunctionOverride: ", mintFunctionOverride); + const mintPrice = await getMintPrice(priceFunctionOverride); if (mintPrice === undefined) return { tx: undefined } @@ -147,7 +153,7 @@ export const mint = async (nTokens) => { from: wallet, value: formatValue(Number(mintPrice) * numberOfTokens), } - const estimatedGas = await getMintTx({ numberOfTokens }) + const estimatedGas = await getMintTx({ numberOfTokens, mintFunctionOverride }) .estimateGas(txParams).catch((e) => { const { code, message } = parseTxError(e); if (code === -32000) { @@ -163,7 +169,7 @@ export const mint = async (nTokens) => { const maxFeePerGas = [1, 4].includes(chainID) ? formatValue(maxGasPrice) : undefined; const maxPriorityFeePerGas = [1, 4].includes(chainID) ? 2e9 : undefined; - const tx = getMintTx({ numberOfTokens }) + const tx = getMintTx({ numberOfTokens, mintFunctionOverride }) .send({ ...txParams, gasLimit: estimatedGas + 5000,