1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00
mihaisc 67621f5639
Various veOCEAN features (#1743)
* change top message, fixes, allocations

* lock ocean tooltip

* asset stats tweaks

* front page allocations refactor

* wording, run empty table messages through markdown

* footer stats tweaks

* profile tinkering

* fix allocations in table

* Tweak lock action logic

* fix allocation 0

* sort by allocation

* search ordering fixes

Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
2022-10-17 15:56:03 +01:00

62 lines
1.8 KiB
TypeScript

import { useAsset } from '@context/Asset'
import { useUserPreferences } from '@context/UserPreferences'
import { useWeb3 } from '@context/Web3'
import Tooltip from '@shared/atoms/Tooltip'
import { formatPrice } from '@shared/Price/PriceUnit'
import { getNftOwnAllocation } from '@utils/veAllocation'
import React, { useEffect, useState } from 'react'
import styles from './index.module.css'
export default function AssetStats() {
const { locale } = useUserPreferences()
const { asset } = useAsset()
const { accountId } = useWeb3()
const [ownAllocation, setOwnAllocation] = useState(0)
useEffect(() => {
if (!asset || !accountId) return
async function init() {
const allocation = await getNftOwnAllocation(
accountId,
asset.nftAddress,
asset.chainId
)
setOwnAllocation(allocation / 100)
}
init()
}, [accountId, asset])
return (
<footer className={styles.stats}>
{asset?.stats?.allocated && asset?.stats?.allocated > 0 ? (
<span className={styles.stat}>
<span className={styles.number}>
{formatPrice(asset.stats.allocated, locale)}
</span>
veOCEAN
</span>
) : null}
{!asset?.stats || asset?.stats?.orders < 0 ? (
'N/A'
) : asset?.stats?.orders === 0 ? (
'No sales yet'
) : (
<span className={styles.stat}>
<span className={styles.number}>{asset.stats.orders}</span> sale
{asset.stats.orders === 1 ? '' : 's'}
</span>
)}
{ownAllocation && ownAllocation > 0 ? (
<span className={styles.stat}>
<span className={styles.number}>{ownAllocation}</span>% allocated
<Tooltip
content={`You have ${ownAllocation}% of your total veOCEAN allocated to this asset.`}
/>
</span>
) : null}
</footer>
)
}