add warning when perp slots are full
This commit is contained in:
parent
3b643c1690
commit
1d07a03b95
|
@ -36,7 +36,7 @@ import TokenListButton from './shared/TokenListButton'
|
|||
import { ACCOUNT_ACTIONS_NUMBER_FORMAT_CLASSES, BackButton } from './BorrowForm'
|
||||
import TokenLogo from './shared/TokenLogo'
|
||||
import SecondaryConnectButton from './shared/SecondaryConnectButton'
|
||||
import useTokenPositionsFull from 'hooks/useTokenPositionsFull'
|
||||
import useTokenPositionsFull from 'hooks/useAccountPositionsFull'
|
||||
import AccountSlotsFullNotification from './shared/AccountSlotsFullNotification'
|
||||
import { handleInputChange } from 'utils/account'
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import useMangoAccount from 'hooks/useMangoAccount'
|
|||
import { useWallet } from '@solana/wallet-adapter-react'
|
||||
import mangoStore from '@store/mangoStore'
|
||||
import useRemainingBorrowsInPeriod from 'hooks/useRemainingBorrowsInPeriod'
|
||||
import useTokenPositionsFull from 'hooks/useTokenPositionsFull'
|
||||
import useTokenPositionsFull from 'hooks/useAccountPositionsFull'
|
||||
import { useMemo } from 'react'
|
||||
import Button from '@components/shared/Button'
|
||||
import Loading from '@components/shared/Loading'
|
||||
|
|
|
@ -43,7 +43,7 @@ import relativeTime from 'dayjs/plugin/relativeTime'
|
|||
import { SwapFormTokenListType } from './SwapFormTokenList'
|
||||
import { formatTokenSymbol } from 'utils/tokens'
|
||||
import Tooltip from '@components/shared/Tooltip'
|
||||
import useTokenPositionsFull from 'hooks/useTokenPositionsFull'
|
||||
import useTokenPositionsFull from 'hooks/useAccountPositionsFull'
|
||||
import { TriggerOrderTypes, handlePlaceTriggerOrder } from 'utils/tradeForm'
|
||||
import TradePriceDifference from '@components/shared/TradePriceDifference'
|
||||
import AccountSlotsFullNotification from '@components/shared/AccountSlotsFullNotification'
|
||||
|
|
|
@ -72,7 +72,7 @@ import TriggerOrderMaxButton from './TriggerOrderMaxButton'
|
|||
import TradePriceDifference from '@components/shared/TradePriceDifference'
|
||||
import { getTokenBalance } from '@components/swap/TriggerSwapForm'
|
||||
import useMangoAccountAccounts from 'hooks/useMangoAccountAccounts'
|
||||
import useTokenPositionsFull from 'hooks/useTokenPositionsFull'
|
||||
import useTokenPositionsFull from 'hooks/useAccountPositionsFull'
|
||||
import AccountSlotsFullNotification from '@components/shared/AccountSlotsFullNotification'
|
||||
import DepositWithdrawModal from '@components/modals/DepositWithdrawModal'
|
||||
import CreateAccountModal from '@components/modals/CreateAccountModal'
|
||||
|
@ -111,7 +111,8 @@ type FormErrors = Partial<Record<keyof TradeForm, string>>
|
|||
const AdvancedTradeForm = () => {
|
||||
const { t } = useTranslation(['common', 'settings', 'swap', 'trade'])
|
||||
const { mangoAccount, mangoAccountAddress } = useMangoAccount()
|
||||
const { usedSerum3, totalSerum3 } = useMangoAccountAccounts()
|
||||
const { usedSerum3, totalSerum3, usedPerps, totalPerps } =
|
||||
useMangoAccountAccounts()
|
||||
const tradeForm = mangoStore((s) => s.tradeForm)
|
||||
const [placingOrder, setPlacingOrder] = useState(false)
|
||||
const [formErrors, setFormErrors] = useState<FormErrors>({})
|
||||
|
@ -144,6 +145,17 @@ const AdvancedTradeForm = () => {
|
|||
)
|
||||
const perpMax = usePerpMarketMax(mangoAccount, selectedMarket, tradeForm.side)
|
||||
|
||||
const baseBank = useMemo(() => {
|
||||
const group = mangoStore.getState().group
|
||||
if (!group || !selectedMarket || selectedMarket instanceof PerpMarket)
|
||||
return
|
||||
const bank = group.getFirstBankByTokenIndex(selectedMarket.baseTokenIndex)
|
||||
return bank
|
||||
}, [selectedMarket])
|
||||
|
||||
// check for available account token slots
|
||||
const tokenPositionsFull = useTokenPositionsFull([baseBank, quoteBank])
|
||||
|
||||
// check for available serum account slots if serum market
|
||||
const serumSlotsFull = useMemo(() => {
|
||||
if (!selectedMarket || selectedMarket instanceof PerpMarket) return false
|
||||
|
@ -153,15 +165,14 @@ const AdvancedTradeForm = () => {
|
|||
return usedSerum3.length >= totalSerum3.length && !hasSlot
|
||||
}, [usedSerum3, totalSerum3, selectedMarket])
|
||||
|
||||
const baseBank = useMemo(() => {
|
||||
const group = mangoStore.getState().group
|
||||
if (!group || !selectedMarket || selectedMarket instanceof PerpMarket)
|
||||
return
|
||||
const bank = group.getFirstBankByTokenIndex(selectedMarket.baseTokenIndex)
|
||||
return bank
|
||||
}, [selectedMarket])
|
||||
|
||||
const tokenPositionsFull = useTokenPositionsFull([baseBank, quoteBank])
|
||||
// check for available perp account slots if perp market
|
||||
const perpSlotsFull = useMemo(() => {
|
||||
if (!selectedMarket || selectedMarket instanceof Serum3Market) return false
|
||||
const hasSlot = usedPerps.find(
|
||||
(market) => market.marketIndex === selectedMarket.perpMarketIndex,
|
||||
)
|
||||
return usedPerps.length >= totalPerps.length && !hasSlot
|
||||
}, [usedPerps, totalPerps, selectedMarket])
|
||||
|
||||
const setTradeType = useCallback(
|
||||
(tradeType: OrderTypes | TriggerOrderTypes) => {
|
||||
|
@ -1071,9 +1082,14 @@ const AdvancedTradeForm = () => {
|
|||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{serumSlotsFull &&
|
||||
selectedMarket instanceof Serum3Market &&
|
||||
mangoAccountAddress ? (
|
||||
{perpSlotsFull && mangoAccountAddress ? (
|
||||
<div className="mb-4 px-4">
|
||||
<AccountSlotsFullNotification
|
||||
message={t('trade:error-perp-positions-full')}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{serumSlotsFull && mangoAccountAddress ? (
|
||||
<div className="mb-4 px-4">
|
||||
<AccountSlotsFullNotification
|
||||
message={t('trade:error-serum-positions-full')}
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
"edit-order": "Edit Order",
|
||||
"error-no-long": "No long position to reduce",
|
||||
"error-no-short": "No borrow position to reduce",
|
||||
"error-serum-positions-full": "You've used all of your spot market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-perp-positions-full": "You've used all of your available perp market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-serum-positions-full": "You've used all of your available spot market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-trigger-above": "Trigger price must be above oracle price",
|
||||
"error-trigger-below": "Trigger price must be below oracle price",
|
||||
"est-liq-price": "Est. Liq. Price",
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
"edit-order": "Edit Order",
|
||||
"error-no-long": "No long position to reduce",
|
||||
"error-no-short": "No borrow position to reduce",
|
||||
"error-serum-positions-full": "You've used all of your spot market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-perp-positions-full": "You've used all of your available perp market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-serum-positions-full": "You've used all of your available spot market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-trigger-above": "Trigger price must be above oracle price",
|
||||
"error-trigger-below": "Trigger price must be below oracle price",
|
||||
"est-liq-price": "Est. Liq. Price",
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
"edit-order": "Edit Order",
|
||||
"error-no-long": "No long position to reduce",
|
||||
"error-no-short": "No borrow position to reduce",
|
||||
"error-serum-positions-full": "You've used all of your spot market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-perp-positions-full": "You've used all of your available perp market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-serum-positions-full": "You've used all of your available spot market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-trigger-above": "Trigger price must be above oracle price",
|
||||
"error-trigger-below": "Trigger price must be below oracle price",
|
||||
"est-liq-price": "Est. Liq. Price",
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
"error-no-short": "无做空持仓可减少",
|
||||
"error-trigger-above": "触发价格必须高于预言机价格",
|
||||
"error-trigger-below": "触发价格必须低于预言机价格",
|
||||
"error-serum-positions-full": "You've used all of your spot market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-perp-positions-full": "You've used all of your available perp market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-serum-positions-full": "You've used all of your available spot market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"est-liq-price": "预计清算价格",
|
||||
"est-slippage": "预计下滑",
|
||||
"falls-to": "下降至",
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
"error-no-short": "無做空持倉可減少",
|
||||
"error-trigger-above": "觸發價格必須高於預言機價格",
|
||||
"error-trigger-below": "觸發價格必須低於預言機價格",
|
||||
"error-serum-positions-full": "You've used all of your spot market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-perp-positions-full": "You've used all of your available perp market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"error-serum-positions-full": "You've used all of your available spot market account slots. Close unused slots to trade this market or open a new account.",
|
||||
"est-liq-price": "預計清算價格",
|
||||
"est-slippage": "預計下滑",
|
||||
"falls-to": "下降至",
|
||||
|
|
Loading…
Reference in New Issue