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

small fix

This commit is contained in:
mihaisc 2020-09-16 15:03:11 +03:00
parent 73a4662bd2
commit 1db0143c46
No known key found for this signature in database
GPG Key ID: BE522BB8C3A5E2E4

View File

@ -82,36 +82,43 @@ export async function getCheapestExchange(
dataTokenAddress: string
) {
if (!ocean || !dataTokenAddress) return
try {
const tokenExchanges = await ocean.fixedRateExchange.searchforDT(
dataTokenAddress,
'1'
)
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)
if (tokenExchanges === undefined || tokenExchanges.length === 0) {
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()
}
} 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 checkAndBuyDT(