1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-02-14 21:10:38 +01:00

Merge pull request #117 from oceanprotocol/fix/publishFixes

Fix/publish fixes
This commit is contained in:
mihaisc 2020-09-16 15:09:36 +03:00 committed by GitHub
commit e3b34eee03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,37 +51,43 @@ export async function getCheapestExchange(
ocean: Ocean,
dataTokenAddress: string
): Promise<{ address?: string; price: string } | null> {
if (!ocean || !dataTokenAddress) return null
if (!ocean || !dataTokenAddress) return
try {
const tokenExchanges = await ocean.fixedRateExchange.searchforDT(
dataTokenAddress,
'1'
)
if (tokenExchanges === undefined || tokenExchanges.length === 0) {
return {
address: '',
price: ''
}
}
let cheapestExchangeAddress = tokenExchanges[0].exchangeID
let cheapestExchangePrice = new Decimal(tokenExchanges[0].fixedRate)
const tokenExchanges = await ocean.fixedRateExchange.searchforDT(
dataTokenAddress,
'1'
)
for (let i = 0; i < tokenExchanges.length; i++) {
const decimalExchangePrice = new Decimal(
Web3.utils.fromWei(tokenExchanges[i].fixedRate)
)
if (tokenExchanges === undefined || tokenExchanges.length === 0) {
if (decimalExchangePrice < cheapestExchangePrice) {
cheapestExchangePrice = decimalExchangePrice
cheapestExchangeAddress = tokenExchanges[i].exchangeID
}
}
return {
address: cheapestExchangeAddress,
price: cheapestExchangePrice.toString()
}
} catch (err) {
Logger.log(err)
return {
address: '',
price: ''
}
}
let cheapestExchangeAddress = tokenExchanges[0].exchangeID
let cheapestExchangePrice = new Decimal(tokenExchanges[0].fixedRate)
for (let i = 0; i < tokenExchanges.length; i++) {
const decimalExchangePrice = new Decimal(
Web3.utils.fromWei(tokenExchanges[i].fixedRate)
)
if (decimalExchangePrice < cheapestExchangePrice) {
cheapestExchangePrice = decimalExchangePrice
cheapestExchangeAddress = tokenExchanges[i].exchangeID
}
}
return {
address: cheapestExchangeAddress,
price: cheapestExchangePrice.toString()
}
}
export async function getBestDataTokenPrice(