From f1934fec3ea5930c7883b17b61cc2598c0132498 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Tue, 27 Oct 2020 09:22:22 -0700 Subject: [PATCH] use Decimal --- src/hooks/usePricing/usePricing.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/hooks/usePricing/usePricing.ts b/src/hooks/usePricing/usePricing.ts index 08ec640..6a50848 100644 --- a/src/hooks/usePricing/usePricing.ts +++ b/src/hooks/usePricing/usePricing.ts @@ -87,10 +87,17 @@ function usePricing(ddo: DDO): UsePricing { tokensToMint: string ): Promise { Logger.log('mint function', dataToken, accountId) - 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) + const balance = new Decimal( + await ocean.datatokens.balance(dataToken, accountId) + ) + const tokens = new Decimal(tokensToMint) + if (tokens > balance) { + const mintAmount = tokens.minus(balance) + const tx = await ocean.datatokens.mint( + dataToken, + accountId, + mintAmount.toString() + ) return tx } }