1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Getting orders from all networks

This commit is contained in:
Jamie Hewitt 2022-12-02 13:43:08 +03:00
parent 65df504f02
commit 343913663f
2 changed files with 27 additions and 11 deletions

View File

@ -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)
}

View File

@ -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<TokenInfo[]> {
const context = getQueryContext(chainId)
): Promise<PublisherOrders[]> {
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)