From 829047cb7159625f33c4e177ee830f3cd7b8d5c6 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Thu, 22 Oct 2020 15:37:26 +0300 Subject: [PATCH] reset values when switching from simple to advanced Signed-off-by: mihaisc --- .../organisms/AssetActions/Pool/Remove.tsx | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/components/organisms/AssetActions/Pool/Remove.tsx b/src/components/organisms/AssetActions/Pool/Remove.tsx index 773fe53b6..675fabbd3 100644 --- a/src/components/organisms/AssetActions/Pool/Remove.tsx +++ b/src/components/organisms/AssetActions/Pool/Remove.tsx @@ -103,6 +103,29 @@ export default function Remove({ setIsAdvanced(!isAdvanced) } + useEffect(() => { + if (!ocean || !poolTokens) return + async function resetValues() { + setAmountPoolShares(`0`) + setAmountPercent('0') + setAmountOcean('0') + + if (isAdvanced === true) { + setAmountMaxPercent('100') + setAmountDatatoken('0') + } else { + const { amountMaxPercent } = await getMaxValuesRemove( + ocean, + poolAddress, + poolTokens, + `0` + ) + setAmountMaxPercent(amountMaxPercent) + } + } + resetValues() + }, [isAdvanced]) + // Check and set outputs when percentage changes useEffect(() => { if (!ocean || !poolTokens) return @@ -113,8 +136,6 @@ export default function Remove({ setAmountPoolShares(`${amountPoolShares}`) if (isAdvanced === true) { - setAmountMaxPercent('100') - const tokens = await ocean.pool.getTokensRemovedforPoolShares( poolAddress, `${amountPoolShares}` @@ -122,13 +143,12 @@ export default function Remove({ setAmountOcean(tokens?.oceanAmount) setAmountDatatoken(tokens?.dtAmount) } else { - const { amountMaxPercent, amountOcean } = await getMaxValuesRemove( + const { amountOcean } = await getMaxValuesRemove( ocean, poolAddress, poolTokens, `${amountPoolShares}` ) - setAmountMaxPercent(amountMaxPercent) setAmountOcean(amountOcean) } }