Skip to content

Commit

Permalink
fix(sltp): fix positions tables in non trade views when sltp flag is …
Browse files Browse the repository at this point in the history
…on (#447)

* needs to be cleaned up

* clean up types

* fix unique stringId

* update localization

* fix lock file

* fix columns

* review comment

* review comments #2
  • Loading branch information
moo-onthelawn authored Apr 22, 2024
1 parent aa978a6 commit aa2ae94
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 30 deletions.
14 changes: 9 additions & 5 deletions src/pages/portfolio/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { AttachedExpandingSection, DetachedSection } from '@/components/ContentS
import { ContentSectionHeader } from '@/components/ContentSectionHeader';
import { PositionsTable, PositionsTableColumnKey } from '@/views/tables/PositionsTable';

import { calculateShouldRenderTriggersInPositionsTable } from '@/state/accountCalculators';
import {
calculateShouldRenderTriggersInPositionsTable,
calculateShouldRenderActionsInPositionsTable,
} from '@/state/accountCalculators';

import { isTruthy } from '@/lib/isTruthy';

Expand All @@ -22,9 +25,10 @@ export const Overview = () => {
const { isTablet } = useBreakpoints();
const navigate = useNavigate();

const showClosePositionAction = false;

const shouldRenderTriggers = useSelector(calculateShouldRenderTriggersInPositionsTable);
// TODO: CT-503
// const shouldRenderActions = useSelector(calculateShouldRenderActionsInPositionsTable);
const shouldRenderActions = useSelector(calculateShouldRenderActionsInPositionsTable(showClosePositionAction));

return (
<div>
Expand Down Expand Up @@ -53,8 +57,7 @@ export const Overview = () => {
PositionsTableColumnKey.RealizedPnl,
PositionsTableColumnKey.AverageOpenAndClose,
shouldRenderTriggers && PositionsTableColumnKey.Triggers,
// TODO: CT-503 re-enable when close positions dialog is created
// shouldRenderActions && PositionsTableColumnKey.Actions,
shouldRenderActions && PositionsTableColumnKey.Actions,
].filter(isTruthy)
}
currentRoute={AppRoute.Portfolio}
Expand All @@ -63,6 +66,7 @@ export const Overview = () => {
state: { from: AppRoute.Portfolio },
})
}
showClosePositionAction={showClosePositionAction}
withOuterBorder
/>
</Styled.AttachedExpandingSection>
Expand Down
14 changes: 9 additions & 5 deletions src/pages/portfolio/Positions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { AttachedExpandingSection } from '@/components/ContentSection';
import { ContentSectionHeader } from '@/components/ContentSectionHeader';
import { PositionsTable, PositionsTableColumnKey } from '@/views/tables/PositionsTable';

import { calculateShouldRenderTriggersInPositionsTable } from '@/state/accountCalculators';
import {
calculateShouldRenderTriggersInPositionsTable,
calculateShouldRenderActionsInPositionsTable,
} from '@/state/accountCalculators';

import { isTruthy } from '@/lib/isTruthy';
import { testFlags } from '@/lib/testFlags';
Expand All @@ -20,9 +23,10 @@ export const Positions = () => {
const { isTablet, isNotTablet } = useBreakpoints();
const navigate = useNavigate();

const showClosePositionAction = false;

const shouldRenderTriggers = useSelector(calculateShouldRenderTriggersInPositionsTable);
// TODO: CT-503
// const shouldRenderActions = useSelector(calculateShouldRenderActionsInPositionsTable);
const shouldRenderActions = useSelector(calculateShouldRenderActionsInPositionsTable(showClosePositionAction));

return (
<AttachedExpandingSection>
Expand All @@ -48,12 +52,12 @@ export const Positions = () => {
PositionsTableColumnKey.AverageOpenAndClose,
PositionsTableColumnKey.NetFunding,
shouldRenderTriggers && PositionsTableColumnKey.Triggers,
// TODO: CT-503 re-enable when close positions dialog is created
// shouldRenderActions && PositionsTableColumnKey.Actions,
shouldRenderActions && PositionsTableColumnKey.Actions,
].filter(isTruthy)
}
currentRoute={`${AppRoute.Portfolio}/${PortfolioRoute.Positions}`}
withOuterBorder={isNotTablet}
showClosePositionAction={showClosePositionAction}
navigateToOrders={() =>
navigate(`${AppRoute.Portfolio}/${PortfolioRoute.Orders}`, {
state: { from: AppRoute.Portfolio },
Expand Down
14 changes: 9 additions & 5 deletions src/pages/trade/HorizontalPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback, useMemo, useState } from 'react';

import { shallowEqual, useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import styled, { type AnyStyledComponent } from 'styled-components';
import styled from 'styled-components';

import { STRING_KEYS } from '@/constants/localization';
import { AppRoute } from '@/constants/routes';
Expand Down Expand Up @@ -72,22 +72,25 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {
const currentMarketId = useSelector(getCurrentMarketId);
const currentMarketAssetId = useSelector(getCurrentMarketAssetId);

const { numTotalPositions, numTotalOpenOrders, numTotalFills, numTotalFundingPayments } =
const { numTotalPositions, numTotalOpenOrders, numTotalFills } =
useSelector(getTradeInfoNumbers, shallowEqual) || {};

const { numOpenOrders, numFills, numFundingPayments } =
const { numOpenOrders, numFills } =
useSelector(getCurrentMarketTradeInfoNumbers, shallowEqual) || {};

const showClosePositionAction = true;

const hasUnseenOrderUpdates = useSelector(getHasUnseenOrderUpdates);
const hasUnseenFillUpdates = useSelector(getHasUnseenFillUpdates);
const isAccountViewOnly = useSelector(calculateIsAccountViewOnly);
const shouldRenderTriggers = useSelector(calculateShouldRenderTriggersInPositionsTable);
const shouldRenderActions = useSelector(calculateShouldRenderActionsInPositionsTable);
const shouldRenderActions = useSelector(
calculateShouldRenderActionsInPositionsTable(showClosePositionAction)
);
const isWaitingForOrderToIndex = useSelector(calculateHasUncommittedOrders);
const showCurrentMarket = isTablet || view === PanelView.CurrentMarket;

const fillsTagNumber = shortenNumberForDisplay(showCurrentMarket ? numFills : numTotalFills);

const ordersTagNumber = shortenNumberForDisplay(
showCurrentMarket ? numOpenOrders : numTotalOpenOrders
);
Expand Down Expand Up @@ -139,6 +142,7 @@ export const HorizontalPanel = ({ isOpen = true, setIsOpen }: ElementProps) => {
shouldRenderActions && PositionsTableColumnKey.Actions,
].filter(isTruthy)
}
showClosePositionAction={showClosePositionAction}
onNavigate={() => setView(PanelView.CurrentMarket)}
navigateToOrders={onViewOrders}
/>
Expand Down
10 changes: 6 additions & 4 deletions src/state/accountCalculators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export const calculateShouldRenderTriggersInPositionsTable = createSelector(
/**
* @description calculate whether positions table should render actions column
*/
export const calculateShouldRenderActionsInPositionsTable = createSelector(
[calculateIsAccountViewOnly],
(isAccountViewOnly: boolean) => !isAccountViewOnly
);
export const calculateShouldRenderActionsInPositionsTable = (isCloseActionShown: boolean) =>
createSelector(
[calculateIsAccountViewOnly, calculateShouldRenderTriggersInPositionsTable],
(isAccountViewOnly: boolean, areTriggersRendered: boolean) =>
!isAccountViewOnly && (areTriggersRendered || isCloseActionShown)
);
6 changes: 6 additions & 0 deletions src/views/tables/PositionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ const getPositionsTableColumnDef = ({
stringGetter,
width,
isAccountViewOnly,
showClosePositionAction,
navigateToOrders,
}: {
key: PositionsTableColumnKey;
stringGetter: StringGetterFunction;
width?: ColumnSize;
isAccountViewOnly: boolean;
showClosePositionAction: boolean;
navigateToOrders: (market: string) => void;
}) => ({
width,
Expand Down Expand Up @@ -338,6 +340,7 @@ const getPositionsTableColumnDef = ({
marketId={id}
assetId={assetId}
isDisabled={isAccountViewOnly}
showClosePositionAction={showClosePositionAction}
stopLossOrders={stopLossOrders}
takeProfitOrders={takeProfitOrders}
navigateToMarketOrders={navigateToOrders}
Expand All @@ -353,6 +356,7 @@ type ElementProps = {
columnWidths?: Partial<Record<PositionsTableColumnKey, ColumnSize>>;
currentRoute?: string;
currentMarket?: string;
showClosePositionAction: boolean;
onNavigate?: () => void;
navigateToOrders: (market: string) => void;
};
Expand All @@ -367,6 +371,7 @@ export const PositionsTable = ({
columnWidths,
currentRoute,
currentMarket,
showClosePositionAction,
onNavigate,
navigateToOrders,
withGradientCardRows,
Expand Down Expand Up @@ -430,6 +435,7 @@ export const PositionsTable = ({
stringGetter,
width: columnWidths?.[key],
isAccountViewOnly,
showClosePositionAction,
navigateToOrders,
})
)}
Expand Down
26 changes: 15 additions & 11 deletions src/views/tables/PositionsTable/PositionsActionsCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ElementProps = {
stopLossOrders: SubaccountOrder[];
takeProfitOrders: SubaccountOrder[];
isDisabled?: boolean;
showClosePositionAction: boolean;
navigateToMarketOrders: (market: string) => void;
};

Expand All @@ -33,6 +34,7 @@ export const PositionsActionsCell = ({
stopLossOrders,
takeProfitOrders,
isDisabled,
showClosePositionAction,
navigateToMarketOrders,
}: ElementProps) => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -81,17 +83,19 @@ export const PositionsActionsCell = ({
isDisabled={isDisabled}
/>
)}
<Styled.CloseButtonToggle
key="closepositions"
isToggle={true}
isPressed={
tradeBoxDialogType === TradeBoxDialogTypes.ClosePosition && currentMarketId === marketId
}
onPressedChange={onCloseButtonToggle}
iconName={IconName.Close}
shape={ButtonShape.Square}
isDisabled={isDisabled}
/>
{showClosePositionAction && (
<Styled.CloseButtonToggle
key="closepositions"
isToggle={true}
isPressed={
tradeBoxDialogType === TradeBoxDialogTypes.ClosePosition && currentMarketId === marketId
}
onPressedChange={onCloseButtonToggle}
iconName={IconName.Close}
shape={ButtonShape.Square}
isDisabled={isDisabled}
/>
)}
</ActionsTableCell>
);
};
Expand Down

0 comments on commit aa2ae94

Please sign in to comment.