diff --git a/src/hooks/usePricing/usePricing.ts b/src/hooks/usePricing/usePricing.ts index 4509330..08ec640 100644 --- a/src/hooks/usePricing/usePricing.ts +++ b/src/hooks/usePricing/usePricing.ts @@ -83,10 +83,16 @@ function usePricing(ddo: DDO): UsePricing { setPricingStepText(messages[index]) } - async function mint(tokensToMint: string): Promise { + async function mint( + tokensToMint: string + ): Promise { Logger.log('mint function', dataToken, accountId) - const tx = await ocean.datatokens.mint(dataToken, accountId, tokensToMint) - return tx + const balance = await ocean.datatokens.balance(dataToken, accountId) + if (parseFloat(tokensToMint) > parseFloat(balance)) { + tokensToMint = String(parseFloat(tokensToMint) - parseFloat(balance)) + const tx = await ocean.datatokens.mint(dataToken, accountId, tokensToMint) + return tx + } } async function buyDT(