From 9f211a14d9181f2d537be87320242a11f1c3a350 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 9 Nov 2020 17:49:09 +0100 Subject: [PATCH] output weights in pool statistics (#218) * output weights in pool statistics * switch to more simple output * output weights only when present --- .../AssetActions/Pool/TokenList.module.css | 9 ------ .../organisms/AssetActions/Pool/TokenList.tsx | 24 +++++++++------- .../AssetActions/Pool/index.module.css | 8 ++++++ .../organisms/AssetActions/Pool/index.tsx | 28 +++++++++++++++++-- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/components/organisms/AssetActions/Pool/TokenList.module.css b/src/components/organisms/AssetActions/Pool/TokenList.module.css index 7110624a2..7bb434069 100644 --- a/src/components/organisms/AssetActions/Pool/TokenList.module.css +++ b/src/components/organisms/AssetActions/Pool/TokenList.module.css @@ -23,15 +23,6 @@ grid-template-columns: 1fr 1fr; } -/* visually tweak the order so tokens are underneath each other */ -.tokens > *:nth-child(1) { - grid-row: 1 / 2; -} - -.tokens > *:nth-child(2) { - grid-row: 2 / 2; -} - .title { composes: title from './index.module.css'; } diff --git a/src/components/organisms/AssetActions/Pool/TokenList.tsx b/src/components/organisms/AssetActions/Pool/TokenList.tsx index 32ef7d905..a04fcc790 100644 --- a/src/components/organisms/AssetActions/Pool/TokenList.tsx +++ b/src/components/organisms/AssetActions/Pool/TokenList.tsx @@ -26,18 +26,22 @@ export default function TokenList({

{title}

- - - +
+ + + {conversion > 0 && ( + + )} +
- {children} +
+ - {conversion > 0 && ( - - )} + {children} +
) diff --git a/src/components/organisms/AssetActions/Pool/index.module.css b/src/components/organisms/AssetActions/Pool/index.module.css index 312ef9dc6..9049b29a0 100644 --- a/src/components/organisms/AssetActions/Pool/index.module.css +++ b/src/components/organisms/AssetActions/Pool/index.module.css @@ -31,6 +31,14 @@ color: var(--color-secondary); } +.titleInfo { + font-size: var(--font-size-mini); + font-family: var(--font-family-base); + font-weight: var(--font-weight-base); + display: inline-block; + margin-left: 0.3rem; +} + .update { composes: container; font-size: var(--font-size-mini); diff --git a/src/components/organisms/AssetActions/Pool/index.tsx b/src/components/organisms/AssetActions/Pool/index.tsx index cac07f9ef..376498bbd 100644 --- a/src/components/organisms/AssetActions/Pool/index.tsx +++ b/src/components/organisms/AssetActions/Pool/index.tsx @@ -12,7 +12,6 @@ import EtherscanLink from '../../../atoms/EtherscanLink' import Token from './Token' import TokenList from './TokenList' import { graphql, useStaticQuery } from 'gatsby' -import PoolTransactions from '../../../molecules/PoolTransactions' import Transactions from './Transactions' export interface Balance { @@ -53,6 +52,8 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { const [totalPoolTokens, setTotalPoolTokens] = useState() const [userLiquidity, setUserLiquidity] = useState() const [swapFee, setSwapFee] = useState() + const [weightOcean, setWeightOcean] = useState() + const [weightDt, setWeightDt] = useState() const [showAdd, setShowAdd] = useState(false) const [showRemove, setShowRemove] = useState(false) @@ -159,10 +160,19 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { 2 ) setCreatorPoolShare(creatorPoolShare) + // Get swap fee // swapFee is tricky: to get 0.1% you need to convert from 0.001 const swapFee = await ocean.pool.getSwapFee(price.address) setSwapFee(`${Number(swapFee) * 100}`) + + // Get weights + const weightDt = await ocean.pool.getDenormalizedWeight( + price.address, + ddo.dataToken + ) + setWeightDt(`${Number(weightDt) * 10}`) + setWeightOcean(`${100 - Number(weightDt) * 10}`) } catch (error) { Logger.error(error.message) } @@ -172,7 +182,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { // Re-fetch price periodically, triggering re-calculation of everything const interval = setInterval(() => refreshPrice(), refreshInterval) return () => clearInterval(interval) - }, [ocean, accountId, price, ddo, refreshPool]) + }, [ocean, accountId, price, ddo, refreshPool, owner]) const refreshInfo = async () => { setRefreshPool(!refreshPool) @@ -252,7 +262,19 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement { + Pool Statistics + {weightDt && ( + + {weightOcean}/{weightDt} + + )} + + } ocean={`${price?.ocean}`} dt={`${price?.datatoken}`} dtSymbol={dtSymbol}