mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +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 Header from './Header'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import Actions from './Actions'
|
import Actions from './Actions'
|
||||||
import { Logger, Ocean } from '@oceanprotocol/lib'
|
import { Logger } 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'
|
||||||
|
import { getMaxValuesRemove } from './utils'
|
||||||
|
|
||||||
const help = {
|
const help = {
|
||||||
simple:
|
simple:
|
||||||
@ -22,33 +23,6 @@ const help = {
|
|||||||
'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,
|
||||||
@ -125,7 +99,7 @@ export default function Remove({
|
|||||||
setAmountOcean(tokens?.oceanAmount)
|
setAmountOcean(tokens?.oceanAmount)
|
||||||
setAmountDatatoken(tokens?.dtAmount)
|
setAmountDatatoken(tokens?.dtAmount)
|
||||||
} else {
|
} else {
|
||||||
const { amountMaxPercent, amountOcean } = await getMaxValues(
|
const { amountMaxPercent, amountOcean } = await getMaxValuesRemove(
|
||||||
ocean,
|
ocean,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
poolTokens,
|
poolTokens,
|
||||||
@ -183,7 +157,9 @@ export default function Remove({
|
|||||||
<div>
|
<div>
|
||||||
<p>You will receive</p>
|
<p>You will receive</p>
|
||||||
<Token symbol="OCEAN" balance={amountOcean} />
|
<Token symbol="OCEAN" balance={amountOcean} />
|
||||||
{isAdvanced && <Token symbol={dtSymbol} balance={amountDatatoken} />}
|
{isAdvanced === true && (
|
||||||
|
<Token symbol={dtSymbol} balance={amountDatatoken} />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</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…
x
Reference in New Issue
Block a user