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

Restore profile header and downloads tab (#1129)

* show results

* sales number displayed correctly

* get downloads

* use totalSales parameter

* fixes

* sum sales fix

Co-authored-by: ClaudiaHolhos <claudia@oceanprotocol.com>
This commit is contained in:
claudiaHash 2022-02-21 17:15:33 +02:00 committed by GitHub
parent c1ab042c5e
commit db7ae82f4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 30 deletions

View File

@ -220,18 +220,14 @@ function ProfileProvider({
async (cancelToken: CancelToken) => {
if (!accountId || !chainIds) return
const didList: string[] = []
const dtList: string[] = []
const tokenOrders = await getUserTokenOrders(accountId, chainIds)
for (let i = 0; i < tokenOrders?.length; i++) {
const did = web3.utils
.toChecksumAddress(tokenOrders[i].datatoken.address)
.replace('0x', 'did:op:')
didList.push(did)
dtList.push(tokenOrders[i].datatoken.address)
}
const downloads = await getDownloadAssets(
didList,
dtList,
tokenOrders,
chainIds,
cancelToken

View File

@ -332,22 +332,21 @@ export async function getPublishedAssets(
}
export async function getDownloadAssets(
didList: string[],
dtList: string[],
tokenOrders: OrdersData[],
chainIds: number[],
cancelToken: CancelToken
): Promise<DownloadedAsset[]> {
const baseQueryparams = {
chainIds,
filters: [
getFilterTerm('services.datatokenAddress', dtList),
getFilterTerm('services.type', 'access')
]
} as BaseQueryParams
const query = generateBaseQuery(baseQueryparams)
try {
const baseQueryparams = {
chainIds,
filters: [
getFilterTerm('_id', didList),
getFilterTerm('service.type', 'access')
]
} as BaseQueryParams
const query = generateBaseQuery(baseQueryparams)
const result = await queryMetadata(query, cancelToken)
const downloadedAssets: DownloadedAsset[] = result.results
.map((asset) => {
const order = tokenOrders.find(
@ -367,6 +366,10 @@ export async function getDownloadAssets(
return downloadedAssets
} catch (error) {
LoggerInstance.error(error.message)
if (axios.isCancel(error)) {
LoggerInstance.log(error.message)
} else {
LoggerInstance.error(error.message)
}
}
}

View File

@ -12,7 +12,10 @@ import {
PoolShares as PoolSharesList,
PoolShares_poolShares as PoolShare
} from '../@types/subgraph/PoolShares'
import { OrdersData_orders as OrdersData } from '../@types/subgraph/OrdersData'
import {
OrdersData_orders as OrdersData,
OrdersData_orders_datatoken as OrdersDatatoken
} from '../@types/subgraph/OrdersData'
import { UserSalesQuery as UsersSalesList } from '../@types/subgraph/UserSalesQuery'
export interface UserLiquidity {
@ -141,7 +144,11 @@ const UserTokenOrders = gql`
orderDirection: desc
where: { consumer: $user }
) {
consumer {
id
}
datatoken {
id
address
symbol
}
@ -155,14 +162,11 @@ const UserTokenOrders = gql`
}
`
// TODO: counting orders might be enough here to get sales for a user
const UserSalesQuery = gql`
query UserSalesQuery($userSalesId: ID) {
users(where: { id: $userSalesId }) {
query UserSalesQuery($user: String!) {
users(where: { id: $user }) {
id
orders(first: 10000) {
id
}
totalSales
}
}
`
@ -378,9 +382,8 @@ export async function getUserTokenOrders(
variables,
chainIds
)
for (let i = 0; i < tokenOrders?.length; i++) {
tokenOrders[i].tokenOrders.forEach((tokenOrder: OrdersData) => {
tokenOrders[i].orders.forEach((tokenOrder: OrdersData) => {
data.push(tokenOrder)
})
}
@ -395,7 +398,7 @@ export async function getUserSales(
accountId: string,
chainIds: number[]
): Promise<number> {
const variables = { userSalesId: accountId?.toLowerCase() }
const variables = { user: accountId?.toLowerCase() }
try {
const userSales = await fetchDataForMultipleChains(
UserSalesQuery,
@ -405,7 +408,7 @@ export async function getUserSales(
let salesSum = 0
for (let i = 0; i < userSales.length; i++) {
if (userSales[i].users.length > 0) {
salesSum += userSales[i].users[0].nrSales
salesSum += parseInt(userSales[i].users[0].totalSales)
}
}
return salesSum
@ -434,7 +437,7 @@ export async function getTopAssetsPublishers(
if (publishersIndex === -1) {
const publisher: AccountTeaserVM = {
address: fetchedUsers.data.users[i].id,
nrSales: fetchedUsers.data.users[i].orders.length
nrSales: fetchedUsers.data.users[i].totalSales
}
publisherSales.push(publisher)
} else {