Skip to content

Commit 40fb1c1

Browse files
authored
Merge pull request #2008 from gmx-io/hide-share-for-non-owners
Hide share for non owner position and trade items
2 parents c7b0893 + 3bb7da7 commit 40fb1c1

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/components/PositionItem/PositionItem.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export type Props = {
6060
showPnlAfterFees: boolean;
6161
onClosePositionClick?: () => void;
6262
onEditCollateralClick?: () => void;
63-
onShareClick: () => void;
63+
onShareClick?: () => void;
6464
onSelectPositionClick?: (tradeMode?: TradeMode, showCurtain?: boolean) => void;
6565
isLarge: boolean;
6666
onOrdersClick?: (key?: string) => void;
@@ -519,15 +519,16 @@ export function PositionItem(p: Props) {
519519
{renderNetValue()}
520520
{displayedPnl !== undefined && (
521521
<div
522-
className={cx("text-body-small flex cursor-pointer items-center gap-2 numbers", {
522+
className={cx("text-body-small flex items-center gap-2 numbers", {
523523
positive: displayedPnl > 0,
524524
negative: displayedPnl < 0,
525525
muted: displayedPnl == 0n,
526+
"cursor-pointer": Boolean(p.onShareClick),
526527
})}
527528
onClick={p.onShareClick}
528529
>
529530
{formatDeltaUsd(displayedPnl, displayedPnlPercentage)}
530-
<NewLinkThinIcon className="mt-1 size-14" />
531+
{p.onShareClick && <NewLinkThinIcon className="mt-1 size-14" />}
531532
</div>
532533
)}
533534
</div>
@@ -664,15 +665,16 @@ export function PositionItem(p: Props) {
664665
</div>
665666
<div>
666667
<span
667-
className={cx("flex cursor-pointer items-center gap-2 numbers", {
668+
className={cx("flex items-center gap-2 numbers", {
668669
positive: displayedPnl > 0,
669670
negative: displayedPnl < 0,
670671
muted: displayedPnl == 0n,
672+
"cursor-pointer": Boolean(p.onShareClick),
671673
})}
672674
onClick={p.onShareClick}
673675
>
674676
{formatDeltaUsd(displayedPnl, displayedPnlPercentage)}
675-
<NewLinkThinIcon className="mt-2 size-16" />
677+
{p.onShareClick && <NewLinkThinIcon className="mt-2 size-16" />}
676678
</span>
677679
</div>
678680
</div>

src/components/PositionList/PositionList.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TradeMode } from "domain/synthetics/trade";
1313
import { getByKey } from "lib/objects";
1414
import { userAnalytics } from "lib/userAnalytics";
1515
import { SharePositionClickEvent } from "lib/userAnalytics/types";
16+
import useWallet from "lib/wallets/useWallet";
1617

1718
import { EmptyTableContent } from "components/EmptyTableContent/EmptyTableContent";
1819
import { OrderEditorContainer } from "components/OrderEditorContainer/OrderEditorContainer";
@@ -188,6 +189,7 @@ const PositionItemWrapper = memo(
188189
hideActions: boolean | undefined;
189190
onCancelOrder: (orderKey: string) => void;
190191
}) => {
192+
const { account } = useWallet();
191193
const showPnlAfterFees = useSelector(selectShowPnlAfterFees);
192194
const handleEditCollateralClick = useCallback(
193195
() => onEditCollateralClick(position.key),
@@ -211,6 +213,8 @@ const PositionItemWrapper = memo(
211213
[onOrdersClick, position.key]
212214
);
213215

216+
const isShareAvailable = account === position.account;
217+
214218
return (
215219
<PositionItem
216220
position={position}
@@ -222,7 +226,7 @@ const PositionItemWrapper = memo(
222226
isLarge={isLarge}
223227
hideActions={hideActions}
224228
onCancelOrder={handleCancelOrder}
225-
onShareClick={handleShareClick}
229+
onShareClick={isShareAvailable ? handleShareClick : undefined}
226230
/>
227231
);
228232
}

src/components/TradeHistory/TradeHistoryRow/TradeHistoryRow.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { EMPTY_ARRAY } from "lib/objects";
2020
import { userAnalytics } from "lib/userAnalytics";
2121
import { SharePositionClickEvent } from "lib/userAnalytics/types";
22+
import useWallet from "lib/wallets/useWallet";
2223
import { buildAccountDashboardUrl } from "pages/AccountDashboard/buildAccountDashboardUrl";
2324

2425
import Button from "components/Button/Button";
@@ -120,6 +121,7 @@ const PRICE_TOOLTIP_WIDTH = 400;
120121

121122
export function TradeHistoryRow({ minCollateralUsd, tradeAction, shouldDisplayAccount, showDebugValues }: Props) {
122123
const chainId = useSelector(selectChainId);
124+
const { account } = useWallet();
123125
const marketsInfoData = useMarketsInfoData();
124126

125127
const msg = useMemo(() => {
@@ -200,6 +202,11 @@ export function TradeHistoryRow({ minCollateralUsd, tradeAction, shouldDisplayAc
200202
setIsShareModalOpen(true);
201203
}, [setIsShareModalOpen]);
202204

205+
const shouldDisplayShareButton =
206+
isDecreaseOrderType(tradeAction.orderType) &&
207+
tradeAction.eventName === TradeActionType.OrderExecuted &&
208+
account === tradeAction.account;
209+
203210
return (
204211
<>
205212
<TableTr
@@ -312,7 +319,7 @@ export function TradeHistoryRow({ minCollateralUsd, tradeAction, shouldDisplayAc
312319
)}
313320
</TableTd>
314321
<TableTd>
315-
{isDecreaseOrderType(tradeAction.orderType) && tradeAction.eventName === TradeActionType.OrderExecuted ? (
322+
{shouldDisplayShareButton ? (
316323
<Button variant="ghost" onClick={handleShareClick}>
317324
<NewLinkIconThin className="size-16" />
318325
<Trans>Share</Trans>

0 commit comments

Comments
 (0)