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
|
||||
) {
|
||||
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(
|
||||
|
Loading…
Reference in New Issue
Block a user