change labels for leverage slider (#738)
This commit is contained in:
parent
000aa71e06
commit
fa4e0530c5
@ -9,17 +9,19 @@ interface Props {
|
|||||||
marginThreshold?: number
|
marginThreshold?: number
|
||||||
max: number
|
max: number
|
||||||
type: LeverageSliderType
|
type: LeverageSliderType
|
||||||
|
min: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const THUMB_WIDTH = 33
|
const THUMB_WIDTH = 33
|
||||||
|
|
||||||
function InputOverlay({ max, value, marginThreshold, type }: Props) {
|
function InputOverlay({ max, value, marginThreshold, type, min }: Props) {
|
||||||
const thumbPosPercent = max === 0 ? 0 : 100 / (max / value)
|
const thumbPosPercent = max === 0 ? 0 : 100 / ((max - min) / (value - min))
|
||||||
const thumbPadRight = (thumbPosPercent / 100) * THUMB_WIDTH
|
const thumbPadRight = (thumbPosPercent / 100) * THUMB_WIDTH
|
||||||
const markPosPercent = 100 / (max / (marginThreshold ?? 1))
|
const markPosPercent = 100 / (max / (marginThreshold ?? 1))
|
||||||
const markPadRight = (markPosPercent / 100) * THUMB_WIDTH
|
const markPadRight = (markPosPercent / 100) * THUMB_WIDTH
|
||||||
const hasPastMarginThreshold = marginThreshold ? value >= marginThreshold : undefined
|
const hasPastMarginThreshold = marginThreshold ? value >= marginThreshold : undefined
|
||||||
|
|
||||||
|
console.log(max, value)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@ -63,7 +65,8 @@ function InputOverlay({ max, value, marginThreshold, type }: Props) {
|
|||||||
style={{ left: `calc(${thumbPosPercent}% - ${thumbPadRight}px)` }}
|
style={{ left: `calc(${thumbPosPercent}% - ${thumbPadRight}px)` }}
|
||||||
>
|
>
|
||||||
{formatValue(value, {
|
{formatValue(value, {
|
||||||
maxDecimals: 2,
|
minDecimals: type !== 'margin' ? 1 : 2,
|
||||||
|
maxDecimals: type !== 'margin' ? 1 : 2,
|
||||||
abbreviated: true,
|
abbreviated: true,
|
||||||
rounded: true,
|
rounded: true,
|
||||||
suffix: type !== 'margin' ? 'x' : '',
|
suffix: type !== 'margin' ? 'x' : '',
|
||||||
|
@ -6,6 +6,7 @@ import InputOverlay from 'components/common/LeverageSlider/InputOverlay'
|
|||||||
const LEFT_MARGIN = 5
|
const LEFT_MARGIN = 5
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
min?: number
|
||||||
max: number
|
max: number
|
||||||
value: number
|
value: number
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
@ -19,6 +20,7 @@ type Props = {
|
|||||||
export type LeverageSliderType = 'margin' | 'long' | 'short'
|
export type LeverageSliderType = 'margin' | 'long' | 'short'
|
||||||
function LeverageSlider(props: Props) {
|
function LeverageSlider(props: Props) {
|
||||||
const { value, max, onChange, wrapperClassName, disabled, marginThreshold, onBlur, type } = props
|
const { value, max, onChange, wrapperClassName, disabled, marginThreshold, onBlur, type } = props
|
||||||
|
const min = props.min ?? 0
|
||||||
|
|
||||||
const handleOnChange = useCallback(
|
const handleOnChange = useCallback(
|
||||||
(event: ChangeEvent<HTMLInputElement>) => {
|
(event: ChangeEvent<HTMLInputElement>) => {
|
||||||
@ -28,7 +30,6 @@ function LeverageSlider(props: Props) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const markPosPercent = 100 / (max / (marginThreshold ?? 1))
|
const markPosPercent = 100 / (max / (marginThreshold ?? 1))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classNames(
|
className={classNames(
|
||||||
@ -49,16 +50,22 @@ function LeverageSlider(props: Props) {
|
|||||||
type='range'
|
type='range'
|
||||||
value={value.toFixed(2)}
|
value={value.toFixed(2)}
|
||||||
step={max / 101}
|
step={max / 101}
|
||||||
min={0}
|
min={min}
|
||||||
max={max}
|
max={max}
|
||||||
onChange={handleOnChange}
|
onChange={handleOnChange}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
/>
|
/>
|
||||||
<InputOverlay max={max} marginThreshold={marginThreshold} value={value} type={type} />
|
<InputOverlay
|
||||||
|
max={max}
|
||||||
|
marginThreshold={marginThreshold}
|
||||||
|
value={value}
|
||||||
|
type={type}
|
||||||
|
min={min}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={'flex w-full justify-between text-xs text-opacity-50 text-white font-bold'}>
|
<div className={'flex w-full justify-between text-xs text-opacity-50 text-white font-bold'}>
|
||||||
<span>{markPosPercent > LEFT_MARGIN ? 0 : ''}</span>
|
<span>{markPosPercent > LEFT_MARGIN ? min : ''}</span>
|
||||||
<span>{max.toFixed(2)}</span>
|
<span>{max.toFixed(type !== 'margin' ? 0 : 2)}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -46,7 +46,13 @@ export function PerpsModule() {
|
|||||||
/>
|
/>
|
||||||
<Or />
|
<Or />
|
||||||
<Text size='sm'>Position Leverage</Text>
|
<Text size='sm'>Position Leverage</Text>
|
||||||
<LeverageSlider max={10} value={leverage} onChange={setLeverage} type={tradeDirection} />
|
<LeverageSlider
|
||||||
|
min={1}
|
||||||
|
max={10}
|
||||||
|
value={leverage}
|
||||||
|
onChange={setLeverage}
|
||||||
|
type={tradeDirection}
|
||||||
|
/>
|
||||||
<LeverageButtons />
|
<LeverageButtons />
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<PerpsSummary
|
<PerpsSummary
|
||||||
|
Loading…
Reference in New Issue
Block a user