Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: undo ui-facing new abacus changes #1390

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions src/pages/trade/HorizontalPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {
calculateShouldRenderActionsInPositionsTable,
} from '@/state/accountCalculators';
import {
createGetUnseenFillsCount,
createGetUnseenOrdersCount,
getCurrentMarketTradeInfoNumbers,
getHasUnseenFillUpdates,
getHasUnseenOrderUpdates,
getTradeInfoNumbers,
} from '@/state/accountSelectors';
import { useAppSelector } from '@/state/appTypes';
Expand Down Expand Up @@ -69,13 +69,14 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {

const currentMarketId = useAppSelector(getCurrentMarketId);

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

const { numOpenOrders } = useAppSelector(getCurrentMarketTradeInfoNumbers, shallowEqual);
const { numOpenOrders, numUnseenFills } =
useAppSelector(getCurrentMarketTradeInfoNumbers, shallowEqual) ?? {};

const hasUnseenOrderUpdates = useAppSelector(getHasUnseenOrderUpdates);
const hasUnseenFillUpdates = useAppSelector(getHasUnseenFillUpdates);
const isAccountViewOnly = useAppSelector(calculateIsAccountViewOnly);
const shouldRenderTriggers = useShouldShowTriggers();
const shouldRenderActions = useParameterizedSelector(
Expand All @@ -84,18 +85,9 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {
const isWaitingForOrderToIndex = useAppSelector(getHasUncommittedOrders);
const showCurrentMarket = isTablet || view === PanelView.CurrentMarket;

const unseenOrders = useParameterizedSelector(
createGetUnseenOrdersCount,
showCurrentMarket ? currentMarketId : undefined
);
const hasUnseenOrderUpdates = unseenOrders > 0;

const numUnseenFills = useParameterizedSelector(
createGetUnseenFillsCount,
showCurrentMarket ? currentMarketId : undefined
const fillsTagNumber = shortenNumberForDisplay(
showCurrentMarket ? numUnseenFills : numTotalUnseenFills
);
const hasUnseenFillUpdates = numUnseenFills > 0;
const fillsTagNumber = shortenNumberForDisplay(numUnseenFills);
const ordersTagNumber = shortenNumberForDisplay(
showCurrentMarket ? numOpenOrders : numTotalOpenOrders
);
Expand Down
61 changes: 32 additions & 29 deletions src/views/MarketDetails/CurrentMarketDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { selectCurrentMarketAssetInfo } from '@/abacus-ts/selectors/assets';
import { selectCurrentMarketInfo } from '@/abacus-ts/selectors/markets';
import { IndexerPerpetualMarketType } from '@/types/indexer/indexerApiGen';
import BigNumber from 'bignumber.js';
import { shallowEqual } from 'react-redux';

import { PerpetualMarketType } from '@/constants/abacus';
import { STRING_KEYS } from '@/constants/localization';

import { useStringGetter } from '@/hooks/useStringGetter';
Expand All @@ -13,51 +11,56 @@ import { DiffOutput } from '@/components/DiffOutput';
import { Output, OutputType } from '@/components/Output';

import { useAppSelector } from '@/state/appTypes';
import { getCurrentMarketAssetData } from '@/state/assetsSelectors';
import { getCurrentMarketData } from '@/state/perpetualsSelectors';

import { getAssetDescriptionStringKeys } from '@/lib/assetUtils';
import { getDisplayableAssetFromBaseAsset } from '@/lib/assetUtils';
import { BIG_NUMBERS } from '@/lib/numbers';
import { orEmptyObj } from '@/lib/typeUtils';

import { MarketDetails } from './MarketDetails';

export const CurrentMarketDetails = () => {
const stringGetter = useStringGetter();
const currentMarketData = useAppSelector(selectCurrentMarketInfo, shallowEqual);
const asset = useAppSelector(selectCurrentMarketAssetInfo);
const { configs, displayId } = useAppSelector(getCurrentMarketData, shallowEqual) ?? {};
const { id, name, resources } = useAppSelector(getCurrentMarketAssetData, shallowEqual) ?? {};

if (!configs) return null;

const {
displayableAsset,
displayableTicker,
effectiveInitialMarginFraction,
initialMarginFraction,
maintenanceMarginFraction,
marketType,
tickSize,
tickSizeDecimals,
stepSize,
initialMarginFraction,
effectiveInitialMarginFraction,
maintenanceMarginFraction,
minOrderSize,
perpetualMarketType,
stepSizeDecimals,
} = orEmptyObj(currentMarketData);
tickSizeDecimals,
} = configs;

const { assetId, logo, name, urls } = orEmptyObj(asset);
const { cmc, website, technicalDoc } = orEmptyObj(urls);
const { primary, secondary } = getAssetDescriptionStringKeys(assetId ?? '');
const {
coinMarketCapsLink,
primaryDescriptionKey,
secondaryDescriptionKey,
websiteLink,
whitepaperLink,
} = resources ?? {};

const preferEIMF = Boolean(
effectiveInitialMarginFraction &&
initialMarginFraction !== effectiveInitialMarginFraction.toString()
effectiveInitialMarginFraction && initialMarginFraction !== effectiveInitialMarginFraction
);

const items = [
{
key: 'ticker',
label: stringGetter({ key: STRING_KEYS.TICKER }),
value: displayableTicker,
value: displayId,
},
{
key: 'market-type',
label: stringGetter({ key: STRING_KEYS.TYPE }),
value:
marketType === IndexerPerpetualMarketType.CROSS
perpetualMarketType === PerpetualMarketType.CROSS
? stringGetter({ key: STRING_KEYS.CROSS })
: stringGetter({ key: STRING_KEYS.ISOLATED }),
},
Expand All @@ -83,7 +86,7 @@ export const CurrentMarketDetails = () => {
useGrouping
value={stepSize}
type={OutputType.Asset}
tag={displayableAsset}
tag={getDisplayableAssetFromBaseAsset(id)}
fractionDigits={stepSizeDecimals}
/>
),
Expand All @@ -94,9 +97,9 @@ export const CurrentMarketDetails = () => {
value: (
<Output
useGrouping
value={stepSize}
value={minOrderSize}
type={OutputType.Asset}
tag={displayableAsset}
tag={getDisplayableAssetFromBaseAsset(id)}
fractionDigits={stepSizeDecimals}
/>
),
Expand Down Expand Up @@ -146,11 +149,11 @@ export const CurrentMarketDetails = () => {
return (
<MarketDetails
assetName={name}
assetIcon={{ symbol: assetId, logoUrl: logo }}
assetIcon={{ symbol: id, logoUrl: resources?.imageUrl }}
marketDetailItems={items}
primaryDescription={stringGetter({ key: primary })}
secondaryDescription={stringGetter({ key: secondary })}
urls={{ technicalDoc, website, cmc }}
primaryDescription={stringGetter({ key: `APP.${primaryDescriptionKey}` })}
secondaryDescription={stringGetter({ key: `APP.${secondaryDescriptionKey}` })}
urls={{ technicalDoc: whitepaperLink, website: websiteLink, cmc: coinMarketCapsLink }}
/>
);
};
12 changes: 9 additions & 3 deletions src/views/tables/FillsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef, Key, useMemo } from 'react';
import { forwardRef, Key, useEffect, useMemo } from 'react';

import { Nullable } from '@dydxprotocol/v4-abacus';
import { OrderSide } from '@dydxprotocol/v4-client-js';
Expand All @@ -13,7 +13,6 @@ import { STRING_KEYS, type StringGetterFunction } from '@/constants/localization
import { EMPTY_ARR } from '@/constants/objects';

import { useBreakpoints } from '@/hooks/useBreakpoints';
import { useViewPanel } from '@/hooks/useSeen';
import { useStringGetter } from '@/hooks/useStringGetter';

import { tradeViewMixins } from '@/styles/tradeViewMixins';
Expand All @@ -29,6 +28,7 @@ import { TableColumnHeader } from '@/components/Table/TableColumnHeader';
import { PageSize } from '@/components/Table/TablePaginationRow';
import { TagSize } from '@/components/Tag';

import { viewedFills } from '@/state/account';
import { getCurrentMarketFills, getSubaccountFills } from '@/state/accountSelectors';
import { useAppDispatch, useAppSelector } from '@/state/appTypes';
import { getAssets } from '@/state/assetsSelectors';
Expand Down Expand Up @@ -370,7 +370,13 @@ export const FillsTable = forwardRef(
const allPerpetualMarkets = orEmptyRecord(useAppSelector(getPerpetualMarkets, shallowEqual));
const allAssets = orEmptyRecord(useAppSelector(getAssets, shallowEqual));

useViewPanel(currentMarket, 'fills');
useEffect(() => {
// marked fills as seen both on mount and dismount (i.e. new fill came in while fills table is being shown)
dispatch(viewedFills(currentMarket));
return () => {
dispatch(viewedFills(currentMarket));
};
}, [currentMarket, dispatch]);

const symbol = mapIfPresent(currentMarket, (market) =>
mapIfPresent(allPerpetualMarkets[market]?.assetId, (assetId) => allAssets[assetId]?.id)
Expand Down
16 changes: 12 additions & 4 deletions src/views/tables/OrdersTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef, Key, ReactNode, useMemo } from 'react';
import { forwardRef, Key, ReactNode, useEffect, useMemo } from 'react';

import { OrderSide } from '@dydxprotocol/v4-client-js';
import { ColumnSize } from '@react-types/table';
Expand All @@ -14,7 +14,6 @@ import { TOKEN_DECIMALS } from '@/constants/numbers';
import { EMPTY_ARR } from '@/constants/objects';

import { useBreakpoints } from '@/hooks/useBreakpoints';
import { useViewPanel } from '@/hooks/useSeen';
import { useStringGetter } from '@/hooks/useStringGetter';

import breakpoints from '@/styles/breakpoints';
Expand All @@ -34,8 +33,13 @@ import { Tag, TagSize } from '@/components/Tag';
import { WithTooltip } from '@/components/WithTooltip';
import { MarketTypeFilter, marketTypeMatchesFilter } from '@/pages/trade/types';

import { viewedOrders } from '@/state/account';
import { calculateIsAccountViewOnly } from '@/state/accountCalculators';
import { getCurrentMarketOrders, getSubaccountUnclearedOrders } from '@/state/accountSelectors';
import {
getCurrentMarketOrders,
getHasUnseenOrderUpdates,
getSubaccountUnclearedOrders,
} from '@/state/accountSelectors';
import { useAppDispatch, useAppSelector } from '@/state/appTypes';
import { getAssets } from '@/state/assetsSelectors';
import { openDialog } from '@/state/dialogs';
Expand Down Expand Up @@ -432,7 +436,11 @@ export const OrdersTable = forwardRef(
const allPerpetualMarkets = orEmptyRecord(useAppSelector(getPerpetualMarkets, shallowEqual));
const allAssets = orEmptyRecord(useAppSelector(getAssets, shallowEqual));

useViewPanel(currentMarket, 'openOrders');
const hasUnseenOrderUpdates = useAppSelector(getHasUnseenOrderUpdates);

useEffect(() => {
if (hasUnseenOrderUpdates) dispatch(viewedOrders());
}, [hasUnseenOrderUpdates]);

const symbol = mapIfPresent(currentMarket, (market) =>
mapIfPresent(allPerpetualMarkets[market]?.assetId, (assetId) => allAssets[assetId]?.id)
Expand Down
Loading