Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo committed Dec 20, 2024
2 parents 1f02709 + 1d27a79 commit 475a781
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 235 deletions.
2 changes: 1 addition & 1 deletion src/abacus-ts/logs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from '@/lib/telemetry';

export function logAbacusTsError(source: string, message: string, ...args: any[]) {
log(`${source}: ${message}`, undefined, { context: args });
log(`${source}: ${message}`, undefined, { context: args }, true);
}
5 changes: 3 additions & 2 deletions src/constants/dialogs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ReactNode } from 'react';

import { IndexerPositionSide } from '@/types/indexer/indexerApiGen';
import { TagsOf, UnionOf, ofType, unionize } from 'unionize';

import { BigNumberish } from '@/lib/numbers';

import { AbacusPositionSides, Nullable, SubaccountOrder, SubaccountPosition } from './abacus';
import { Nullable, SubaccountOrder, SubaccountPosition } from './abacus';
import { IAffiliateStats } from './affiliates';
import { DydxChainAsset } from './wallets';

Expand Down Expand Up @@ -64,7 +65,7 @@ export type SharePNLAnalyticsDialogProps = {
oraclePrice: Nullable<number>;
entryPrice: Nullable<number>;
unrealizedPnl: Nullable<number>;
side: Nullable<AbacusPositionSides>;
side: Nullable<IndexerPositionSide>;
sideLabel: Nullable<string>;
};
export type StakeDialogProps = {};
Expand Down
3 changes: 3 additions & 0 deletions src/lib/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const MustBigNumber = (amount?: BigNumberish | null): BigNumber =>
export const MaybeBigNumber = (amount?: BigNumberish | null): BigNumber | undefined =>
amount ? MustBigNumber(amount) : undefined;

export const MaybeNumber = (amount?: BigNumberish | null): number | undefined =>
amount ? MustBigNumber(amount).toNumber() : undefined;

// doesnt allow null, always returns big number
// empty string becomes null though
export const ToBigNumber = (amount: BigNumberish): BigNumber => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { isDev } from '@/constants/networks';
import { track } from './analytics/analytics';
import { dd } from './analytics/datadog';

export const log = (location: string, error?: Error, metadata?: object) => {
if (isDev) {
export const log = (location: string, error?: Error, metadata?: object, forceLog?: boolean) => {
if (isDev || forceLog) {
// eslint-disable-next-line no-console
console.warn('telemetry/log:', { location, error, metadata });
}
Expand Down
8 changes: 6 additions & 2 deletions src/pages/portfolio/Portfolio.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { lazy, Suspense } from 'react';

import { selectParentSubaccountOpenPositions } from '@/abacus-ts/selectors/account';
import { shallowEqual } from 'react-redux';
import { Navigate, Route, Routes } from 'react-router-dom';
import styled from 'styled-components';
Expand All @@ -9,6 +10,7 @@ import { ButtonAction } from '@/constants/buttons';
import { ComplianceStates } from '@/constants/compliance';
import { DialogTypes } from '@/constants/dialogs';
import { STRING_KEYS } from '@/constants/localization';
import { EMPTY_ARR } from '@/constants/objects';
import { HistoryRoute, PortfolioRoute } from '@/constants/routes';

import { useAccountBalance } from '@/hooks/useAccountBalance';
Expand Down Expand Up @@ -61,8 +63,10 @@ const PortfolioPage = () => {
const { freeCollateral } = useAppSelector(getSubaccount, shallowEqual) ?? {};
const { nativeTokenBalance } = useAccountBalance();

const { numTotalPositions, numTotalOpenOrders } =
useAppSelector(getTradeInfoNumbers, shallowEqual) ?? {};
const { numTotalOpenOrders } = useAppSelector(getTradeInfoNumbers, shallowEqual);
const numTotalPositions = (useAppSelector(selectParentSubaccountOpenPositions) ?? EMPTY_ARR)
.length;

const numPositions = shortenNumberForDisplay(numTotalPositions);
const numOrders = shortenNumberForDisplay(numTotalOpenOrders);

Expand Down
9 changes: 5 additions & 4 deletions src/pages/trade/HorizontalPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useCallback, useMemo, useState } from 'react';

import { BonsaiCore } from '@/abacus-ts/ontology';
import { shallowEqual } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import styled from 'styled-components';

import { STRING_KEYS } from '@/constants/localization';
import { EMPTY_ARR } from '@/constants/objects';
import { AppRoute } from '@/constants/routes';

import { useBreakpoints } from '@/hooks/useBreakpoints';
Expand All @@ -31,7 +31,6 @@ import {
createGetUnseenFillsCount,
createGetUnseenOpenOrdersCount,
createGetUnseenOrderHistoryCount,
getTradeInfoNumbers,
} from '@/state/accountSelectors';
import { useAppSelector } from '@/state/appTypes';
import { getDefaultToAllMarketsInPositionsOrdersFills } from '@/state/appUiConfigsSelectors';
Expand Down Expand Up @@ -72,8 +71,6 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {

const currentMarketId = useAppSelector(getCurrentMarketId);

const { numTotalPositions } = useAppSelector(getTradeInfoNumbers, shallowEqual);

const isAccountViewOnly = useAppSelector(calculateIsAccountViewOnly);
const shouldRenderTriggers = useShouldShowTriggers();
const shouldRenderActions = useParameterizedSelector(
Expand All @@ -87,6 +84,10 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {
createGetOpenOrdersCount,
showCurrentMarket ? currentMarketId : undefined
);
const numTotalPositions = (
useAppSelector(BonsaiCore.account.parentSubaccountPositions.data) ?? EMPTY_ARR
).length;

const unseenOrders = useParameterizedSelector(
createGetUnseenOpenOrdersCount,
showCurrentMarket ? currentMarketId : undefined
Expand Down
11 changes: 11 additions & 0 deletions src/pages/trade/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MarginMode } from '@/abacus-ts/summaryTypes';

export enum MarketTypeFilter {
AllMarkets = 'AllMarkets',
Cross = 'Cross',
Expand All @@ -13,6 +15,15 @@ export function marketTypeMatchesFilter(type: 'Isolated' | 'Cross', filter?: Mar
);
}

export function marginModeMatchesFilter(type: MarginMode, filter?: MarketTypeFilter) {
return (
filter == null ||
filter === MarketTypeFilter.AllMarkets ||
(type === 'ISOLATED' && filter === MarketTypeFilter.Isolated) ||
(type === 'CROSS' && filter === MarketTypeFilter.Cross)
);
}

export enum PanelView {
AllMarkets = 'AllMarkets',
CurrentMarket = 'CurrentMarket',
Expand Down
8 changes: 4 additions & 4 deletions src/views/dialogs/SharePNLAnalyticsDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo } from 'react';

import { IndexerPositionSide } from '@/types/indexer/indexerApiGen';
import { useToBlob } from '@hugocxl/react-to-image';
import styled from 'styled-components';
import tw from 'twin.macro';
Expand All @@ -8,7 +9,6 @@ import { AnalyticsEvents } from '@/constants/analytics';
import { ButtonAction } from '@/constants/buttons';
import { DialogProps, SharePNLAnalyticsDialogProps } from '@/constants/dialogs';
import { STRING_KEYS } from '@/constants/localization';
import { PositionSide } from '@/constants/trade';

import { useStringGetter } from '@/hooks/useStringGetter';

Expand Down Expand Up @@ -82,10 +82,10 @@ export const SharePNLAnalyticsDialog = ({
});

const sideSign = useMemo(() => {
switch (side?.name) {
case PositionSide.Long:
switch (side) {
case IndexerPositionSide.LONG:
return TagSign.Positive;
case PositionSide.Short:
case IndexerPositionSide.SHORT:
return TagSign.Negative;
default:
return TagSign.Neutral;
Expand Down
Loading

0 comments on commit 475a781

Please sign in to comment.