From d0d7de83f8931aed86df1ba17b4ac8e4137cc250 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 27 Oct 2020 09:16:34 -0700 Subject: [PATCH] fix mint --- src/hooks/usePricing/usePricing.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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(