mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
combine both flows
This commit is contained in:
parent
96ce7b518b
commit
207b61933a
@ -2,6 +2,7 @@
|
|||||||
composes: addInput from './Add.module.css';
|
composes: addInput from './Add.module.css';
|
||||||
padding-left: calc(var(--spacer) * 2);
|
padding-left: calc(var(--spacer) * 2);
|
||||||
padding-right: calc(var(--spacer) * 2);
|
padding-right: calc(var(--spacer) * 2);
|
||||||
|
padding-bottom: calc(var(--spacer) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.userLiquidity {
|
.userLiquidity {
|
||||||
@ -22,4 +23,11 @@
|
|||||||
|
|
||||||
.range p {
|
.range p {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
|
margin-left: -2rem;
|
||||||
|
margin-right: -2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.range button {
|
||||||
|
margin-top: calc(var(--spacer) / 4);
|
||||||
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
import React, { ReactElement, useState, ChangeEvent, useEffect } from 'react'
|
import React, {
|
||||||
|
ReactElement,
|
||||||
|
useState,
|
||||||
|
ChangeEvent,
|
||||||
|
useEffect,
|
||||||
|
FormEvent
|
||||||
|
} from 'react'
|
||||||
import styles from './Remove.module.css'
|
import styles from './Remove.module.css'
|
||||||
import { useOcean } from '@oceanprotocol/react'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
import Header from './Header'
|
import Header from './Header'
|
||||||
@ -7,20 +13,32 @@ import Actions from './Actions'
|
|||||||
import { Logger } 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'
|
||||||
|
|
||||||
|
const help = {
|
||||||
|
simple:
|
||||||
|
'You will get the equivalent value in OCEAN, limited to xxx% of the total liquidity.',
|
||||||
|
advanced:
|
||||||
|
'You will get OCEAN and Datatokens equivalent to your pool share, without any limit.'
|
||||||
|
}
|
||||||
|
|
||||||
export default function Remove({
|
export default function Remove({
|
||||||
setShowRemove,
|
setShowRemove,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
poolTokens
|
poolTokens,
|
||||||
|
dtSymbol
|
||||||
}: {
|
}: {
|
||||||
setShowRemove: (show: boolean) => void
|
setShowRemove: (show: boolean) => void
|
||||||
poolAddress: string
|
poolAddress: string
|
||||||
poolTokens: string
|
poolTokens: string
|
||||||
|
dtSymbol: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { ocean, accountId } = useOcean()
|
const { ocean, accountId } = useOcean()
|
||||||
const [amountPercent, setAmountPercent] = useState('0')
|
const [amountPercent, setAmountPercent] = useState('0')
|
||||||
const [amountPoolShares, setAmountPoolShares] = useState('0')
|
const [amountPoolShares, setAmountPoolShares] = useState('0')
|
||||||
const [amountOcean, setAmountOcean] = useState<string>()
|
const [amountOcean, setAmountOcean] = useState<string>()
|
||||||
|
const [amountDatatoken, setAmountDatatoken] = useState<string>()
|
||||||
|
const [isAdvanced, setIsAdvanced] = useState(false)
|
||||||
const [isLoading, setIsLoading] = useState<boolean>()
|
const [isLoading, setIsLoading] = useState<boolean>()
|
||||||
const [txId, setTxId] = useState<string>()
|
const [txId, setTxId] = useState<string>()
|
||||||
|
|
||||||
@ -28,12 +46,21 @@ export default function Remove({
|
|||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await ocean.pool.removePoolLiquidity(
|
const result =
|
||||||
accountId,
|
isAdvanced === true
|
||||||
poolAddress,
|
? await ocean.pool.removePoolLiquidity(
|
||||||
amountPoolShares
|
accountId,
|
||||||
)
|
poolAddress,
|
||||||
setTxId(result.transactionHash)
|
amountPoolShares
|
||||||
|
)
|
||||||
|
: await ocean.pool.removeOceanLiquidity(
|
||||||
|
accountId,
|
||||||
|
poolAddress,
|
||||||
|
amountDatatoken,
|
||||||
|
amountPoolShares
|
||||||
|
)
|
||||||
|
|
||||||
|
setTxId(result?.transactionHash)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(error.message)
|
Logger.error(error.message)
|
||||||
toast.error(error.message)
|
toast.error(error.message)
|
||||||
@ -46,6 +73,11 @@ export default function Remove({
|
|||||||
setAmountPercent(e.target.value)
|
setAmountPercent(e.target.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleAdvancedButton(e: FormEvent<HTMLButtonElement>) {
|
||||||
|
e.preventDefault()
|
||||||
|
setIsAdvanced(!isAdvanced)
|
||||||
|
}
|
||||||
|
|
||||||
// Check and set outputs when percentage changes
|
// Check and set outputs when percentage changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean || !poolTokens) return
|
if (!ocean || !poolTokens) return
|
||||||
@ -63,9 +95,17 @@ export default function Remove({
|
|||||||
`${amountPoolShares}`
|
`${amountPoolShares}`
|
||||||
)
|
)
|
||||||
setAmountOcean(amountOcean)
|
setAmountOcean(amountOcean)
|
||||||
|
|
||||||
|
if (!isAdvanced) return
|
||||||
|
|
||||||
|
const amountDatatoken = await ocean.pool.getDTRemovedforPoolShares(
|
||||||
|
poolAddress,
|
||||||
|
`${amountPoolShares}`
|
||||||
|
)
|
||||||
|
setAmountDatatoken(amountDatatoken)
|
||||||
}
|
}
|
||||||
getValues()
|
getValues()
|
||||||
}, [amountPercent, ocean, poolTokens, poolAddress])
|
}, [amountPercent, ocean, poolTokens, poolAddress, isAdvanced])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.remove}>
|
<div className={styles.remove}>
|
||||||
@ -81,14 +121,18 @@ export default function Remove({
|
|||||||
type="range"
|
type="range"
|
||||||
min="0"
|
min="0"
|
||||||
max="100"
|
max="100"
|
||||||
step="25"
|
step="10"
|
||||||
value={amountPercent}
|
value={amountPercent}
|
||||||
onChange={handleAmountPercentChange}
|
onChange={handleAmountPercentChange}
|
||||||
/>
|
/>
|
||||||
<FormHelp>
|
<FormHelp>
|
||||||
Set the amount of your pool shares to spend. You will get the
|
{`Set the amount of your pool shares to spend. ${
|
||||||
equivalent value in OCEAN.
|
isAdvanced === true ? help.advanced : help.simple
|
||||||
|
}`}
|
||||||
</FormHelp>
|
</FormHelp>
|
||||||
|
<Button style="text" size="small" onClick={handleAdvancedButton}>
|
||||||
|
{isAdvanced === true ? 'Simple' : 'Advanced'}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@ -99,6 +143,7 @@ export default function Remove({
|
|||||||
<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} />}
|
||||||
|
|
||||||
<Actions
|
<Actions
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
|
@ -129,6 +129,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
|||||||
setShowRemove={setShowRemove}
|
setShowRemove={setShowRemove}
|
||||||
poolAddress={price.address}
|
poolAddress={price.address}
|
||||||
poolTokens={poolTokens}
|
poolTokens={poolTokens}
|
||||||
|
dtSymbol={dtSymbol}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
Loading…
Reference in New Issue
Block a user