mirror of
https://github.com/oceanprotocol/react.git
synced 2025-01-27 18:46:35 +01:00
fix
Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
parent
6757454ff2
commit
3a1da5e313
@ -128,6 +128,41 @@ export async function getFirstPool(
|
||||
}
|
||||
}
|
||||
|
||||
export async function getBestDataTokenPrice(
|
||||
ocean: Ocean,
|
||||
dataTokenAddress: string,
|
||||
poolAddress?: string
|
||||
): Promise<BestPrice> {
|
||||
const cheapestPool = await getFirstPool(ocean, dataTokenAddress, poolAddress)
|
||||
const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress)
|
||||
Decimal.set({ precision: 5 })
|
||||
|
||||
const cheapestPoolPrice = new Decimal(
|
||||
cheapestPool && cheapestPool.price !== 0 ? cheapestPool.price : 999999999999
|
||||
)
|
||||
const cheapestExchangePrice = new Decimal(
|
||||
cheapestExchange && cheapestExchange?.price !== 0
|
||||
? cheapestExchange.price
|
||||
: 999999999999
|
||||
)
|
||||
|
||||
if (cheapestPoolPrice < cheapestExchangePrice) {
|
||||
return {
|
||||
type: 'pool',
|
||||
address: cheapestPool?.address,
|
||||
value: cheapestPool?.price,
|
||||
ocean: cheapestPool?.ocean,
|
||||
datatoken: cheapestPool?.datatoken
|
||||
} as BestPrice
|
||||
} else {
|
||||
return {
|
||||
type: 'exchange',
|
||||
address: cheapestExchange?.address,
|
||||
value: Number(cheapestExchange?.price)
|
||||
} as BestPrice
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDataTokenPrice(
|
||||
ocean: Ocean,
|
||||
dataTokenAddress: string,
|
||||
@ -165,38 +200,3 @@ export async function getDataTokenPrice(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getBestDataTokenPrice(
|
||||
ocean: Ocean,
|
||||
dataTokenAddress: string,
|
||||
poolAddress?: string
|
||||
): Promise<BestPrice> {
|
||||
const cheapestPool = await getFirstPool(ocean, dataTokenAddress, poolAddress)
|
||||
const cheapestExchange = await getCheapestExchange(ocean, dataTokenAddress)
|
||||
Decimal.set({ precision: 5 })
|
||||
|
||||
const cheapestPoolPrice = new Decimal(
|
||||
cheapestPool && cheapestPool.price !== 0 ? cheapestPool.price : 999999999999
|
||||
)
|
||||
const cheapestExchangePrice = new Decimal(
|
||||
cheapestExchange && cheapestExchange?.price !== 0
|
||||
? cheapestExchange.price
|
||||
: 999999999999
|
||||
)
|
||||
|
||||
if (cheapestPoolPrice < cheapestExchangePrice) {
|
||||
return {
|
||||
type: 'pool',
|
||||
address: cheapestPool?.address,
|
||||
value: cheapestPool?.price,
|
||||
ocean: cheapestPool?.ocean,
|
||||
datatoken: cheapestPool?.datatoken
|
||||
} as BestPrice
|
||||
} else {
|
||||
return {
|
||||
type: 'exchange',
|
||||
address: cheapestExchange?.address,
|
||||
value: Number(cheapestExchange?.price)
|
||||
} as BestPrice
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user