mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-15 01:34:57 +01:00
refactor
This commit is contained in:
parent
2646e181cf
commit
959158d82a
@ -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>
|
||||
|
||||
|
28
src/components/organisms/AssetActions/Pool/utils.ts
Normal file
28
src/components/organisms/AssetActions/Pool/utils.ts
Normal 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 }
|
||||
}
|
Loading…
Reference in New Issue
Block a user