1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Merge pull request #117 from oceanprotocol/fix/liquidity-remove

reset values when switching from simple to advanced
This commit is contained in:
mihaisc 2020-10-22 15:46:36 +03:00 committed by GitHub
commit cded299a79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}
}