mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
* get all neded data for the header from 3box, aqua and subgraph * fix tvl display error * WIP metadata header styling * added more styling for the header * make page title optional so we can remove it on account page * stroke change for svg images and default values * more styling added to the header * fixed linter * added ocean balance to tvl * update styling for statistcs * fixed eror for go to my account from another account page * updated styling for mobile use * wip show more on explorer links and description * properly display read more for explorer links and description * replaced show more with 3box redirect on description * change accounts default picture and check links length before display element * use optional on links * grid cleanup, new number unit, split up stats * rename all the things, more profile header styling * visual hierarchy, improve image loading experience * layout flow & visual tweaks * more description * replaced account route with profile when accesing a profile by the eth address * use account id from url if exists when fetching data * bump @oceanprotocol/art to v3.2.0 * styling, fallbacks, edge case fixes * clean up Publisher atom, link to profile page * fixed issue when switching to my profile from another profile * output accountId, make it copyable, remove stats icons * render tweaks, markup cleanup * add 3box reference * mobile tabs spacing tweaks * text flow and spacing tweaks Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
import { DDO, Logger } from '@oceanprotocol/lib'
|
|
import React, { useEffect, useState } from 'react'
|
|
import { ReactElement } from 'react-markdown'
|
|
import { useUserPreferences } from '../../../providers/UserPreferences'
|
|
import {
|
|
getAccountLiquidityInOwnAssets,
|
|
getAccountNumberOfOrders,
|
|
getAssetsBestPrices,
|
|
UserTVL
|
|
} from '../../../utils/subgraph'
|
|
import Conversion from '../../atoms/Price/Conversion'
|
|
import NumberUnit from '../../molecules/NumberUnit'
|
|
import styles from './Stats.module.css'
|
|
import {
|
|
queryMetadata,
|
|
transformChainIdsListToQuery
|
|
} from '../../../utils/aquarius'
|
|
import axios from 'axios'
|
|
|
|
export default function Stats({
|
|
accountId
|
|
}: {
|
|
accountId: string
|
|
}): ReactElement {
|
|
const { chainIds } = useUserPreferences()
|
|
|
|
const [publishedAssets, setPublishedAssets] = useState<DDO[]>()
|
|
const [numberOfAssets, setNumberOfAssets] = useState(0)
|
|
const [sold, setSold] = useState(0)
|
|
const [tvl, setTvl] = useState<UserTVL>()
|
|
|
|
useEffect(() => {
|
|
if (!accountId) {
|
|
setNumberOfAssets(0)
|
|
setSold(0)
|
|
setTvl({ price: '0', oceanBalance: '0' })
|
|
return
|
|
}
|
|
|
|
async function getPublished() {
|
|
const queryPublishedAssets = {
|
|
query: {
|
|
query_string: {
|
|
query: `(publicKey.owner:${accountId}) AND (${transformChainIdsListToQuery(
|
|
chainIds
|
|
)})`
|
|
}
|
|
}
|
|
}
|
|
try {
|
|
const source = axios.CancelToken.source()
|
|
const result = await queryMetadata(queryPublishedAssets, source.token)
|
|
setPublishedAssets(result.results)
|
|
setNumberOfAssets(result.totalResults)
|
|
} catch (error) {
|
|
Logger.error(error.message)
|
|
}
|
|
}
|
|
getPublished()
|
|
|
|
async function getAccountSoldValue() {
|
|
const nrOrders = await getAccountNumberOfOrders(accountId, chainIds)
|
|
setSold(nrOrders)
|
|
}
|
|
getAccountSoldValue()
|
|
}, [accountId, chainIds])
|
|
|
|
useEffect(() => {
|
|
if (!publishedAssets) return
|
|
|
|
async function getAccountTVL() {
|
|
try {
|
|
const accountPoolAdresses: string[] = []
|
|
const assetsPrices = await getAssetsBestPrices(publishedAssets)
|
|
for (const priceInfo of assetsPrices) {
|
|
if (priceInfo.price.type === 'pool') {
|
|
accountPoolAdresses.push(priceInfo.price.address.toLowerCase())
|
|
}
|
|
}
|
|
const userTvl: UserTVL = await getAccountLiquidityInOwnAssets(
|
|
accountId,
|
|
chainIds,
|
|
accountPoolAdresses
|
|
)
|
|
setTvl(userTvl)
|
|
} catch (error) {
|
|
Logger.error(error.message)
|
|
}
|
|
}
|
|
getAccountTVL()
|
|
}, [publishedAssets])
|
|
|
|
return (
|
|
<div className={styles.stats}>
|
|
<NumberUnit label="Published" value={numberOfAssets} />
|
|
<NumberUnit label="Sold" value={sold} />
|
|
<NumberUnit
|
|
label="Total Value Locked"
|
|
value={<Conversion price={tvl?.price} hideApproximateSymbol />}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|