mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
first cut at actual UI
This commit is contained in:
parent
297c6a1ab1
commit
ebdd46efe0
32
src/components/organisms/AssetActions/Pool/Token.module.css
Normal file
32
src/components/organisms/AssetActions/Pool/Token.module.css
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
.token {
|
||||||
|
font-weight: var(--font-weight-bold);
|
||||||
|
margin-bottom: calc(var(--spacer) / 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.symbol {
|
||||||
|
font-weight: var(--font-weight-base);
|
||||||
|
color: var(--color-secondary);
|
||||||
|
font-size: var(--font-size-base);
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid var(--brand-grey-lighter);
|
||||||
|
border-radius: 50%;
|
||||||
|
padding: 0.4rem;
|
||||||
|
vertical-align: middle;
|
||||||
|
margin-right: calc(var(--spacer) / 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon svg {
|
||||||
|
width: var(--font-size-large);
|
||||||
|
height: var(--font-size-large);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Data Token Icon Style */
|
||||||
|
.icon[class*='DT'] path {
|
||||||
|
fill: var(--brand-grey-dimmed);
|
||||||
|
stroke: var(--brand-black);
|
||||||
|
stroke-width: 5px;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
}
|
22
src/components/organisms/AssetActions/Pool/Token.tsx
Normal file
22
src/components/organisms/AssetActions/Pool/Token.tsx
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import React, { ReactElement } from 'react'
|
||||||
|
import styles from './Token.module.css'
|
||||||
|
import { ReactComponent as Logo } from '../../../../images/logo.svg'
|
||||||
|
import { formatCurrency } from '@coingecko/cryptoformat'
|
||||||
|
|
||||||
|
export default function Token({
|
||||||
|
symbol,
|
||||||
|
balance
|
||||||
|
}: {
|
||||||
|
symbol: string
|
||||||
|
balance: string
|
||||||
|
}): ReactElement {
|
||||||
|
return (
|
||||||
|
<div className={styles.token}>
|
||||||
|
<figure className={`${styles.icon} ${symbol}`}>
|
||||||
|
<Logo />
|
||||||
|
</figure>
|
||||||
|
{formatCurrency(Number(balance), '', 'en', false, true)}{' '}
|
||||||
|
<span className={styles.symbol}>{symbol}</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
.symbol {
|
.title {
|
||||||
font-weight: var(--font-weight-base);
|
font-size: var(--font-size-large);
|
||||||
color: var(--color-secondary);
|
margin-bottom: calc(var(--spacer) / 4);
|
||||||
font-size: var(--font-size-base);
|
}
|
||||||
|
|
||||||
|
.tokens {
|
||||||
|
margin-bottom: var(--spacer);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import { useOcean, useMetadata } from '@oceanprotocol/react'
|
|||||||
import { DDO } from '@oceanprotocol/lib'
|
import { DDO } from '@oceanprotocol/lib'
|
||||||
import { formatCurrency } from '@coingecko/cryptoformat'
|
import { formatCurrency } from '@coingecko/cryptoformat'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
|
import Token from './Token'
|
||||||
|
|
||||||
interface Balance {
|
interface Balance {
|
||||||
ocean: string
|
ocean: string
|
||||||
@ -12,12 +13,11 @@ interface Balance {
|
|||||||
export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
||||||
const { ocean, accountId } = useOcean()
|
const { ocean, accountId } = useOcean()
|
||||||
const { getBestPool } = useMetadata()
|
const { getBestPool } = useMetadata()
|
||||||
const [numTokens, setNumTokens] = useState()
|
const [totalBalance, setTotalBalance] = useState<Balance>()
|
||||||
const [balance, setBalance] = useState<Balance>()
|
|
||||||
const [sharesBalance, setSharesBalance] = useState()
|
|
||||||
const [poolPrice, setPoolPrice] = useState<string>()
|
const [poolPrice, setPoolPrice] = useState<string>()
|
||||||
const [dtPrice, setDtPrice] = useState<string>()
|
const [dtPrice, setDtPrice] = useState<string>()
|
||||||
const [dtSymbol, setDtSymbol] = useState<string>()
|
const [dtSymbol, setDtSymbol] = useState<string>()
|
||||||
|
const [userBalance, setUserBalance] = useState<Balance>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function init() {
|
async function init() {
|
||||||
@ -34,15 +34,12 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
|||||||
const dtPrice = await ocean.pool.getDTPrice(accountId, poolAddress)
|
const dtPrice = await ocean.pool.getDTPrice(accountId, poolAddress)
|
||||||
setDtPrice(dtPrice)
|
setDtPrice(dtPrice)
|
||||||
|
|
||||||
const numTokens = await ocean.pool.getNumTokens(accountId, poolAddress)
|
|
||||||
setNumTokens(numTokens)
|
|
||||||
|
|
||||||
const oceanReserve = await ocean.pool.getOceanReserve(
|
const oceanReserve = await ocean.pool.getOceanReserve(
|
||||||
accountId,
|
accountId,
|
||||||
poolAddress
|
poolAddress
|
||||||
)
|
)
|
||||||
const dtReserve = await ocean.pool.getDTReserve(accountId, poolAddress)
|
const dtReserve = await ocean.pool.getDTReserve(accountId, poolAddress)
|
||||||
setBalance({
|
setTotalBalance({
|
||||||
ocean: oceanReserve,
|
ocean: oceanReserve,
|
||||||
dt: dtReserve
|
dt: dtReserve
|
||||||
})
|
})
|
||||||
@ -51,7 +48,13 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
|||||||
accountId,
|
accountId,
|
||||||
poolAddress
|
poolAddress
|
||||||
)
|
)
|
||||||
setSharesBalance(sharesBalance)
|
|
||||||
|
const userBalance = {
|
||||||
|
ocean: `${(sharesBalance / dtReserve) * oceanReserve}`,
|
||||||
|
dt: sharesBalance
|
||||||
|
}
|
||||||
|
|
||||||
|
setUserBalance(userBalance)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message)
|
console.error(error.message)
|
||||||
}
|
}
|
||||||
@ -61,17 +64,22 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>
|
<h3 className={styles.title}>Your Pooled Tokens</h3>
|
||||||
{numTokens} Pooled Tokens: <br />
|
{userBalance && (
|
||||||
{balance && (
|
<div className={styles.tokens}>
|
||||||
<>
|
<Token symbol="OCEAN" balance={userBalance.ocean} />
|
||||||
<span className={styles.symbol}>OCEAN</span>{' '}
|
<Token symbol={dtSymbol} balance={userBalance.dt} />
|
||||||
{formatCurrency(Number(balance.ocean), '', 'en', false, true)}
|
</div>
|
||||||
<br />
|
|
||||||
<span className={styles.symbol}>{dtSymbol}</span> {balance.dt}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</p>
|
|
||||||
|
<h3 className={styles.title}>Total Pooled Tokens</h3>
|
||||||
|
{totalBalance && (
|
||||||
|
<div className={styles.tokens}>
|
||||||
|
<Token symbol="OCEAN" balance={totalBalance.ocean} />
|
||||||
|
<Token symbol={dtSymbol} balance={totalBalance.dt} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{poolPrice && (
|
{poolPrice && (
|
||||||
<p>
|
<p>
|
||||||
Pool Price: <br />
|
Pool Price: <br />
|
||||||
@ -86,12 +94,6 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
|||||||
{formatCurrency(Number(dtPrice), '', 'en', false, true)}
|
{formatCurrency(Number(dtPrice), '', 'en', false, true)}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
{sharesBalance && (
|
|
||||||
<p>
|
|
||||||
Your Pool Shares: <br />
|
|
||||||
{sharesBalance}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user