From 37b0f4f0473c1efcf708a64e5c908213a74af204 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 9 Oct 2020 19:44:50 +0200 Subject: [PATCH] prototype --- .../AssetActions/Pool/Remove.module.css | 11 ++ .../organisms/AssetActions/Pool/Remove.tsx | 112 +++++++++++++----- .../organisms/AssetActions/Pool/index.tsx | 1 + 3 files changed, 93 insertions(+), 31 deletions(-) diff --git a/src/components/organisms/AssetActions/Pool/Remove.module.css b/src/components/organisms/AssetActions/Pool/Remove.module.css index fe0697c94..f565b05a7 100644 --- a/src/components/organisms/AssetActions/Pool/Remove.module.css +++ b/src/components/organisms/AssetActions/Pool/Remove.module.css @@ -4,8 +4,19 @@ .buttonMax { composes: buttonMax from './Add.module.css'; + bottom: -1rem; + right: 0; } .userLiquidity { composes: userLiquidity from './Add.module.css'; } + +.removeRow { + position: relative; + margin-bottom: var(--spacer); +} + +.removeRow:last-child { + margin-bottom: 0; +} diff --git a/src/components/organisms/AssetActions/Pool/Remove.tsx b/src/components/organisms/AssetActions/Pool/Remove.tsx index 245f1e2a1..7eae14de3 100644 --- a/src/components/organisms/AssetActions/Pool/Remove.tsx +++ b/src/components/organisms/AssetActions/Pool/Remove.tsx @@ -14,26 +14,33 @@ export default function Remove({ setShowRemove, poolAddress, totalPoolTokens, - userLiquidity + userLiquidity, + dtSymbol }: { setShowRemove: (show: boolean) => void poolAddress: string totalPoolTokens: string userLiquidity: Balance + dtSymbol: string }): ReactElement { const { ocean, accountId } = useOcean() - const [amount, setAmount] = useState('') + const [amountOcean, setAmountOcean] = useState('') + const [amountDatatoken, setAmountDatatoken] = useState('') const [isLoading, setIsLoading] = useState() const [txId, setTxId] = useState('') async function handleRemoveLiquidity() { setIsLoading(true) + // TODO: can remove OCEAN & DT in one transaction? + // exitswapExternAmountOut? exitswapPoolAmountIn? + // TODO: when user hits 'use max', use pool.exitPool() + try { const result = await ocean.pool.removeOceanLiquidity( accountId, poolAddress, - amount, + amountOcean, totalPoolTokens ) setTxId(result.transactionHash) @@ -45,12 +52,25 @@ export default function Remove({ } } - function handleAmountChange(e: ChangeEvent) { - setAmount(e.target.value) + // TODO: enforce correct weight rules + function handleOceanAmountChange(e: ChangeEvent) { + setAmountOcean(e.target.value) + setAmountDatatoken(`${Number(e.target.value) * 9}`) } - function handleMax() { - setAmount(`${userLiquidity.ocean}`) + function handleMaxOcean() { + setAmountOcean(`${userLiquidity.ocean}`) + setAmountDatatoken(`${userLiquidity.ocean * 9}`) + } + + function handleMaxDatatoken() { + setAmountDatatoken(`${userLiquidity.datatoken}`) + setAmountOcean(`${userLiquidity.ocean / 9}`) + } + + function handleDatatokenAmountChange(e: ChangeEvent) { + setAmountDatatoken(e.target.value) + setAmountOcean(`${Number(e.target.value) / 9}`) } return ( @@ -61,33 +81,63 @@ export default function Remove({ />
-
- Your pool liquidity: - -
- +
+
+ Your pool liquidity: + +
+ - {userLiquidity.ocean > Number(amount) && ( - - )} + {userLiquidity.ocean > Number(amountOcean) && ( + + )} +
+ +
+
+ Your pool liquidity: + +
+ + + {userLiquidity.datatoken > Number(amountDatatoken) && ( + + )} +
- {/* */} -

You will receive

) : ( <>