1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-01-24 17:21:58 +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
): Promise<TransactionReceipt | void> {
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
}
}