From 207b61933a711b76647271ae354b4cc6e63f6821 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 14 Oct 2020 12:04:55 +0200 Subject: [PATCH] combine both flows --- .../AssetActions/Pool/Remove.module.css | 8 +++ .../organisms/AssetActions/Pool/Remove.tsx | 69 +++++++++++++++---- .../organisms/AssetActions/Pool/index.tsx | 1 + 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/components/organisms/AssetActions/Pool/Remove.module.css b/src/components/organisms/AssetActions/Pool/Remove.module.css index 360910e0a..9451a224b 100644 --- a/src/components/organisms/AssetActions/Pool/Remove.module.css +++ b/src/components/organisms/AssetActions/Pool/Remove.module.css @@ -2,6 +2,7 @@ composes: addInput from './Add.module.css'; padding-left: calc(var(--spacer) * 2); padding-right: calc(var(--spacer) * 2); + padding-bottom: calc(var(--spacer) / 2); } .userLiquidity { @@ -22,4 +23,11 @@ .range p { margin-bottom: 0; + margin-left: -2rem; + margin-right: -2rem; +} + +.range button { + margin-top: calc(var(--spacer) / 4); + margin-bottom: 0; } diff --git a/src/components/organisms/AssetActions/Pool/Remove.tsx b/src/components/organisms/AssetActions/Pool/Remove.tsx index c16279bd1..881edd301 100644 --- a/src/components/organisms/AssetActions/Pool/Remove.tsx +++ b/src/components/organisms/AssetActions/Pool/Remove.tsx @@ -1,4 +1,10 @@ -import React, { ReactElement, useState, ChangeEvent, useEffect } from 'react' +import React, { + ReactElement, + useState, + ChangeEvent, + useEffect, + FormEvent +} from 'react' import styles from './Remove.module.css' import { useOcean } from '@oceanprotocol/react' import Header from './Header' @@ -7,20 +13,32 @@ import Actions from './Actions' import { Logger } from '@oceanprotocol/lib' import Token from './Token' import FormHelp from '../../../atoms/Input/Help' +import Button from '../../../atoms/Button' + +const help = { + simple: + 'You will get the equivalent value in OCEAN, limited to xxx% of the total liquidity.', + advanced: + 'You will get OCEAN and Datatokens equivalent to your pool share, without any limit.' +} export default function Remove({ setShowRemove, poolAddress, - poolTokens + poolTokens, + dtSymbol }: { setShowRemove: (show: boolean) => void poolAddress: string poolTokens: string + dtSymbol: string }): ReactElement { const { ocean, accountId } = useOcean() const [amountPercent, setAmountPercent] = useState('0') const [amountPoolShares, setAmountPoolShares] = useState('0') const [amountOcean, setAmountOcean] = useState() + const [amountDatatoken, setAmountDatatoken] = useState() + const [isAdvanced, setIsAdvanced] = useState(false) const [isLoading, setIsLoading] = useState() const [txId, setTxId] = useState() @@ -28,12 +46,21 @@ export default function Remove({ setIsLoading(true) try { - const result = await ocean.pool.removePoolLiquidity( - accountId, - poolAddress, - amountPoolShares - ) - setTxId(result.transactionHash) + const result = + isAdvanced === true + ? await ocean.pool.removePoolLiquidity( + accountId, + poolAddress, + amountPoolShares + ) + : await ocean.pool.removeOceanLiquidity( + accountId, + poolAddress, + amountDatatoken, + amountPoolShares + ) + + setTxId(result?.transactionHash) } catch (error) { Logger.error(error.message) toast.error(error.message) @@ -46,6 +73,11 @@ export default function Remove({ setAmountPercent(e.target.value) } + function handleAdvancedButton(e: FormEvent) { + e.preventDefault() + setIsAdvanced(!isAdvanced) + } + // Check and set outputs when percentage changes useEffect(() => { if (!ocean || !poolTokens) return @@ -63,9 +95,17 @@ export default function Remove({ `${amountPoolShares}` ) setAmountOcean(amountOcean) + + if (!isAdvanced) return + + const amountDatatoken = await ocean.pool.getDTRemovedforPoolShares( + poolAddress, + `${amountPoolShares}` + ) + setAmountDatatoken(amountDatatoken) } getValues() - }, [amountPercent, ocean, poolTokens, poolAddress]) + }, [amountPercent, ocean, poolTokens, poolAddress, isAdvanced]) return (
@@ -81,14 +121,18 @@ export default function Remove({ type="range" min="0" max="100" - step="25" + step="10" value={amountPercent} onChange={handleAmountPercentChange} /> - Set the amount of your pool shares to spend. You will get the - equivalent value in OCEAN. + {`Set the amount of your pool shares to spend. ${ + isAdvanced === true ? help.advanced : help.simple + }`} +
@@ -99,6 +143,7 @@ export default function Remove({

You will receive

+ {isAdvanced && } ) : ( <>