mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
add max amount checks
This commit is contained in:
parent
93672ac14a
commit
8bec69986c
@ -21,15 +21,18 @@
|
|||||||
right: calc(var(--spacer) * 3);
|
right: calc(var(--spacer) * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.userLiquidity {
|
.userLiquidity > div {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
font-size: var(--font-size-mini);
|
font-size: var(--font-size-mini);
|
||||||
margin-bottom: calc(var(--spacer) / 4);
|
|
||||||
color: var(--color-secondary);
|
color: var(--color-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.userLiquidity > div:last-child {
|
||||||
|
margin-bottom: calc(var(--spacer) / 4);
|
||||||
|
}
|
||||||
|
|
||||||
.userLiquidity span + div {
|
.userLiquidity span + div {
|
||||||
transform: scale(0.8);
|
transform: scale(0.8);
|
||||||
transform-origin: right center;
|
transform-origin: right center;
|
||||||
|
@ -12,6 +12,7 @@ import Actions from './Actions'
|
|||||||
import Tooltip from '../../../atoms/Tooltip'
|
import Tooltip from '../../../atoms/Tooltip'
|
||||||
import { ReactComponent as Caret } from '../../../../images/caret.svg'
|
import { ReactComponent as Caret } from '../../../../images/caret.svg'
|
||||||
import { graphql, useStaticQuery } from 'gatsby'
|
import { graphql, useStaticQuery } from 'gatsby'
|
||||||
|
import FormHelp from '../../../atoms/Input/Help'
|
||||||
|
|
||||||
const contentQuery = graphql`
|
const contentQuery = graphql`
|
||||||
query PoolAddQuery {
|
query PoolAddQuery {
|
||||||
@ -62,6 +63,7 @@ export default function Add({
|
|||||||
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 [dtBalance, setDtBalance] = useState<string>()
|
||||||
|
const [amountMax, setAmountMax] = useState<string>()
|
||||||
|
|
||||||
const newPoolTokens =
|
const newPoolTokens =
|
||||||
totalBalance &&
|
totalBalance &&
|
||||||
@ -71,15 +73,30 @@ export default function Add({
|
|||||||
totalBalance &&
|
totalBalance &&
|
||||||
((Number(newPoolTokens) / Number(totalPoolTokens)) * 100).toFixed(2)
|
((Number(newPoolTokens) / Number(totalPoolTokens)) * 100).toFixed(2)
|
||||||
|
|
||||||
|
// Get datatoken balance when datatoken selected
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean) return
|
if (!ocean || coin === 'OCEAN') return
|
||||||
|
|
||||||
async function getDtBalance() {
|
async function getDtBalance() {
|
||||||
const dtBalance = await ocean.datatokens.balance(dtAddress, accountId)
|
const dtBalance = await ocean.datatokens.balance(dtAddress, accountId)
|
||||||
setDtBalance(dtBalance)
|
setDtBalance(dtBalance)
|
||||||
}
|
}
|
||||||
getDtBalance()
|
getDtBalance()
|
||||||
}, [ocean, accountId, dtAddress])
|
}, [ocean, accountId, dtAddress, coin])
|
||||||
|
|
||||||
|
// Get maximum amount for either OCEAN or datatoken
|
||||||
|
useEffect(() => {
|
||||||
|
if (!ocean) return
|
||||||
|
|
||||||
|
async function getMaximum() {
|
||||||
|
const amountMax =
|
||||||
|
coin === 'OCEAN'
|
||||||
|
? await ocean.pool.getOceanMaxAddLiquidity(poolAddress)
|
||||||
|
: await ocean.pool.getDTMaxAddLiquidity(poolAddress)
|
||||||
|
setAmountMax(amountMax)
|
||||||
|
}
|
||||||
|
getMaximum()
|
||||||
|
}, [ocean, poolAddress, coin])
|
||||||
|
|
||||||
async function handleAddLiquidity() {
|
async function handleAddLiquidity() {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
@ -104,7 +121,7 @@ export default function Add({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleMax() {
|
function handleMax() {
|
||||||
setAmount(coin === 'OCEAN' ? balance.ocean : dtBalance)
|
setAmount(amountMax)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this is only a prototype and is an accessibility nightmare.
|
// TODO: this is only a prototype and is an accessibility nightmare.
|
||||||
@ -124,18 +141,25 @@ export default function Add({
|
|||||||
|
|
||||||
<div className={styles.addInput}>
|
<div className={styles.addInput}>
|
||||||
<div className={styles.userLiquidity}>
|
<div className={styles.userLiquidity}>
|
||||||
<span>Available: </span>
|
<div>
|
||||||
{coin === 'OCEAN' ? (
|
<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 />
|
) : (
|
||||||
)}
|
<PriceUnit price={dtBalance} symbol={dtSymbol} small />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>Maximum:</span>
|
||||||
|
<PriceUnit price={amountMax} symbol={coin} small />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<InputElement
|
<InputElement
|
||||||
value={amount}
|
value={amount}
|
||||||
name="coin"
|
name="coin"
|
||||||
type="number"
|
type="number"
|
||||||
|
max={amountMax}
|
||||||
prefix={
|
prefix={
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={<CoinSelect />}
|
content={<CoinSelect />}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user