diff --git a/package-lock.json b/package-lock.json index 81941ee59..cc1026ce2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18101,7 +18101,7 @@ } }, "ethereumjs-abi": { - "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1a27c59c15ab1e95ee8e5c4ed6ad814c49cc439e", + "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1ce6a1d64235fabe2aaf827fd606def55693508f", "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git", "requires": { "bn.js": "^4.11.8", diff --git a/src/providers/Asset.tsx b/src/providers/Asset.tsx index d6e947e57..548128f38 100644 --- a/src/providers/Asset.tsx +++ b/src/providers/Asset.tsx @@ -117,13 +117,8 @@ function AssetProvider({ const initMetadata = useCallback(async (ddo: DDO): Promise => { if (!ddo) return - // Set price & metadata from DDO first - // TODO Hacky hack, temporary™: set isConsumable to true by default since Aquarius can't be trusted. - // setPrice({ ...ddo.price, isConsumable: 'true' }) - const returnedPrice = await getPrice(ddo) - console.log('returnedPrice', returnedPrice) - setPrice({ ...returnedPrice, isConsumable: 'true' }) + setPrice({ ...returnedPrice }) // Get metadata from DDO const { attributes } = ddo.findServiceByType('metadata') diff --git a/src/utils/subgraph.ts b/src/utils/subgraph.ts index f07cfefb0..69c995eec 100644 --- a/src/utils/subgraph.ts +++ b/src/utils/subgraph.ts @@ -32,8 +32,9 @@ const AssetFreQuery = gql` const PoolQuery = gql` query AssetsPoolPrice($datatokenAddress_in: [String!]) { pools(where: { datatokenAddress_in: $datatokenAddress_in }) { - spotPrice id + spotPrice + consumePrice datatokenAddress } } @@ -44,9 +45,10 @@ const AssetPoolPriceQuerry = gql` pools(where: { datatokenAddress: $datatokenAddress }) { id spotPrice + consumePrice + datatokenAddress datatokenReserve oceanReserve - datatokenAddress } } ` @@ -127,7 +129,10 @@ export async function getAssetPrices(assets: DDO[]): Promise { } const poolPriceResponse: any = await fetchData(PoolQuery, poolVariables) for (const poolPrice of poolPriceResponse.data?.pools) { - priceList[didDTMap[poolPrice.datatokenAddress]] = poolPrice.spotPrice + priceList[didDTMap[poolPrice.datatokenAddress]] = + poolPrice.consumePrice === '-1' + ? poolPrice.spotPrice + : poolPrice.consumePrice } const frePriceResponse: any = await fetchData(FreQuery, freVariables) for (const frePrice of frePriceResponse.data?.fixedRateExchanges) { @@ -154,13 +159,22 @@ export async function getPrice(asset: DDO): Promise { const price: BestPrice = { type: 'pool', address: poolPriceResponse.data?.pools[0]?.id, - value: poolPriceResponse.data?.pools[0]?.spotPrice, + value: + poolPriceResponse.data?.pools[0]?.consumePrice === '-1' + ? poolPriceResponse.data?.pools[0]?.spotPrice + : poolPriceResponse.data?.pools[0]?.consumePrice, ocean: poolPriceResponse.data?.pools[0]?.oceanReserve, datatoken: poolPriceResponse.data?.pools[0]?.datatokenReserve, - pools: [poolPriceResponse.data?.pools[0]?.id] + pools: [poolPriceResponse.data?.pools[0]?.id], + isConsumable: + poolPriceResponse.data?.pools[0]?.consumePrice === '-1' + ? 'false' + : 'true' } return price } else if (frePriceResponse.data?.fixedRateExchanges.length > 0) { + // TODO Hacky hack, temporary™: set isConsumable to true for fre assets. + // isConsumable: 'true' const price: BestPrice = { type: 'exchange', value: frePriceResponse.data?.fixedRateExchanges[0]?.rate, @@ -168,7 +182,8 @@ export async function getPrice(asset: DDO): Promise { exchange_id: frePriceResponse.data?.fixedRateExchanges[0]?.id, ocean: 0, datatoken: 0, - pools: [] + pools: [], + isConsumable: 'true' } return price } else {