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