1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00

max checks

This commit is contained in:
Matthias Kretschmann 2020-10-14 15:57:30 +02:00
parent 5b7843d3d4
commit 056b6e6c2c
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 61 additions and 21 deletions

View File

@ -32,6 +32,20 @@
margin-bottom: 0; margin-bottom: 0;
} }
.slider {
position: relative;
z-index: 1;
}
.maximum {
position: absolute;
right: -1.5rem;
bottom: 1.5rem;
font-size: var(--font-size-small);
z-index: 0;
pointer-events: none;
}
.output { .output {
composes: output from './Add.module.css'; composes: output from './Add.module.css';
} }

View File

@ -10,18 +10,45 @@ import { useOcean } from '@oceanprotocol/react'
import Header from './Header' import Header from './Header'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import Actions from './Actions' import Actions from './Actions'
import { Logger } from '@oceanprotocol/lib' import { Logger, Ocean } from '@oceanprotocol/lib'
import Token from './Token' import Token from './Token'
import FormHelp from '../../../atoms/Input/Help' import FormHelp from '../../../atoms/Input/Help'
import Button from '../../../atoms/Button' import Button from '../../../atoms/Button'
const help = { const help = {
simple: simple:
'You will get the equivalent value in OCEAN, limited to xxx% of the total liquidity.', 'You will get the equivalent value in OCEAN, limited to 60% of the total liquidity.',
advanced: advanced:
'You will get OCEAN and Datatokens equivalent to your pool share, without any limit.' 'You will get OCEAN and Datatokens equivalent to your pool share, without any limit.'
} }
async function getMaxValues(
ocean: Ocean,
poolAddress: string,
poolTokens: string,
amountPoolShares: string
) {
const amountMaxOcean = await ocean.pool.getOceanMaxRemoveLiquidity(
poolAddress
)
const amountMaxPoolShares = await ocean.pool.getPoolSharesRequiredToRemoveOcean(
poolAddress,
amountMaxOcean
)
const amountMaxPercent = `${Math.floor(
(Number(amountMaxPoolShares) / Number(poolTokens)) * 100
)}`
const amountOcean = await ocean.pool.getOceanRemovedforPoolShares(
poolAddress,
amountPoolShares
)
return { amountMaxPercent, amountOcean }
}
export default function Remove({ export default function Remove({
setShowRemove, setShowRemove,
poolAddress, poolAddress,
@ -96,20 +123,13 @@ export default function Remove({
setAmountOcean(tokens?.oceanAmount) setAmountOcean(tokens?.oceanAmount)
setAmountDatatoken(tokens?.dtAmount) setAmountDatatoken(tokens?.dtAmount)
} else { } else {
const amountMaxOcean = await ocean.pool.getOceanMaxRemoveLiquidity( const { amountMaxPercent, amountOcean } = await getMaxValues(
poolAddress ocean,
)
console.log(amountMaxOcean)
// TODO: Calculate maximum percentage a user can remove based on maximum OCEAN
// to limit the range slider
// const maxPercent = ??
// setAmountMaxPercent(maxPercent)
const amountOcean = await ocean.pool.getOceanRemovedforPoolShares(
poolAddress, poolAddress,
poolTokens,
`${amountPoolShares}` `${amountPoolShares}`
) )
setAmountMaxPercent(amountMaxPercent)
setAmountOcean(amountOcean) setAmountOcean(amountOcean)
} }
} }
@ -126,14 +146,20 @@ export default function Remove({
<form className={styles.removeInput}> <form className={styles.removeInput}>
<div className={styles.range}> <div className={styles.range}>
<h3>{amountPercent}%</h3> <h3>{amountPercent}%</h3>
<input <div className={styles.slider}>
type="range" <input
min="0" type="range"
max={amountMaxPercent} min="0"
step="10" max={amountMaxPercent}
value={amountPercent} step={Number(amountMaxPercent) < 10 ? '1' : '10'}
onChange={handleAmountPercentChange} value={amountPercent}
/> onChange={handleAmountPercentChange}
/>
<span
className={styles.maximum}
>{`${amountMaxPercent}% max.`}</span>
</div>
<FormHelp> <FormHelp>
{`Set the amount of your pool shares to spend. ${ {`Set the amount of your pool shares to spend. ${
isAdvanced === true ? help.advanced : help.simple isAdvanced === true ? help.advanced : help.simple