mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
small fix
This commit is contained in:
parent
73a4662bd2
commit
1db0143c46
@ -82,36 +82,43 @@ export async function getCheapestExchange(
|
|||||||
dataTokenAddress: string
|
dataTokenAddress: string
|
||||||
) {
|
) {
|
||||||
if (!ocean || !dataTokenAddress) return
|
if (!ocean || !dataTokenAddress) return
|
||||||
|
try {
|
||||||
|
const tokenExchanges = await ocean.fixedRateExchange.searchforDT(
|
||||||
|
dataTokenAddress,
|
||||||
|
'1'
|
||||||
|
)
|
||||||
|
|
||||||
const tokenExchanges = await ocean.fixedRateExchange.searchforDT(
|
if (tokenExchanges === undefined || tokenExchanges.length === 0) {
|
||||||
dataTokenAddress,
|
return {
|
||||||
'1'
|
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 {
|
return {
|
||||||
address: '',
|
address: '',
|
||||||
price: ''
|
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(
|
export async function checkAndBuyDT(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user