1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-01-27 18:46:35 +01:00
Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2020-10-29 20:07:51 +02:00
parent 6757454ff2
commit 3a1da5e313
No known key found for this signature in database
GPG Key ID: 4FB0C2329B4C6E29

View File

@ -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
}
}