Check wallet balance in real time during collection creation
This commit is contained in:
parent
8a7f093d39
commit
609b7fce47
@ -147,8 +147,15 @@ const CollectionCreationPage: NextPage = () => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
checkWhitelistDetails()
|
checkWhitelistDetails()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
checkwalletBalance()
|
void checkwalletBalance()
|
||||||
setReadyToCreateVm(true)
|
.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) => {
|
.catch((error) => {
|
||||||
if (String(error.message).includes('Insufficient wallet balance')) {
|
if (String(error.message).includes('Insufficient wallet balance')) {
|
||||||
@ -191,8 +198,15 @@ const CollectionCreationPage: NextPage = () => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
checkWhitelistDetails()
|
checkWhitelistDetails()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
checkwalletBalance()
|
void checkwalletBalance()
|
||||||
setReadyToCreateBm(true)
|
.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) => {
|
.catch((error) => {
|
||||||
toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
|
toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
|
||||||
@ -1104,40 +1118,41 @@ const CollectionCreationPage: NextPage = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkwalletBalance = () => {
|
const checkwalletBalance = async () => {
|
||||||
if (!wallet.initialized) throw new Error('Wallet not connected.')
|
const walletBalance = await wallet.client?.getBalance(wallet.address, 'ustars').then((balance) => {
|
||||||
if (minterType === 'vending' && whitelistDetails?.whitelistState === 'new' && whitelistDetails.memberLimit) {
|
if (minterType === 'vending' && whitelistDetails?.whitelistState === 'new' && whitelistDetails.memberLimit) {
|
||||||
const amountNeeded =
|
const amountNeeded =
|
||||||
Math.ceil(Number(whitelistDetails.memberLimit) / 1000) * 100000000 +
|
Math.ceil(Number(whitelistDetails.memberLimit) / 1000) * 100000000 +
|
||||||
(whitelistDetails.whitelistType === 'flex'
|
(whitelistDetails.whitelistType === 'flex'
|
||||||
? Number(vendingMinterFlexCreationFee)
|
|
||||||
: collectionDetails?.updatable
|
|
||||||
? Number(vendingMinterUpdatableCreationFee)
|
|
||||||
: Number(vendingMinterCreationFee))
|
|
||||||
if (amountNeeded >= Number(wallet.balance[0].amount))
|
|
||||||
throw new Error(
|
|
||||||
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
|
|
||||||
amountNeeded / 1000000
|
|
||||||
).toString()} STARS`,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
const amountNeeded =
|
|
||||||
minterType === 'vending'
|
|
||||||
? whitelistDetails?.whitelistState === 'existing' && whitelistDetails.whitelistType === 'flex'
|
|
||||||
? Number(vendingMinterFlexCreationFee)
|
? Number(vendingMinterFlexCreationFee)
|
||||||
: collectionDetails?.updatable
|
: collectionDetails?.updatable
|
||||||
? Number(vendingMinterUpdatableCreationFee)
|
? Number(vendingMinterUpdatableCreationFee)
|
||||||
: Number(vendingMinterCreationFee)
|
: Number(vendingMinterCreationFee))
|
||||||
: collectionDetails?.updatable
|
if (amountNeeded >= Number(balance.amount))
|
||||||
? Number(baseMinterUpdatableCreationFee)
|
throw new Error(
|
||||||
: Number(baseMinterCreationFee)
|
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
|
||||||
if (amountNeeded >= Number(wallet.balance[0].amount))
|
amountNeeded / 1000000
|
||||||
throw new Error(
|
).toString()} STARS`,
|
||||||
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
|
)
|
||||||
amountNeeded / 1000000
|
} else {
|
||||||
).toString()} STARS`,
|
const amountNeeded =
|
||||||
)
|
minterType === 'vending'
|
||||||
}
|
? whitelistDetails?.whitelistState === 'existing' && whitelistDetails.whitelistType === 'flex'
|
||||||
|
? Number(vendingMinterFlexCreationFee)
|
||||||
|
: collectionDetails?.updatable
|
||||||
|
? Number(vendingMinterUpdatableCreationFee)
|
||||||
|
: Number(vendingMinterCreationFee)
|
||||||
|
: collectionDetails?.updatable
|
||||||
|
? Number(baseMinterUpdatableCreationFee)
|
||||||
|
: Number(baseMinterCreationFee)
|
||||||
|
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 () => {
|
const syncCollections = useCallback(async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user