Check wallet balance in real time during collection creation

This commit is contained in:
Serkan Reis 2023-07-05 09:01:10 +03:00
parent 8a7f093d39
commit 609b7fce47

View File

@ -147,9 +147,16 @@ const CollectionCreationPage: NextPage = () => {
.then(() => {
checkWhitelistDetails()
.then(() => {
checkwalletBalance()
void checkwalletBalance()
.then(() => {
setReadyToCreateVm(true)
})
.catch((error) => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToCreateVm(false)
})
})
.catch((error) => {
if (String(error.message).includes('Insufficient wallet balance')) {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
@ -191,9 +198,16 @@ const CollectionCreationPage: NextPage = () => {
.then(() => {
checkWhitelistDetails()
.then(() => {
checkwalletBalance()
void checkwalletBalance()
.then(() => {
setReadyToCreateBm(true)
})
.catch((error) => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToCreateVm(false)
})
})
.catch((error) => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
@ -1104,8 +1118,8 @@ const CollectionCreationPage: NextPage = () => {
}
}
const checkwalletBalance = () => {
if (!wallet.initialized) throw new Error('Wallet not connected.')
const checkwalletBalance = async () => {
const walletBalance = await wallet.client?.getBalance(wallet.address, 'ustars').then((balance) => {
if (minterType === 'vending' && whitelistDetails?.whitelistState === 'new' && whitelistDetails.memberLimit) {
const amountNeeded =
Math.ceil(Number(whitelistDetails.memberLimit) / 1000) * 100000000 +
@ -1114,7 +1128,7 @@ const CollectionCreationPage: NextPage = () => {
: collectionDetails?.updatable
? Number(vendingMinterUpdatableCreationFee)
: Number(vendingMinterCreationFee))
if (amountNeeded >= Number(wallet.balance[0].amount))
if (amountNeeded >= Number(balance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
amountNeeded / 1000000
@ -1131,13 +1145,14 @@ const CollectionCreationPage: NextPage = () => {
: collectionDetails?.updatable
? Number(baseMinterUpdatableCreationFee)
: Number(baseMinterCreationFee)
if (amountNeeded >= Number(wallet.balance[0].amount))
if (amountNeeded >= Number(balance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
amountNeeded / 1000000
).toString()} STARS`,
)
}
})
}
const syncCollections = useCallback(async () => {