mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Feature/decimal (#541)
* use Decimal instead of parseFloat * use Decimal
This commit is contained in:
parent
5c4ead9359
commit
a3fbb4dad3
@ -5,6 +5,7 @@ import { Pool } from './Pool'
|
||||
import { EventData, Filter } from 'web3-eth-contract'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import { SubscribablePromise, Logger, didNoZeroX, didPrefixed } from '../utils'
|
||||
import Decimal from 'decimal.js'
|
||||
|
||||
declare type PoolTransactionType = 'swap' | 'join' | 'exit'
|
||||
|
||||
@ -120,7 +121,7 @@ export class OceanPool extends Pool {
|
||||
this.dtAddress = dtAddress
|
||||
let txid
|
||||
const dtAllowance = await this.allowance(dtAddress, account, address)
|
||||
if (parseFloat(dtAllowance) < parseFloat(dtAmount)) {
|
||||
if (new Decimal(dtAllowance).lt(dtAmount)) {
|
||||
observer.next(PoolCreateProgressStep.ApprovingDatatoken)
|
||||
txid = await this.approve(
|
||||
account,
|
||||
@ -134,7 +135,7 @@ export class OceanPool extends Pool {
|
||||
}
|
||||
}
|
||||
const oceanAllowance = await this.allowance(this.oceanAddress, account, address)
|
||||
if (parseFloat(oceanAllowance) < parseFloat(oceanAmount)) {
|
||||
if (new Decimal(oceanAllowance).lt(oceanAmount)) {
|
||||
observer.next(PoolCreateProgressStep.ApprovingOcean)
|
||||
txid = await this.approve(
|
||||
account,
|
||||
|
@ -6,6 +6,7 @@ import BigNumber from 'bignumber.js'
|
||||
import jsonpoolABI from '@oceanprotocol/contracts/artifacts/BPool.json'
|
||||
import defaultDatatokensABI from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
||||
import { PoolFactory } from './PoolFactory'
|
||||
import Decimal from 'decimal.js'
|
||||
|
||||
const MaxUint256 =
|
||||
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
|
||||
@ -1036,7 +1037,7 @@ export class Pool extends PoolFactory {
|
||||
): Promise<string> {
|
||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||
let amount = null
|
||||
if (parseFloat(tokenAmountOut) >= parseFloat(tokenBalanceOut)) return null
|
||||
if (new Decimal(tokenAmountOut).gte(tokenBalanceOut)) return null
|
||||
try {
|
||||
const result = await pool.methods
|
||||
.calcInGivenOut(
|
||||
|
@ -7,6 +7,7 @@ import { Logger, getFairGasPrice } from '../utils'
|
||||
import wordListDefault from '../data/words.json'
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import Decimal from 'decimal.js'
|
||||
|
||||
/**
|
||||
* Provides an interface to DataTokens
|
||||
@ -174,7 +175,7 @@ export class DataTokens {
|
||||
from: address
|
||||
})
|
||||
const capAvailble = await this.getCap(dataTokenAddress)
|
||||
if (parseFloat(capAvailble) >= parseFloat(amount)) {
|
||||
if (new Decimal(capAvailble).gte(amount)) {
|
||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
||||
let estGas
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user