@gloom-sh/terminal 0.20.22 → 0.20.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/package.json +1 -1
  2. package/src/account/heard-from-question.tsx +6 -4
  3. package/src/account/heard-from.ts +3 -4
  4. package/src/api-client/exchange-announcements.ts +2 -2
  5. package/src/api-client/heard-from.ts +5 -7
  6. package/src/api-client/ownership-disclosures.ts +38 -5
  7. package/src/api-client/types/ticker-data.ts +3 -1
  8. package/src/architecture/dom-cell-metrics-allowlist.json +2 -2
  9. package/src/cli/commands/market.ts +5 -3
  10. package/src/cli/commands/overview.ts +7 -9
  11. package/src/cli/listing-arg.ts +45 -18
  12. package/src/cli/pane-functions/catalog-snapshot.json +2 -2
  13. package/src/cli/pane-functions/data.ts +3 -1
  14. package/src/cli/pane-functions/freshness.ts +6 -1
  15. package/src/cli/pane-functions/function-help.ts +0 -2
  16. package/src/cli/pane-functions/market-session.ts +12 -2
  17. package/src/cli/pane-functions/screenshot-payload.ts +3 -1
  18. package/src/cli/symbol-list.ts +52 -14
  19. package/src/cli/ticker-resolution.ts +133 -38
  20. package/src/components/chart/composite/composite-chart.tsx +12 -0
  21. package/src/components/chart/composite/types.ts +18 -0
  22. package/src/components/chart/composite/use-composite-chart-keyboard.ts +38 -15
  23. package/src/components/chart-table/header.tsx +11 -5
  24. package/src/components/chart-table/selection.ts +20 -1
  25. package/src/components/data-table/view.tsx +2 -0
  26. package/src/components/feed-data-table/stack-view.tsx +85 -5
  27. package/src/components/layout/pane/header.tsx +12 -30
  28. package/src/components/ticker/badge/index.tsx +9 -4
  29. package/src/components/ticker/badge/list.tsx +3 -1
  30. package/src/components/ui/data-table/index.tsx +7 -1
  31. package/src/components/ui/data-table/muted-row.tsx +47 -0
  32. package/src/components/ui/data-table/opentui/index.tsx +42 -11
  33. package/src/components/ui/data-table/spill.ts +36 -0
  34. package/src/components/ui/data-table/types.ts +17 -1
  35. package/src/components/ui/data-table/use-column-order.ts +11 -0
  36. package/src/components/ui/icon.tsx +50 -3
  37. package/src/components/ui/list-view.tsx +2 -2
  38. package/src/components/ui/table-layout.ts +32 -0
  39. package/src/components/ui/terminal-hover-label.tsx +49 -0
  40. package/src/components/use-pinned-moment.ts +222 -13
  41. package/src/core/state/app/state.ts +11 -2
  42. package/src/core/state/app/types.ts +2 -1
  43. package/src/data/sqlite/access.ts +14 -1
  44. package/src/data/sqlite/checkpointer.ts +2 -2
  45. package/src/data/sqlite/database.ts +4 -0
  46. package/src/docs/snapshot.json +180 -26
  47. package/src/i18n/es.ts +1 -0
  48. package/src/i18n/ja.ts +1 -0
  49. package/src/i18n/ko.ts +1 -0
  50. package/src/i18n/zh-cn.ts +1 -0
  51. package/src/i18n/zh-tw.ts +1 -0
  52. package/src/market-data/market/freshness.ts +2 -2
  53. package/src/market-data/market/globex-day.ts +14 -0
  54. package/src/market-data/published-us-sessions.ts +3 -2
  55. package/src/market-data/quotes/live-valuation.ts +4 -2
  56. package/src/market-data/quotes/metadata.ts +48 -5
  57. package/src/market-data/quotes/regular-session-valuation.ts +12 -1
  58. package/src/plugins/builtin/alerts/history-pane.tsx +19 -3
  59. package/src/plugins/builtin/broker-trading/orders.tsx +4 -2
  60. package/src/plugins/builtin/chat/attachments/desktop.tsx +46 -12
  61. package/src/plugins/builtin/chat/channels.ts +5 -2
  62. package/src/plugins/builtin/chat/content/composer-runtime.ts +64 -65
  63. package/src/plugins/builtin/chat/content/footer.tsx +17 -7
  64. package/src/plugins/builtin/chat/content/index.tsx +108 -36
  65. package/src/plugins/builtin/chat/content/new-dm-dialog.tsx +21 -8
  66. package/src/plugins/builtin/chat/content/selection-runtime.ts +16 -0
  67. package/src/plugins/builtin/chat/content/shortcuts.ts +3 -0
  68. package/src/plugins/builtin/chat/content/snapshot.ts +37 -13
  69. package/src/plugins/builtin/chat/content/transcript.tsx +12 -0
  70. package/src/plugins/builtin/chat/content/types.ts +2 -0
  71. package/src/plugins/builtin/chat/controller/channels.ts +15 -15
  72. package/src/plugins/builtin/chat/controller/index.ts +140 -34
  73. package/src/plugins/builtin/chat/controller/lifecycle.ts +8 -12
  74. package/src/plugins/builtin/chat/controller/persistence.ts +32 -4
  75. package/src/plugins/builtin/chat/controller/send.ts +41 -17
  76. package/src/plugins/builtin/chat/controller/session-runtime.ts +28 -27
  77. package/src/plugins/builtin/chat/controller/state.ts +17 -8
  78. package/src/plugins/builtin/chat/controller/storage.ts +41 -4
  79. package/src/plugins/builtin/chat/controller/view.ts +6 -3
  80. package/src/plugins/builtin/chat/index.tsx +1 -1
  81. package/src/plugins/builtin/chat/layout.ts +8 -1
  82. package/src/plugins/builtin/chat/message/desktop.tsx +15 -11
  83. package/src/plugins/builtin/chat/message/header.tsx +112 -30
  84. package/src/plugins/builtin/chat/message/reactions.tsx +10 -11
  85. package/src/plugins/builtin/chat/message/render-state.ts +4 -2
  86. package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
  87. package/src/plugins/builtin/chat/message/types.ts +5 -0
  88. package/src/plugins/builtin/cloud-tweets/table.tsx +25 -2
  89. package/src/plugins/builtin/company-kpis/model.ts +11 -3
  90. package/src/plugins/builtin/correlation/compute.ts +6 -1
  91. package/src/plugins/builtin/custom-view/loader.ts +95 -34
  92. package/src/plugins/builtin/custom-view/pane.tsx +31 -41
  93. package/src/plugins/builtin/custom-view/table.ts +201 -0
  94. package/src/plugins/builtin/dividend-yield/client.ts +14 -17
  95. package/src/plugins/builtin/dividend-yield/headless.ts +0 -1
  96. package/src/plugins/builtin/dividend-yield/model.ts +45 -6
  97. package/src/plugins/builtin/dividend-yield/pane.tsx +70 -7
  98. package/src/plugins/builtin/dividend-yield/types.ts +2 -3
  99. package/src/plugins/builtin/dividend-yield/view.ts +22 -2
  100. package/src/plugins/builtin/econ/calendar-model.ts +135 -0
  101. package/src/plugins/builtin/econ/columns.ts +132 -0
  102. package/src/plugins/builtin/econ/index.tsx +25 -65
  103. package/src/plugins/builtin/holders/disclosures-view.tsx +9 -6
  104. package/src/plugins/builtin/holders/disclosures.ts +20 -6
  105. package/src/plugins/builtin/holders/headless.ts +2 -2
  106. package/src/plugins/builtin/ipo-calendar/model.ts +30 -1
  107. package/src/plugins/builtin/ipo-calendar/pane.tsx +7 -3
  108. package/src/plugins/builtin/kelly-sizer/headless.ts +9 -4
  109. package/src/plugins/builtin/kelly-sizer/pane.tsx +19 -9
  110. package/src/plugins/builtin/kelly-sizer/units.ts +26 -0
  111. package/src/plugins/builtin/market-halts/pane.tsx +14 -2
  112. package/src/plugins/builtin/news/wire/news/row.ts +5 -12
  113. package/src/plugins/builtin/news/wire/news/table.tsx +32 -41
  114. package/src/plugins/builtin/pe-band/headless.ts +1 -1
  115. package/src/plugins/builtin/pe-band/model.ts +41 -18
  116. package/src/plugins/builtin/pe-band/pane.tsx +6 -5
  117. package/src/plugins/builtin/perps/equity-row.tsx +4 -6
  118. package/src/plugins/builtin/perps/markets-section.tsx +19 -15
  119. package/src/plugins/builtin/perps/model.ts +10 -2
  120. package/src/plugins/builtin/portfolio-list/cli/import-positions.ts +6 -18
  121. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +1 -1
  122. package/src/plugins/builtin/portfolio-list/pane/purchase-date-fx.ts +1 -1
  123. package/src/plugins/builtin/portfolio-list/positions-import/index.tsx +1 -1
  124. package/src/plugins/builtin/portfolio-list/positions-import/lookup.ts +28 -57
  125. package/src/plugins/builtin/research/event-data.ts +3 -1
  126. package/src/plugins/builtin/research/event-model.ts +17 -15
  127. package/src/plugins/builtin/research/relative-valuation-columns.ts +19 -6
  128. package/src/plugins/builtin/research/relative-valuation-headless.ts +1 -1
  129. package/src/plugins/builtin/scanner/flow-pane.tsx +10 -0
  130. package/src/plugins/builtin/sec/exchange-filings.ts +32 -7
  131. package/src/plugins/builtin/sec/headless.ts +8 -8
  132. package/src/plugins/builtin/sec/index.tsx +69 -29
  133. package/src/plugins/builtin/shared/report-freshness.ts +4 -1
  134. package/src/plugins/builtin/ticker-detail/financials/aggregation.ts +1 -2
  135. package/src/plugins/builtin/ticker-detail/financials/exchange-table.tsx +61 -0
  136. package/src/plugins/builtin/ticker-detail/financials/model.ts +38 -4
  137. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +9 -2
  138. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +68 -39
  139. package/src/plugins/builtin/ticker-detail/headless.ts +4 -1
  140. package/src/plugins/builtin/ticker-detail/overview/model.ts +61 -15
  141. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +5 -0
  142. package/src/plugins/builtin/time-sales/model.ts +16 -9
  143. package/src/plugins/builtin/time-sales/pane.tsx +27 -24
  144. package/src/plugins/builtin/treasury-daily/client.ts +43 -9
  145. package/src/plugins/builtin/treasury-daily/pane.tsx +48 -27
  146. package/src/plugins/builtin/treasury-daily/resource.ts +33 -0
  147. package/src/portfolio/positions-import/parse.ts +14 -6
  148. package/src/portfolio/positions-import/plan.ts +3 -2
  149. package/src/react/async-resource.ts +3 -1
  150. package/src/renderers/dom/data-table/index.tsx +40 -0
  151. package/src/renderers/dom/data-table/row.tsx +39 -3
  152. package/src/renderers/dom/desktop/icons.tsx +147 -3
  153. package/src/renderers/dom/desktop/popover.tsx +2 -2
  154. package/src/renderers/dom/host/media-surface.tsx +204 -45
  155. package/src/renderers/dom/host/tabs.tsx +1 -0
  156. package/src/renderers/dom/styles.css +14 -2
  157. package/src/renderers/electrobun/bun/desktop/backend.ts +2 -0
  158. package/src/renderers/electrobun/bun/desktop/rpc-timing.ts +9 -3
  159. package/src/renderers/electrobun/shared/protocol.ts +2 -0
  160. package/src/renderers/electrobun/view/backend-rpc.ts +5 -2
  161. package/src/renderers/electrobun/view/rpc-timeout.ts +44 -3
  162. package/src/sources/gloomberb-cloud/index.ts +8 -7
  163. package/src/sources/gloomberb-cloud/normalizers.ts +7 -2
  164. package/src/sources/listing-symbols.ts +7 -1
  165. package/src/sources/provider-router/cache.ts +5 -4
  166. package/src/sources/provider-router/financials.ts +40 -18
  167. package/src/state/app/tab-cursor.ts +47 -6
  168. package/src/telemetry/stall-clocks.ts +3 -0
  169. package/src/telemetry/stall-reports.ts +12 -3
  170. package/src/telemetry/windows-process-activity.ts +41 -0
  171. package/src/telemetry/windows-time.ts +32 -0
  172. package/src/test-support/scoped-earnings.ts +24 -0
  173. package/src/tickers/terminal-codes.ts +1 -6
  174. package/src/time-series/daily-valuation.ts +13 -6
  175. package/src/time-series/filed-trailing-eps.ts +16 -3
  176. package/src/time-series/fundamentals/current-valuation.ts +8 -0
  177. package/src/time-series/fundamentals/historical-valuation.ts +20 -0
  178. package/src/time-series/fundamentals/series.ts +13 -1
  179. package/src/time-series/valuation-currency.ts +2 -0
  180. package/src/types/financials.ts +46 -10
  181. package/src/ui/dialog-context.ts +8 -0
  182. package/src/utils/datetime-format.ts +23 -1
  183. package/src/utils/declared-dividends.ts +12 -2
  184. package/src/utils/exchange-announcements.ts +4 -1
  185. package/src/utils/exchange-notation.generated.ts +3 -1
  186. package/src/utils/exchanges.ts +2 -1
  187. package/src/utils/fundamentals.ts +1 -0
  188. package/src/utils/main-thread-stall.ts +9 -1
  189. package/src/utils/rpc-timeout-error.ts +36 -11
  190. package/src/utils/sec.ts +3 -1
  191. package/src/utils/share-multiples.ts +1 -1
  192. package/src/utils/stall-process-activity.ts +70 -0
  193. package/src/utils/statement-scope.ts +103 -0
  194. package/src/utils/trailing-eps.ts +1 -1
  195. package/src/utils/zoned-date-time.ts +1 -0
@@ -7,6 +7,8 @@ import { usePaneStateValue, usePaneTicker } from "../../../../state/app/context"
7
7
  import {
8
8
  DataTableView,
9
9
  DisclosureMarker,
10
+ Notice,
11
+ PaneLinkMenu,
10
12
  PaneStatusBody,
11
13
  QueryBar,
12
14
  usePaneFooter,
@@ -34,9 +36,11 @@ import {
34
36
  financialColumnPeriod,
35
37
  financialGrowthNotice,
36
38
  financialPeriodEnd,
39
+ financialPeriodFiling,
37
40
  financialPeriodHeaderLabel,
38
41
  formatFinancialCell,
39
42
  formatFinancialCellValue,
43
+ financialStatementBasisNote,
40
44
  financialStatementCurrency,
41
45
  financialStatementLimitations,
42
46
  financialStatementPeriods,
@@ -80,16 +84,18 @@ import {
80
84
  type RatioTableColumn,
81
85
  } from "./ratio-table";
82
86
  import { useExchangeResultsNotes } from "./exchange-results";
87
+ import { ExchangeStatementTable } from "./exchange-table";
83
88
  import { latestBalanceSheetDate, useOfferingNote, useRunwayOfferings } from "./offerings";
84
89
  import { burnsCash, cashRunway, runwayOfferingNote } from "../../../../utils/cash-runway";
85
90
  import { useBoundTicker } from "../../shared/ticker-request";
86
91
  import { createValuationCurrencyContext } from "../../../../time-series/valuation-currency";
87
92
 
88
93
  const RATIOS_SEGMENT = "ratios";
94
+ type FinancialView = FinancialPeriod | "exchange";
89
95
 
90
96
  type FinancialTableColumn = DataTableColumn & (
91
97
  | { id: "metric"; kind: "metric" }
92
- | { id: string; kind: "statement"; statement: FinancialTableStatement; /** The table's last column. */ last: boolean }
98
+ | { id: string; kind: "statement"; statement: FinancialTableStatement; filingUrl?: string; /** The table's last column. */ last: boolean }
93
99
  );
94
100
 
95
101
  const NO_COLLAPSED_GROUPS: ReadonlySet<string> = new Set();
@@ -168,7 +174,7 @@ export function ResolvedFinancialsTab({
168
174
  const hasAnnualStatements = annualStatements.length > 0;
169
175
  const hasQuarterlyStatements = quarterlyStatements.length > 0;
170
176
  const fallbackPeriod: FinancialPeriod = hasAnnualStatements ? "annual" : "quarterly";
171
- const [storedPeriod, setStoredPeriod] = usePaneStateValue<FinancialPeriod>("financialPeriod", fallbackPeriod);
177
+ const [storedPeriod, setStoredPeriod] = usePaneStateValue<FinancialView>("financialPeriod", fallbackPeriod);
172
178
  const period = resolveFinancialPeriodOption(storedPeriod) ?? fallbackPeriod;
173
179
  const [storedSubTab, setStoredSubTab] = usePaneStateValue<string>("financialSubTab", FINANCIAL_SUB_TABS[0]!.key);
174
180
  const resolvedSubTabKey = resolveFinancialSectionKey(storedSubTab);
@@ -188,17 +194,21 @@ export function ResolvedFinancialsTab({
188
194
  const ratioTab = section.kind === "ratio" ? section.tab : null;
189
195
  // A ratio tab builds its own rows; the statement rows below idle on Income.
190
196
  const subTab = section.kind === "statement" ? section.tab : FINANCIAL_SUB_TABS[0]!;
197
+ const exchangeStatements = useMemo(() => ratioTab ? [] : (financials?.taiwanExchangeStatements ?? [])
198
+ .filter((statement) => statement.kind === subTab.key)
199
+ .sort((a, b) => b.periodEnd.localeCompare(a.periodEnd)), [financials?.taiwanExchangeStatements, ratioTab, subTab.key]);
200
+ const [exchangePeriod, setExchangePeriod] = usePaneStateValue<string>("financialExchangePeriod", "");
201
+ const exchangeStatement = exchangeStatements.find((statement) => statement.periodEnd === exchangePeriod)
202
+ ?? exchangeStatements[0];
203
+ const showExchange = !!exchangeStatement && (storedPeriod === "exchange" || (!hasAnnualStatements && !hasQuarterlyStatements));
191
204
  // A ratio read over one quarter is not on the annual view, so its state does not count there.
192
205
  const quarterlyView = resolveFinancialPeriod(period, hasAnnualStatements, hasQuarterlyStatements) === "quarterly";
193
206
  const currentGroupIds = useMemo(
194
207
  () => ratioTab ? visibleRatios(ratioTab, quarterlyView).map((ratio) => ratio.id) : collectGroupIds(subTab.rows),
195
208
  [quarterlyView, ratioTab, subTab],
196
209
  );
197
- const hasCollapsedCurrentGroup = currentGroupIds.some((id) => collapsedGroups.has(id));
198
- const hasExpandedCurrentGroup = currentGroupIds.some((id) => !collapsedGroups.has(id));
199
- const setPeriod = useCallback((next: SetStateAction<FinancialPeriod>) => {
200
- setStoredPeriod(next);
201
- }, [setStoredPeriod]);
210
+ const hasCollapsedCurrentGroup = !showExchange && currentGroupIds.some((id) => collapsedGroups.has(id));
211
+ const hasExpandedCurrentGroup = !showExchange && currentGroupIds.some((id) => !collapsedGroups.has(id));
202
212
  const setSubTabIdx = useCallback((next: SetStateAction<number>) => {
203
213
  setStoredSubTab((currentKey) => {
204
214
  const currentSubTabKey = resolveFinancialSectionKey(currentKey);
@@ -219,15 +229,19 @@ export function ResolvedFinancialsTab({
219
229
  const selectAdjacentSubTab = useCallback((direction: -1 | 1) => {
220
230
  setSubTabIdx((current) => current + direction);
221
231
  }, [setSubTabIdx]);
232
+ const views = useMemo(() => [
233
+ { label: "Annual", value: "annual" as const, disabled: !hasAnnualStatements },
234
+ { label: "Quarterly", value: "quarterly" as const, disabled: !hasQuarterlyStatements },
235
+ ...(exchangeStatement ? [{ label: "Exchange", value: "exchange" as const, disabled: false }] : []),
236
+ ], [hasAnnualStatements, hasQuarterlyStatements, !!exchangeStatement]);
237
+ const resolvedPeriod = resolveFinancialPeriod(period, hasAnnualStatements, hasQuarterlyStatements);
238
+ const activeView = showExchange ? "exchange" : resolvedPeriod;
239
+ const canTogglePeriod = views.filter((view) => !view.disabled).length > 1;
222
240
  const togglePeriod = useCallback(() => {
223
- if (!hasAnnualStatements && !hasQuarterlyStatements) return;
224
- setPeriod((current) => {
225
- const resolved = resolveFinancialPeriod(current, hasAnnualStatements, hasQuarterlyStatements);
226
- if (resolved === "annual" && hasQuarterlyStatements) return "quarterly";
227
- if (hasAnnualStatements) return "annual";
228
- return "quarterly";
229
- });
230
- }, [hasAnnualStatements, hasQuarterlyStatements, setPeriod]);
241
+ const options = views.filter((view) => !view.disabled);
242
+ const next = options[(options.findIndex(({ value }) => value === activeView) + 1) % options.length];
243
+ if (next) setStoredPeriod(next.value);
244
+ }, [activeView, setStoredPeriod, views]);
231
245
  const toggleGroup = useCallback((groupId: string) => {
232
246
  setCollapsedGroups((current) => {
233
247
  const next = new Set(current);
@@ -267,7 +281,7 @@ export function ResolvedFinancialsTab({
267
281
  id: "period",
268
282
  key: "p",
269
283
  label: "eriod",
270
- disabled: !hasAnnualStatements && !hasQuarterlyStatements,
284
+ disabled: !canTogglePeriod,
271
285
  onPress: togglePeriod,
272
286
  },
273
287
  {
@@ -286,13 +300,12 @@ export function ResolvedFinancialsTab({
286
300
  },
287
301
  ],
288
302
  }), [
303
+ canTogglePeriod,
289
304
  collapseCurrentGroups,
290
305
  expandCurrentGroups,
291
306
  financials,
292
- hasAnnualStatements,
293
307
  hasCollapsedCurrentGroup,
294
308
  hasExpandedCurrentGroup,
295
- hasQuarterlyStatements,
296
309
  setSubTabIdx,
297
310
  togglePeriod,
298
311
  ]);
@@ -337,14 +350,14 @@ export function ResolvedFinancialsTab({
337
350
  }, { phase: "before" });
338
351
 
339
352
  useEffect(() => {
353
+ if (storedPeriod === "exchange") return;
340
354
  if (period === "annual" && !hasAnnualStatements && hasQuarterlyStatements) {
341
- setPeriod("quarterly");
355
+ setStoredPeriod("quarterly");
342
356
  } else if (period === "quarterly" && !hasQuarterlyStatements && hasAnnualStatements) {
343
- setPeriod("annual");
357
+ setStoredPeriod("annual");
344
358
  }
345
- }, [hasAnnualStatements, hasQuarterlyStatements, period, setPeriod]);
359
+ }, [hasAnnualStatements, hasQuarterlyStatements, period, setStoredPeriod, storedPeriod]);
346
360
 
347
- const resolvedPeriod = resolveFinancialPeriod(period, hasAnnualStatements, hasQuarterlyStatements);
348
361
  const isAnnual = resolvedPeriod === "annual";
349
362
  const selected = useMemo(
350
363
  () => selectFinancialStatements(resolvedPeriod, subTab.key, annualStatements, quarterlyStatements, undefined, financials?.trailingStatement),
@@ -357,13 +370,14 @@ export function ResolvedFinancialsTab({
357
370
  // One currency for every column goes in the query bar with the growth basis;
358
371
  // a column in a different currency (or none) says so in its own header.
359
372
  const growthBasis = isAnnual ? "YoY" : "QoQ";
360
- useRemoteUiNode(!ratioTab && displayStatements.length ? {
373
+ useRemoteUiNode(!showExchange && !ratioTab && displayStatements.length ? {
361
374
  role: "report-notice",
362
375
  label: "Growth",
363
376
  getMetadata: () => ({ text: financialGrowthNotice(resolvedPeriod, displayStatements), key: "growthBasis", value: growthBasis }),
364
377
  } : null);
365
378
  const yearEndMonth = useMemo(() => fiscalYearEndMonth(annualStatements), [annualStatements]);
366
379
  const annualDates = useMemo(() => new Set(annualStatements.map(({ date }) => date)), [annualStatements]);
380
+ const periodFilings = financials?.periodFilings;
367
381
  const { rows, unit } = useMemo(
368
382
  () => shareFinancialUnit(buildFinancialRows(subTab.rows, displayStatements, collapsedGroups)),
369
383
  [collapsedGroups, displayStatements, subTab.rows],
@@ -408,13 +422,14 @@ export function ResolvedFinancialsTab({
408
422
  id: `statement:${statement.date}:${index}`,
409
423
  kind: "statement",
410
424
  statement,
425
+ filingUrl: financialPeriodFiling(periodFilings, statement, financialColumnPeriod(statement, resolvedPeriod, annualDates))?.url,
411
426
  last: index === displayStatements.length - 1,
412
427
  label: financialPeriodHeaderLabel(periodHeaders[index]!, periodWidth),
413
428
  width: periodWidth,
414
429
  align: "right",
415
430
  headerColor: statement.date === "TTM" ? colors.textBright : colors.textDim,
416
431
  })),
417
- ], [displayStatements, metricHeader, nativePaneChrome, periodHeaders, periodWidth, width]);
432
+ ], [annualDates, displayStatements, metricHeader, nativePaneChrome, periodFilings, periodHeaders, periodWidth, resolvedPeriod, width]);
418
433
  const periodEnd = latestFinancialPeriodEnd(displayStatements);
419
434
  const renderCell = useCallback((
420
435
  row: StatementTableRow,
@@ -422,7 +437,7 @@ export function ResolvedFinancialsTab({
422
437
  ): DataTableCell => {
423
438
  if (row.kind === "period-end") {
424
439
  if (column.kind === "metric") return PERIOD_END_NAME_CELL;
425
- return periodEndCell(financialPeriodEnd(column.statement), column.width, nativePaneChrome || column.last);
440
+ return periodEndCell(financialPeriodEnd(column.statement), column.width, nativePaneChrome || column.last, column.filingUrl);
426
441
  }
427
442
  if (column.kind === "metric") {
428
443
  if (row.kind === "group") {
@@ -547,7 +562,7 @@ export function ResolvedFinancialsTab({
547
562
  const blankRatioLine = ratioModel ? blankRatioPeriodsNote(ratioModel, resolvedPeriod, yearEndMonth) : null;
548
563
  usePaneNoticeFooter({
549
564
  registrationId: "financials-notices",
550
- notices: [
565
+ notices: showExchange ? [] : [
551
566
  ...(notInYetLine ? [notInYetLine] : []),
552
567
  ...(blankRatioLine ? [blankRatioLine] : []),
553
568
  ...exchangeResults,
@@ -562,7 +577,7 @@ export function ResolvedFinancialsTab({
562
577
  });
563
578
 
564
579
  // A null snapshot is still in flight; only a loaded one can say "no coverage".
565
- if (!financials || (!hasAnnualStatements && !hasQuarterlyStatements)) {
580
+ if (!financials || (!hasAnnualStatements && !hasQuarterlyStatements && !financials.taiwanExchangeStatements?.length)) {
566
581
  return (
567
582
  <PaneStatusBody
568
583
  loading={!financials}
@@ -574,7 +589,11 @@ export function ResolvedFinancialsTab({
574
589
  );
575
590
  }
576
591
 
577
- const queryBar = (meta: string) => (
592
+ // A scoped series says what it is filed as, and a newer filing under review, under the bar at every width: the bar's
593
+ // meta gives way first and would cut it. Statements with no scope keep their meta as it was.
594
+ const basisNote = financialStatementBasisNote(financials);
595
+ const pendingReview = !basisNote && financials.statementReview?.status === "pending" ? "New filing under review" : undefined;
596
+ const queryBar = (meta: string) => (<>
578
597
  <QueryBar
579
598
  width={Math.max(1, width - 2)}
580
599
  filters={[
@@ -591,18 +610,22 @@ export function ResolvedFinancialsTab({
591
610
  value: ratioTab.key,
592
611
  options: RATIO_TABS.map((tab) => ({ label: tab.name, value: tab.key })),
593
612
  onChange: selectSection }] : []),
613
+ ...(showExchange && exchangeStatement && exchangeStatements.length > 1 ? [{
614
+ id: "exchange-period", label: "Period ending", value: exchangeStatement.periodEnd,
615
+ options: exchangeStatements.map(({ periodEnd }) => ({ label: formatDay(periodEnd), value: periodEnd })),
616
+ onChange: setExchangePeriod,
617
+ }] : []),
594
618
  ]}
595
619
  view={{
596
- value: isAnnual ? "annual" : "quarterly",
597
- options: [
598
- { label: "Annual", value: "annual", disabled: !hasAnnualStatements },
599
- { label: "Quarterly", value: "quarterly", disabled: !hasQuarterlyStatements },
600
- ],
601
- onChange: (value: string) => setPeriod(value as FinancialPeriod),
620
+ value: activeView,
621
+ options: views,
622
+ onChange: (value: string) => setStoredPeriod(value as FinancialView),
602
623
  }}
603
- meta={meta || undefined}
624
+ meta={[showExchange ? undefined : pendingReview, meta].filter(Boolean).join(" · ") || undefined}
604
625
  />
605
- );
626
+ {/* Lined up with the bar's text and the table's; on the desktop the notice takes the pane's inset itself. */}
627
+ {basisNote && !showExchange ? <Box flexShrink={0} paddingX={nativePaneChrome ? 0 : 1}><Notice tone="muted">{basisNote}</Notice></Box> : null}
628
+ </>);
606
629
 
607
630
  return (
608
631
  <Box
@@ -615,7 +638,9 @@ export function ResolvedFinancialsTab({
615
638
  overflow="hidden"
616
639
  >
617
640
  {isValuation && oldestPeriodEnd ? <PeriodEndHistoryLoader oldestPeriodEnd={oldestPeriodEnd} fxCurrencies={valuationFxCurrencies} onChange={setHistory} /> : null}
618
- {ratioModel ? (
641
+ {showExchange && exchangeStatement ? (
642
+ <ExchangeStatementTable focused={focused} statement={exchangeStatement} width={width} queryBar={queryBar("")} />
643
+ ) : ratioModel ? (
619
644
  <RatioTable
620
645
  focused={focused}
621
646
  model={ratioModel}
@@ -627,13 +652,14 @@ export function ResolvedFinancialsTab({
627
652
  bodyScrollId={bodyScrollId}
628
653
  onToggle={toggleGroup}
629
654
  exportMetadata={() => [
655
+ ...(financials.statementScope ? [["Statement basis", financials.statementScope.label]] : []),
630
656
  ["Currency", comparisonCurrency ?? "per column"],
631
657
  ...(periodEnd ? [["As of", periodEnd]] : []),
632
658
  ]}
633
659
  resetScrollKey={`${resolvedPeriod}:${section.key}:${displayStatements.length}`}
634
660
  rootBefore={queryBar(comparisonCurrency ?? "")}
635
661
  />
636
- ) : (
662
+ ) : (<PaneLinkMenu>
637
663
  <DataTableView<StatementTableRow, FinancialTableColumn>
638
664
  focused={focused}
639
665
  headerScrollRef={headerScrollRef}
@@ -669,16 +695,19 @@ export function ResolvedFinancialsTab({
669
695
  renderCell={renderCell}
670
696
  emptyStateTitle="No financial data"
671
697
  getExportMetadata={() => [
698
+ ...(financials.statementScope ? [["Statement basis", financials.statementScope.label]] : []),
672
699
  ["Currency", comparisonCurrency ?? "per column"],
673
700
  ...(unit ? [["Unit", unit]] : []),
674
701
  ["Growth", growthBasis],
675
702
  ...(periodEnd ? [["As of", periodEnd]] : []),
703
+ ...columns.flatMap((column) => column.kind === "statement" && column.filingUrl
704
+ ? [[`Issuer filing for ${financialPeriodEnd(column.statement)}`, column.filingUrl]] : []),
676
705
  ]}
677
706
  showHorizontalScrollbar
678
707
  resetScrollKey={`${resolvedPeriod}:${subTab.key}:${displayStatements.length}`}
679
708
  rootBefore={queryBar(growthBasis ?? "")}
680
709
  />
681
- )}
710
+ </PaneLinkMenu>)}
682
711
  </Box>
683
712
  );
684
713
  }
@@ -20,7 +20,7 @@ import {
20
20
  } from "../../../utils/price-history-integrity";
21
21
  import { indexBarVolume } from "../../../market-data/market/index-level";
22
22
  import {
23
- buildFinancialTableModel, financialColumnLabel, financialGrowthNotice, financialStatementCurrency, financialStatementDateNotice, financialStatementLimitations,
23
+ buildFinancialTableModel, financialColumnLabel, financialColumnPeriod, financialGrowthNotice, financialPeriodFiling, financialStatementCurrency, financialStatementDateNotice, financialStatementLimitations,
24
24
  financialReportHeader, financialStatementPeriods, financialSubTabFields, formatFinancialAmount, isPerShareFinancialRow, notInYetNote, receiptShareCountLabel, trailingNotInYetNote,
25
25
  } from "./financials/model";
26
26
  import { FINANCIAL_SUB_TABS } from "./financials/schema";
@@ -353,9 +353,11 @@ async function loadFinancialReport(symbol: string, options: HeadlessPaneOptionVa
353
353
  const yearEndMonth = fiscalYearEndMonth(financials.annualStatements);
354
354
  // The list a column comes from: a comparative column is dated by the row a year on in it.
355
355
  const listRows = requestedPeriod === "quarterly" ? financials.quarterlyStatements : financials.annualStatements;
356
+ const annualDates = new Set(financials.annualStatements.map(({ date }) => date));
356
357
  const dates = table?.statements.map((statement) => {
357
358
  const { date, currency, dateSource, providerDate, dateEvidence, availableAt, fieldAvailability, fieldSources, unavailableFields, epsBasis, unavailableEarnings, aggregation, shareBasis, filledFrom } = statement;
358
359
  const filled = date === "TTM" || filledFrom?.source !== "results" ? null : fillDate(statement, listRows);
360
+ const issuerFiling = financialPeriodFiling(financials.periodFilings, statement, financialColumnPeriod(statement, requestedPeriod, annualDates));
359
361
  return {
360
362
  date, currency: currency ?? statementCurrency ?? null,
361
363
  shareBasis: shareBasis ?? null,
@@ -363,6 +365,7 @@ async function loadFinancialReport(symbol: string, options: HeadlessPaneOptionVa
363
365
  fieldAvailability: fieldAvailability ? { ...fieldAvailability } : null,
364
366
  ...(fieldSources ? { fieldSources } : {}),
365
367
  ...(filledFrom ? { filledFrom } : {}),
368
+ ...(issuerFiling ? { issuerFiling } : {}),
366
369
  // The day the company's results announcement published the period's filled lines, or, for a later
367
370
  // period's comparative column, that period's first announcement.
368
371
  ...(filled?.label === "published" && filled.date ? { announced: filled.date } : {}),
@@ -4,7 +4,7 @@ import { convertMarketCapitalization } from "../../../../utils/market-capitaliza
4
4
  import { priceColor } from "../../../../theme/colors";
5
5
  import { notMeaningfulColor } from "../../../../components/ui/not-meaningful";
6
6
  import type { CryptoMarketAsset } from "../../../../api-client/crypto-markets";
7
- import { NOT_MEANINGFUL_TEXT } from "../../../../utils/growth";
7
+ import { NOT_MEANINGFUL_TEXT, revenueMargin } from "../../../../utils/growth";
8
8
  import type { ServedRate } from "../../../../utils/served-rates";
9
9
  import type { CedearRatio, CompanyProfile, DepositaryPair, NextEarnings, Quote, TickerFinancials } from "../../../../types/financials";
10
10
  import { adrRatioText } from "../../../../utils/depositary-receipt";
@@ -37,6 +37,7 @@ import type { OverviewFunctionLink, PositionTableRow, StatField } from "./types"
37
37
  import type { OverviewDividendState } from "./dividend";
38
38
  import { lapseValue, UNEVEN_REGULAR_PAYMENTS } from "../../../../utils/forward-dividend";
39
39
  import { getPortfolioPositionMetrics, getPortfolioQuoteDisplay, resolvePortfolioMarketValue, resolvePortfolioPositionPnl, portfolioPnlPercent, signedPositionDirection } from "../../../../portfolio/position-metrics";
40
+ import { withPurchaseDateCostFx, type PurchaseDateCostFx } from "../../../../portfolio/cost-fx";
40
41
  import { listingDividendYield, liveForwardPE, liveTrailingPE } from "../../../../market-data/quotes/live-valuation";
41
42
  import { atRegularSessionPrice, regularSessionMarketCapitalization } from "../../../../market-data/quotes/regular-session-valuation";
42
43
  import { listingEnterpriseValue, type ListingEnterpriseValue } from "../../../../market-data/quotes/listing-enterprise-value";
@@ -48,6 +49,9 @@ import type { FundBondFacts } from "../../../../api-client/fund-facts";
48
49
  import { bondFigures } from "../../../../market-data/bond-funds";
49
50
  import { quoteStatsBasisText } from "../../../../market-data/quotes/export-identity";
50
51
  import { burnsCash, formatRunwayMonths, type CashRunway, type RunwayEstimate } from "../../../../utils/cash-runway";
52
+ import { listingOwnsRow, listingOwnsSeries } from "../../../../utils/statement-scope";
53
+ import { hasStatementGap } from "../../../../utils/statement-gaps";
54
+ import { financialStatementCurrency, selectFinancialStatements } from "../financials/model";
51
55
 
52
56
  type CurrencyConverter = (value: number, fromCurrency: string) => number;
53
57
 
@@ -176,11 +180,41 @@ function runwayStat(runway: CashRunway | null | undefined): StatField | null {
176
180
  };
177
181
  }
178
182
 
183
+ type OverviewStatements = Pick<TickerFinancials, "annualStatements" | "quarterlyStatements" | "financialCurrency" | "statementScope" | "trailingStatement">;
184
+
185
+ function overviewTrailingIncome(statements: OverviewStatements, fundamentals: TickerFinancials["fundamentals"], currency: string | undefined) {
186
+ const { statements: [trailing] } = selectFinancialStatements("annual", "income", statements.annualStatements,
187
+ statements.quarterlyStatements, 1, statements.trailingStatement);
188
+ const end = trailing?.aggregation?.periodEnd;
189
+ if (!end || !trailing) return {};
190
+ if (!listingOwnsSeries(statements) || trailing.aggregation?.kind === "annual-plus-interim" && !listingOwnsRow(statements.statementScope, trailing)) {
191
+ return { difference: ["Different scope from Financials", "Different scope"] };
192
+ }
193
+ const summaryEnd = fundamentals?.trailingPeriodEnd;
194
+ if (summaryEnd && summaryEnd !== end) {
195
+ return { difference: ["Different period from Financials", "Different period"] };
196
+ }
197
+ if (!summaryEnd && statements.quarterlyStatements.some((quarter) => quarter.date > end)) {
198
+ return { difference: ["Overview period unverified", "Period unverified"] };
199
+ }
200
+ const reportingCurrency = financialStatementCurrency(statements, [trailing])?.trim();
201
+ if (!currency || !reportingCurrency || currency !== reportingCurrency || fundamentals?.ttmConversion) {
202
+ return { difference: ["Different currency basis from Financials", "Currency basis differs"] };
203
+ }
204
+ const { totalRevenue, netIncome, operatingIncome } = trailing;
205
+ if (!finite(totalRevenue) || !finite(netIncome) || hasStatementGap(trailing, "totalRevenue") || hasStatementGap(trailing, "netIncome")) {
206
+ return { difference: ["Financials TTM income incomplete", "Incomplete TTM"] };
207
+ }
208
+ return { income: { end, revenue: totalRevenue, netIncome, profitMargin: revenueMargin(netIncome, totalRevenue),
209
+ operatingMargin: hasStatementGap(trailing, "operatingIncome") ? undefined : revenueMargin(operatingIncome, totalRevenue) } };
210
+ }
211
+
179
212
  export function buildOverviewStats({
180
213
  quote,
181
214
  fundamentals,
182
215
  coin,
183
216
  financialCurrency,
217
+ statementFinancials,
184
218
  quoteCurrency,
185
219
  baseCurrency,
186
220
  marketCapExchangeRates = new Map(),
@@ -203,6 +237,7 @@ export function buildOverviewStats({
203
237
  coin?: CryptoMarketAsset | null;
204
238
  /** The currency the statements report in, for fundamentals that declare none on a listing that trades in it. */
205
239
  financialCurrency?: TickerFinancials["financialCurrency"];
240
+ statementFinancials?: OverviewStatements | null;
206
241
  quoteCurrency: string;
207
242
  baseCurrency: string;
208
243
  toBase: CurrencyConverter;
@@ -247,7 +282,8 @@ export function buildOverviewStats({
247
282
  unsourcedSaid = true;
248
283
  return { value: text, detail: [REPORTING_CURRENCY_NOT_SOURCED, "currency not sourced"] };
249
284
  };
250
- const money = (value: number) => reported(value, fundamentalsCurrency({ fundamentals, financialCurrency, quote }));
285
+ const incomeCurrency = fundamentalsCurrency({ fundamentals, financialCurrency, quote });
286
+ const money = (value: number) => reported(value, incomeCurrency);
251
287
 
252
288
  // An index's 0 is volume nobody counts, not a quiet session: no Volume row.
253
289
  const quoteVolume = reportedQuoteVolume(quote);
@@ -382,29 +418,36 @@ export function buildOverviewStats({
382
418
  link: DIVIDENDS,
383
419
  });
384
420
  }
385
- if (fundamentals?.revenue != null) {
421
+ const { income, difference } = statementFinancials ? overviewTrailingIncome(statementFinancials, fundamentals, incomeCurrency) : {};
422
+ const revenueValue = income?.revenue ?? fundamentals?.revenue;
423
+ const netIncome = income?.netIncome ?? fundamentals?.netIncome;
424
+ if (revenueValue != null) {
386
425
  // Which twelve months the revenue, net income and margin are, as Financials' TTM column names them.
387
- const end = fundamentals.trailingPeriodEnd;
388
- const revenue = money(fundamentals.revenue);
426
+ const end = income?.end ?? fundamentals?.trailingPeriodEnd;
427
+ const revenue = money(revenueValue);
389
428
  const through = end && ISO_DATE.test(end) && !revenue.detail ? [formatDay(end), formatDay(end, "no-year")] : null;
390
429
  stats.push({ label: "Revenue", ...revenue, ...(through ? { detail: [`TTM to ${through[0]}`, ...through.map((day) => `to ${day}`)] } : {}) });
391
430
  }
392
- if (fundamentals?.netIncome != null) {
393
- stats.push({ label: "Net Income", ...money(fundamentals.netIncome) });
431
+ if (netIncome != null) {
432
+ const net = money(netIncome);
433
+ stats.push({ label: "Net Income", ...net, ...(!net.detail && difference ? { detail: difference } : {}) });
394
434
  }
395
435
  if (fundamentals?.freeCashFlow != null) {
396
- stats.push({ label: "FCF", ...money(fundamentals.freeCashFlow) });
436
+ const currency = (fundamentals.freeCashFlowCurrency === undefined ? fundamentals.financialCurrency : fundamentals.freeCashFlowCurrency)?.trim();
437
+ stats.push({ label: "FCF", value: formatReportedMoney(fundamentals.freeCashFlow, currency),
438
+ ...(!currency && Number.isFinite(fundamentals.freeCashFlow) ? { detail: ["currency unknown"] } : {}) });
397
439
  }
398
440
  const runwayField = runwayStat(runway);
399
441
  if (runwayField) stats.push(runwayField);
400
442
  // A margin over revenue at or below zero, and growth off it, read N/M in N/M's own colour, never a sign's.
401
443
  const notMeaningfulStat = (label: string): StatField => ({ label, value: NOT_MEANINGFUL_TEXT, valueColor: notMeaningfulColor() });
402
- if (fundamentals?.operatingMargin != null) {
403
- stats.push(notMeaningful.operatingMargin ? notMeaningfulStat("Op Margin") : { label: "Op Margin", value: formatLevelPercent(fundamentals.operatingMargin) });
404
- }
405
- if (fundamentals?.profitMargin != null) {
406
- stats.push(notMeaningful.profitMargin ? notMeaningfulStat("Profit Marg") : { label: "Profit Marg", value: formatLevelPercent(fundamentals.profitMargin) });
407
- }
444
+ const margin = (label: string, value: number | typeof NOT_MEANINGFUL | undefined, key: "operatingMargin" | "profitMargin") => {
445
+ if (value == null) return;
446
+ stats.push(value === NOT_MEANINGFUL || (!income && notMeaningful[key]) ? notMeaningfulStat(label)
447
+ : { label, value: formatLevelPercent(value) });
448
+ };
449
+ margin("Op Margin", income ? income.operatingMargin : fundamentals?.operatingMargin, "operatingMargin");
450
+ margin("Profit Marg", income ? income.profitMargin : fundamentals?.profitMargin, "profitMargin");
408
451
  if (fundamentals?.revenueGrowth != null) {
409
452
  stats.push(notMeaningful.revenueGrowth ? notMeaningfulStat("Rev Growth") : {
410
453
  label: "Rev Growth",
@@ -495,6 +538,7 @@ export function buildPositionRows({
495
538
  quoteCurrency,
496
539
  baseCurrency,
497
540
  toBase,
541
+ purchaseDateFx,
498
542
  accountNames = NO_ACCOUNT_NAMES,
499
543
  }: {
500
544
  ticker: TickerRecord;
@@ -502,9 +546,11 @@ export function buildPositionRows({
502
546
  quoteCurrency: string;
503
547
  baseCurrency: string;
504
548
  toBase: CurrencyConverter;
549
+ purchaseDateFx?: PurchaseDateCostFx;
505
550
  accountNames?: PositionAccountNames;
506
551
  }): PositionTableRow[] {
507
- return ticker.metadata.positions.filter((position) => position.shares !== 0).map((position) => {
552
+ const valuedTicker = purchaseDateFx ? withPurchaseDateCostFx([ticker], purchaseDateFx, baseCurrency)[0]! : ticker;
553
+ return valuedTicker.metadata.positions.filter((position) => position.shares !== 0).map((position) => {
508
554
  const positionCurrency = getPortfolioPositionMetrics(
509
555
  { ...ticker, metadata: { ...ticker.metadata, positions: [position] } }, undefined, quoteCurrency, undefined, quote,
510
556
  ).positionCurrency;
@@ -72,6 +72,7 @@ import type { OverviewDividendState } from "./overview/dividend";
72
72
  import { optionContractFields, useOptionContractRow } from "./overview/option-contract";
73
73
  import { resolveOptionsTarget } from "../../../utils/options";
74
74
  import { buildOverviewStats, buildPositionRows, buildProfileFields, FINANCIALS } from "./overview/model";
75
+ import { usePurchaseDateCostFx } from "../portfolio-list/pane/purchase-date-fx";
75
76
  import { hasStatementFinancials } from "./financials/model";
76
77
  import type { OverviewFunctionLink, StatField } from "./overview/types";
77
78
  import type { CryptoMarketAsset } from "../../../api-client/crypto-markets";
@@ -526,6 +527,7 @@ function ResolvedOverviewTab({
526
527
  fundamentals: shownFundamentals,
527
528
  coin,
528
529
  financialCurrency: financials?.financialCurrency,
530
+ statementFinancials: financials,
529
531
  quoteCurrency,
530
532
  baseCurrency,
531
533
  toBase,
@@ -553,12 +555,15 @@ function ResolvedOverviewTab({
553
555
  isin: ticker.metadata.isin,
554
556
  });
555
557
  const hasPerformance = performanceFields.some((field) => field.value != null || field.unavailableReason);
558
+ const positionTickers = useMemo(() => [ticker], [ticker]);
559
+ const purchaseDateFx = usePurchaseDateCostFx(positionTickers, { enabled: ticker.metadata.positions.length > 0, into: baseCurrency });
556
560
  const positionRows = buildPositionRows({
557
561
  ticker,
558
562
  quote,
559
563
  quoteCurrency,
560
564
  baseCurrency,
561
565
  toBase,
566
+ purchaseDateFx,
562
567
  accountNames,
563
568
  });
564
569
 
@@ -38,17 +38,24 @@ export const quoteKey = (row: TapeQuote) => JSON.stringify([tapeTimeKey(row.time
38
38
  export function newestFirst<T extends { timestamp: string }>(rows: readonly T[]): T[] {
39
39
  return [...rows].sort((a, b) => tapeTimeKey(b.timestamp).localeCompare(tapeTimeKey(a.timestamp)));
40
40
  }
41
+ /** Two SIP stamps in time order, nanoseconds kept: negative when `a` is earlier. */
42
+ export function tapeTimeOrder(a: string, b: string): number {
43
+ const left = tapeTimeKey(a);
44
+ const right = tapeTimeKey(b);
45
+ return left < right ? -1 : left > right ? 1 : 0;
46
+ }
47
+ /** A SIP stamp to the millisecond, the clock a pinned moment is on; `tapeAfterMoment` and `tapeTimeOrder` keep the nanoseconds. */
48
+ export const tapeMoment = (timestamp: string) => Date.parse(`${tapeTimeKey(timestamp).slice(0, 23)}Z`);
49
+ let momentKey: { at: number; key: string } | null = null;
41
50
  /**
42
- * A moment in milliseconds as a tape key, the one comparison both picking the
43
- * row at a pinned moment and muting the rows after it use, so a print at
44
- * 14:30:00.000000002 is after a moment of 14:30:00.000 for both.
51
+ * Whether a SIP stamp is after a moment in milliseconds, nanoseconds kept: the
52
+ * one comparison both picking the row at a pinned moment and muting the rows
53
+ * after it use, so a print at 14:30:00.000000002 is after a moment of
54
+ * 14:30:00.000 for both.
45
55
  */
46
- export const tapeMomentKey = (at: number) => tapeTimeKey(new Date(at).toISOString());
47
- /** Whether a SIP stamp is after a moment's key (`tapeMomentKey`). */
48
- export const tapeAfter = (timestamp: string, momentKey: string) => tapeTimeKey(timestamp) > momentKey;
49
- /** Of rows newest first, the first printed at or before a moment's key: null when every row is later. */
50
- export function tapeRowAtOrBefore<T>(rows: readonly T[], timestamp: (row: T) => string, momentKey: string): T | null {
51
- return rows.find((row) => !tapeAfter(timestamp(row), momentKey)) ?? null;
56
+ export function tapeAfterMoment(timestamp: string, at: number): boolean {
57
+ if (momentKey?.at !== at) momentKey = { at, key: tapeTimeKey(new Date(at).toISOString()) };
58
+ return tapeTimeKey(timestamp) > momentKey.key;
52
59
  }
53
60
  export function tapeStatistics(data: Pick<TapeSnapshot, "trades">) {
54
61
  const trades = newestFirst(data.trades);