mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
prototype adding liquidity
This commit is contained in:
parent
0570d30596
commit
ef874fd837
@ -1,13 +1,32 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement, useState, ChangeEvent } from 'react'
|
||||||
import styles from './Add.module.css'
|
import styles from './Add.module.css'
|
||||||
import stylesIndex from './index.module.css'
|
import stylesIndex from './index.module.css'
|
||||||
import Button from '../../../atoms/Button'
|
import Button from '../../../atoms/Button'
|
||||||
|
import Input from '../../../atoms/Input'
|
||||||
|
import { Ocean } from '@oceanprotocol/lib'
|
||||||
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
|
|
||||||
export default function Add({
|
export default function Add({
|
||||||
setShowAdd
|
setShowAdd,
|
||||||
|
dtSymbol,
|
||||||
|
poolAddress
|
||||||
}: {
|
}: {
|
||||||
setShowAdd: (show: boolean) => void
|
setShowAdd: (show: boolean) => void
|
||||||
|
dtSymbol: string
|
||||||
|
poolAddress: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
|
const { ocean, accountId } = useOcean()
|
||||||
|
|
||||||
|
const [amount, setAmount] = useState<string>()
|
||||||
|
|
||||||
|
function handleAmountChange(e: ChangeEvent<HTMLInputElement>) {
|
||||||
|
setAmount(e.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleAddLiquidity() {
|
||||||
|
await ocean.pool.addOceanLiquidity(accountId, poolAddress, amount)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.add}>
|
<div className={styles.add}>
|
||||||
<Button
|
<Button
|
||||||
@ -19,6 +38,21 @@ export default function Add({
|
|||||||
← Back
|
← Back
|
||||||
</Button>
|
</Button>
|
||||||
<h3 className={stylesIndex.title}>Add Liquidity</h3>
|
<h3 className={stylesIndex.title}>Add Liquidity</h3>
|
||||||
|
|
||||||
|
<Input
|
||||||
|
name="ocean"
|
||||||
|
label="OCEAN"
|
||||||
|
type="number"
|
||||||
|
placeholder="0"
|
||||||
|
onChange={handleAmountChange}
|
||||||
|
/>
|
||||||
|
{/* <Input name="dt" label={dtSymbol} type="number" placeholder="0" /> */}
|
||||||
|
|
||||||
|
<p>You will receive:</p>
|
||||||
|
|
||||||
|
<Button style="primary" size="small" onClick={() => handleAddLiquidity()}>
|
||||||
|
Add
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ interface Balance {
|
|||||||
export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
||||||
const { ocean, accountId } = useOcean()
|
const { ocean, accountId } = useOcean()
|
||||||
const { getBestPool } = useMetadata()
|
const { getBestPool } = useMetadata()
|
||||||
|
const [poolAddress, setPoolAddress] = useState<string>()
|
||||||
const [totalBalance, setTotalBalance] = useState<Balance>()
|
const [totalBalance, setTotalBalance] = useState<Balance>()
|
||||||
const [dtPrice, setDtPrice] = useState<string>()
|
const [dtPrice, setDtPrice] = useState<string>()
|
||||||
const [dtSymbol, setDtSymbol] = useState<string>()
|
const [dtSymbol, setDtSymbol] = useState<string>()
|
||||||
@ -32,6 +33,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
|||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
const { poolAddress } = await getBestPool(ddo.dataToken)
|
const { poolAddress } = await getBestPool(ddo.dataToken)
|
||||||
|
setPoolAddress(poolAddress)
|
||||||
|
|
||||||
const dtSymbol = await ocean.datatokens.getSymbol(
|
const dtSymbol = await ocean.datatokens.getSymbol(
|
||||||
ddo.dataToken,
|
ddo.dataToken,
|
||||||
@ -77,7 +79,11 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
|||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<Loader message="Retrieving pools..." />
|
<Loader message="Retrieving pools..." />
|
||||||
) : showAdd ? (
|
) : showAdd ? (
|
||||||
<Add setShowAdd={setShowAdd} dtSymbol={dtSymbol} />
|
<Add
|
||||||
|
setShowAdd={setShowAdd}
|
||||||
|
dtSymbol={dtSymbol}
|
||||||
|
poolAddress={poolAddress}
|
||||||
|
/>
|
||||||
) : showRemove ? (
|
) : showRemove ? (
|
||||||
<Remove setShowRemove={setShowRemove} />
|
<Remove setShowRemove={setShowRemove} />
|
||||||
) : (
|
) : (
|
||||||
|
Loading…
Reference in New Issue
Block a user