mango-ui-v3/components/trade_form/SimpleTradeForm.tsx

745 lines
23 KiB
TypeScript
Raw Normal View History

2021-09-24 05:24:17 -07:00
import { useState, useEffect, useRef, useMemo } from 'react'
2021-09-26 06:20:51 -07:00
import useIpAddress from '../../hooks/useIpAddress'
2021-09-24 05:24:17 -07:00
import {
getTokenBySymbol,
getMarketIndexBySymbol,
I80F48,
PerpMarket,
} from '@blockworks-foundation/mango-client'
2021-09-26 06:20:51 -07:00
import { notify } from '../../utils/notifications'
import { calculateTradePrice, getDecimalCount, sleep } from '../../utils'
import { floorToDecimal, capitalize } from '../../utils/index'
2021-09-26 06:20:51 -07:00
import useMangoStore from '../../stores/useMangoStore'
import Button from '../Button'
import Input from '../Input'
2021-09-24 05:24:17 -07:00
import { Market } from '@project-serum/serum'
import Big from 'big.js'
2021-09-26 06:20:51 -07:00
import MarketFee from '../MarketFee'
import Loading from '../Loading'
import { ElementTitle } from '../styles'
import ButtonGroup from '../ButtonGroup'
import Checkbox from '../Checkbox'
2021-09-25 02:40:35 -07:00
import OrderSideTabs from './OrderSideTabs'
2021-09-26 06:20:51 -07:00
import Tooltip from '../Tooltip'
2021-09-30 07:21:45 -07:00
import EstPriceImpact from './EstPriceImpact'
import { useTranslation } from 'next-i18next'
2021-09-24 05:24:17 -07:00
2021-09-25 02:40:35 -07:00
export default function SimpleTradeForm({ initLeverage }) {
const { t } = useTranslation('common')
2021-09-24 05:24:17 -07:00
const set = useMangoStore((s) => s.set)
2021-11-22 15:54:51 -08:00
const { ipAllowed, spotAllowed } = useIpAddress()
2021-09-24 05:24:17 -07:00
const connected = useMangoStore((s) => s.wallet.connected)
const actions = useMangoStore((s) => s.actions)
const groupConfig = useMangoStore((s) => s.selectedMangoGroup.config)
const marketConfig = useMangoStore((s) => s.selectedMarket.config)
const walletTokens = useMangoStore((s) => s.wallet.tokens)
2021-09-24 05:24:17 -07:00
const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current)
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
const mangoClient = useMangoStore((s) => s.connection.client)
const mangoCache = useMangoStore((s) => s.selectedMangoGroup.cache)
const marketIndex = getMarketIndexBySymbol(
groupConfig,
marketConfig.baseSymbol
)
const market = useMangoStore((s) => s.selectedMarket.current)
2021-09-25 05:41:04 -07:00
const { side, baseSize, quoteSize, price, triggerPrice, tradeType } =
2021-09-24 05:24:17 -07:00
useMangoStore((s) => s.tradeForm)
const [postOnly, setPostOnly] = useState(false)
const [ioc, setIoc] = useState(false)
const [submitting, setSubmitting] = useState(false)
const [positionSizePercent, setPositionSizePercent] = useState('')
const [showStopForm, setShowStopForm] = useState(false)
2021-09-25 02:40:35 -07:00
const [showTakeProfitForm, setShowTakeProfitForm] = useState(false)
2021-09-24 05:24:17 -07:00
const [stopSizePercent, setStopSizePercent] = useState('5%')
2021-09-25 05:41:04 -07:00
const [reduceOnly, setReduceOnly] = useState(false)
const [spotMargin, setSpotMargin] = useState(false)
const [insufficientSol, setinsufficientSol] = useState(false)
2021-09-24 05:24:17 -07:00
const orderBookRef = useRef(useMangoStore.getState().selectedMarket.orderBook)
const orderbook = orderBookRef.current
2021-09-24 05:24:17 -07:00
useEffect(
() =>
useMangoStore.subscribe(
// @ts-ignore
(orderBook) => (orderBookRef.current = orderBook),
(state) => state.selectedMarket.orderBook
),
[]
)
useEffect(() => {
const walletSol = walletTokens.find((a) => a.config.symbol === 'SOL')
walletSol ? setinsufficientSol(walletSol.uiBalance < 0.01) : null
}, [walletTokens])
2021-09-25 05:41:04 -07:00
useEffect(() => {
if (tradeType !== 'Market' && tradeType !== 'Limit') {
setTradeType('Limit')
}
}, [])
2021-09-24 05:24:17 -07:00
useEffect(() => {
if (tradeType === 'Market') {
set((s) => {
s.tradeForm.price = ''
})
}
}, [tradeType, set])
const setSide = (side) =>
set((s) => {
s.tradeForm.side = side
})
const setBaseSize = (baseSize) =>
set((s) => {
if (!Number.isNaN(parseFloat(baseSize))) {
s.tradeForm.baseSize = parseFloat(baseSize)
} else {
s.tradeForm.baseSize = baseSize
}
})
const setQuoteSize = (quoteSize) =>
set((s) => {
if (!Number.isNaN(parseFloat(quoteSize))) {
s.tradeForm.quoteSize = parseFloat(quoteSize)
} else {
s.tradeForm.quoteSize = quoteSize
}
})
const setPrice = (price) =>
set((s) => {
if (!Number.isNaN(parseFloat(price))) {
s.tradeForm.price = parseFloat(price)
} else {
s.tradeForm.price = price
}
})
const setTriggerPrice = (price) =>
2021-09-24 05:24:17 -07:00
set((s) => {
if (!Number.isNaN(parseFloat(price))) {
s.tradeForm.tripperPrice = parseFloat(price)
2021-09-24 05:24:17 -07:00
} else {
s.tradeForm.tripperPrice = price
2021-09-24 05:24:17 -07:00
}
})
const setTradeType = (type) =>
set((s) => {
s.tradeForm.tradeType = type
})
const markPriceRef = useRef(useMangoStore.getState().selectedMarket.markPrice)
const markPrice = markPriceRef.current
useEffect(
() =>
useMangoStore.subscribe(
(markPrice) => (markPriceRef.current = markPrice as number),
(state) => state.selectedMarket.markPrice
),
[]
)
let minOrderSize = '0'
if (market instanceof Market && market.minOrderSize) {
minOrderSize = market.minOrderSize.toString()
} else if (market instanceof PerpMarket) {
const baseDecimals = getTokenBySymbol(
groupConfig,
marketConfig.baseSymbol
).decimals
minOrderSize = new Big(market.baseLotSize)
.div(new Big(10).pow(baseDecimals))
.toString()
}
const sizeDecimalCount = getDecimalCount(minOrderSize)
let tickSize = 1
if (market instanceof Market) {
tickSize = market.tickSize
} else if (market instanceof PerpMarket) {
const baseDecimals = getTokenBySymbol(
groupConfig,
marketConfig.baseSymbol
).decimals
const quoteDecimals = getTokenBySymbol(
groupConfig,
groupConfig.quoteSymbol
).decimals
const nativeToUi = new Big(10).pow(baseDecimals - quoteDecimals)
const lotsToNative = new Big(market.quoteLotSize).div(
new Big(market.baseLotSize)
)
tickSize = lotsToNative.mul(nativeToUi).toNumber()
}
const onSetPrice = (price: number | '') => {
setPrice(price)
if (!price) return
if (baseSize) {
onSetBaseSize(baseSize)
}
}
const onSetBaseSize = (baseSize: number | '') => {
const { price } = useMangoStore.getState().tradeForm
setPositionSizePercent('')
setBaseSize(baseSize)
if (!baseSize) {
setQuoteSize('')
return
}
const usePrice = Number(price) || markPrice
if (!usePrice) {
setQuoteSize('')
return
}
const rawQuoteSize = baseSize * usePrice
setQuoteSize(rawQuoteSize.toFixed(6))
}
const onSetQuoteSize = (quoteSize: number | '') => {
setPositionSizePercent('')
setQuoteSize(quoteSize)
if (!quoteSize) {
setBaseSize('')
return
}
if (!Number(price) && tradeType === 'Limit') {
setBaseSize('')
return
}
const usePrice = Number(price) || markPrice
const rawBaseSize = quoteSize / usePrice
const baseSize = quoteSize && floorToDecimal(rawBaseSize, sizeDecimalCount)
setBaseSize(baseSize)
}
const onTradeTypeChange = (tradeType) => {
setTradeType(tradeType)
setPositionSizePercent('')
if (tradeType === 'Market') {
setIoc(true)
setPrice('')
} else {
const priceOnBook = side === 'buy' ? orderbook?.asks : orderbook?.bids
if (priceOnBook && priceOnBook.length > 0 && priceOnBook[0].length > 0) {
setPrice(priceOnBook[0][0])
}
setIoc(false)
}
}
const postOnChange = (checked) => {
if (checked) {
setIoc(false)
}
setPostOnly(checked)
}
const iocOnChange = (checked) => {
if (checked) {
setPostOnly(false)
}
setIoc(checked)
}
2021-09-25 05:41:04 -07:00
const reduceOnChange = (checked) => {
if (checked) {
setReduceOnly(false)
}
setReduceOnly(checked)
}
2021-09-24 05:24:17 -07:00
async function onSubmit() {
if (!price && tradeType === 'Limit') {
notify({
title: t('missing-price'),
2021-09-24 05:24:17 -07:00
type: 'error',
})
return
} else if (!baseSize) {
notify({
title: t('missing-size'),
2021-09-24 05:24:17 -07:00
type: 'error',
})
return
}
const mangoAccount = useMangoStore.getState().selectedMangoAccount.current
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
const { askInfo, bidInfo } = useMangoStore.getState().selectedMarket
const wallet = useMangoStore.getState().wallet.current
if (!wallet || !mangoGroup || !mangoAccount || !market) return
setSubmitting(true)
try {
const orderPrice = calculateTradePrice(
marketConfig.kind,
2021-09-24 05:24:17 -07:00
tradeType,
orderbook,
baseSize,
side,
price
)
if (!orderPrice) {
notify({
title: t('price-unavailable'),
description: t('try-again'),
2021-09-24 05:24:17 -07:00
type: 'error',
})
}
const orderType = ioc ? 'ioc' : postOnly ? 'postOnly' : 'limit'
let txid
if (market instanceof Market) {
txid = await mangoClient.placeSpotOrder(
mangoGroup,
mangoAccount,
mangoGroup.mangoCache,
market,
wallet,
side,
orderPrice,
baseSize,
orderType
)
} else {
txid = await mangoClient.placePerpOrder(
mangoGroup,
mangoAccount,
mangoGroup.mangoCache,
market,
wallet,
side,
orderPrice,
baseSize,
orderType,
0,
side === 'buy' ? askInfo : bidInfo
)
}
notify({ title: t('successfully-placed'), txid })
2021-09-24 05:24:17 -07:00
setPrice('')
onSetBaseSize('')
} catch (e) {
notify({
title: t('order-error'),
2021-09-24 05:24:17 -07:00
description: e.message,
txid: e.txid,
type: 'error',
})
} finally {
await sleep(600)
actions.reloadMangoAccount()
actions.loadMarketFills()
setSubmitting(false)
}
}
const { max, deposits, borrows } = useMemo(() => {
if (!mangoAccount) return { max: 0 }
const priceOrDefault = price
? I80F48.fromNumber(price)
: mangoGroup.getPrice(marketIndex, mangoCache)
const {
max: maxQuote,
deposits,
borrows,
} = mangoAccount.getMaxLeverageForMarket(
mangoGroup,
mangoCache,
marketIndex,
market,
side,
priceOrDefault
)
if (maxQuote.toNumber() <= 0) return { max: 0 }
// multiply the maxQuote by a scaler value to account for
// srm fees or rounding issues in getMaxLeverageForMarket
const maxScaler = market instanceof PerpMarket ? 0.99 : 0.95
const scaledMax = price
? (maxQuote.toNumber() * maxScaler) / price
: (maxQuote.toNumber() * maxScaler) /
mangoGroup.getPrice(marketIndex, mangoCache).toNumber()
return { max: scaledMax, deposits, borrows }
}, [mangoAccount, mangoGroup, mangoCache, marketIndex, market, side, price])
const handleSetPositionSize = (percent) => {
setPositionSizePercent(percent)
const baseSize = max * (parseInt(percent) / 100)
const step = parseFloat(minOrderSize)
const roundedSize = (Math.round(baseSize / step) * step).toFixed(
sizeDecimalCount
)
setBaseSize(parseFloat(roundedSize))
const usePrice = Number(price) || markPrice
if (!usePrice) {
setQuoteSize('')
}
const rawQuoteSize = parseFloat(roundedSize) * usePrice
setQuoteSize(rawQuoteSize.toFixed(6))
}
const percentToClose = (size, total) => {
return (size / total) * 100
}
const roundedDeposits = parseFloat(deposits?.toFixed(sizeDecimalCount))
const roundedBorrows = parseFloat(borrows?.toFixed(sizeDecimalCount))
const closeDepositString =
percentToClose(baseSize, roundedDeposits) > 100
? t('close-open-short', {
size: (+baseSize - roundedDeposits).toFixed(sizeDecimalCount),
symbol: marketConfig.baseSymbol,
})
: `${percentToClose(baseSize, roundedDeposits).toFixed(0)}% ${t(
'close-position'
).toLowerCase()}`
2021-09-24 05:24:17 -07:00
const closeBorrowString =
percentToClose(baseSize, roundedBorrows) > 100
? t('close-open-long', {
size: (+baseSize - roundedDeposits).toFixed(sizeDecimalCount),
symbol: marketConfig.baseSymbol,
})
: `${percentToClose(baseSize, roundedBorrows).toFixed(0)}% ${t(
'close-position'
).toLowerCase()}`
2021-09-24 05:24:17 -07:00
const disabledTradeButton =
(!price && tradeType === 'Limit') ||
!baseSize ||
!connected ||
submitting ||
!mangoAccount ||
insufficientSol
2021-09-24 05:24:17 -07:00
2021-09-25 02:40:35 -07:00
const hideProfitStop =
2021-09-24 05:24:17 -07:00
(side === 'sell' && baseSize === roundedDeposits) ||
(side === 'buy' && baseSize === roundedBorrows)
2021-11-22 15:54:51 -08:00
const canTrade = ipAllowed || (market instanceof Market && spotAllowed)
2021-09-26 06:20:51 -07:00
return (
2021-09-25 05:41:04 -07:00
<div className="flex flex-col h-full">
2021-09-24 05:24:17 -07:00
<ElementTitle>
2021-09-25 02:40:35 -07:00
{marketConfig.name}
2021-09-24 05:24:17 -07:00
<span className="border border-th-primary ml-2 px-1 py-0.5 rounded text-xs text-th-primary">
{initLeverage}x
</span>
</ElementTitle>
2021-09-27 05:43:23 -07:00
<OrderSideTabs isSimpleForm onChange={setSide} side={side} />
2021-09-25 05:41:04 -07:00
<div className="grid grid-cols-12 gap-2 text-left">
2021-09-30 07:21:45 -07:00
<div className="col-span-6">
<label className="text-xxs text-th-fgd-3">{t('type')}</label>
2021-09-24 05:24:17 -07:00
<ButtonGroup
activeValue={tradeType}
2021-09-30 07:21:45 -07:00
className="h-10"
2021-09-24 05:24:17 -07:00
onChange={(p) => onTradeTypeChange(p)}
values={['Limit', 'Market']}
/>
</div>
2021-09-30 07:21:45 -07:00
<div className="col-span-6">
<label className="text-xxs text-th-fgd-3">{t('price')}</label>
2021-09-24 05:24:17 -07:00
<Input
type="number"
min="0"
step={tickSize}
onChange={(e) => onSetPrice(e.target.value)}
value={price}
disabled={tradeType === 'Market'}
2021-09-26 06:20:51 -07:00
placeholder={tradeType === 'Market' ? markPrice : null}
2021-09-24 05:24:17 -07:00
prefix={
<img
src={`/assets/icons/${groupConfig.quoteSymbol.toLowerCase()}.svg`}
width="16"
height="16"
/>
}
/>
</div>
2021-09-30 07:21:45 -07:00
<div className="col-span-6">
<label className="text-xxs text-th-fgd-3">{t('size')}</label>
2021-09-30 07:21:45 -07:00
<Input
type="number"
min="0"
step={minOrderSize}
onChange={(e) => onSetBaseSize(e.target.value)}
value={baseSize}
prefix={
<img
src={`/assets/icons/${marketConfig.baseSymbol.toLowerCase()}.svg`}
width="16"
height="16"
/>
}
/>
2021-09-24 05:24:17 -07:00
</div>
2021-09-30 07:21:45 -07:00
<div className="col-span-6">
<label className="text-xxs text-th-fgd-3">{t('quantity')}</label>
2021-09-30 07:21:45 -07:00
<Input
type="number"
min="0"
step={minOrderSize}
onChange={(e) => onSetQuoteSize(e.target.value)}
value={quoteSize}
prefix={
<img
src={`/assets/icons/${groupConfig.quoteSymbol.toLowerCase()}.svg`}
width="16"
height="16"
/>
}
2021-09-24 05:24:17 -07:00
/>
2021-09-30 07:21:45 -07:00
</div>
<div className="col-span-12">
<div className="-mt-1">
<ButtonGroup
activeValue={positionSizePercent}
onChange={(p) => handleSetPositionSize(p)}
unit="%"
values={['10', '25', '50', '75', '100']}
/>
</div>
2021-09-24 05:24:17 -07:00
{side === 'sell' ? (
<div className="text-th-fgd-3 text-xs tracking-normal mt-2">
<span>{roundedDeposits > 0 ? closeDepositString : null}</span>
</div>
) : (
<div className="text-th-fgd-3 text-xs tracking-normal mt-2">
<span>{roundedBorrows > 0 ? closeBorrowString : null}</span>
</div>
)}
2021-09-25 05:41:04 -07:00
<div className="flex items-center space-x-1">
2021-09-25 02:40:35 -07:00
{!hideProfitStop ? (
2021-09-25 05:41:04 -07:00
<div
className={`${
showStopForm ? 'bg-th-bkg-4' : 'bg-th-bkg-3'
2021-09-30 07:21:45 -07:00
} mt-1 p-2 rounded-md w-1/2`}
2021-09-25 05:41:04 -07:00
>
2021-09-26 06:20:51 -07:00
<Checkbox
checked={showStopForm}
onChange={(e) => setShowStopForm(e.target.checked)}
>
{t('set-stop-loss')}
2021-09-26 06:20:51 -07:00
</Checkbox>
2021-09-25 02:40:35 -07:00
</div>
) : null}
{!hideProfitStop ? (
2021-09-25 05:41:04 -07:00
<div
className={`${
showTakeProfitForm ? 'bg-th-bkg-4' : 'bg-th-bkg-3'
2021-09-30 07:21:45 -07:00
} mt-1 p-2 rounded-md w-1/2`}
2021-09-25 05:41:04 -07:00
>
2021-09-26 06:20:51 -07:00
<Checkbox
checked={showTakeProfitForm}
onChange={(e) => setShowTakeProfitForm(e.target.checked)}
>
{t('set-take-profit')}
2021-09-26 06:20:51 -07:00
</Checkbox>
2021-09-25 02:40:35 -07:00
</div>
) : null}
</div>
2021-09-24 05:24:17 -07:00
</div>
2021-09-25 02:40:35 -07:00
{showStopForm && !hideProfitStop ? (
2021-09-24 05:24:17 -07:00
<>
2021-09-30 07:21:45 -07:00
<div className="col-span-12">
<label className="text-xxs text-th-fgd-3">
{t('stop-price')}
</label>
2021-09-24 05:24:17 -07:00
<Input
type="number"
min="0"
step={tickSize}
onChange={(e) => setTriggerPrice(e.target.value)}
2021-09-25 05:41:04 -07:00
value={triggerPrice}
2021-09-24 05:24:17 -07:00
prefix={
<img
src={`/assets/icons/${groupConfig.quoteSymbol.toLowerCase()}.svg`}
width="16"
height="16"
/>
}
/>
</div>
2021-09-30 07:21:45 -07:00
<div className="col-span-12 -mt-1">
2021-09-24 05:24:17 -07:00
<ButtonGroup
activeValue={stopSizePercent}
onChange={(p) => setStopSizePercent(p)}
values={['5%', '10%', '15%', '20%', '25%']}
/>
</div>
</>
) : null}
2021-09-25 02:40:35 -07:00
{showTakeProfitForm && !hideProfitStop ? (
<>
2021-09-30 07:21:45 -07:00
<div className="col-span-12">
2021-09-25 02:40:35 -07:00
<label className="text-left text-xs text-th-fgd-3">
{t('profit-price')}
2021-09-25 02:40:35 -07:00
</label>
<Input
type="number"
min="0"
step={tickSize}
onChange={(e) => setTriggerPrice(e.target.value)}
2021-09-25 05:41:04 -07:00
value={triggerPrice}
2021-09-25 02:40:35 -07:00
prefix={
<img
src={`/assets/icons/${groupConfig.quoteSymbol.toLowerCase()}.svg`}
width="16"
height="16"
/>
}
/>
</div>
2021-09-30 07:21:45 -07:00
<div className="col-span-12 -mt-1">
2021-09-25 02:40:35 -07:00
<ButtonGroup
activeValue={stopSizePercent}
onChange={(p) => setStopSizePercent(p)}
values={['5%', '10%', '15%', '20%', '25%']}
/>
</div>
</>
) : null}
2021-09-30 07:21:45 -07:00
<div className="col-span-12 flex pt-2">
2021-09-25 05:41:04 -07:00
{tradeType === 'Limit' ? (
<>
<div className="mr-4">
2021-09-25 05:41:04 -07:00
<Tooltip
delay={250}
placement="left"
content={t('tooltip-post')}
2021-09-25 05:41:04 -07:00
>
2021-09-26 06:20:51 -07:00
<Checkbox
2021-09-25 05:41:04 -07:00
checked={postOnly}
2021-09-26 06:20:51 -07:00
onChange={(e) => postOnChange(e.target.checked)}
2021-09-25 05:41:04 -07:00
>
POST
2021-09-26 06:20:51 -07:00
</Checkbox>
2021-09-25 05:41:04 -07:00
</Tooltip>
</div>
<div className="mr-4">
2021-09-25 05:41:04 -07:00
<Tooltip
delay={250}
placement="left"
content={t('tooltip-ioc')}
2021-09-25 05:41:04 -07:00
>
2021-09-26 06:20:51 -07:00
<div className="flex items-center text-th-fgd-3 text-xs">
<Checkbox
checked={ioc}
onChange={(e) => iocOnChange(e.target.checked)}
>
IOC
</Checkbox>
</div>
2021-09-25 05:41:04 -07:00
</Tooltip>
</div>
</>
) : null}
{marketConfig.kind === 'perp' ? (
<Tooltip delay={250} placement="left" content={t('tooltip-reduce')}>
<Checkbox
checked={reduceOnly}
onChange={(e) => reduceOnChange(e.target.checked)}
2021-09-25 05:41:04 -07:00
>
Reduce Only
</Checkbox>
</Tooltip>
2021-09-25 05:41:04 -07:00
) : null}
{marketConfig.kind === 'spot' ? (
<Tooltip
delay={250}
placement="left"
content={t('tooltip-enable-margin')}
>
<Checkbox
checked={spotMargin}
onChange={(e) => setSpotMargin(e.target.checked)}
>
Margin
</Checkbox>
</Tooltip>
) : null}
2021-09-25 05:41:04 -07:00
</div>
2021-09-30 07:21:45 -07:00
{tradeType === 'Market' ? (
<div className="col-span-12">
<EstPriceImpact />
</div>
) : null}
<div className={`col-span-12 flex pt-2`}>
2021-11-22 15:54:51 -08:00
{canTrade ? (
2021-09-25 02:40:35 -07:00
<Button
disabled={disabledTradeButton}
onClick={onSubmit}
className={`${
!disabledTradeButton
? 'bg-th-bkg-2 border border-th-green hover:border-th-green-dark'
: 'border border-th-bkg-4'
} text-th-green hover:text-th-fgd-1 hover:bg-th-green-dark flex-grow`}
>
{submitting ? (
<div className="w-full">
<Loading className="mx-auto" />
</div>
) : side.toLowerCase() === 'buy' ? (
market instanceof PerpMarket ? (
`${
baseSize > 0
? `${capitalize(t('long'))} ` + baseSize
: `${capitalize(t('long'))} `
} ${marketConfig.name}`
2021-09-24 05:24:17 -07:00
) : (
`${
baseSize > 0 ? `${t('buy')} ` + baseSize : `${t('buy')} `
} ${marketConfig.baseSymbol}`
2021-09-25 02:40:35 -07:00
)
) : market instanceof PerpMarket ? (
`${
baseSize > 0
? `${capitalize(t('short'))} ` + baseSize
: `${capitalize(t('short'))} `
} ${marketConfig.name}`
2021-09-25 02:40:35 -07:00
) : (
`${
baseSize > 0 ? `${t('sell')} ` + baseSize : `${t('sell')} `
} ${marketConfig.baseSymbol}`
2021-09-25 02:40:35 -07:00
)}
</Button>
2021-09-24 05:24:17 -07:00
) : (
<div className="flex-grow">
<Tooltip content={t('country-not-allowed-tooltip')}>
<div className="flex">
<Button disabled className="flex-grow">
<span>{t('country-not-allowed')}</span>
</Button>
</div>
</Tooltip>
</div>
2021-09-24 05:24:17 -07:00
)}
</div>
{insufficientSol ? (
<div className="tiny-text text-center text-th-red mt-1 -mb-3">
You must leave enough SOL in your wallet to pay for the transaction
</div>
) : null}
2021-09-30 07:21:45 -07:00
<div className="col-span-12 flex pt-2 text-xs text-th-fgd-4">
2021-09-25 05:41:04 -07:00
<MarketFee />
2021-09-24 05:24:17 -07:00
</div>
2021-09-25 05:41:04 -07:00
</div>
2021-09-24 05:24:17 -07:00
</div>
)
}