(undefined)
const [isSuccess, setIsSuccess] = useState(false)
const [isLoading, setIsLoading] = useState(false)
const onAmountChange = (amount: number | undefined) => {
setIsSuccess(false)
setAmount(amount)
// Check for errors.
if (amount !== undefined) {
if (user && user.balance < amount) {
setError('Insufficient balance')
} else if (amount < 1) {
setError('Minimum amount: ' + formatMoney(1))
} else {
setError(undefined)
}
}
}
const submit = () => {
if (!amount) return
setIsLoading(true)
setIsSuccess(false)
addLiquidity({ amount, contractId })
.then((r) => {
if (r.status === 'success') {
setIsSuccess(true)
setError(undefined)
setIsLoading(false)
} else {
setError('Server error')
}
})
.catch((e) => setError('Server error'))
}
return (
<>
Subsidize this market by adding liquidity for traders.
{isSuccess && amount && (
Success! Added {formatMoney(amount)} in liquidity.
)}
{isLoading && Processing...
}
>
)
}
function WithdrawLiquidityPanel(props: {
contract: CPMMContract
lpShares: { YES: number; NO: number }
}) {
const { contract, lpShares } = props
const { YES: yesShares, NO: noShares } = lpShares
const [error, setError] = useState(undefined)
const [isSuccess, setIsSuccess] = useState(false)
const [isLoading, setIsLoading] = useState(false)
const submit = () => {
setIsLoading(true)
setIsSuccess(false)
withdrawLiquidity({ contractId: contract.id })
.then((r) => {
setIsSuccess(true)
setError(undefined)
setIsLoading(false)
})
.catch((e) => setError('Server error'))
}
if (isSuccess)
return (
Success! Your liquidity was withdrawn.
)
if (!yesShares && !noShares)
return (
You do not have any liquidity positions to withdraw.
)
return (
Your liquidity position is currently:
{yesShares.toFixed(2)} shares
{noShares.toFixed(2)} shares
{isLoading && Processing...
}
)
}