From 343913663fe2633954f42ff521862334f50d0c57 Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Fri, 2 Dec 2022 13:43:08 +0300 Subject: [PATCH] Getting orders from all networks --- src/@context/Profile/index.tsx | 14 ++++++++++---- src/@utils/subgraph.ts | 24 +++++++++++++++++------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/@context/Profile/index.tsx b/src/@context/Profile/index.tsx index 9192c0ab5..3d45981df 100644 --- a/src/@context/Profile/index.tsx +++ b/src/@context/Profile/index.tsx @@ -20,6 +20,7 @@ import web3 from 'web3' import { useMarketMetadata } from '../MarketMetadata' import { getEnsProfile } from '@utils/ens' import { getPublisherOrders } from '../../@utils/subgraph' +import { PublisherOrders } from 'src/@types/subgraph/OrdersData' interface ProfileProviderValue { profile: Profile @@ -224,12 +225,17 @@ function ProfileProvider({ try { const result = await getUserSales(accountId, chainIds) setSales(result) - const graphData = await getPublisherOrders(137, accountId) - LoggerInstance.log(`[profile] Fetched sales number:`, result) + const graphData = await getPublisherOrders(accountId) + let orderValue = 0 + graphData.forEach((order) => { + orderValue += Number(order.lastPriceValue) + }) LoggerInstance.log( - `[profile] Fetched sales Data: ${graphData}.`, - graphData + `[profile] Fetched sales number: ${result}.`, + result, + graphData.length ) + LoggerInstance.log(`[profile] Fetched sales orderValue:`, orderValue) } catch (error) { LoggerInstance.error(error.message) } diff --git a/src/@utils/subgraph.ts b/src/@utils/subgraph.ts index 12b36a4a6..fe274a65d 100644 --- a/src/@utils/subgraph.ts +++ b/src/@utils/subgraph.ts @@ -2,7 +2,10 @@ import { gql, OperationResult, TypedDocumentNode, OperationContext } from 'urql' import { LoggerInstance } from '@oceanprotocol/lib' import { getUrqlClientInstance } from '@context/UrqlProvider' import { getOceanConfig } from './ocean' -import { OrdersData_orders as OrdersData } from '../@types/subgraph/OrdersData' +import { + OrdersData_orders as OrdersData, + PublisherOrders +} from '../@types/subgraph/OrdersData' import { OpcFeesQuery as OpcFeesData } from '../@types/subgraph/OpcFeesQuery' import appConfig from '../../app.config' @@ -185,15 +188,22 @@ export async function getOpcsApprovedTokens( } export async function getPublisherOrders( - chainId: number, accountId: string -): Promise { - const context = getQueryContext(chainId) +): Promise { const variables = { user: accountId?.toLowerCase() } - try { - const response = await fetchData(publisherOrdersQuery, variables, context) - return response.data.user.orders + const response = await fetchDataForMultipleChains( + publisherOrdersQuery, + variables, + [1, 137, 56, 246, 1285] + ) + let data: PublisherOrders[] = [] + response.forEach((element) => { + if (element.user.orders) { + data = data.concat(element.user.orders) + } + }) + return data } catch (error) { LoggerInstance.error('Error getOpcsApprovedTokens: ', error.message) throw Error(error.message)