1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00
This commit is contained in:
Matthias Kretschmann 2020-10-14 16:08:49 +02:00
parent 2646e181cf
commit 959158d82a
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 34 additions and 30 deletions

View File

@ -10,10 +10,11 @@ import { useOcean } from '@oceanprotocol/react'
import Header from './Header'
import { toast } from 'react-toastify'
import Actions from './Actions'
import { Logger, Ocean } from '@oceanprotocol/lib'
import { Logger } from '@oceanprotocol/lib'
import Token from './Token'
import FormHelp from '../../../atoms/Input/Help'
import Button from '../../../atoms/Button'
import { getMaxValuesRemove } from './utils'
const help = {
simple:
@ -22,33 +23,6 @@ const help = {
'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({
setShowRemove,
poolAddress,
@ -125,7 +99,7 @@ export default function Remove({
setAmountOcean(tokens?.oceanAmount)
setAmountDatatoken(tokens?.dtAmount)
} else {
const { amountMaxPercent, amountOcean } = await getMaxValues(
const { amountMaxPercent, amountOcean } = await getMaxValuesRemove(
ocean,
poolAddress,
poolTokens,
@ -183,7 +157,9 @@ export default function Remove({
<div>
<p>You will receive</p>
<Token symbol="OCEAN" balance={amountOcean} />
{isAdvanced && <Token symbol={dtSymbol} balance={amountDatatoken} />}
{isAdvanced === true && (
<Token symbol={dtSymbol} balance={amountDatatoken} />
)}
</div>
</div>

View File

@ -0,0 +1,28 @@
import { Ocean } from '@oceanprotocol/lib'
export async function getMaxValuesRemove(
ocean: Ocean,
poolAddress: string,
poolTokens: string,
amountPoolShares: string
): Promise<{ amountMaxPercent: string; amountOcean: 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 }
}