mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-15 01:34:57 +01:00
handle user data token balance
This commit is contained in:
parent
f7f3a259f7
commit
6b901adf4e
@ -1,4 +1,4 @@
|
|||||||
import React, { ReactElement, useState, ChangeEvent } from 'react'
|
import React, { ReactElement, useState, ChangeEvent, useEffect } from 'react'
|
||||||
import styles from './Add.module.css'
|
import styles from './Add.module.css'
|
||||||
import { useOcean } from '@oceanprotocol/react'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
import Header from './Header'
|
import Header from './Header'
|
||||||
@ -19,7 +19,8 @@ export default function Add({
|
|||||||
totalPoolTokens,
|
totalPoolTokens,
|
||||||
totalBalance,
|
totalBalance,
|
||||||
swapFee,
|
swapFee,
|
||||||
dtSymbol
|
dtSymbol,
|
||||||
|
dtAddress
|
||||||
}: {
|
}: {
|
||||||
setShowAdd: (show: boolean) => void
|
setShowAdd: (show: boolean) => void
|
||||||
poolAddress: string
|
poolAddress: string
|
||||||
@ -27,6 +28,7 @@ export default function Add({
|
|||||||
totalBalance: Balance
|
totalBalance: Balance
|
||||||
swapFee: string
|
swapFee: string
|
||||||
dtSymbol: string
|
dtSymbol: string
|
||||||
|
dtAddress: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { debug } = useUserPreferences()
|
const { debug } = useUserPreferences()
|
||||||
const { ocean, accountId, balance } = useOcean()
|
const { ocean, accountId, balance } = useOcean()
|
||||||
@ -34,6 +36,7 @@ export default function Add({
|
|||||||
const [txId, setTxId] = useState<string>('')
|
const [txId, setTxId] = useState<string>('')
|
||||||
const [isLoading, setIsLoading] = useState<boolean>()
|
const [isLoading, setIsLoading] = useState<boolean>()
|
||||||
const [coin, setCoin] = useState<string>('OCEAN')
|
const [coin, setCoin] = useState<string>('OCEAN')
|
||||||
|
const [dtBalance, setDtBalance] = useState<string>()
|
||||||
|
|
||||||
const newPoolTokens =
|
const newPoolTokens =
|
||||||
totalBalance &&
|
totalBalance &&
|
||||||
@ -43,6 +46,16 @@ export default function Add({
|
|||||||
totalBalance &&
|
totalBalance &&
|
||||||
((Number(newPoolTokens) / Number(totalPoolTokens)) * 100).toFixed(2)
|
((Number(newPoolTokens) / Number(totalPoolTokens)) * 100).toFixed(2)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!ocean) return
|
||||||
|
|
||||||
|
async function getDtBalance() {
|
||||||
|
const dtBalance = await ocean.datatokens.balance(dtAddress, accountId)
|
||||||
|
setDtBalance(dtBalance)
|
||||||
|
}
|
||||||
|
getDtBalance()
|
||||||
|
}, [ocean, accountId, dtAddress])
|
||||||
|
|
||||||
async function handleAddLiquidity() {
|
async function handleAddLiquidity() {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
|
|
||||||
@ -67,7 +80,7 @@ export default function Add({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleMax() {
|
function handleMax() {
|
||||||
setAmount(balance.ocean)
|
setAmount(coin === 'OCEAN' ? balance.ocean : dtBalance)
|
||||||
}
|
}
|
||||||
|
|
||||||
const CoinSelect = () => (
|
const CoinSelect = () => (
|
||||||
@ -84,7 +97,11 @@ export default function Add({
|
|||||||
<div className={styles.addInput}>
|
<div className={styles.addInput}>
|
||||||
<div className={styles.userLiquidity}>
|
<div className={styles.userLiquidity}>
|
||||||
<span>Available: </span>
|
<span>Available: </span>
|
||||||
<PriceUnit price={balance.ocean} symbol="OCEAN" small />
|
{coin === 'OCEAN' ? (
|
||||||
|
<PriceUnit price={balance.ocean} symbol="OCEAN" small />
|
||||||
|
) : (
|
||||||
|
<PriceUnit price={dtBalance} symbol={dtSymbol} small />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<InputElement
|
<InputElement
|
||||||
@ -106,7 +123,7 @@ export default function Add({
|
|||||||
onChange={handleAmountChange}
|
onChange={handleAmountChange}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{balance.ocean > amount && (
|
{(balance.ocean || dtBalance) > amount && (
|
||||||
<Button
|
<Button
|
||||||
className={styles.buttonMax}
|
className={styles.buttonMax}
|
||||||
style="text"
|
style="text"
|
||||||
|
@ -122,6 +122,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
|
|||||||
totalBalance={totalBalance}
|
totalBalance={totalBalance}
|
||||||
swapFee={swapFee}
|
swapFee={swapFee}
|
||||||
dtSymbol={dtSymbol}
|
dtSymbol={dtSymbol}
|
||||||
|
dtAddress={ddo.dataToken}
|
||||||
/>
|
/>
|
||||||
) : showRemove ? (
|
) : showRemove ? (
|
||||||
<Remove
|
<Remove
|
||||||
|
Loading…
Reference in New Issue
Block a user