diff --git a/src/components/organisms/AssetActions/Pool/Add.tsx b/src/components/organisms/AssetActions/Pool/Add.tsx index a0928b409..669ca1c9d 100644 --- a/src/components/organisms/AssetActions/Pool/Add.tsx +++ b/src/components/organisms/AssetActions/Pool/Add.tsx @@ -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 { useOcean } from '@oceanprotocol/react' import Header from './Header' @@ -19,7 +19,8 @@ export default function Add({ totalPoolTokens, totalBalance, swapFee, - dtSymbol + dtSymbol, + dtAddress }: { setShowAdd: (show: boolean) => void poolAddress: string @@ -27,6 +28,7 @@ export default function Add({ totalBalance: Balance swapFee: string dtSymbol: string + dtAddress: string }): ReactElement { const { debug } = useUserPreferences() const { ocean, accountId, balance } = useOcean() @@ -34,6 +36,7 @@ export default function Add({ const [txId, setTxId] = useState('') const [isLoading, setIsLoading] = useState() const [coin, setCoin] = useState('OCEAN') + const [dtBalance, setDtBalance] = useState() const newPoolTokens = totalBalance && @@ -43,6 +46,16 @@ export default function Add({ totalBalance && ((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() { setIsLoading(true) @@ -67,7 +80,7 @@ export default function Add({ } function handleMax() { - setAmount(balance.ocean) + setAmount(coin === 'OCEAN' ? balance.ocean : dtBalance) } const CoinSelect = () => ( @@ -84,7 +97,11 @@ export default function Add({
Available: - + {coin === 'OCEAN' ? ( + + ) : ( + + )}
- {balance.ocean > amount && ( + {(balance.ocean || dtBalance) > amount && (