1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-01-25 01:32:08 +01:00

use Decimal

This commit is contained in:
alexcos20 2020-10-27 09:22:22 -07:00
parent d0d7de83f8
commit f1934fec3e

View File

@ -87,10 +87,17 @@ function usePricing(ddo: DDO): UsePricing {
tokensToMint: string tokensToMint: string
): Promise<TransactionReceipt | void> { ): Promise<TransactionReceipt | void> {
Logger.log('mint function', dataToken, accountId) Logger.log('mint function', dataToken, accountId)
const balance = await ocean.datatokens.balance(dataToken, accountId) const balance = new Decimal(
if (parseFloat(tokensToMint) > parseFloat(balance)) { await ocean.datatokens.balance(dataToken, accountId)
tokensToMint = String(parseFloat(tokensToMint) - parseFloat(balance)) )
const tx = await ocean.datatokens.mint(dataToken, accountId, tokensToMint) 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 return tx
} }
} }