From 8bec69986c9379ddaf39ee6ab25038e4e10be9ee Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 15 Oct 2020 12:48:01 +0200 Subject: [PATCH] add max amount checks --- .../AssetActions/Pool/Add.module.css | 7 +++- .../organisms/AssetActions/Pool/Add.tsx | 42 +++++++++++++++---- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/components/organisms/AssetActions/Pool/Add.module.css b/src/components/organisms/AssetActions/Pool/Add.module.css index 1fc546251..3aab2d915 100644 --- a/src/components/organisms/AssetActions/Pool/Add.module.css +++ b/src/components/organisms/AssetActions/Pool/Add.module.css @@ -21,15 +21,18 @@ right: calc(var(--spacer) * 3); } -.userLiquidity { +.userLiquidity > div { display: flex; justify-content: space-between; align-items: center; font-size: var(--font-size-mini); - margin-bottom: calc(var(--spacer) / 4); color: var(--color-secondary); } +.userLiquidity > div:last-child { + margin-bottom: calc(var(--spacer) / 4); +} + .userLiquidity span + div { transform: scale(0.8); transform-origin: right center; diff --git a/src/components/organisms/AssetActions/Pool/Add.tsx b/src/components/organisms/AssetActions/Pool/Add.tsx index 270b97de5..e49ea0327 100644 --- a/src/components/organisms/AssetActions/Pool/Add.tsx +++ b/src/components/organisms/AssetActions/Pool/Add.tsx @@ -12,6 +12,7 @@ import Actions from './Actions' import Tooltip from '../../../atoms/Tooltip' import { ReactComponent as Caret } from '../../../../images/caret.svg' import { graphql, useStaticQuery } from 'gatsby' +import FormHelp from '../../../atoms/Input/Help' const contentQuery = graphql` query PoolAddQuery { @@ -62,6 +63,7 @@ export default function Add({ const [isLoading, setIsLoading] = useState() const [coin, setCoin] = useState('OCEAN') const [dtBalance, setDtBalance] = useState() + const [amountMax, setAmountMax] = useState() const newPoolTokens = totalBalance && @@ -71,15 +73,30 @@ export default function Add({ totalBalance && ((Number(newPoolTokens) / Number(totalPoolTokens)) * 100).toFixed(2) + // Get datatoken balance when datatoken selected useEffect(() => { - if (!ocean) return + if (!ocean || coin === 'OCEAN') return async function getDtBalance() { const dtBalance = await ocean.datatokens.balance(dtAddress, accountId) setDtBalance(dtBalance) } getDtBalance() - }, [ocean, accountId, dtAddress]) + }, [ocean, accountId, dtAddress, coin]) + + // Get maximum amount for either OCEAN or datatoken + useEffect(() => { + if (!ocean) return + + async function getMaximum() { + const amountMax = + coin === 'OCEAN' + ? await ocean.pool.getOceanMaxAddLiquidity(poolAddress) + : await ocean.pool.getDTMaxAddLiquidity(poolAddress) + setAmountMax(amountMax) + } + getMaximum() + }, [ocean, poolAddress, coin]) async function handleAddLiquidity() { setIsLoading(true) @@ -104,7 +121,7 @@ export default function Add({ } function handleMax() { - setAmount(coin === 'OCEAN' ? balance.ocean : dtBalance) + setAmount(amountMax) } // TODO: this is only a prototype and is an accessibility nightmare. @@ -124,18 +141,25 @@ export default function Add({
- Available: - {coin === 'OCEAN' ? ( - - ) : ( - - )} +
+ Available: + {coin === 'OCEAN' ? ( + + ) : ( + + )} +
+
+ Maximum: + +
}