From f7eac26f98873f4f21165e3304da4df944354992 Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Tue, 20 Dec 2022 14:54:49 +0300 Subject: [PATCH] Check minting price & start time before update_mint_price() on Vending Minter/execute tab --- pages/contracts/vendingMinter/execute.tsx | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pages/contracts/vendingMinter/execute.tsx b/pages/contracts/vendingMinter/execute.tsx index ff6caf9..45ddf89 100644 --- a/pages/contracts/vendingMinter/execute.tsx +++ b/pages/contracts/vendingMinter/execute.tsx @@ -108,6 +108,52 @@ const VendingMinterExecutePage: NextPage = () => { if (!wallet.initialized) { throw new Error('Please connect your wallet.') } + if (contractState.value === '') { + throw new Error('Please enter the contract address.') + } + if (type === 'update_mint_price' && priceState.value < 50) { + throw new Error('Mint price must be at least 50 STARS') + } + + if (wallet.client && type === 'update_mint_price') { + const contractConfig = wallet.client.queryContractSmart(contractState.value, { + config: {}, + }) + await toast + .promise( + wallet.client.queryContractSmart(contractState.value, { + mint_price: {}, + }), + { + error: `Querying mint price failed!`, + loading: 'Querying current mint price...', + success: (price) => { + console.log(price) + return `Current mint price is ${Number(price.public_price.amount) / 1000000} STARS` + }, + }, + ) + .then(async (price) => { + if (Number(price.public_price.amount) / 1000000 <= priceState.value) { + await contractConfig + .then((config) => { + console.log(config.start_time, Date.now() * 1000000) + if (Number(config.start_time) < Date.now() * 1000000) { + throw new Error( + `Minting has already started on ${new Date( + Number(config.start_time) / 1000000, + ).toLocaleString()}. Updated mint price cannot be higher than the current price of ${ + Number(price.public_price.amount) / 1000000 + } STARS`, + ) + } + }) + .catch((error) => { + throw new Error(String(error).substring(String(error).lastIndexOf('Error:') + 7)) + }) + } + }) + } const txHash = await toast.promise(dispatchExecute(payload), { error: `${type.charAt(0).toUpperCase() + type.slice(1)} execute failed!`, loading: 'Executing message...',