add slippage presets
This commit is contained in:
parent
33ae76ac98
commit
9b7fa7a539
|
@ -19,7 +19,7 @@ const Button: FunctionComponent<ButtonProps> = ({
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
className={`${className} px-6 py-2 bg-th-bkg-4 rounded-full text-th-fgd-1
|
className={`${className} px-6 py-2 bg-th-bkg-4 rounded-full text-th-fgd-1
|
||||||
hover:brightness-[1.15] focus:outline-none disabled:bg-th-bkg-4
|
hover:brightness-[1.15] focus:outline-none disabled:bg-th-bkg-4
|
||||||
disabled:text-th-fgd-4 disabled:cursor-not-allowed`}
|
disabled:text-th-fgd-4 disabled:cursor-not-allowed disabled:hover:brightness-100`}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
@ -18,7 +18,7 @@ const ButtonGroup: FunctionComponent<ButtonGroupProps> = ({
|
||||||
return (
|
return (
|
||||||
<div className="bg-th-bkg-3 rounded-md">
|
<div className="bg-th-bkg-3 rounded-md">
|
||||||
<div className="flex relative">
|
<div className="flex relative">
|
||||||
{activeValue ? (
|
{activeValue && values.includes(activeValue) ? (
|
||||||
<div
|
<div
|
||||||
className={`absolute bg-th-bkg-4 default-transition h-full left-0 top-0 rounded-md transform`}
|
className={`absolute bg-th-bkg-4 default-transition h-full left-0 top-0 rounded-md transform`}
|
||||||
style={{
|
style={{
|
||||||
|
|
|
@ -122,6 +122,8 @@ export default function AdvancedTradeForm({
|
||||||
clamp(parseFloat(maxSlippage), 0, 1) * 100
|
clamp(parseFloat(maxSlippage), 0, 1) * 100
|
||||||
)
|
)
|
||||||
const [editMaxSlippage, setEditMaxSlippage] = useState(false)
|
const [editMaxSlippage, setEditMaxSlippage] = useState(false)
|
||||||
|
const [showCustomSlippageForm, setShowCustomSlippageForm] = useState(false)
|
||||||
|
const slippagePresets = ['1', '1.5', '2', '2.5', '3']
|
||||||
|
|
||||||
const saveMaxSlippage = (slippage) => {
|
const saveMaxSlippage = (slippage) => {
|
||||||
setMaxSlippage(clamp(slippage / 100, 0, 1).toString())
|
setMaxSlippage(clamp(slippage / 100, 0, 1).toString())
|
||||||
|
@ -1003,14 +1005,31 @@ export default function AdvancedTradeForm({
|
||||||
{tradeType === 'Market' && priceImpact ? (
|
{tradeType === 'Market' && priceImpact ? (
|
||||||
<div className="col-span-12 md:col-span-10 md:col-start-3 mt-4">
|
<div className="col-span-12 md:col-span-10 md:col-start-3 mt-4">
|
||||||
{editMaxSlippage ? (
|
{editMaxSlippage ? (
|
||||||
<>
|
<div className="flex items-end">
|
||||||
<div className="mb-1 text-xs text-th-fgd-3">Max Slippage</div>
|
<div className="w-full">
|
||||||
<div className="flex">
|
<div className="flex justify-between mb-1">
|
||||||
|
<div className="text-xs text-th-fgd-3">
|
||||||
|
{t('max-slippage')}
|
||||||
|
</div>
|
||||||
|
{!isMobile ? (
|
||||||
|
<LinkButton
|
||||||
|
className="font-normal text-xs"
|
||||||
|
onClick={() =>
|
||||||
|
setShowCustomSlippageForm(!showCustomSlippageForm)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{showCustomSlippageForm ? t('presets') : t('custom')}
|
||||||
|
</LinkButton>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
{showCustomSlippageForm || isMobile ? (
|
||||||
<Input
|
<Input
|
||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0"
|
||||||
max="100"
|
max="100"
|
||||||
onChange={(e) => setMaxSlippagePercentage(e.target.value)}
|
onChange={(e) =>
|
||||||
|
setMaxSlippagePercentage(e.target.value)
|
||||||
|
}
|
||||||
suffix={
|
suffix={
|
||||||
<div className="font-bold text-base text-th-fgd-3">
|
<div className="font-bold text-base text-th-fgd-3">
|
||||||
%
|
%
|
||||||
|
@ -1018,20 +1037,29 @@ export default function AdvancedTradeForm({
|
||||||
}
|
}
|
||||||
value={maxSlippagePercentage}
|
value={maxSlippagePercentage}
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<ButtonGroup
|
||||||
|
activeValue={maxSlippagePercentage.toString()}
|
||||||
|
className="h-10"
|
||||||
|
onChange={(p) => setMaxSlippagePercentage(p)}
|
||||||
|
unit="%"
|
||||||
|
values={slippagePresets}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<Button
|
<Button
|
||||||
className="ml-2"
|
className="h-10 ml-3"
|
||||||
onClick={() => saveMaxSlippage(maxSlippagePercentage)}
|
onClick={() => saveMaxSlippage(maxSlippagePercentage)}
|
||||||
>
|
>
|
||||||
{t('save')}
|
{t('save')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{isPerpMarket ? (
|
{isPerpMarket ? (
|
||||||
<div className="flex justify-between mb-1 text-th-fgd-3 text-xs">
|
<div className="flex justify-between mb-1 text-th-fgd-3 text-xs">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
Max Slippage
|
{t('max-slippage')}
|
||||||
<Tooltip content="If price slips more than your max slippage, your order will be partially filled up to that price.">
|
<Tooltip content="If price slips more than your max slippage, your order will be partially filled up to that price.">
|
||||||
<div className="outline-none focus:outline-none">
|
<div className="outline-none focus:outline-none">
|
||||||
<InformationCircleIcon className="h-4 w-4 ml-1.5 text-th-fgd-3" />
|
<InformationCircleIcon className="h-4 w-4 ml-1.5 text-th-fgd-3" />
|
||||||
|
|
|
@ -55,8 +55,8 @@
|
||||||
"close-and-long": "Close position and open long",
|
"close-and-long": "Close position and open long",
|
||||||
"close-and-short": "Close position and open short",
|
"close-and-short": "Close position and open short",
|
||||||
"close-confirm": "Are you sure you want to market close your {{config_name}} position?",
|
"close-confirm": "Are you sure you want to market close your {{config_name}} position?",
|
||||||
"close-open-long": "100% close position and Open {{size}} {{symbol}} long",
|
"close-open-long": "100% close position and open {{size}} {{symbol}} long",
|
||||||
"close-open-short": "100% close position and Open {{size}} {{symbol}} short",
|
"close-open-short": "100% close position and open {{size}} {{symbol}} short",
|
||||||
"close-position": "Close Position",
|
"close-position": "Close Position",
|
||||||
"collateral-available": "Collateral Available",
|
"collateral-available": "Collateral Available",
|
||||||
"collateral-available-tip-desc": "The collateral value that can be used to take on leverage. Assets carry different collateral weights depending on the risk they present to the platform.",
|
"collateral-available-tip-desc": "The collateral value that can be used to take on leverage. Assets carry different collateral weights depending on the risk they present to the platform.",
|
||||||
|
@ -178,6 +178,7 @@
|
||||||
"max": "Max",
|
"max": "Max",
|
||||||
"max-borrow": "Max Borrow Amount",
|
"max-borrow": "Max Borrow Amount",
|
||||||
"max-depth-bps": "Max Depth Bps",
|
"max-depth-bps": "Max Depth Bps",
|
||||||
|
"max-slippage": "Max Slippage",
|
||||||
"max-with-borrow": "Max With Borrow",
|
"max-with-borrow": "Max With Borrow",
|
||||||
"minutes": "mins",
|
"minutes": "mins",
|
||||||
"missing-price": "Missing price",
|
"missing-price": "Missing price",
|
||||||
|
@ -239,6 +240,7 @@
|
||||||
"position-size": "Position Size",
|
"position-size": "Position Size",
|
||||||
"positions": "Positions",
|
"positions": "Positions",
|
||||||
"post": "Post",
|
"post": "Post",
|
||||||
|
"presets": "Presets",
|
||||||
"price": "Price",
|
"price": "Price",
|
||||||
"price-expect": "The price you receive may be worse than you expect and full execution is not guaranteed. Max slippage is 2.5% for your safety. The part of your position with slippage beyond 2.5% will not be closed.",
|
"price-expect": "The price you receive may be worse than you expect and full execution is not guaranteed. Max slippage is 2.5% for your safety. The part of your position with slippage beyond 2.5% will not be closed.",
|
||||||
"price-impact": "Est. Price Impact",
|
"price-impact": "Est. Price Impact",
|
||||||
|
|
|
@ -176,6 +176,7 @@
|
||||||
"max": "Maximo",
|
"max": "Maximo",
|
||||||
"max-borrow": "Monto máximo del préstamo",
|
"max-borrow": "Monto máximo del préstamo",
|
||||||
"max-depth-bps": "Max Depth Bps",
|
"max-depth-bps": "Max Depth Bps",
|
||||||
|
"max-slippage": "Máximo deslizamiento",
|
||||||
"max-with-borrow": "Máximo con préstamo",
|
"max-with-borrow": "Máximo con préstamo",
|
||||||
"minutes": "mins",
|
"minutes": "mins",
|
||||||
"missing-price": "Falta el precio",
|
"missing-price": "Falta el precio",
|
||||||
|
@ -237,6 +238,7 @@
|
||||||
"position-size": "Tamaño de la posición",
|
"position-size": "Tamaño de la posición",
|
||||||
"positions": "Posiciones",
|
"positions": "Posiciones",
|
||||||
"post": "Correo",
|
"post": "Correo",
|
||||||
|
"presets": "Preajustes",
|
||||||
"price": "Precio",
|
"price": "Precio",
|
||||||
"price-expect": "El precio que reciba puede ser mayor o menor de lo esperado.",
|
"price-expect": "El precio que reciba puede ser mayor o menor de lo esperado.",
|
||||||
"price-impact": "Est. Impacto en el precio:",
|
"price-impact": "Est. Impacto en el precio:",
|
||||||
|
|
|
@ -176,6 +176,7 @@
|
||||||
"max": "最多",
|
"max": "最多",
|
||||||
"max-borrow": "最多借贷数量",
|
"max-borrow": "最多借贷数量",
|
||||||
"max-depth-bps": "最大深度Bps",
|
"max-depth-bps": "最大深度Bps",
|
||||||
|
"max-slippage": "最多滑移",
|
||||||
"max-with-borrow": "借用最大值",
|
"max-with-borrow": "借用最大值",
|
||||||
"minutes": "分钟",
|
"minutes": "分钟",
|
||||||
"missing-price": "没有价格",
|
"missing-price": "没有价格",
|
||||||
|
@ -237,6 +238,7 @@
|
||||||
"position-size": "当前持仓数量",
|
"position-size": "当前持仓数量",
|
||||||
"positions": "当前持仓",
|
"positions": "当前持仓",
|
||||||
"post": "Post",
|
"post": "Post",
|
||||||
|
"presets": "预设",
|
||||||
"price": "价格",
|
"price": "价格",
|
||||||
"price-expect": "成交前价格也许会有变化。",
|
"price-expect": "成交前价格也许会有变化。",
|
||||||
"price-impact": "预计价格影响",
|
"price-impact": "预计价格影响",
|
||||||
|
|
|
@ -176,6 +176,7 @@
|
||||||
"max": "最多",
|
"max": "最多",
|
||||||
"max-borrow": "最多借貸數量",
|
"max-borrow": "最多借貸數量",
|
||||||
"max-depth-bps": "最大深度Bps",
|
"max-depth-bps": "最大深度Bps",
|
||||||
|
"max-slippage": "最多滑移",
|
||||||
"max-with-borrow": "借用最大值",
|
"max-with-borrow": "借用最大值",
|
||||||
"minutes": "分鐘",
|
"minutes": "分鐘",
|
||||||
"missing-price": "沒有價格",
|
"missing-price": "沒有價格",
|
||||||
|
@ -237,6 +238,7 @@
|
||||||
"position-size": "當前持倉數量",
|
"position-size": "當前持倉數量",
|
||||||
"positions": "當前持倉",
|
"positions": "當前持倉",
|
||||||
"post": "Post",
|
"post": "Post",
|
||||||
|
"presets": "預設",
|
||||||
"price": "價格",
|
"price": "價格",
|
||||||
"price-expect": "成交前價格也許會有變化。",
|
"price-expect": "成交前價格也許會有變化。",
|
||||||
"price-impact": "預計價格影響",
|
"price-impact": "預計價格影響",
|
||||||
|
|
Loading…
Reference in New Issue