mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
refactor getAssetPrices method, not using ddo.price.type anymore
This commit is contained in:
parent
a27bc6718a
commit
1c2d81049d
@ -122,7 +122,7 @@ export async function transformDDOToAssetSelection(
|
||||
const ddoNames = await getAssetsNames(didList, metadataCacheUri, source.token)
|
||||
const algorithmList: AssetSelectionAsset[] = []
|
||||
didList?.forEach((did: string) => {
|
||||
if (priceList[did] !== 'none') {
|
||||
if (priceList[did]) {
|
||||
let selected = false
|
||||
selectedAlgorithms?.forEach((algorithm: PublisherTrustedAlgorithm) => {
|
||||
if (algorithm.did === did) {
|
||||
|
@ -87,34 +87,26 @@ export async function getPreviousOrders(
|
||||
|
||||
export async function getAssetPrices(assets: DDO[]): Promise<any> {
|
||||
const priceList: any = {}
|
||||
const poolPriceAssets: string[] = []
|
||||
const poolDTadressDID: any = {}
|
||||
const frePriceAssets: string[] = []
|
||||
const freDTadressDID: any = {}
|
||||
const didDTMap: any = {}
|
||||
const dataTokenList: string[] = []
|
||||
|
||||
for (const ddo of assets) {
|
||||
if (ddo.price?.type === 'pool') {
|
||||
poolDTadressDID[ddo?.dataToken.toLowerCase()] = ddo.id
|
||||
poolPriceAssets.push(ddo?.dataToken.toLowerCase())
|
||||
} else if (ddo.price?.type === 'exchange') {
|
||||
freDTadressDID[ddo?.dataToken.toLowerCase()] = ddo.id
|
||||
frePriceAssets.push(ddo?.dataToken.toLowerCase())
|
||||
} else {
|
||||
priceList[ddo.id] = 'none'
|
||||
}
|
||||
didDTMap[ddo?.dataToken.toLowerCase()] = ddo.id
|
||||
dataTokenList.push(ddo?.dataToken.toLowerCase())
|
||||
}
|
||||
const freVariables = {
|
||||
datatoken_in: frePriceAssets
|
||||
datatoken_in: dataTokenList
|
||||
}
|
||||
const poolVariables = {
|
||||
datatokenAddress_in: poolPriceAssets
|
||||
datatokenAddress_in: dataTokenList
|
||||
}
|
||||
const poolPriceResponse: any = await fetchData(poolQuery, poolVariables)
|
||||
for (const poolPrice of poolPriceResponse.data?.pools) {
|
||||
priceList[poolDTadressDID[poolPrice.datatokenAddress]] = poolPrice.spotPrice
|
||||
priceList[didDTMap[poolPrice.datatokenAddress]] = poolPrice.spotPrice
|
||||
}
|
||||
const frePriceResponse: any = await fetchData(freQuery, freVariables)
|
||||
for (const frePrice of frePriceResponse.data?.fixedRateExchanges) {
|
||||
priceList[freDTadressDID[frePrice.datatoken?.address]] = frePrice.rate
|
||||
priceList[didDTMap[frePrice.datatoken?.address]] = frePrice.rate
|
||||
}
|
||||
return priceList
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user