Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
604ec43f3f | ||
|
|
0deced8545 |
+15
-15
@@ -42,7 +42,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydxprotocol-testnet",
|
"dydxChainId": "dydxprotocol-testnet",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydxprotocol-testnet",
|
"dydxChainId": "dydxprotocol-testnet",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -189,7 +189,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydxprotocol-testnet",
|
"dydxChainId": "dydxprotocol-testnet",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -262,7 +262,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydxprotocol-testnet",
|
"dydxChainId": "dydxprotocol-testnet",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -335,7 +335,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydxprotocol-testnet",
|
"dydxChainId": "dydxprotocol-testnet",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -410,7 +410,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydxprotocol-testnet",
|
"dydxChainId": "dydxprotocol-testnet",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -483,7 +483,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydxprotocol-testnet",
|
"dydxChainId": "dydxprotocol-testnet",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -558,7 +558,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydx-testnet-4",
|
"dydxChainId": "dydx-testnet-4",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -637,7 +637,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydx-testnet-4",
|
"dydxChainId": "dydx-testnet-4",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -713,7 +713,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydx-testnet-4",
|
"dydxChainId": "dydx-testnet-4",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -789,7 +789,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydx-testnet-4",
|
"dydxChainId": "dydx-testnet-4",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -865,7 +865,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydx-testnet-4",
|
"dydxChainId": "dydx-testnet-4",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -941,7 +941,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydx-testnet-4",
|
"dydxChainId": "dydx-testnet-4",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -1008,7 +1008,7 @@
|
|||||||
"ethereumChainId": "5",
|
"ethereumChainId": "5",
|
||||||
"dydxChainId": "dydx-testnet-4",
|
"dydxChainId": "dydx-testnet-4",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "dYdX-api",
|
"squidIntegratorId": "dYdX-api",
|
||||||
"isMainNet": false,
|
"isMainNet": false,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
@@ -1084,7 +1084,7 @@
|
|||||||
"ethereumChainId": "1",
|
"ethereumChainId": "1",
|
||||||
"dydxChainId": "[mainnet chain id]",
|
"dydxChainId": "[mainnet chain id]",
|
||||||
"chainName": "dYdX Chain",
|
"chainName": "dYdX Chain",
|
||||||
"chainLogo": "/dydx-chain.png",
|
"chainLogo": "dydx-chain.png",
|
||||||
"squidIntegratorId": "[mainnet squid integrator id]",
|
"squidIntegratorId": "[mainnet squid integrator id]",
|
||||||
"isMainNet": true,
|
"isMainNet": true,
|
||||||
"tokens": {
|
"tokens": {
|
||||||
|
|||||||
+20
-28
@@ -10,7 +10,7 @@ import {
|
|||||||
USD_DECIMALS,
|
USD_DECIMALS,
|
||||||
} from '@/constants/numbers';
|
} from '@/constants/numbers';
|
||||||
|
|
||||||
import { BIG_NUMBERS } from '@/lib/numbers';
|
import { BIG_NUMBERS, MustBigNumber } from '@/lib/numbers';
|
||||||
import { useLocaleSeparators } from '@/hooks';
|
import { useLocaleSeparators } from '@/hooks';
|
||||||
|
|
||||||
export enum InputType {
|
export enum InputType {
|
||||||
@@ -29,38 +29,31 @@ type StyleProps = {
|
|||||||
type ElementProps = {
|
type ElementProps = {
|
||||||
type?: InputType;
|
type?: InputType;
|
||||||
value?: string | number | null;
|
value?: string | number | null;
|
||||||
|
|
||||||
|
allowNegative?: boolean;
|
||||||
|
decimals?: number;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
id?: string;
|
id?: string;
|
||||||
|
max?: number;
|
||||||
onBlur?: () => void;
|
onBlur?: () => void;
|
||||||
|
onChange?:
|
||||||
|
| Dispatch<SetStateAction<string>>
|
||||||
|
| React.ReactEventHandler<HTMLInputElement>
|
||||||
|
| ((values: NumberFormatValues, e: SourceInfo) => void);
|
||||||
onFocus?: () => void;
|
onFocus?: () => void;
|
||||||
|
onInput?: ({
|
||||||
|
value,
|
||||||
|
floatValue,
|
||||||
|
formattedValue,
|
||||||
|
}: {
|
||||||
|
value: string;
|
||||||
|
floatValue?: number;
|
||||||
|
formattedValue: string;
|
||||||
|
}) => void;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ConditionalProps =
|
export type InputProps = ElementProps & StyleProps;
|
||||||
| {
|
|
||||||
allowNegative?: boolean;
|
|
||||||
decimals?: number;
|
|
||||||
max?: number;
|
|
||||||
onChange?: (values: NumberFormatValues, e: SourceInfo) => void;
|
|
||||||
onInput?: ({
|
|
||||||
value,
|
|
||||||
floatValue,
|
|
||||||
formattedValue,
|
|
||||||
}: {
|
|
||||||
value: string;
|
|
||||||
floatValue?: number;
|
|
||||||
formattedValue: string;
|
|
||||||
}) => void;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
allowNegative?: never;
|
|
||||||
decimals?: never;
|
|
||||||
max?: never;
|
|
||||||
onChange?: Dispatch<SetStateAction<string>> | React.ReactEventHandler<HTMLInputElement>;
|
|
||||||
onInput?: (e: SyntheticInputEvent) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type InputProps = ElementProps & StyleProps & ConditionalProps;
|
|
||||||
|
|
||||||
export const Input = forwardRef<HTMLInputElement, InputProps>(
|
export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||||
(
|
(
|
||||||
@@ -145,7 +138,6 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
|
|||||||
ref={ref as React.Ref<typeof NumericFormat<unknown>>}
|
ref={ref as React.Ref<typeof NumericFormat<unknown>>}
|
||||||
id={id}
|
id={id}
|
||||||
// NumericFormat
|
// NumericFormat
|
||||||
valueIsNumericString
|
|
||||||
allowNegative={allowNegative}
|
allowNegative={allowNegative}
|
||||||
decimalScale={decimals}
|
decimalScale={decimals}
|
||||||
decimalSeparator={LOCALE_DECIMAL_SEPARATOR}
|
decimalSeparator={LOCALE_DECIMAL_SEPARATOR}
|
||||||
@@ -169,7 +161,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
|
|||||||
? undefined
|
? undefined
|
||||||
: Number(formattedValue.replace(',', '.'));
|
: Number(formattedValue.replace(',', '.'));
|
||||||
|
|
||||||
onInput?.({ value, floatValue, formattedValue, ...e });
|
onInput?.({ value, floatValue, formattedValue });
|
||||||
}}
|
}}
|
||||||
// Native
|
// Native
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|||||||
@@ -51,14 +51,4 @@ export const MARKETS_TO_DISPLAY = [
|
|||||||
'SUI-USD',
|
'SUI-USD',
|
||||||
'DOT-USD',
|
'DOT-USD',
|
||||||
'ETC-USD',
|
'ETC-USD',
|
||||||
'ARB-USD',
|
|
||||||
'CRV-USD',
|
|
||||||
'BLUR-USD',
|
|
||||||
'FIL-USD',
|
|
||||||
'XLM-USD',
|
|
||||||
'PEPE-USD',
|
|
||||||
'WLD-USD',
|
|
||||||
'SEI-USD',
|
|
||||||
'LTC-USD',
|
|
||||||
'BCH-USD',
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -11,19 +11,22 @@ export const useTradeFormInputs = () => {
|
|||||||
const { limitPriceInput, triggerPriceInput, trailingPercentInput } = tradeFormInputValues;
|
const { limitPriceInput, triggerPriceInput, trailingPercentInput } = tradeFormInputValues;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const floatValue = parseFloat(triggerPriceInput);
|
||||||
abacusStateManager.setTradeValue({
|
abacusStateManager.setTradeValue({
|
||||||
value: triggerPriceInput,
|
value: floatValue,
|
||||||
field: TradeInputField.triggerPrice,
|
field: TradeInputField.triggerPrice,
|
||||||
});
|
});
|
||||||
}, [triggerPriceInput]);
|
}, [triggerPriceInput]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
abacusStateManager.setTradeValue({ value: limitPriceInput, field: TradeInputField.limitPrice });
|
const floatValue = parseFloat(limitPriceInput);
|
||||||
|
abacusStateManager.setTradeValue({ value: floatValue, field: TradeInputField.limitPrice });
|
||||||
}, [limitPriceInput]);
|
}, [limitPriceInput]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const floatValue = parseFloat(trailingPercentInput);
|
||||||
abacusStateManager.setTradeValue({
|
abacusStateManager.setTradeValue({
|
||||||
value: trailingPercentInput,
|
value: floatValue,
|
||||||
field: TradeInputField.trailingPercent,
|
field: TradeInputField.trailingPercent,
|
||||||
});
|
});
|
||||||
}, [trailingPercentInput]);
|
}, [trailingPercentInput]);
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ export const TradeForm = ({
|
|||||||
dispatch(setTradeFormInputs({ triggerPriceInput: value }));
|
dispatch(setTradeFormInputs({ triggerPriceInput: value }));
|
||||||
},
|
},
|
||||||
value: triggerPriceInput ?? '',
|
value: triggerPriceInput ?? '',
|
||||||
decimals: tickSizeDecimals ?? USD_DECIMALS,
|
decimals: tickSizeDecimals || USD_DECIMALS,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +226,7 @@ export const TradeForm = ({
|
|||||||
dispatch(setTradeFormInputs({ limitPriceInput: value }));
|
dispatch(setTradeFormInputs({ limitPriceInput: value }));
|
||||||
},
|
},
|
||||||
value: limitPriceInput,
|
value: limitPriceInput,
|
||||||
decimals: tickSizeDecimals ?? USD_DECIMALS,
|
decimals: tickSizeDecimals || USD_DECIMALS,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export const TradeSizeInputs = () => {
|
|||||||
useSelector(getCurrentMarketConfig, shallowEqual) || {};
|
useSelector(getCurrentMarketConfig, shallowEqual) || {};
|
||||||
const { size, usdcSize, leverage, input: lastEditedInput } = inputTradeSizeData || {};
|
const { size, usdcSize, leverage, input: lastEditedInput } = inputTradeSizeData || {};
|
||||||
const { needsLeverage } = currentTradeInputOptions || {};
|
const { needsLeverage } = currentTradeInputOptions || {};
|
||||||
const decimals = stepSizeDecimals ?? TOKEN_DECIMALS;
|
const decimals = stepSizeDecimals || TOKEN_DECIMALS;
|
||||||
|
|
||||||
const { amountInput, usdAmountInput, leverageInput } = useSelector(
|
const { amountInput, usdAmountInput, leverageInput } = useSelector(
|
||||||
getTradeFormInputs,
|
getTradeFormInputs,
|
||||||
@@ -70,34 +70,22 @@ export const TradeSizeInputs = () => {
|
|||||||
}
|
}
|
||||||
}, [size, usdcSize, leverage, lastEditedInput]);
|
}, [size, usdcSize, leverage, lastEditedInput]);
|
||||||
|
|
||||||
const onSizeInput = ({
|
const onSizeInput = ({ value, floatValue }: { value: string; floatValue?: number }) => {
|
||||||
floatValue,
|
dispatch(setTradeFormInputs({ amountInput: value }));
|
||||||
formattedValue,
|
|
||||||
}: {
|
|
||||||
floatValue?: number;
|
|
||||||
formattedValue: string;
|
|
||||||
}) => {
|
|
||||||
dispatch(setTradeFormInputs({ amountInput: MustBigNumber(floatValue).toString() }));
|
|
||||||
const newAmount = MustBigNumber(floatValue).toFixed(decimals);
|
const newAmount = MustBigNumber(floatValue).toFixed(decimals);
|
||||||
|
|
||||||
abacusStateManager.setTradeValue({
|
abacusStateManager.setTradeValue({
|
||||||
value: formattedValue === '' || newAmount === 'NaN' ? null : newAmount,
|
value: value === '' || newAmount === 'NaN' ? null : newAmount,
|
||||||
field: TradeInputField.size,
|
field: TradeInputField.size,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onUSDCInput = ({
|
const onUSDCInput = ({ value, floatValue }: { value: string; floatValue?: number }) => {
|
||||||
floatValue,
|
dispatch(setTradeFormInputs({ usdAmountInput: value }));
|
||||||
formattedValue,
|
const newUsdcAmount = MustBigNumber(floatValue).toFixed();
|
||||||
}: {
|
|
||||||
floatValue?: number;
|
|
||||||
formattedValue: string;
|
|
||||||
}) => {
|
|
||||||
dispatch(setTradeFormInputs({ usdAmountInput: MustBigNumber(floatValue).toString() }));
|
|
||||||
const newUsdcAmount = MustBigNumber(floatValue).toFixed(tickSizeDecimals || USD_DECIMALS);
|
|
||||||
|
|
||||||
abacusStateManager.setTradeValue({
|
abacusStateManager.setTradeValue({
|
||||||
value: formattedValue === '' || newUsdcAmount === 'NaN' ? null : newUsdcAmount,
|
value: value === '' || newUsdcAmount === 'NaN' ? null : newUsdcAmount,
|
||||||
field: TradeInputField.usdcSize,
|
field: TradeInputField.usdcSize,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,11 +42,7 @@ type StyleProps = {
|
|||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type RowData = Pick<OrderbookLine, 'depth' | 'offset' | 'price' | 'size'> & {
|
type RowData = OrderbookLine & { side: 'bid' | 'ask'; mine?: number };
|
||||||
side: 'bid' | 'ask';
|
|
||||||
mine?: number;
|
|
||||||
key: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const useCalculateOrderbookData = ({ maxRowsPerSide }: { maxRowsPerSide: number }) => {
|
const useCalculateOrderbookData = ({ maxRowsPerSide }: { maxRowsPerSide: number }) => {
|
||||||
const orderbook = useSelector(getCurrentMarketOrderbook, shallowEqual);
|
const orderbook = useSelector(getCurrentMarketOrderbook, shallowEqual);
|
||||||
@@ -57,9 +53,8 @@ const useCalculateOrderbookData = ({ maxRowsPerSide }: { maxRowsPerSide: number
|
|||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const asks = (orderbook?.asks?.toArray() ?? [])
|
const asks = (orderbook?.asks?.toArray() ?? [])
|
||||||
.map(
|
.map(
|
||||||
(row: OrderbookLine, idx: number) =>
|
(row: OrderbookLine) =>
|
||||||
({
|
({
|
||||||
key: `ask-${idx}`,
|
|
||||||
side: 'ask',
|
side: 'ask',
|
||||||
mine: openOrdersBySideAndPrice[OrderSide.SELL]?.[row.price]?.size,
|
mine: openOrdersBySideAndPrice[OrderSide.SELL]?.[row.price]?.size,
|
||||||
...row,
|
...row,
|
||||||
@@ -69,9 +64,8 @@ const useCalculateOrderbookData = ({ maxRowsPerSide }: { maxRowsPerSide: number
|
|||||||
|
|
||||||
const bids = (orderbook?.bids?.toArray() ?? [])
|
const bids = (orderbook?.bids?.toArray() ?? [])
|
||||||
.map(
|
.map(
|
||||||
(row: OrderbookLine, idx: number) =>
|
(row: OrderbookLine) =>
|
||||||
({
|
({
|
||||||
key: `bid-${idx}`,
|
|
||||||
side: 'bid',
|
side: 'bid',
|
||||||
mine: openOrdersBySideAndPrice[OrderSide.BUY]?.[row.price]?.size,
|
mine: openOrdersBySideAndPrice[OrderSide.BUY]?.[row.price]?.size,
|
||||||
...row,
|
...row,
|
||||||
@@ -103,44 +97,15 @@ const useCalculateOrderbookData = ({ maxRowsPerSide }: { maxRowsPerSide: number
|
|||||||
}
|
}
|
||||||
|
|
||||||
const spread =
|
const spread =
|
||||||
asks[0]?.price && bids[0]?.price ? MustBigNumber(asks[0].price).minus(bids[0].price) : null;
|
asks[0] && bids[0] ? MustBigNumber(asks[0]?.price ?? 0).minus(bids[0]?.price ?? 0) : null;
|
||||||
|
|
||||||
const spreadPercent = orderbook?.spreadPercent;
|
const spreadPercent = orderbook?.spreadPercent;
|
||||||
|
|
||||||
const histogramRange = Math.max(
|
const histogramRange = Math.max(
|
||||||
isNaN(Number(bids[bids.length - 1]?.depth)) ? 0 : Number(bids[bids.length - 1]?.depth),
|
Number(bids[bids.length - 1]?.depth),
|
||||||
isNaN(Number(asks[asks.length - 1]?.depth)) ? 0 : Number(asks[asks.length - 1]?.depth)
|
Number(asks[asks.length - 1]?.depth)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Ensure asks and bids are of length maxRowsPerSide by adding empty rows.
|
|
||||||
let idx = asks.length - 1;
|
|
||||||
while (asks.length < maxRowsPerSide) {
|
|
||||||
idx += 1;
|
|
||||||
|
|
||||||
asks.push({
|
|
||||||
key: `ask-${idx}`,
|
|
||||||
side: 'ask',
|
|
||||||
size: 0,
|
|
||||||
price: 0,
|
|
||||||
offset: 0,
|
|
||||||
depth: 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
idx = bids.length - 1;
|
|
||||||
while (bids.length < maxRowsPerSide) {
|
|
||||||
idx += 1;
|
|
||||||
|
|
||||||
bids.push({
|
|
||||||
key: `bid-${idx}`,
|
|
||||||
side: 'bid',
|
|
||||||
size: 0,
|
|
||||||
price: 0,
|
|
||||||
offset: 0,
|
|
||||||
depth: 0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return { asks, bids, spread, spreadPercent, histogramRange, hasOrderbook: !!orderbook };
|
return { asks, bids, spread, spreadPercent, histogramRange, hasOrderbook: !!orderbook };
|
||||||
}, [orderbook, openOrdersBySideAndPrice]);
|
}, [orderbook, openOrdersBySideAndPrice]);
|
||||||
};
|
};
|
||||||
@@ -177,33 +142,31 @@ const OrderbookTable = ({
|
|||||||
getCellValue: (row: RowData) => row.size,
|
getCellValue: (row: RowData) => row.size,
|
||||||
label: stringGetter({ key: STRING_KEYS.ORDERBOOK_ORDER_SIZE }),
|
label: stringGetter({ key: STRING_KEYS.ORDERBOOK_ORDER_SIZE }),
|
||||||
tag: symbol,
|
tag: symbol,
|
||||||
renderCell: (row: RowData) =>
|
renderCell: (row: RowData) => (
|
||||||
row.size > 0 && (
|
<Styled.HistogramOutput
|
||||||
<Styled.HistogramOutput
|
highlightText
|
||||||
highlightText
|
type={OutputType.Asset}
|
||||||
type={OutputType.Asset}
|
value={row.size}
|
||||||
value={row.size}
|
fractionDigits={stepSizeDecimals}
|
||||||
fractionDigits={stepSizeDecimals}
|
histogramSide={histogramSide === 'left' && 'left'}
|
||||||
histogramSide={histogramSide === 'left' && 'left'}
|
useGrouping={false}
|
||||||
useGrouping={false}
|
/>
|
||||||
/>
|
),
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
columnKey: 'price',
|
columnKey: 'price',
|
||||||
getCellValue: (row: RowData) => row.price,
|
getCellValue: (row: RowData) => row.price,
|
||||||
label: stringGetter({ key: STRING_KEYS.PRICE }),
|
label: stringGetter({ key: STRING_KEYS.PRICE }),
|
||||||
tag: 'USD',
|
tag: 'USD',
|
||||||
renderCell: (row: RowData) =>
|
renderCell: (row: RowData) => (
|
||||||
row.price > 0 && (
|
<OrderbookTradesOutput
|
||||||
<OrderbookTradesOutput
|
highlightText
|
||||||
highlightText
|
type={OutputType.Number}
|
||||||
type={OutputType.Number}
|
value={row.price}
|
||||||
value={row.price}
|
fractionDigits={tickSizeDecimals}
|
||||||
fractionDigits={tickSizeDecimals}
|
useGrouping={false}
|
||||||
useGrouping={false}
|
/>
|
||||||
/>
|
),
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
columnKey: 'subaccount-orders',
|
columnKey: 'subaccount-orders',
|
||||||
@@ -231,13 +194,12 @@ const OrderbookTable = ({
|
|||||||
label="Orderbook"
|
label="Orderbook"
|
||||||
data={data}
|
data={data}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
getRowKey={(row: RowData) => row.key}
|
getRowKey={(row: RowData) => `${row.side}-${row.price}`}
|
||||||
getRowAttributes={(row: RowData) => ({
|
getRowAttributes={(row: RowData) => ({
|
||||||
'data-side': row.side,
|
'data-side': row.side,
|
||||||
style: {
|
style: {
|
||||||
'--histogram-bucket-size': row.size,
|
'--histogram-bucket-size': row.size,
|
||||||
'--histogram-bucket-depth': row.depth,
|
'--histogram-bucket-depth': row.depth,
|
||||||
'--tr-pointerEvents': row.price ? 'auto' : 'none',
|
|
||||||
},
|
},
|
||||||
})}
|
})}
|
||||||
onRowAction={onRowAction}
|
onRowAction={onRowAction}
|
||||||
@@ -276,10 +238,19 @@ export const Orderbook = ({
|
|||||||
maxRowsPerSide,
|
maxRowsPerSide,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [showRowsPerSide, setShowRowsPerSide] = useState(0);
|
||||||
|
|
||||||
|
// Make rows visible one by one so avoid jumps in initial scroll position
|
||||||
|
useEffect(() => {
|
||||||
|
if (showRowsPerSide < maxRowsPerSide) {
|
||||||
|
setShowRowsPerSide((showRows) => showRows + 1);
|
||||||
|
}
|
||||||
|
}, [showRowsPerSide]);
|
||||||
|
|
||||||
const data = useMemo(
|
const data = useMemo(
|
||||||
() =>
|
() =>
|
||||||
[
|
[
|
||||||
...bids.reverse(),
|
...bids.slice(0, showRowsPerSide).reverse(),
|
||||||
{
|
{
|
||||||
key: 'spread',
|
key: 'spread',
|
||||||
slotCustomRow: (props) => (
|
slotCustomRow: (props) => (
|
||||||
@@ -296,9 +267,9 @@ export const Orderbook = ({
|
|||||||
</Styled.SpreadTableRow>
|
</Styled.SpreadTableRow>
|
||||||
),
|
),
|
||||||
} as CustomRowConfig,
|
} as CustomRowConfig,
|
||||||
...asks,
|
...asks.slice(0, showRowsPerSide),
|
||||||
].reverse(),
|
].reverse(),
|
||||||
[asks, bids, spread, spreadPercent, isTablet]
|
[asks, bids, spread, spreadPercent, showRowsPerSide, isTablet]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onRowAction = useCallback(
|
const onRowAction = useCallback(
|
||||||
@@ -354,7 +325,7 @@ export const Orderbook = ({
|
|||||||
</Styled.Header>
|
</Styled.Header>
|
||||||
<Styled.SplitOrderbook>
|
<Styled.SplitOrderbook>
|
||||||
<OrderbookTable data={asks} histogramSide="right" {...orderbookTableProps} />
|
<OrderbookTable data={asks} histogramSide="right" {...orderbookTableProps} />
|
||||||
<OrderbookTable data={bids.reverse()} histogramSide="left" {...orderbookTableProps} />
|
<OrderbookTable data={bids} histogramSide="left" {...orderbookTableProps} />
|
||||||
</Styled.SplitOrderbook>
|
</Styled.SplitOrderbook>
|
||||||
</Styled.HorizontalLayout>
|
</Styled.HorizontalLayout>
|
||||||
);
|
);
|
||||||
@@ -524,7 +495,6 @@ Styled.OrderbookTable = styled(OrderbookTradesTable)<StyleProps>`
|
|||||||
|
|
||||||
tr {
|
tr {
|
||||||
--histogram-bucket-depth: 0;
|
--histogram-bucket-depth: 0;
|
||||||
pointer-events: var(--tr-pointerEvents);
|
|
||||||
|
|
||||||
&[data-side='bid'] {
|
&[data-side='bid'] {
|
||||||
--accent-color: var(--color-positive);
|
--accent-color: var(--color-positive);
|
||||||
|
|||||||
Reference in New Issue
Block a user