fix type for placeOrder analytics
This commit is contained in:
+100
-115
@@ -4,7 +4,7 @@ import type { OnboardingState, OnboardingSteps } from './account';
|
||||
import type { DydxAddress, WalletType, WalletConnectionType, EthereumAddress } from './wallets';
|
||||
import type { DialogTypes } from './dialogs';
|
||||
import type { TradeTypes } from './trade';
|
||||
import type { AbacusApiStatus, SubaccountPlaceOrderPayload } from './abacus';
|
||||
import type { AbacusApiStatus, HumanReadablePlaceOrderPayload } from './abacus';
|
||||
|
||||
// User properties
|
||||
export enum AnalyticsUserProperty {
|
||||
@@ -25,37 +25,28 @@ export enum AnalyticsUserProperty {
|
||||
SubaccountNumber = 'subaccountNumber',
|
||||
}
|
||||
|
||||
export type AnalyticsUserPropertyValue<T extends AnalyticsUserProperty> =
|
||||
export type AnalyticsUserPropertyValue<T extends AnalyticsUserProperty> =
|
||||
// Environment
|
||||
T extends AnalyticsUserProperty.Breakpoint ?
|
||||
| 'MOBILE'
|
||||
| 'TABLET'
|
||||
| 'DESKTOP_SMALL'
|
||||
| 'DESKTOP_MEDIUM'
|
||||
| 'DESKTOP_LARGE'
|
||||
| 'UNSUPPORTED'
|
||||
: T extends AnalyticsUserProperty.Locale ?
|
||||
SupportedLocales
|
||||
|
||||
// Network
|
||||
: T extends AnalyticsUserProperty.Network ?
|
||||
DydxNetwork
|
||||
|
||||
// Wallet
|
||||
: T extends AnalyticsUserProperty.WalletType ?
|
||||
WalletType | undefined
|
||||
: T extends AnalyticsUserProperty.WalletConnectionType ?
|
||||
WalletConnectionType | undefined
|
||||
: T extends AnalyticsUserProperty.WalletAddress ?
|
||||
EthereumAddress | DydxAddress | undefined
|
||||
|
||||
// Account
|
||||
: T extends AnalyticsUserProperty.DydxAddress ?
|
||||
DydxAddress | undefined
|
||||
: T extends AnalyticsUserProperty.SubaccountNumber ?
|
||||
number | undefined
|
||||
|
||||
: undefined;
|
||||
T extends AnalyticsUserProperty.Breakpoint
|
||||
? 'MOBILE' | 'TABLET' | 'DESKTOP_SMALL' | 'DESKTOP_MEDIUM' | 'DESKTOP_LARGE' | 'UNSUPPORTED'
|
||||
: T extends AnalyticsUserProperty.Locale
|
||||
? SupportedLocales
|
||||
: // Network
|
||||
T extends AnalyticsUserProperty.Network
|
||||
? DydxNetwork
|
||||
: // Wallet
|
||||
T extends AnalyticsUserProperty.WalletType
|
||||
? WalletType | undefined
|
||||
: T extends AnalyticsUserProperty.WalletConnectionType
|
||||
? WalletConnectionType | undefined
|
||||
: T extends AnalyticsUserProperty.WalletAddress
|
||||
? EthereumAddress | DydxAddress | undefined
|
||||
: // Account
|
||||
T extends AnalyticsUserProperty.DydxAddress
|
||||
? DydxAddress | undefined
|
||||
: T extends AnalyticsUserProperty.SubaccountNumber
|
||||
? number | undefined
|
||||
: undefined;
|
||||
|
||||
// Events
|
||||
export enum AnalyticsEvent {
|
||||
@@ -91,87 +82,81 @@ export enum AnalyticsEvent {
|
||||
|
||||
export type AnalyticsEventData<T extends AnalyticsEvent> =
|
||||
// App
|
||||
T extends AnalyticsEvent.AppStart ?
|
||||
{}
|
||||
: T extends AnalyticsEvent.NetworkStatus ?
|
||||
{
|
||||
status: typeof AbacusApiStatus['name'];
|
||||
/** Last time indexer node was queried successfully */
|
||||
lastSuccessfulIndexerRpcQuery?: number;
|
||||
/** Time elapsed since indexer node was queried successfully */
|
||||
elapsedTime?: number;
|
||||
blockHeight?: number;
|
||||
indexerBlockHeight?: number;
|
||||
}
|
||||
|
||||
// Navigation
|
||||
: T extends AnalyticsEvent.NavigatePage ?
|
||||
{
|
||||
path: string;
|
||||
}
|
||||
: T extends AnalyticsEvent.NavigateDialog ?
|
||||
{
|
||||
type: DialogTypes;
|
||||
}
|
||||
: T extends AnalyticsEvent.NavigateDialogClose ?
|
||||
{
|
||||
type: DialogTypes;
|
||||
}
|
||||
: T extends AnalyticsEvent.NavigateExternal ?
|
||||
{
|
||||
link: string;
|
||||
}
|
||||
|
||||
// Wallet
|
||||
: T extends AnalyticsEvent.ConnectWallet ?
|
||||
{
|
||||
walletType: WalletType;
|
||||
walletConnectionType: WalletConnectionType;
|
||||
}
|
||||
: T extends AnalyticsEvent.DisconnectWallet ?
|
||||
{}
|
||||
|
||||
// Onboarding
|
||||
: T extends AnalyticsEvent.OnboardingStepChanged ?
|
||||
{
|
||||
state: OnboardingState;
|
||||
step?: OnboardingSteps;
|
||||
}
|
||||
: T extends AnalyticsEvent.OnboardingAccountDerived ?
|
||||
{
|
||||
hasPreviousTransactions: boolean;
|
||||
}
|
||||
|
||||
// Transfers
|
||||
: T extends AnalyticsEvent.TransferFaucet ?
|
||||
{}
|
||||
: T extends AnalyticsEvent.TransferDeposit ?
|
||||
{}
|
||||
: T extends AnalyticsEvent.TransferWithdraw ?
|
||||
{}
|
||||
|
||||
// Trading
|
||||
: T extends AnalyticsEvent.TradeOrderTypeSelected ?
|
||||
{
|
||||
type: TradeTypes;
|
||||
}
|
||||
: T extends AnalyticsEvent.TradePlaceOrder ?
|
||||
SubaccountPlaceOrderPayload & {
|
||||
isClosePosition: boolean;
|
||||
}
|
||||
: T extends AnalyticsEvent.TradePlaceOrderConfirmed ?
|
||||
{
|
||||
/** roundtrip time between user placing an order and confirmation from indexer (client → validator → indexer → client) */
|
||||
roundtripMs: number;
|
||||
/** URL/IP of node the order was sent to */
|
||||
validator: string;
|
||||
}
|
||||
: T extends AnalyticsEvent.TradeCancelOrderConfirmed ?
|
||||
{
|
||||
/** roundtrip time between user canceling an order and confirmation from indexer (client → validator → indexer → client) */
|
||||
roundtripMs: number;
|
||||
/** URL/IP of node the order was sent to */
|
||||
validator: string;
|
||||
}
|
||||
:
|
||||
never;
|
||||
T extends AnalyticsEvent.AppStart
|
||||
? {}
|
||||
: T extends AnalyticsEvent.NetworkStatus
|
||||
? {
|
||||
status: (typeof AbacusApiStatus)['name'];
|
||||
/** Last time indexer node was queried successfully */
|
||||
lastSuccessfulIndexerRpcQuery?: number;
|
||||
/** Time elapsed since indexer node was queried successfully */
|
||||
elapsedTime?: number;
|
||||
blockHeight?: number;
|
||||
indexerBlockHeight?: number;
|
||||
}
|
||||
: // Navigation
|
||||
T extends AnalyticsEvent.NavigatePage
|
||||
? {
|
||||
path: string;
|
||||
}
|
||||
: T extends AnalyticsEvent.NavigateDialog
|
||||
? {
|
||||
type: DialogTypes;
|
||||
}
|
||||
: T extends AnalyticsEvent.NavigateDialogClose
|
||||
? {
|
||||
type: DialogTypes;
|
||||
}
|
||||
: T extends AnalyticsEvent.NavigateExternal
|
||||
? {
|
||||
link: string;
|
||||
}
|
||||
: // Wallet
|
||||
T extends AnalyticsEvent.ConnectWallet
|
||||
? {
|
||||
walletType: WalletType;
|
||||
walletConnectionType: WalletConnectionType;
|
||||
}
|
||||
: T extends AnalyticsEvent.DisconnectWallet
|
||||
? {}
|
||||
: // Onboarding
|
||||
T extends AnalyticsEvent.OnboardingStepChanged
|
||||
? {
|
||||
state: OnboardingState;
|
||||
step?: OnboardingSteps;
|
||||
}
|
||||
: T extends AnalyticsEvent.OnboardingAccountDerived
|
||||
? {
|
||||
hasPreviousTransactions: boolean;
|
||||
}
|
||||
: // Transfers
|
||||
T extends AnalyticsEvent.TransferFaucet
|
||||
? {}
|
||||
: T extends AnalyticsEvent.TransferDeposit
|
||||
? {}
|
||||
: T extends AnalyticsEvent.TransferWithdraw
|
||||
? {}
|
||||
: // Trading
|
||||
T extends AnalyticsEvent.TradeOrderTypeSelected
|
||||
? {
|
||||
type: TradeTypes;
|
||||
}
|
||||
: T extends AnalyticsEvent.TradePlaceOrder
|
||||
? HumanReadablePlaceOrderPayload & {
|
||||
isClosePosition: boolean;
|
||||
}
|
||||
: T extends AnalyticsEvent.TradePlaceOrderConfirmed
|
||||
? {
|
||||
/** roundtrip time between user placing an order and confirmation from indexer (client → validator → indexer → client) */
|
||||
roundtripMs: number;
|
||||
/** URL/IP of node the order was sent to */
|
||||
validator: string;
|
||||
}
|
||||
: T extends AnalyticsEvent.TradeCancelOrderConfirmed
|
||||
? {
|
||||
/** roundtrip time between user canceling an order and confirmation from indexer (client → validator → indexer → client) */
|
||||
roundtripMs: number;
|
||||
/** URL/IP of node the order was sent to */
|
||||
validator: string;
|
||||
}
|
||||
: never;
|
||||
|
||||
@@ -215,6 +215,7 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
type,
|
||||
side,
|
||||
price,
|
||||
triggerPrice,
|
||||
size,
|
||||
clientId,
|
||||
timeInForce,
|
||||
@@ -228,6 +229,7 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
type: OrderType;
|
||||
side: OrderSide;
|
||||
price: number;
|
||||
triggerPrice: Nullable<number>;
|
||||
size: number;
|
||||
clientId: number;
|
||||
timeInForce: OrderTimeInForce;
|
||||
@@ -250,7 +252,8 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
goodTilTimeInSeconds,
|
||||
execution,
|
||||
postOnly,
|
||||
reduceOnly
|
||||
reduceOnly,
|
||||
triggerPrice ?? undefined
|
||||
);
|
||||
|
||||
const endTimestamp = performance.now();
|
||||
@@ -287,7 +290,7 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
clobPairId,
|
||||
goodTilBlock,
|
||||
goodTilBlockTime
|
||||
)
|
||||
);
|
||||
|
||||
const endTimestamp = performance.now();
|
||||
|
||||
@@ -435,6 +438,7 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
type,
|
||||
side,
|
||||
price,
|
||||
triggerPrice,
|
||||
size,
|
||||
clientId,
|
||||
timeInForce,
|
||||
@@ -461,6 +465,7 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
type: type as OrderType,
|
||||
side: side as OrderSide,
|
||||
price,
|
||||
triggerPrice,
|
||||
size,
|
||||
clientId,
|
||||
timeInForce: timeInForce as OrderTimeInForce,
|
||||
@@ -490,7 +495,10 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
||||
);
|
||||
}
|
||||
|
||||
track(AnalyticsEvent.TradePlaceOrder, { ...orderParams, isClosePosition });
|
||||
track(AnalyticsEvent.TradePlaceOrder, {
|
||||
...orderParams,
|
||||
isClosePosition,
|
||||
} as HumanReadablePlaceOrderPayload & { isClosePosition: boolean });
|
||||
onSuccess?.();
|
||||
} catch (error) {
|
||||
const errorStringKey = error?.code && ORDER_ERROR_CODE_MAP[error.code as number];
|
||||
|
||||
Reference in New Issue
Block a user