1
0
mirror of https://github.com/oceanprotocol/react.git synced 2024-12-25 02:26:25 +01:00

decimal fix

This commit is contained in:
mihaisc 2020-08-04 15:00:12 +03:00
parent 53ca5ad6cb
commit 6d33304c9a

View File

@ -1,5 +1,5 @@
import { Logger, Ocean, Account } from '@oceanprotocol/lib' import { Logger, Ocean, Account } from '@oceanprotocol/lib'
const Decimal = await require('decimal.js') import { Decimal } from 'decimal.js'
export async function getCheapestPool( export async function getCheapestPool(
ocean: Ocean, ocean: Ocean,
accountId: string, accountId: string,
@ -11,7 +11,7 @@ export async function getCheapestPool(
) )
Logger.log('DT Pool found', tokenPools) Logger.log('DT Pool found', tokenPools)
let cheapestPoolAddress let cheapestPoolAddress
let cheapestPoolPrice = 999999 let cheapestPoolPrice = new Decimal(999999999999)
if (tokenPools) { if (tokenPools) {
for (let i = 0; i < tokenPools.length; i++) { for (let i = 0; i < tokenPools.length; i++) {
@ -20,9 +20,10 @@ export async function getCheapestPool(
tokenPools[i], tokenPools[i],
'1' '1'
) )
const decimalPoolPrice = new Decimal(poolPrice)
Logger.log('Pool price ', tokenPools[i], poolPrice) Logger.log('Pool price ', tokenPools[i], poolPrice)
if (Decimal(poolPrice) < cheapestPoolPrice) { if (decimalPoolPrice < cheapestPoolPrice) {
cheapestPoolPrice = Decimal(poolPrice) cheapestPoolPrice = decimalPoolPrice
cheapestPoolAddress = tokenPools[i] cheapestPoolAddress = tokenPools[i]
} }
} }