Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
604ec43f3f | ||
|
|
0deced8545 |
+3
-3
@@ -39,9 +39,9 @@
|
||||
"@cosmjs/proto-signing": "^0.31.0",
|
||||
"@cosmjs/stargate": "^0.31.0",
|
||||
"@cosmjs/tendermint-rpc": "^0.31.0",
|
||||
"@dydxprotocol/v4-abacus": "^1.1.22",
|
||||
"@dydxprotocol/v4-client-js": "^1.0.11",
|
||||
"@dydxprotocol/v4-localization": "^1.0.18",
|
||||
"@dydxprotocol/v4-abacus": "^1.1.4",
|
||||
"@dydxprotocol/v4-client-js": "^1.0.6",
|
||||
"@dydxprotocol/v4-localization": "^1.0.17",
|
||||
"@ethersproject/providers": "^5.7.2",
|
||||
"@js-joda/core": "^5.5.3",
|
||||
"@radix-ui/react-checkbox": "^1.0.4",
|
||||
|
||||
Generated
+13
-26
@@ -27,14 +27,14 @@ dependencies:
|
||||
specifier: ^0.31.0
|
||||
version: 0.31.0
|
||||
'@dydxprotocol/v4-abacus':
|
||||
specifier: ^1.1.22
|
||||
version: 1.1.22
|
||||
specifier: ^1.1.4
|
||||
version: 1.1.4
|
||||
'@dydxprotocol/v4-client-js':
|
||||
specifier: ^1.0.11
|
||||
version: 1.0.11
|
||||
specifier: ^1.0.6
|
||||
version: 1.0.6
|
||||
'@dydxprotocol/v4-localization':
|
||||
specifier: ^1.0.18
|
||||
version: 1.0.18
|
||||
specifier: ^1.0.17
|
||||
version: 1.0.17
|
||||
'@ethersproject/providers':
|
||||
specifier: ^5.7.2
|
||||
version: 5.7.2
|
||||
@@ -988,12 +988,12 @@ packages:
|
||||
resolution: {integrity: sha512-RpfLEtTlyIxeNPGKcokS+p3BZII/Q3bYxryFRglh5H3A3T8q9fsLYm72VYAMEOOIBLEa8o93kFLiBDUWKrwXZA==}
|
||||
dev: true
|
||||
|
||||
/@dydxprotocol/v4-abacus@1.1.22:
|
||||
resolution: {integrity: sha512-txinqnKGblCEcn1FjMj5nW9Tv2446fbkRaquodwQSk0GTP92/78xl4VSOwMngc0f4heiVGbirlCKyHmtZUADmA==}
|
||||
/@dydxprotocol/v4-abacus@1.1.4:
|
||||
resolution: {integrity: sha512-gml6qheFsPShE9p3FmzFeStYM9ZVhgMq0K0+y12V7pObnMKbumkOIISgCzc47idkah0GMNhiqwi9faD5SjOy/A==}
|
||||
dev: false
|
||||
|
||||
/@dydxprotocol/v4-client-js@1.0.11:
|
||||
resolution: {integrity: sha512-rJNFGTO+HU1GQppXeRLKXNk4HWx/h+DjU2sUCieEv5mnRIMQpLw8dH/L+Uyhxx2oovccY1MaKB4Fr9IngdrF0A==}
|
||||
/@dydxprotocol/v4-client-js@1.0.6:
|
||||
resolution: {integrity: sha512-xiWH+kbix+zhI6EsAnd+NDvkjBgxWtGwQmvpd0PjljWNYSFgUtNe5M+piDdRbl2nhy6YWbxAGTwwS3K/ih5qSw==}
|
||||
dependencies:
|
||||
'@cosmjs/amino': 0.30.1
|
||||
'@cosmjs/encoding': 0.31.1
|
||||
@@ -1013,15 +1013,15 @@ packages:
|
||||
ethers: 6.6.1
|
||||
long: 4.0.0
|
||||
protobufjs: 6.11.4
|
||||
ws: 8.15.0
|
||||
ws: 8.13.0(bufferutil@4.0.7)(utf-8-validate@5.0.10)
|
||||
transitivePeerDependencies:
|
||||
- bufferutil
|
||||
- debug
|
||||
- utf-8-validate
|
||||
dev: false
|
||||
|
||||
/@dydxprotocol/v4-localization@1.0.18:
|
||||
resolution: {integrity: sha512-790ajXfGzqRs7JVA3vISCg0Vh4EEN7SlcI8u04iryPcBp1WwkQ5TFGllF32+YPs1+mgjMRhwrg6jP8zEGMQFyw==}
|
||||
/@dydxprotocol/v4-localization@1.0.17:
|
||||
resolution: {integrity: sha512-fybNpi1ono1IdwFQJTszsHbHmGti2BdhTo1nz9KOmKh3tmXdhWObKb64Ve6/6Fjk6h/9+DeZ5ZG4UbYyYMyhCA==}
|
||||
dev: false
|
||||
|
||||
/@dydxprotocol/v4-proto@0.4.1:
|
||||
@@ -14037,19 +14037,6 @@ packages:
|
||||
utf-8-validate: 5.0.10
|
||||
dev: false
|
||||
|
||||
/ws@8.15.0:
|
||||
resolution: {integrity: sha512-H/Z3H55mrcrgjFwI+5jKavgXvwQLtfPCUEp6pi35VhoB0pfcHnSoyuTzkBEZpzq49g1193CUEwIvmsjcotenYw==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
peerDependencies:
|
||||
bufferutil: ^4.0.1
|
||||
utf-8-validate: '>=5.0.2'
|
||||
peerDependenciesMeta:
|
||||
bufferutil:
|
||||
optional: true
|
||||
utf-8-validate:
|
||||
optional: true
|
||||
dev: false
|
||||
|
||||
/ws@8.5.0:
|
||||
resolution: {integrity: sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
|
||||
+15
-15
@@ -42,7 +42,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydxprotocol-testnet",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -116,7 +116,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydxprotocol-testnet",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -189,7 +189,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydxprotocol-testnet",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -262,7 +262,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydxprotocol-testnet",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -335,7 +335,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydxprotocol-testnet",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -410,7 +410,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydxprotocol-testnet",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -483,7 +483,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydxprotocol-testnet",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -558,7 +558,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydx-testnet-4",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -637,7 +637,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydx-testnet-4",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -713,7 +713,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydx-testnet-4",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -789,7 +789,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydx-testnet-4",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -865,7 +865,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydx-testnet-4",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -941,7 +941,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydx-testnet-4",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -1008,7 +1008,7 @@
|
||||
"ethereumChainId": "5",
|
||||
"dydxChainId": "dydx-testnet-4",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "dYdX-api",
|
||||
"isMainNet": false,
|
||||
"tokens": {
|
||||
@@ -1084,7 +1084,7 @@
|
||||
"ethereumChainId": "1",
|
||||
"dydxChainId": "[mainnet chain id]",
|
||||
"chainName": "dYdX Chain",
|
||||
"chainLogo": "/dydx-chain.png",
|
||||
"chainLogo": "dydx-chain.png",
|
||||
"squidIntegratorId": "[mainnet squid integrator id]",
|
||||
"isMainNet": true,
|
||||
"tokens": {
|
||||
|
||||
+20
-28
@@ -10,7 +10,7 @@ import {
|
||||
USD_DECIMALS,
|
||||
} from '@/constants/numbers';
|
||||
|
||||
import { BIG_NUMBERS } from '@/lib/numbers';
|
||||
import { BIG_NUMBERS, MustBigNumber } from '@/lib/numbers';
|
||||
import { useLocaleSeparators } from '@/hooks';
|
||||
|
||||
export enum InputType {
|
||||
@@ -29,38 +29,31 @@ type StyleProps = {
|
||||
type ElementProps = {
|
||||
type?: InputType;
|
||||
value?: string | number | null;
|
||||
|
||||
allowNegative?: boolean;
|
||||
decimals?: number;
|
||||
disabled?: boolean;
|
||||
id?: string;
|
||||
max?: number;
|
||||
onBlur?: () => void;
|
||||
onChange?:
|
||||
| Dispatch<SetStateAction<string>>
|
||||
| React.ReactEventHandler<HTMLInputElement>
|
||||
| ((values: NumberFormatValues, e: SourceInfo) => void);
|
||||
onFocus?: () => void;
|
||||
onInput?: ({
|
||||
value,
|
||||
floatValue,
|
||||
formattedValue,
|
||||
}: {
|
||||
value: string;
|
||||
floatValue?: number;
|
||||
formattedValue: string;
|
||||
}) => void;
|
||||
placeholder?: string;
|
||||
};
|
||||
|
||||
type ConditionalProps =
|
||||
| {
|
||||
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 type InputProps = ElementProps & StyleProps;
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
(
|
||||
@@ -145,7 +138,6 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
ref={ref as React.Ref<typeof NumericFormat<unknown>>}
|
||||
id={id}
|
||||
// NumericFormat
|
||||
valueIsNumericString
|
||||
allowNegative={allowNegative}
|
||||
decimalScale={decimals}
|
||||
decimalSeparator={LOCALE_DECIMAL_SEPARATOR}
|
||||
@@ -169,7 +161,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
? undefined
|
||||
: Number(formattedValue.replace(',', '.'));
|
||||
|
||||
onInput?.({ value, floatValue, formattedValue, ...e });
|
||||
onInput?.({ value, floatValue, formattedValue });
|
||||
}}
|
||||
// Native
|
||||
disabled={disabled}
|
||||
|
||||
@@ -51,14 +51,4 @@ export const MARKETS_TO_DISPLAY = [
|
||||
'SUI-USD',
|
||||
'DOT-USD',
|
||||
'ETC-USD',
|
||||
'ARB-USD',
|
||||
'CRV-USD',
|
||||
'BLUR-USD',
|
||||
'FIL-USD',
|
||||
'XLM-USD',
|
||||
'PEPE-USD',
|
||||
'WLD-USD',
|
||||
'SEI-USD',
|
||||
'LTC-USD',
|
||||
'BCH-USD',
|
||||
];
|
||||
|
||||
@@ -122,15 +122,9 @@ export type NotificationDisplayData = {
|
||||
toastDuration?: number;
|
||||
};
|
||||
|
||||
export enum TransferNotificationTypes {
|
||||
Withdrawal = 'withdrawal',
|
||||
Deposit = 'deposit',
|
||||
}
|
||||
|
||||
// Notification types
|
||||
export type TransferNotifcation = {
|
||||
txHash: string;
|
||||
type?: TransferNotificationTypes;
|
||||
toChainId?: string;
|
||||
fromChainId?: string;
|
||||
toAmount?: number;
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
type NotificationTypeConfig,
|
||||
NotificationType,
|
||||
DEFAULT_TOAST_AUTO_CLOSE_MS,
|
||||
TransferNotificationTypes,
|
||||
} from '@/constants/notifications';
|
||||
|
||||
import { useSelectedNetwork, useStringGetter } from '@/hooks';
|
||||
@@ -153,20 +152,20 @@ export const notificationTypes: NotificationTypeConfig[] = [
|
||||
|
||||
useEffect(() => {
|
||||
for (const transfer of transferNotifications) {
|
||||
const { fromChainId, status, txHash, toAmount, type } = transfer;
|
||||
const { fromChainId, status, txHash, toAmount } = transfer;
|
||||
const isFinished = Boolean(status) && status?.squidTransactionStatus !== 'ongoing';
|
||||
const icon = <Icon iconName={isFinished ? IconName.Transfer : IconName.Clock} />;
|
||||
|
||||
const transferType = type ??
|
||||
const type =
|
||||
fromChainId === ENVIRONMENT_CONFIG_MAP[selectedNetwork].dydxChainId
|
||||
? TransferNotificationTypes.Withdrawal
|
||||
: TransferNotificationTypes.Deposit;
|
||||
? 'withdrawal'
|
||||
: 'deposit';
|
||||
|
||||
const title = stringGetter({
|
||||
key: {
|
||||
deposit: isFinished ? STRING_KEYS.DEPOSIT : STRING_KEYS.DEPOSIT_IN_PROGRESS,
|
||||
withdrawal: isFinished ? STRING_KEYS.WITHDRAW : STRING_KEYS.WITHDRAW_IN_PROGRESS,
|
||||
}[transferType],
|
||||
}[type],
|
||||
});
|
||||
|
||||
const toChainEta = status?.toChain?.chainData?.estimatedRouteDuration || 0;
|
||||
@@ -191,7 +190,7 @@ export const notificationTypes: NotificationTypeConfig[] = [
|
||||
slotIcon={icon}
|
||||
slotTitle={title}
|
||||
transfer={transfer}
|
||||
type={transferType}
|
||||
type={type}
|
||||
triggeredAt={transfer.triggeredAt}
|
||||
notification={notification}
|
||||
/>
|
||||
|
||||
@@ -31,7 +31,6 @@ import { log } from '@/lib/telemetry';
|
||||
import { useAccounts } from './useAccounts';
|
||||
import { useTokenConfigs } from './useTokenConfigs';
|
||||
import { useDydxClient } from './useDydxClient';
|
||||
import { hashFromTx } from '@/lib/hashfromTx';
|
||||
|
||||
type SubaccountContextType = ReturnType<typeof useSubaccountContext>;
|
||||
const SubaccountContext = createContext<SubaccountContextType>({} as SubaccountContextType);
|
||||
@@ -294,29 +293,12 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
);
|
||||
|
||||
const sendSquidWithdraw = useCallback(
|
||||
async (amount: number, payload: string, isCctp?: boolean) => {
|
||||
|
||||
const cctpWithdraw = () => {
|
||||
return new Promise<string>((resolve, reject) =>
|
||||
abacusStateManager.cctpWithdraw((success, error, data) => {
|
||||
const parsedData = JSON.parse(data);
|
||||
if (success && parsedData?.code == 0) {
|
||||
resolve(parsedData?.transactionHash);
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
if (isCctp) {
|
||||
return await cctpWithdraw();
|
||||
}
|
||||
|
||||
async (amount: number, payload: string) => {
|
||||
if (!subaccountClient) {
|
||||
return;
|
||||
}
|
||||
const tx = await sendSquidWithdrawFromSubaccount({ subaccountClient, amount, payload });
|
||||
return hashFromTx(tx?.hash);
|
||||
|
||||
return await sendSquidWithdrawFromSubaccount({ subaccountClient, amount, payload });
|
||||
},
|
||||
[subaccountClient, sendSquidWithdrawFromSubaccount]
|
||||
);
|
||||
|
||||
@@ -11,19 +11,22 @@ export const useTradeFormInputs = () => {
|
||||
const { limitPriceInput, triggerPriceInput, trailingPercentInput } = tradeFormInputValues;
|
||||
|
||||
useEffect(() => {
|
||||
const floatValue = parseFloat(triggerPriceInput);
|
||||
abacusStateManager.setTradeValue({
|
||||
value: triggerPriceInput,
|
||||
value: floatValue,
|
||||
field: TradeInputField.triggerPrice,
|
||||
});
|
||||
}, [triggerPriceInput]);
|
||||
|
||||
useEffect(() => {
|
||||
abacusStateManager.setTradeValue({ value: limitPriceInput, field: TradeInputField.limitPrice });
|
||||
const floatValue = parseFloat(limitPriceInput);
|
||||
abacusStateManager.setTradeValue({ value: floatValue, field: TradeInputField.limitPrice });
|
||||
}, [limitPriceInput]);
|
||||
|
||||
useEffect(() => {
|
||||
const floatValue = parseFloat(trailingPercentInput);
|
||||
abacusStateManager.setTradeValue({
|
||||
value: trailingPercentInput,
|
||||
value: floatValue,
|
||||
field: TradeInputField.trailingPercent,
|
||||
});
|
||||
}, [trailingPercentInput]);
|
||||
|
||||
@@ -2,7 +2,6 @@ import Abacus, { type Nullable } from '@dydxprotocol/v4-abacus';
|
||||
import Long from 'long';
|
||||
import type { IndexedTx } from '@cosmjs/stargate';
|
||||
import { GAS_MULTIPLIER, encodeJson } from '@dydxprotocol/v4-client-js';
|
||||
import { EncodeObject } from '@cosmjs/proto-signing';
|
||||
|
||||
import {
|
||||
CompositeClient,
|
||||
@@ -42,7 +41,6 @@ import { openDialog } from '@/state/dialogs';
|
||||
import { StatefulOrderError } from '../errors';
|
||||
import { bytesToBigInt } from '../numbers';
|
||||
import { log } from '../telemetry';
|
||||
import { hashFromTx } from '../hashfromTx';
|
||||
|
||||
class DydxChainTransactions implements AbacusDYDXChainTransactionsProtocol {
|
||||
private compositeClient: CompositeClient | undefined;
|
||||
@@ -382,90 +380,6 @@ class DydxChainTransactions implements AbacusDYDXChainTransactionsProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
async withdrawToNobleIBC(
|
||||
params: {
|
||||
subaccountNumber: number,
|
||||
amount: string,
|
||||
ibcPayload: string,
|
||||
}
|
||||
): Promise<string> {
|
||||
if (!this.compositeClient || !this.localWallet) {
|
||||
throw new Error('Missing compositeClient or localWallet');
|
||||
}
|
||||
|
||||
const { subaccountNumber, amount, ibcPayload } = params ?? {};
|
||||
const parsedIbcPayload: {
|
||||
msgTypeUrl: string,
|
||||
msg: any,
|
||||
} = ibcPayload ? JSON.parse(ibcPayload) : undefined;
|
||||
|
||||
try {
|
||||
const msg = this.compositeClient.withdrawFromSubaccountMessage(
|
||||
new SubaccountClient(this.localWallet, subaccountNumber),
|
||||
parseFloat(amount).toFixed(this.compositeClient.validatorClient.config.denoms.USDC_DECIMALS)
|
||||
);
|
||||
const ibcMsg: EncodeObject = {
|
||||
typeUrl: parsedIbcPayload.msgTypeUrl,
|
||||
value: parsedIbcPayload.msg,
|
||||
};
|
||||
|
||||
const tx = await this.compositeClient.send(
|
||||
this.localWallet,
|
||||
() => Promise.resolve([msg, ibcMsg]),
|
||||
false
|
||||
);
|
||||
|
||||
return JSON.stringify({
|
||||
txHash: hashFromTx(tx?.hash)
|
||||
});
|
||||
} catch (error) {
|
||||
log('DydxChainTransactions/withdrawToNobleIBC', error);
|
||||
|
||||
return JSON.stringify({
|
||||
error,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async cctpWithdraw(params: {
|
||||
typeUrl: string,
|
||||
value: any,
|
||||
}): Promise<string> {
|
||||
if (!this.nobleClient?.isConnected) {
|
||||
throw new Error('Missing nobleClient or localWallet');
|
||||
}
|
||||
|
||||
try {
|
||||
const ibcMsg = {
|
||||
typeUrl: params.typeUrl, // '/circle.cctp.v1.MsgDepositForBurn',
|
||||
value: params.value,
|
||||
};
|
||||
const fee = await this.nobleClient.simulateTransaction([ibcMsg]);
|
||||
|
||||
// take out fee from amount before sweeping
|
||||
const amount = parseInt(ibcMsg.value.amount, 10) -
|
||||
Math.floor(parseInt(fee.amount[0].amount, 10) * GAS_MULTIPLIER);
|
||||
|
||||
if (amount <= 0) {
|
||||
throw new Error('noble balance does not cover fees');
|
||||
}
|
||||
|
||||
ibcMsg.value.amount = amount.toString();
|
||||
|
||||
const tx = await this.nobleClient.send([ibcMsg]);
|
||||
|
||||
const parsedTx = this.parseToPrimitives(tx);
|
||||
|
||||
return JSON.stringify(parsedTx);
|
||||
} catch (error) {
|
||||
log('DydxChainTransactions/cctpWithdraw', error);
|
||||
|
||||
return JSON.stringify({
|
||||
error,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async transaction(
|
||||
type: TransactionTypes,
|
||||
paramsInJson: Abacus.Nullable<string>,
|
||||
@@ -500,17 +414,6 @@ class DydxChainTransactions implements AbacusDYDXChainTransactionsProtocol {
|
||||
callback(result);
|
||||
break;
|
||||
}
|
||||
case TransactionType.WithdrawToNobleIBC: {
|
||||
const result = await this.withdrawToNobleIBC(params);
|
||||
callback(result);
|
||||
break;
|
||||
}
|
||||
case TransactionType.CctpWithdraw: {
|
||||
const result = await this.cctpWithdraw(params);
|
||||
callback(result);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class AbacusStateManager {
|
||||
|
||||
const appConfigs = AbacusAppConfig.Companion.forWeb;
|
||||
if (!isMainnet || testFlags.withCCTP)
|
||||
appConfigs.squidVersion = AbacusAppConfig.SquidVersion.V2;
|
||||
appConfigs.squidVersion = AbacusAppConfig.SquidVersion.V2DepositOnly;
|
||||
|
||||
this.stateManager = new AsyncAbacusStateManager(
|
||||
'',
|
||||
@@ -262,14 +262,6 @@ class AbacusStateManager {
|
||||
) => void
|
||||
) => this.stateManager.cancelOrder(orderId, callback);
|
||||
|
||||
cctpWithdraw = (
|
||||
callback: (
|
||||
success: boolean,
|
||||
parsingError: Nullable<ParsingError>,
|
||||
data: string,
|
||||
) => void
|
||||
): void => this.stateManager.commitCCTPWithdraw(callback);
|
||||
|
||||
// ------ Utils ------ //
|
||||
getHistoricalPnlPeriod = (): Nullable<HistoricalPnlPeriods> =>
|
||||
this.stateManager.historicalPnlPeriod;
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export const hashFromTx = (
|
||||
txHash: string | Uint8Array
|
||||
): string => `0x${Buffer.from(txHash).toString('hex')}`;
|
||||
@@ -10,7 +10,7 @@ import { AlertType } from '@/constants/alerts';
|
||||
import { ButtonSize } from '@/constants/buttons';
|
||||
import { STRING_KEYS } from '@/constants/localization';
|
||||
import { ENVIRONMENT_CONFIG_MAP } from '@/constants/networks';
|
||||
import { NotificationStatus, TransferNotificationTypes } from '@/constants/notifications';
|
||||
import { NotificationStatus } from '@/constants/notifications';
|
||||
import { NumberSign } from '@/constants/numbers';
|
||||
|
||||
import {
|
||||
@@ -45,7 +45,6 @@ import { getTransferInputs } from '@/state/inputsSelectors';
|
||||
|
||||
import abacusStateManager from '@/lib/abacus';
|
||||
import { MustBigNumber } from '@/lib/numbers';
|
||||
import { getNobleChainId } from '@/lib/squid';
|
||||
|
||||
import { TokenSelectMenu } from './TokenSelectMenu';
|
||||
import { WithdrawButtonAndReceipt } from './WithdrawForm/WithdrawButtonAndReceipt';
|
||||
@@ -168,16 +167,16 @@ export const WithdrawForm = () => {
|
||||
})
|
||||
);
|
||||
} else {
|
||||
const txHash = await sendSquidWithdraw(debouncedAmountBN.toNumber(), requestPayload.data, isCctp);
|
||||
if (txHash) {
|
||||
const txHash = await sendSquidWithdraw(debouncedAmountBN.toNumber(), requestPayload.data);
|
||||
if (txHash?.hash) {
|
||||
const hash = `0x${Buffer.from(txHash.hash).toString('hex')}`;
|
||||
addTransferNotification({
|
||||
txHash: txHash,
|
||||
type: TransferNotificationTypes.Withdrawal,
|
||||
fromChainId: !isCctp ? ENVIRONMENT_CONFIG_MAP[selectedNetwork].dydxChainId : getNobleChainId(),
|
||||
txHash: hash,
|
||||
fromChainId: ENVIRONMENT_CONFIG_MAP[selectedNetwork].dydxChainId,
|
||||
toChainId: chainIdStr || undefined,
|
||||
toAmount: debouncedAmountBN.toNumber(),
|
||||
triggeredAt: Date.now(),
|
||||
isCctp,
|
||||
notificationStatus: NotificationStatus.Triggered,
|
||||
});
|
||||
abacusStateManager.clearTransferInputValues();
|
||||
setWithdrawAmount('');
|
||||
|
||||
@@ -206,7 +206,7 @@ export const TradeForm = ({
|
||||
dispatch(setTradeFormInputs({ triggerPriceInput: value }));
|
||||
},
|
||||
value: triggerPriceInput ?? '',
|
||||
decimals: tickSizeDecimals ?? USD_DECIMALS,
|
||||
decimals: tickSizeDecimals || USD_DECIMALS,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ export const TradeForm = ({
|
||||
dispatch(setTradeFormInputs({ limitPriceInput: value }));
|
||||
},
|
||||
value: limitPriceInput,
|
||||
decimals: tickSizeDecimals ?? USD_DECIMALS,
|
||||
decimals: tickSizeDecimals || USD_DECIMALS,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { type Dispatch, type SetStateAction, useCallback, useMemo } from 'react';
|
||||
import styled, { AnyStyledComponent, css } from 'styled-components';
|
||||
import { Root, Thumb, Track } from '@radix-ui/react-slider';
|
||||
import _ from 'lodash';
|
||||
import { OrderSide } from '@dydxprotocol/v4-client-js';
|
||||
|
||||
import { TradeInputField } from '@/constants/abacus';
|
||||
import { type Nullable, TradeInputField } from '@/constants/abacus';
|
||||
import { PositionSide } from '@/constants/trade';
|
||||
|
||||
import { MustBigNumber, type BigNumberish } from '@/lib/numbers';
|
||||
@@ -12,11 +12,11 @@ import abacusStateManager from '@/lib/abacus';
|
||||
|
||||
type ElementProps = {
|
||||
leverage?: BigNumberish | null;
|
||||
leverageInputValue: string;
|
||||
leverageInputValue: Nullable<number>;
|
||||
maxLeverage: BigNumberish | null;
|
||||
orderSide: OrderSide;
|
||||
positionSide: PositionSide;
|
||||
setLeverageInputValue: (value: string) => void;
|
||||
setLeverageInputValue: Dispatch<SetStateAction<Nullable<number>>>;
|
||||
};
|
||||
|
||||
type StyleProps = { className?: string };
|
||||
@@ -33,7 +33,6 @@ export const LeverageSlider = ({
|
||||
const leverageBN = MustBigNumber(leverage);
|
||||
const maxLeverageBN = MustBigNumber(maxLeverage);
|
||||
const leverageInputBN = MustBigNumber(leverageInputValue || leverage);
|
||||
const leverageInputNumber = isNaN(leverageInputBN.toNumber()) ? 0 : leverageInputBN.toNumber();
|
||||
|
||||
const sliderConfig = useMemo(
|
||||
() => ({
|
||||
@@ -80,12 +79,12 @@ export const LeverageSlider = ({
|
||||
);
|
||||
|
||||
const onSliderDrag = ([newLeverage]: number[]) => {
|
||||
setLeverageInputValue(`${newLeverage}`);
|
||||
setLeverageInputValue(newLeverage);
|
||||
debouncedSetAbacusLeverage(newLeverage);
|
||||
};
|
||||
|
||||
const onValueCommit = ([newLeverage]: number[]) => {
|
||||
setLeverageInputValue(`${newLeverage}`);
|
||||
setLeverageInputValue(newLeverage);
|
||||
|
||||
// Ensure Abacus is updated with the latest, committed value
|
||||
debouncedSetAbacusLeverage.cancel();
|
||||
@@ -103,7 +102,7 @@ export const LeverageSlider = ({
|
||||
min={min}
|
||||
max={max}
|
||||
step={0.1}
|
||||
value={[Math.min(Math.max(leverageInputNumber, min), max)]}
|
||||
value={[Math.min(Math.max(leverageInputBN.toNumber(), min), max)]}
|
||||
onValueChange={onSliderDrag}
|
||||
onValueCommit={onValueCommit}
|
||||
>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { Dispatch, SetStateAction } from 'react';
|
||||
import { shallowEqual, useSelector } from 'react-redux';
|
||||
import styled, { AnyStyledComponent } from 'styled-components';
|
||||
import { OrderSide } from '@dydxprotocol/v4-client-js';
|
||||
|
||||
import { TradeInputField } from '@/constants/abacus';
|
||||
import { TradeInputField, Nullable } from '@/constants/abacus';
|
||||
import { ButtonShape } from '@/constants/buttons';
|
||||
import { STRING_KEYS } from '@/constants/localization';
|
||||
import { LEVERAGE_DECIMALS } from '@/constants/numbers';
|
||||
@@ -61,7 +62,21 @@ export const MarketLeverageInput = ({
|
||||
|
||||
const leveragePosition = postOrderLeverage ? newPositionSide : currentPositionSide;
|
||||
|
||||
const getSignedLeverage = (newLeverage: string | number) => {
|
||||
const onLeverageInput = ({ value, floatValue }: { value: string; floatValue?: number }) => {
|
||||
const newLeverage = MustBigNumber(floatValue).toFixed();
|
||||
|
||||
if (value === '' || newLeverage === 'NaN' || !floatValue) {
|
||||
setLeverageInputValue('');
|
||||
abacusStateManager.setTradeValue({
|
||||
value: null,
|
||||
field: TradeInputField.leverage,
|
||||
});
|
||||
} else {
|
||||
updateLeverage(floatValue);
|
||||
}
|
||||
};
|
||||
|
||||
const updateLeverage = (newLeverage: string | number) => {
|
||||
const newLeverageBN = MustBigNumber(newLeverage);
|
||||
const newLeverageSignedBN =
|
||||
leveragePosition === PositionSide.Short ||
|
||||
@@ -69,33 +84,10 @@ export const MarketLeverageInput = ({
|
||||
? newLeverageBN.abs().negated()
|
||||
: newLeverageBN.abs();
|
||||
|
||||
return newLeverageSignedBN.toFixed(LEVERAGE_DECIMALS);
|
||||
};
|
||||
|
||||
const onLeverageInput = ({
|
||||
floatValue,
|
||||
formattedValue,
|
||||
}: {
|
||||
floatValue?: number;
|
||||
formattedValue: string;
|
||||
}) => {
|
||||
setLeverageInputValue(formattedValue);
|
||||
const newLeverage = MustBigNumber(floatValue).toFixed();
|
||||
setLeverageInputValue(newLeverageSignedBN.toString());
|
||||
|
||||
abacusStateManager.setTradeValue({
|
||||
value:
|
||||
formattedValue === '' || newLeverage === 'NaN' ? null : getSignedLeverage(formattedValue),
|
||||
field: TradeInputField.leverage,
|
||||
});
|
||||
};
|
||||
|
||||
const updateLeverage = (newLeverage: string | number) => {
|
||||
const newLeverageSigned = getSignedLeverage(newLeverage);
|
||||
|
||||
setLeverageInputValue(newLeverageSigned);
|
||||
|
||||
abacusStateManager.setTradeValue({
|
||||
value: newLeverageSigned,
|
||||
value: newLeverageSignedBN.toFixed(LEVERAGE_DECIMALS),
|
||||
field: TradeInputField.leverage,
|
||||
});
|
||||
};
|
||||
@@ -138,7 +130,7 @@ export const MarketLeverageInput = ({
|
||||
>
|
||||
<Styled.LeverageSlider
|
||||
leverage={currentLeverage}
|
||||
leverageInputValue={getSignedLeverage(leverageInputValue)}
|
||||
leverageInputValue={leverageInputValue}
|
||||
maxLeverage={maxLeverage}
|
||||
orderSide={orderSide}
|
||||
positionSide={currentPositionSide}
|
||||
|
||||
@@ -49,7 +49,7 @@ export const TradeSizeInputs = () => {
|
||||
useSelector(getCurrentMarketConfig, shallowEqual) || {};
|
||||
const { size, usdcSize, leverage, input: lastEditedInput } = inputTradeSizeData || {};
|
||||
const { needsLeverage } = currentTradeInputOptions || {};
|
||||
const decimals = stepSizeDecimals ?? TOKEN_DECIMALS;
|
||||
const decimals = stepSizeDecimals || TOKEN_DECIMALS;
|
||||
|
||||
const { amountInput, usdAmountInput, leverageInput } = useSelector(
|
||||
getTradeFormInputs,
|
||||
@@ -70,34 +70,22 @@ export const TradeSizeInputs = () => {
|
||||
}
|
||||
}, [size, usdcSize, leverage, lastEditedInput]);
|
||||
|
||||
const onSizeInput = ({
|
||||
floatValue,
|
||||
formattedValue,
|
||||
}: {
|
||||
floatValue?: number;
|
||||
formattedValue: string;
|
||||
}) => {
|
||||
dispatch(setTradeFormInputs({ amountInput: formattedValue }));
|
||||
const onSizeInput = ({ value, floatValue }: { value: string; floatValue?: number }) => {
|
||||
dispatch(setTradeFormInputs({ amountInput: value }));
|
||||
const newAmount = MustBigNumber(floatValue).toFixed(decimals);
|
||||
|
||||
abacusStateManager.setTradeValue({
|
||||
value: formattedValue === '' || newAmount === 'NaN' ? null : newAmount,
|
||||
value: value === '' || newAmount === 'NaN' ? null : newAmount,
|
||||
field: TradeInputField.size,
|
||||
});
|
||||
};
|
||||
|
||||
const onUSDCInput = ({
|
||||
floatValue,
|
||||
formattedValue,
|
||||
}: {
|
||||
floatValue?: number;
|
||||
formattedValue: string;
|
||||
}) => {
|
||||
dispatch(setTradeFormInputs({ usdAmountInput: formattedValue }));
|
||||
const newUsdcAmount = MustBigNumber(floatValue).toFixed(tickSizeDecimals || USD_DECIMALS);
|
||||
const onUSDCInput = ({ value, floatValue }: { value: string; floatValue?: number }) => {
|
||||
dispatch(setTradeFormInputs({ usdAmountInput: value }));
|
||||
const newUsdcAmount = MustBigNumber(floatValue).toFixed();
|
||||
|
||||
abacusStateManager.setTradeValue({
|
||||
value: formattedValue === '' || newUsdcAmount === 'NaN' ? null : newUsdcAmount,
|
||||
value: value === '' || newUsdcAmount === 'NaN' ? null : newUsdcAmount,
|
||||
field: TradeInputField.usdcSize,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -12,11 +12,10 @@ import { LoadingSpinner } from '@/components/Loading/LoadingSpinner';
|
||||
import { layoutMixins } from '@/styles/layoutMixins';
|
||||
import { STRING_KEYS } from '@/constants/localization';
|
||||
import { ENVIRONMENT_CONFIG_MAP } from '@/constants/networks';
|
||||
import { TransferNotificationTypes } from '@/constants/notifications';
|
||||
|
||||
type ElementProps = {
|
||||
status?: StatusResponse;
|
||||
type: TransferNotificationTypes;
|
||||
type: 'withdrawal' | 'deposit';
|
||||
};
|
||||
|
||||
type StyleProps = {
|
||||
@@ -47,13 +46,11 @@ export const TransferStatusSteps = ({ className, status, type }: ElementProps &
|
||||
{
|
||||
label: stringGetter({
|
||||
key:
|
||||
type === TransferNotificationTypes.Deposit
|
||||
? STRING_KEYS.INITIATED_DEPOSIT
|
||||
: STRING_KEYS.INITIATED_WITHDRAWAL,
|
||||
type === 'deposit' ? STRING_KEYS.INITIATED_DEPOSIT : STRING_KEYS.INITIATED_WITHDRAWAL,
|
||||
}),
|
||||
step: TransferStatusStep.FromChain,
|
||||
link:
|
||||
type === TransferNotificationTypes.Deposit
|
||||
link:
|
||||
type === 'deposit'
|
||||
? status?.fromChain?.transactionUrl
|
||||
: routeStatus?.[0]?.chainId === dydxChainId && routeStatus[0].txHash
|
||||
? `${mintscanTxUrl?.replace('{tx_hash}', routeStatus[0].txHash.replace('0x', ''))}`
|
||||
@@ -66,20 +63,14 @@ export const TransferStatusSteps = ({ className, status, type }: ElementProps &
|
||||
},
|
||||
{
|
||||
label: stringGetter({
|
||||
key:
|
||||
type === TransferNotificationTypes.Deposit
|
||||
? STRING_KEYS.DEPOSIT_TO_CHAIN
|
||||
: STRING_KEYS.WITHDRAW_TO_CHAIN,
|
||||
key: type === 'deposit' ? STRING_KEYS.DEPOSIT_TO_CHAIN : STRING_KEYS.WITHDRAW_TO_CHAIN,
|
||||
params: {
|
||||
CHAIN:
|
||||
type === TransferNotificationTypes.Deposit
|
||||
? 'dYdX'
|
||||
: status?.toChain?.chainData?.chainName,
|
||||
CHAIN: type === 'deposit' ? 'dYdX' : status?.toChain?.chainData?.chainName,
|
||||
},
|
||||
}),
|
||||
step: TransferStatusStep.ToChain,
|
||||
link:
|
||||
type === TransferNotificationTypes.Withdrawal
|
||||
type === 'withdrawal'
|
||||
? status?.toChain?.transactionUrl
|
||||
: currentStatus?.chainId === dydxChainId && currentStatus?.txHash
|
||||
? `${mintscanTxUrl?.replace('{tx_hash}', currentStatus.txHash.replace('0x', ''))}`
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useInterval, useStringGetter } from '@/hooks';
|
||||
|
||||
import { AlertType } from '@/constants/alerts';
|
||||
import { STRING_KEYS } from '@/constants/localization';
|
||||
import { TransferNotifcation, TransferNotificationTypes } from '@/constants/notifications';
|
||||
import { TransferNotifcation } from '@/constants/notifications';
|
||||
|
||||
import { formatSeconds } from '@/lib/timeUtils';
|
||||
|
||||
@@ -22,7 +22,7 @@ import { layoutMixins } from '@/styles/layoutMixins';
|
||||
import { TransferStatusSteps } from './TransferStatusSteps';
|
||||
|
||||
type ElementProps = {
|
||||
type: TransferNotificationTypes;
|
||||
type: 'withdrawal' | 'deposit';
|
||||
transfer: TransferNotifcation;
|
||||
triggeredAt?: number;
|
||||
};
|
||||
@@ -55,7 +55,7 @@ export const TransferStatusNotification = ({
|
||||
useInterval({ callback: updateSecondsLeft });
|
||||
|
||||
const inProgressStatusString =
|
||||
type === TransferNotificationTypes.Deposit
|
||||
type === 'deposit'
|
||||
? secondsLeft > 0
|
||||
? STRING_KEYS.DEPOSIT_STATUS
|
||||
: STRING_KEYS.DEPOSIT_STATUS_SHORTLY
|
||||
@@ -64,7 +64,7 @@ export const TransferStatusNotification = ({
|
||||
: STRING_KEYS.WITHDRAW_STATUS_SHORTLY;
|
||||
|
||||
const statusString =
|
||||
type === TransferNotificationTypes.Deposit
|
||||
type === 'deposit'
|
||||
? status?.squidTransactionStatus === 'success'
|
||||
? STRING_KEYS.DEPOSIT_COMPLETE
|
||||
: inProgressStatusString
|
||||
|
||||
@@ -42,11 +42,7 @@ type StyleProps = {
|
||||
className?: string;
|
||||
};
|
||||
|
||||
type RowData = Pick<OrderbookLine, 'depth' | 'offset' | 'price' | 'size'> & {
|
||||
side: 'bid' | 'ask';
|
||||
mine?: number;
|
||||
key: string;
|
||||
};
|
||||
type RowData = OrderbookLine & { side: 'bid' | 'ask'; mine?: number };
|
||||
|
||||
const useCalculateOrderbookData = ({ maxRowsPerSide }: { maxRowsPerSide: number }) => {
|
||||
const orderbook = useSelector(getCurrentMarketOrderbook, shallowEqual);
|
||||
@@ -57,9 +53,8 @@ const useCalculateOrderbookData = ({ maxRowsPerSide }: { maxRowsPerSide: number
|
||||
return useMemo(() => {
|
||||
const asks = (orderbook?.asks?.toArray() ?? [])
|
||||
.map(
|
||||
(row: OrderbookLine, idx: number) =>
|
||||
(row: OrderbookLine) =>
|
||||
({
|
||||
key: `ask-${idx}`,
|
||||
side: 'ask',
|
||||
mine: openOrdersBySideAndPrice[OrderSide.SELL]?.[row.price]?.size,
|
||||
...row,
|
||||
@@ -69,9 +64,8 @@ const useCalculateOrderbookData = ({ maxRowsPerSide }: { maxRowsPerSide: number
|
||||
|
||||
const bids = (orderbook?.bids?.toArray() ?? [])
|
||||
.map(
|
||||
(row: OrderbookLine, idx: number) =>
|
||||
(row: OrderbookLine) =>
|
||||
({
|
||||
key: `bid-${idx}`,
|
||||
side: 'bid',
|
||||
mine: openOrdersBySideAndPrice[OrderSide.BUY]?.[row.price]?.size,
|
||||
...row,
|
||||
@@ -103,44 +97,15 @@ const useCalculateOrderbookData = ({ maxRowsPerSide }: { maxRowsPerSide: number
|
||||
}
|
||||
|
||||
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 histogramRange = Math.max(
|
||||
isNaN(Number(bids[bids.length - 1]?.depth)) ? 0 : Number(bids[bids.length - 1]?.depth),
|
||||
isNaN(Number(asks[asks.length - 1]?.depth)) ? 0 : Number(asks[asks.length - 1]?.depth)
|
||||
Number(bids[bids.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 };
|
||||
}, [orderbook, openOrdersBySideAndPrice]);
|
||||
};
|
||||
@@ -177,33 +142,31 @@ const OrderbookTable = ({
|
||||
getCellValue: (row: RowData) => row.size,
|
||||
label: stringGetter({ key: STRING_KEYS.ORDERBOOK_ORDER_SIZE }),
|
||||
tag: symbol,
|
||||
renderCell: (row: RowData) =>
|
||||
row.size > 0 && (
|
||||
<Styled.HistogramOutput
|
||||
highlightText
|
||||
type={OutputType.Asset}
|
||||
value={row.size}
|
||||
fractionDigits={stepSizeDecimals}
|
||||
histogramSide={histogramSide === 'left' && 'left'}
|
||||
useGrouping={false}
|
||||
/>
|
||||
),
|
||||
renderCell: (row: RowData) => (
|
||||
<Styled.HistogramOutput
|
||||
highlightText
|
||||
type={OutputType.Asset}
|
||||
value={row.size}
|
||||
fractionDigits={stepSizeDecimals}
|
||||
histogramSide={histogramSide === 'left' && 'left'}
|
||||
useGrouping={false}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
columnKey: 'price',
|
||||
getCellValue: (row: RowData) => row.price,
|
||||
label: stringGetter({ key: STRING_KEYS.PRICE }),
|
||||
tag: 'USD',
|
||||
renderCell: (row: RowData) =>
|
||||
row.price > 0 && (
|
||||
<OrderbookTradesOutput
|
||||
highlightText
|
||||
type={OutputType.Number}
|
||||
value={row.price}
|
||||
fractionDigits={tickSizeDecimals}
|
||||
useGrouping={false}
|
||||
/>
|
||||
),
|
||||
renderCell: (row: RowData) => (
|
||||
<OrderbookTradesOutput
|
||||
highlightText
|
||||
type={OutputType.Number}
|
||||
value={row.price}
|
||||
fractionDigits={tickSizeDecimals}
|
||||
useGrouping={false}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
columnKey: 'subaccount-orders',
|
||||
@@ -231,13 +194,12 @@ const OrderbookTable = ({
|
||||
label="Orderbook"
|
||||
data={data}
|
||||
columns={columns}
|
||||
getRowKey={(row: RowData) => row.key}
|
||||
getRowKey={(row: RowData) => `${row.side}-${row.price}`}
|
||||
getRowAttributes={(row: RowData) => ({
|
||||
'data-side': row.side,
|
||||
style: {
|
||||
'--histogram-bucket-size': row.size,
|
||||
'--histogram-bucket-depth': row.depth,
|
||||
'--tr-pointerEvents': row.price ? 'auto' : 'none',
|
||||
},
|
||||
})}
|
||||
onRowAction={onRowAction}
|
||||
@@ -276,10 +238,19 @@ export const Orderbook = ({
|
||||
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(
|
||||
() =>
|
||||
[
|
||||
...bids.reverse(),
|
||||
...bids.slice(0, showRowsPerSide).reverse(),
|
||||
{
|
||||
key: 'spread',
|
||||
slotCustomRow: (props) => (
|
||||
@@ -296,9 +267,9 @@ export const Orderbook = ({
|
||||
</Styled.SpreadTableRow>
|
||||
),
|
||||
} as CustomRowConfig,
|
||||
...asks,
|
||||
...asks.slice(0, showRowsPerSide),
|
||||
].reverse(),
|
||||
[asks, bids, spread, spreadPercent, isTablet]
|
||||
[asks, bids, spread, spreadPercent, showRowsPerSide, isTablet]
|
||||
);
|
||||
|
||||
const onRowAction = useCallback(
|
||||
@@ -354,7 +325,7 @@ export const Orderbook = ({
|
||||
</Styled.Header>
|
||||
<Styled.SplitOrderbook>
|
||||
<OrderbookTable data={asks} histogramSide="right" {...orderbookTableProps} />
|
||||
<OrderbookTable data={bids.reverse()} histogramSide="left" {...orderbookTableProps} />
|
||||
<OrderbookTable data={bids} histogramSide="left" {...orderbookTableProps} />
|
||||
</Styled.SplitOrderbook>
|
||||
</Styled.HorizontalLayout>
|
||||
);
|
||||
@@ -524,7 +495,6 @@ Styled.OrderbookTable = styled(OrderbookTradesTable)<StyleProps>`
|
||||
|
||||
tr {
|
||||
--histogram-bucket-depth: 0;
|
||||
pointer-events: var(--tr-pointerEvents);
|
||||
|
||||
&[data-side='bid'] {
|
||||
--accent-color: var(--color-positive);
|
||||
|
||||
Reference in New Issue
Block a user