Skip to content

Commit f02eab5

Browse files
committed
fix: small update
1 parent 157f822 commit f02eab5

2 files changed

Lines changed: 57 additions & 6 deletions

File tree

app/components/Views/SocialLeaderboard/FeedView/utils/mapFeedItem.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,55 @@ describe('mapFeedItem', () => {
170170
expect(result?.action).toBe('sold');
171171
});
172172

173+
it('keeps a perp enter fill as "opened" even when the snapshot looks closed', () => {
174+
const result = mapFeedItem(
175+
mockPerpFeedItem({
176+
// A closed-looking snapshot (Clicker reports currentValueUSD === 0) must
177+
// not override the triggering trade's `enter` intent.
178+
currentValueUSD: 0,
179+
trades: [
180+
{
181+
direction: 'buy',
182+
intent: 'enter',
183+
tokenAmount: 5,
184+
usdCost: 50600,
185+
timestamp: 1_700_000_500,
186+
transactionHash: '0xhash',
187+
classification: 'perp',
188+
perpPositionType: 'long',
189+
perpLeverage: 8,
190+
},
191+
],
192+
}),
193+
);
194+
195+
expect(result?.action).toBe('opened');
196+
});
197+
198+
it('keeps a spot enter fill as "bought" even when the snapshot looks closed', () => {
199+
const result = mapFeedItem(
200+
mockSpotFeedItem({
201+
// Closed-looking spot snapshot (fully sold out) must still defer to the
202+
// triggering trade's `enter` intent.
203+
positionAmount: 0,
204+
soldUsd: 100_000,
205+
trades: [
206+
{
207+
direction: 'buy',
208+
intent: 'enter',
209+
tokenAmount: 1000,
210+
usdCost: 120000,
211+
timestamp: 1_700_000_000,
212+
transactionHash: '0xhash',
213+
classification: 'spot',
214+
},
215+
],
216+
}),
217+
);
218+
219+
expect(result?.action).toBe('bought');
220+
});
221+
173222
it('returns null for a spot trade on an unsupported chain', () => {
174223
const result = mapFeedItem(mockSpotFeedItem({ chain: 'fantom' }));
175224

app/components/Views/SocialLeaderboard/FeedView/utils/mapFeedItem.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,19 @@ function findTriggeringTrade(
6868
}
6969

7070
/**
71-
* Feed rows are keyed off a triggering trade when one exists. Exit fills must
72-
* use the closed presentation path (realized PnL) even when
73-
* {@link isClosedPosition} misclassifies a perp that still carries stale
74-
* non-zero margin in the Clicker payload.
71+
* Feed rows are keyed off a triggering trade when one exists, and the trade's
72+
* intent is authoritative in both directions: an `exit` fill reads as closed
73+
* (even when {@link isClosedPosition} misclassifies a perp that still carries
74+
* stale non-zero margin in the Clicker payload), and an `enter` fill reads as
75+
* open (even when the position snapshot looks closed). We only fall back to the
76+
* {@link isClosedPosition} snapshot heuristic when there is no triggering trade.
7577
*/
7678
function isFeedItemClosed(
7779
coreItem: CoreFeedItem,
7880
trade: Trade | undefined,
7981
): boolean {
80-
if (trade?.intent === 'exit') {
81-
return true;
82+
if (trade) {
83+
return trade.intent === 'exit';
8284
}
8385
return isClosedPosition(coreItem);
8486
}

0 commit comments

Comments
 (0)