Check minting price & start time before update_mint_price() on Vending Minter/execute tab

This commit is contained in:
Serkan Reis 2022-12-20 14:54:49 +03:00
parent 6046d899b3
commit f7eac26f98

View File

@ -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...',