Implement wallet balance checks

This commit is contained in:
Serkan Reis 2023-06-16 14:57:47 +03:00
parent 9f513857c9
commit 663b1d9999

View File

@ -106,8 +106,15 @@ export const OpenEditionMinterCreator = ({
checkMintingDetails()
void checkRoyaltyDetails()
.then(() => {
// TODO: check wallet balance
setReadyToCreate(true)
void checkwalletBalance()
.then(() => {
setReadyToCreate(true)
})
.catch((error: any) => {
toast.error(`Error in Wallet Balance: ${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToCreate(false)
})
})
.catch((error: any) => {
toast.error(`Error in Royalty Details: ${error.message}`, { style: { maxWidth: 'none' } })
@ -286,6 +293,21 @@ export const OpenEditionMinterCreator = ({
}
}
const checkwalletBalance = async () => {
if (!wallet.initialized) throw new Error('Wallet not connected.')
const amountNeeded = collectionDetails?.updatable
? Number(openEditionMinterUpdatableCreationFee)
: Number(openEditionMinterCreationFee)
await wallet.client?.getBalance(wallet.address, 'ustars').then((balance) => {
if (amountNeeded >= Number(balance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
amountNeeded / 1000000
).toString()} STARS`,
)
})
}
const createOpenEditionMinter = async () => {
try {
setCreationInProgress(true)