gloomberb 0.20.14 → 0.20.16
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.
- package/package.json +1 -1
- package/src/api-client/index.ts +54 -0
- package/src/api-client/install-experiments.ts +8 -7
- package/src/api-client/paths.ts +2 -1
- package/src/api-client/product-waitlist.ts +63 -0
- package/src/api-client/request.ts +4 -2
- package/src/api-client/types/billing.ts +45 -0
- package/src/api-client/yearly-plan.ts +132 -0
- package/src/app/global-shortcuts.ts +5 -3
- package/src/app/pane-runtime/index.tsx +2 -2
- package/src/app/pane-runtime/plugin-bindings.ts +3 -1
- package/src/app/pane-runtime/ticker-open-runtime.ts +6 -1
- package/src/app/since-last-visit/keys.ts +26 -0
- package/src/app/since-last-visit/model.ts +266 -0
- package/src/app/since-last-visit/strip.tsx +193 -0
- package/src/app/since-last-visit/use-since-last-visit.ts +289 -0
- package/src/app/since-last-visit/visit-tracker.ts +191 -0
- package/src/app.tsx +15 -0
- package/src/cli/commands/market.ts +8 -4
- package/src/cli/commands/system.ts +29 -1
- package/src/cli/commands/ticker.ts +12 -5
- package/src/cli/desktop-pane-shot-api-policy.ts +4 -1
- package/src/cli/desktop-pane-shot-browser.ts +2 -1
- package/src/cli/desktop-pane-shot-view.ts +3 -7
- package/src/cli/desktop-pane-shot.ts +26 -28
- package/src/cli/help.ts +1 -0
- package/src/cli/history-rows.ts +24 -0
- package/src/cli/index.ts +4 -0
- package/src/cli/options.ts +29 -1
- package/src/cli/pane-functions/catalog.ts +41 -4
- package/src/cli/pane-functions/function-help.ts +1 -1
- package/src/cli/pane-functions/headless.ts +63 -1
- package/src/cli/pane-functions/index.ts +2 -2
- package/src/cli/pane-functions/resolver.ts +43 -0
- package/src/cli/pane-functions/screenshot-payload.ts +3 -0
- package/src/cli/report-tables.ts +20 -5
- package/src/cli/shot-temp-dir.ts +30 -0
- package/src/cli/suffixed-listing-rows.ts +11 -0
- package/src/components/chart/composite/composite-chart.tsx +3 -3
- package/src/components/command-bar/commands/direct/index.ts +31 -8
- package/src/components/command-bar/commands/registry.ts +7 -0
- package/src/components/command-bar/routes/root/command-items.ts +8 -0
- package/src/components/command-bar/routes/root/results.ts +16 -0
- package/src/components/company-logo.tsx +10 -3
- package/src/components/data-table/sections.ts +6 -1
- package/src/components/layout/pane/title.ts +6 -2
- package/src/components/layout/shell/index.tsx +5 -1
- package/src/components/layout/shell/ticker-link-menu.ts +12 -9
- package/src/components/ticker/badge/format.ts +12 -3
- package/src/components/ticker/badge/index.tsx +9 -3
- package/src/components/ticker/list-table-view.tsx +119 -17
- package/src/components/ui/data-table/display-columns.ts +16 -0
- package/src/components/ui/data-table/index.tsx +40 -9
- package/src/components/ui/data-table/types.ts +14 -0
- package/src/core/state/app/layout-reducer.ts +3 -1
- package/src/core/state/app/layout.ts +2 -2
- package/src/data/config/layout.ts +14 -0
- package/src/data/config/store/normalize.ts +11 -1
- package/src/i18n/es.ts +38 -0
- package/src/i18n/ja.ts +38 -0
- package/src/i18n/ko.ts +38 -0
- package/src/i18n/zh-cn.ts +38 -0
- package/src/i18n/zh-tw.ts +38 -0
- package/src/layout/pane-follow.ts +141 -4
- package/src/layout/pane-layout-move.ts +10 -7
- package/src/layout/ticker-navigation.ts +13 -19
- package/src/layout/ticker-retarget.ts +3 -2
- package/src/market-data/market/index-level.ts +19 -0
- package/src/plugins/builtin/account-management/keyboard.ts +14 -0
- package/src/plugins/builtin/account-management/model.ts +2 -0
- package/src/plugins/builtin/account-management/pane.tsx +79 -7
- package/src/plugins/builtin/account-management/payment-recovery-row.tsx +97 -0
- package/src/plugins/builtin/account-management/yearly-plan-row.tsx +359 -0
- package/src/plugins/builtin/awards/pane.tsx +6 -8
- package/src/plugins/builtin/changelog/index.tsx +6 -44
- package/src/plugins/builtin/changelog/versions.ts +17 -68
- package/src/plugins/builtin/cloud/askg/executor.ts +2 -1
- package/src/plugins/builtin/cloud/askg/sources.ts +2 -1
- package/src/plugins/builtin/cpi/pane.tsx +1 -1
- package/src/plugins/builtin/debt-maturities/model.ts +1 -1
- package/src/plugins/builtin/earnings/board-table.ts +1 -1
- package/src/plugins/builtin/earnings/board.tsx +36 -16
- package/src/plugins/builtin/earnings/highlight.ts +47 -0
- package/src/plugins/builtin/earnings/history-table.ts +1 -1
- package/src/plugins/builtin/earnings/index.tsx +1 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +2 -2
- package/src/plugins/builtin/estimate-revisions/model.ts +1 -1
- package/src/plugins/builtin/exposure/index.tsx +1 -1
- package/src/plugins/builtin/macro-day/model.ts +6 -4
- package/src/plugins/builtin/market-valuation/detail.tsx +3 -3
- package/src/plugins/builtin/market-valuation/headless.ts +11 -4
- package/src/plugins/builtin/market-valuation/pane.tsx +3 -1
- package/src/plugins/builtin/market-valuation/view.ts +14 -0
- package/src/plugins/builtin/news/wire/news/detail-view.tsx +20 -8
- package/src/plugins/builtin/pe-band/pane.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/cli/render.ts +8 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +176 -17
- package/src/plugins/builtin/portfolio-list/pane/groups.tsx +220 -0
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +90 -15
- package/src/plugins/builtin/portfolio-list/table.tsx +13 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +4 -2
- package/src/plugins/builtin/research/relative-valuation-headless.ts +15 -5
- package/src/plugins/builtin/research/relative-valuation-model.ts +7 -1
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +7 -4
- package/src/plugins/builtin/shared/headless-options.ts +1 -1
- package/src/plugins/builtin/social-mentions/model.ts +2 -2
- package/src/plugins/builtin/thirteenf/pane.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/financials/model.ts +51 -16
- package/src/plugins/builtin/ticker-detail/financials/nopat.ts +16 -0
- package/src/plugins/builtin/ticker-detail/financials/ratios.ts +44 -13
- package/src/plugins/builtin/ticker-detail/financials/schema.ts +33 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +4 -2
- package/src/plugins/builtin/ticker-detail/headless-schema.ts +30 -4
- package/src/plugins/builtin/ticker-detail/headless.ts +254 -34
- package/src/plugins/builtin/ticker-detail/overview/model.ts +7 -3
- package/src/plugins/builtin/ticker-detail/pharma-signals/eligibility.ts +32 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/tab.tsx +162 -0
- package/src/plugins/builtin/ticker-detail/pharma-signals/waitlist.ts +126 -0
- package/src/plugins/builtin/ticker-detail/research-groups.ts +6 -4
- package/src/plugins/builtin/ticker-detail/research-tabs.ts +11 -0
- package/src/portfolio/column-values.ts +20 -8
- package/src/portfolio/suffixed-listings.ts +3 -1
- package/src/portfolio/watchlist-groups.ts +212 -0
- package/src/react/ticker-source.ts +3 -1
- package/src/renderers/dom/styles.css +7 -0
- package/src/state/app/bootstrap.ts +11 -0
- package/src/state/app/context/index.tsx +6 -0
- package/src/sync/collections-contributor.ts +5 -2
- package/src/sync/config-merge.ts +10 -2
- package/src/sync/sanitize.ts +28 -0
- package/src/telemetry/usage-counts.ts +17 -0
- package/src/time-series/chart-seed.ts +1 -1
- package/src/time-series/financial-period-coverage.ts +4 -12
- package/src/time-series/parsed-history-cache.ts +1 -1
- package/src/time-series/resolve.ts +1 -1
- package/src/time-series/use-chart-resolution.ts +6 -1
- package/src/types/config.ts +32 -0
- package/src/types/headless.ts +5 -0
- package/src/types/plugin-context.ts +5 -0
- package/src/types/ticker.ts +14 -0
- package/src/ui/ascii-font.ts +1 -4
- package/src/utils/async-deadline.ts +2 -2
- package/src/utils/csv.ts +44 -5
- package/src/utils/futures-generic.ts +3 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { instrumentFromTicker, type InstrumentRef } from "../../market-data/request-types";
|
|
2
|
+
import { hasValidQuoteObservationTime, isQuoteStaleForCurrentSession } from "../../market-data/quotes/freshness";
|
|
3
|
+
import { savedCopyAt } from "../../data/saved-copies";
|
|
4
|
+
import type { AppConfig } from "../../types/config";
|
|
5
|
+
import type { Quote } from "../../types/financials";
|
|
6
|
+
import type { TickerRecord } from "../../types/ticker";
|
|
7
|
+
import { formatClockTime, formatShortDate } from "../../utils/datetime-format";
|
|
8
|
+
import { canonicalExchange } from "../../utils/exchanges";
|
|
9
|
+
import { instrumentIdentityKey } from "../../utils/instrument-identity";
|
|
10
|
+
import { isRecord } from "../../utils/guards";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* What moved in the user's own tickers since their last visit. A visit keeps
|
|
14
|
+
* the last price it had of each listing in the user's portfolios and
|
|
15
|
+
* watchlists; the next visit compares the price it has now with that one.
|
|
16
|
+
* A move is only ever the difference between two prices of the same listing,
|
|
17
|
+
* in the same currency and on the same basis, the newer printed after the
|
|
18
|
+
* older; a listing with no such pair has no move, never a zero.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Listings a visit keeps, portfolios first: one batch of quotes, and a small row in the state store. */
|
|
22
|
+
const MAX_TRACKED_LISTINGS = 50;
|
|
23
|
+
/** Less time away than this is the same visit (a restart, an update). */
|
|
24
|
+
export const MIN_AWAY_MS = 60 * 60_000;
|
|
25
|
+
/** The smallest move, in percent either way, the strip names. */
|
|
26
|
+
const MIN_MOVE_PERCENT = 1;
|
|
27
|
+
/** The most moves the strip names; a narrow window shows fewer. */
|
|
28
|
+
const MAX_STRIP_MOVES = 5;
|
|
29
|
+
|
|
30
|
+
/** One price of a listing, as a visit keeps it for the next one. */
|
|
31
|
+
export interface VisitObservation {
|
|
32
|
+
/** The key the ticker is saved under (`TickerMetadata.ticker`). */
|
|
33
|
+
symbol: string;
|
|
34
|
+
price: number;
|
|
35
|
+
currency: string;
|
|
36
|
+
/** What the price counts: `per-unit`, `percent-of-par`, `points`, `thirty-seconds`, or a fund's `nav`. */
|
|
37
|
+
basis: string;
|
|
38
|
+
/** The listing's venue as the quote named it, canonical; empty when it named none. */
|
|
39
|
+
venue: string;
|
|
40
|
+
/** When the source printed the price (the quote's `lastUpdated`), epoch ms. */
|
|
41
|
+
at: number;
|
|
42
|
+
/** The quote came from the session a split took effect in, so a price from before it is on another share basis. */
|
|
43
|
+
split?: true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** What a visit leaves for the next one. */
|
|
47
|
+
export interface VisitBaseline {
|
|
48
|
+
/** The account the prices were seen under (`visitScope`): another account never reads them. */
|
|
49
|
+
scope: string;
|
|
50
|
+
/** The last moment the user was in the app with these prices. */
|
|
51
|
+
seenAt: number;
|
|
52
|
+
/** By listing (`instrumentIdentityKey`). */
|
|
53
|
+
observations: Record<string, VisitObservation>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface VisitMove {
|
|
57
|
+
/** The listing (`instrumentIdentityKey`). */
|
|
58
|
+
key: string;
|
|
59
|
+
symbol: string;
|
|
60
|
+
/** Percent from the last visit's price to the current one, when the recap was made. */
|
|
61
|
+
percent: number;
|
|
62
|
+
/** The last visit's price, which the move keeps being measured from. */
|
|
63
|
+
before: VisitObservation;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The return recap: the moves since `seenAt`, biggest first. */
|
|
67
|
+
export interface VisitRecap {
|
|
68
|
+
seenAt: number;
|
|
69
|
+
moves: VisitMove[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface TrackedListing {
|
|
73
|
+
key: string;
|
|
74
|
+
symbol: string;
|
|
75
|
+
instrument: InstrumentRef;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Whose prices a visit keeps: the signed-in account, or this device signed out. */
|
|
79
|
+
export function visitScope(accountId: string | null | undefined): string {
|
|
80
|
+
return accountId ? `account:${accountId}` : "local";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Option contracts move by tens of percent on a quiet day; the strip is about tickers. */
|
|
84
|
+
const OPTION_CATEGORIES = new Set(["OPT", "FOP"]);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The listings in the user's own portfolios and watchlists, holdings first,
|
|
88
|
+
* at most `limit`. Collections shared with a team (the server keeps their
|
|
89
|
+
* rows) and portfolios imported from someone else's filing are not the
|
|
90
|
+
* user's own and are left out, as is a ticker whose listing is ambiguous.
|
|
91
|
+
*/
|
|
92
|
+
export function trackedListings(
|
|
93
|
+
config: Pick<AppConfig, "portfolios" | "watchlists">,
|
|
94
|
+
tickers: ReadonlyMap<string, TickerRecord>,
|
|
95
|
+
limit = MAX_TRACKED_LISTINGS,
|
|
96
|
+
): TrackedListing[] {
|
|
97
|
+
const portfolios = new Set(config.portfolios.filter((entry) => !entry.teamId && !entry.importedFrom).map((entry) => entry.id));
|
|
98
|
+
const watchlists = new Set(config.watchlists.filter((entry) => !entry.teamId).map((entry) => entry.id));
|
|
99
|
+
const held: TrackedListing[] = [];
|
|
100
|
+
const watched: TrackedListing[] = [];
|
|
101
|
+
const seen = new Set<string>();
|
|
102
|
+
for (const [symbol, ticker] of tickers) {
|
|
103
|
+
const metadata = ticker.metadata;
|
|
104
|
+
if (OPTION_CATEGORIES.has(metadata.assetCategory?.toUpperCase() ?? "")) continue;
|
|
105
|
+
const inPortfolio = metadata.portfolios.some((id) => portfolios.has(id));
|
|
106
|
+
const inWatchlist = metadata.watchlists.some((id) => watchlists.has(id));
|
|
107
|
+
if (!inPortfolio && !inWatchlist) continue;
|
|
108
|
+
const instrument = instrumentFromTicker(ticker, symbol);
|
|
109
|
+
if (!instrument) continue;
|
|
110
|
+
const key = instrumentIdentityKey(instrument);
|
|
111
|
+
if (seen.has(key)) continue;
|
|
112
|
+
seen.add(key);
|
|
113
|
+
(inPortfolio ? held : watched).push({ key, symbol, instrument });
|
|
114
|
+
}
|
|
115
|
+
return [...held, ...watched].slice(0, Math.max(0, limit));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A quote as a price the user can be said to have seen, or null when it is
|
|
120
|
+
* not one: no positive price or currency, no valid print time, stale for its
|
|
121
|
+
* market's current session, answered from a saved copy after a refresh
|
|
122
|
+
* failed, a nominal price nothing traded at, or a line that stopped trading.
|
|
123
|
+
*/
|
|
124
|
+
export function observeQuote(symbol: string, quote: Quote | null | undefined, now: number): VisitObservation | null {
|
|
125
|
+
if (!quote) return null;
|
|
126
|
+
if (!Number.isFinite(quote.price) || quote.price <= 0) return null;
|
|
127
|
+
if (typeof quote.currency !== "string" || !quote.currency.trim()) return null;
|
|
128
|
+
if (!hasValidQuoteObservationTime(quote, now)) return null;
|
|
129
|
+
if (quote.nominalPrice || quote.delisting || savedCopyAt(quote) != null) return null;
|
|
130
|
+
if (isQuoteStaleForCurrentSession(quote, now)) return null;
|
|
131
|
+
return {
|
|
132
|
+
symbol,
|
|
133
|
+
price: quote.price,
|
|
134
|
+
currency: quote.currency.trim(),
|
|
135
|
+
basis: quote.priceObservation === "nav" ? "nav" : quote.priceBasis ?? "per-unit",
|
|
136
|
+
venue: canonicalExchange(quote.listingExchangeName || quote.exchangeName || ""),
|
|
137
|
+
at: quote.lastUpdated,
|
|
138
|
+
...(quote.sessionSplit ? { split: true as const } : {}),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Share counts a split multiplies by: a price that moved by one of these
|
|
144
|
+
* (or its inverse, a reverse split) cannot be told from a split, and a move
|
|
145
|
+
* that is a split was never made.
|
|
146
|
+
*/
|
|
147
|
+
const SPLIT_FACTORS = [2, 3, 4, 5, 6, 7, 8, 10, 12, 15, 20, 25, 30, 40, 50, 100, 1.5];
|
|
148
|
+
const SPLIT_TOLERANCE = 0.01;
|
|
149
|
+
|
|
150
|
+
function looksLikeSplit(ratio: number): boolean {
|
|
151
|
+
return SPLIT_FACTORS.some((factor) => (
|
|
152
|
+
Math.abs(ratio * factor - 1) <= SPLIT_TOLERANCE || Math.abs(ratio / factor - 1) <= SPLIT_TOLERANCE
|
|
153
|
+
));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Percent from `before` to `after`, or null when the two are not two prices
|
|
158
|
+
* of one listing that can be compared: another ticker, currency, basis or
|
|
159
|
+
* venue, a print no newer than the one before, either side in a split's
|
|
160
|
+
* session, or a ratio a split would give.
|
|
161
|
+
*/
|
|
162
|
+
export function moveSince(before: VisitObservation, after: VisitObservation): number | null {
|
|
163
|
+
if (before.symbol !== after.symbol || before.currency !== after.currency
|
|
164
|
+
|| before.basis !== after.basis || before.venue !== after.venue) return null;
|
|
165
|
+
if (before.split || after.split) return null;
|
|
166
|
+
if (!(after.at > before.at)) return null;
|
|
167
|
+
if (!(before.price > 0) || !(after.price > 0)) return null;
|
|
168
|
+
const ratio = after.price / before.price;
|
|
169
|
+
if (!Number.isFinite(ratio) || looksLikeSplit(ratio)) return null;
|
|
170
|
+
return (ratio - 1) * 100;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The moves since `baseline` for the listings still tracked, from the
|
|
175
|
+
* prices on hand now (`current`, by listing): the ones of at least
|
|
176
|
+
* `minPercent` either way, biggest first, at most `limit`. Null when
|
|
177
|
+
* there is no baseline, the user was away less than `minAwayMs`, or
|
|
178
|
+
* nothing moved enough; the strip then does not show.
|
|
179
|
+
*/
|
|
180
|
+
export function recapSince(
|
|
181
|
+
baseline: VisitBaseline | null,
|
|
182
|
+
tracked: readonly TrackedListing[],
|
|
183
|
+
current: ReadonlyMap<string, VisitObservation>,
|
|
184
|
+
now: number,
|
|
185
|
+
{ minAwayMs = MIN_AWAY_MS, minPercent = MIN_MOVE_PERCENT, limit = MAX_STRIP_MOVES } = {},
|
|
186
|
+
): VisitRecap | null {
|
|
187
|
+
if (!baseline || !(now - baseline.seenAt >= minAwayMs)) return null;
|
|
188
|
+
const moves: VisitMove[] = [];
|
|
189
|
+
for (const listing of tracked) {
|
|
190
|
+
const before = baseline.observations[listing.key];
|
|
191
|
+
const after = current.get(listing.key);
|
|
192
|
+
if (!before || !after) continue;
|
|
193
|
+
const percent = moveSince(before, after);
|
|
194
|
+
if (percent == null || !(Math.abs(percent) >= minPercent)) continue;
|
|
195
|
+
moves.push({ key: listing.key, symbol: listing.symbol, percent, before });
|
|
196
|
+
}
|
|
197
|
+
if (moves.length === 0) return null;
|
|
198
|
+
moves.sort((left, right) => Math.abs(right.percent) - Math.abs(left.percent) || left.symbol.localeCompare(right.symbol));
|
|
199
|
+
return { seenAt: baseline.seenAt, moves: moves.slice(0, Math.max(0, limit)) };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* A recap's move as of now, so a strip left up for hours keeps saying what
|
|
204
|
+
* is true rather than a number from its first second: measured again from
|
|
205
|
+
* the last visit's price to the quote on hand, or as it was when the recap
|
|
206
|
+
* was made while no current price is on hand (a stale or missing quote).
|
|
207
|
+
* Null once the quote on hand is a price the last one no longer compares
|
|
208
|
+
* with (another currency, a split): the move is not shown at all.
|
|
209
|
+
*/
|
|
210
|
+
export function liveMovePercent(move: VisitMove, quote: Quote | null | undefined, now: number): number | null {
|
|
211
|
+
const after = observeQuote(move.symbol, quote, now);
|
|
212
|
+
return after ? moveSince(move.before, after) : move.percent;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const WEEKDAY = new Intl.DateTimeFormat("en-US", { weekday: "short" });
|
|
216
|
+
const DAY_MS = 24 * 60 * 60_000;
|
|
217
|
+
|
|
218
|
+
function localDayStart(time: number): number {
|
|
219
|
+
const date = new Date(time);
|
|
220
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* When the last visit was, as the strip dates its moves, in local time on
|
|
225
|
+
* the 24-hour clock: `09:30` earlier today, `yesterday 16:05`, `Wed 16:05`
|
|
226
|
+
* within the week, then the day (`4 Nov`, `4 Nov 2025` in another year).
|
|
227
|
+
*/
|
|
228
|
+
export function formatVisitTime(seenAt: number, now: number): string {
|
|
229
|
+
const days = Math.round((localDayStart(now) - localDayStart(seenAt)) / DAY_MS);
|
|
230
|
+
const clock = formatClockTime(seenAt);
|
|
231
|
+
if (days <= 0) return clock;
|
|
232
|
+
if (days === 1) return `yesterday ${clock}`;
|
|
233
|
+
if (days < 7) return `${WEEKDAY.format(new Date(seenAt))} ${clock}`;
|
|
234
|
+
const sameYear = new Date(seenAt).getFullYear() === new Date(now).getFullYear();
|
|
235
|
+
return formatShortDate(seenAt, { year: sameYear ? false : "numeric" });
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** The most observations a stored baseline is read with, whatever it holds. */
|
|
239
|
+
const MAX_STORED_OBSERVATIONS = MAX_TRACKED_LISTINGS * 2;
|
|
240
|
+
|
|
241
|
+
function readObservation(value: unknown): VisitObservation | null {
|
|
242
|
+
if (!isRecord(value)) return null;
|
|
243
|
+
const { symbol, price, currency, basis, venue, at, split } = value;
|
|
244
|
+
if (typeof symbol !== "string" || !symbol || typeof currency !== "string" || !currency
|
|
245
|
+
|| typeof basis !== "string" || !basis || typeof venue !== "string") return null;
|
|
246
|
+
if (typeof price !== "number" || !Number.isFinite(price) || price <= 0) return null;
|
|
247
|
+
if (typeof at !== "number" || !Number.isFinite(at) || at <= 0) return null;
|
|
248
|
+
return { symbol, price, currency, basis, venue, at, ...(split === true ? { split: true as const } : {}) };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** A stored baseline as this build reads it: null unless it is whole and belongs to `scope`. */
|
|
252
|
+
export function readVisitBaseline(value: unknown, scope: string): VisitBaseline | null {
|
|
253
|
+
if (!isRecord(value) || value.scope !== scope || !isRecord(value.observations)) return null;
|
|
254
|
+
const seenAt = value.seenAt;
|
|
255
|
+
if (typeof seenAt !== "number" || !Number.isFinite(seenAt) || seenAt <= 0) return null;
|
|
256
|
+
const observations: Record<string, VisitObservation> = {};
|
|
257
|
+
let count = 0;
|
|
258
|
+
for (const [key, entry] of Object.entries(value.observations)) {
|
|
259
|
+
if (count >= MAX_STORED_OBSERVATIONS) break;
|
|
260
|
+
const observation = readObservation(entry);
|
|
261
|
+
if (!key || !observation) continue;
|
|
262
|
+
observations[key] = observation;
|
|
263
|
+
count += 1;
|
|
264
|
+
}
|
|
265
|
+
return { scope, seenAt, observations };
|
|
266
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { Box, Text, useActionShortcut, useUiCapabilities } from "../../ui";
|
|
3
|
+
import { Button, terminalButtonColumns } from "../../components/ui/button";
|
|
4
|
+
import { TickerBadge } from "../../components/ticker/badge";
|
|
5
|
+
import { getTickerBadgeText, TICKER_BADGE_CHROME_WIDTH } from "../../components/ticker/badge/format";
|
|
6
|
+
import { t, tf } from "../../i18n";
|
|
7
|
+
import { useAppLanguage } from "../../i18n/react";
|
|
8
|
+
import { useQuoteEntries } from "../../market-data/hooks";
|
|
9
|
+
import { buildQuoteKey, resolveEntryData } from "../../market-data/selectors";
|
|
10
|
+
import { useViewport } from "../../react/input";
|
|
11
|
+
import { useThemeColors } from "../../theme/theme-context";
|
|
12
|
+
import type { Quote } from "../../types/financials";
|
|
13
|
+
import { displayWidth } from "../../utils/format";
|
|
14
|
+
import { bindSinceLastVisitKeys } from "./keys";
|
|
15
|
+
import { formatVisitTime, liveMovePercent, type VisitMove } from "./model";
|
|
16
|
+
import type { SinceLastVisit, SinceLastVisitMove } from "./use-since-last-visit";
|
|
17
|
+
|
|
18
|
+
/** Cells between the lead and the chips, and between the two actions. */
|
|
19
|
+
const GAP = 2;
|
|
20
|
+
/** A window this wide (in cells) says "since your last visit" in full on the desktop and the web. */
|
|
21
|
+
const NATIVE_FULL_LEAD_COLUMNS = 110;
|
|
22
|
+
|
|
23
|
+
interface StripChip {
|
|
24
|
+
move: VisitMove;
|
|
25
|
+
percent: number;
|
|
26
|
+
quote: Quote | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface TerminalFit {
|
|
30
|
+
lead: string;
|
|
31
|
+
chips: number;
|
|
32
|
+
/** Hide says its key. */
|
|
33
|
+
hideKey: boolean;
|
|
34
|
+
turnOff: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* What the terminal's one row has room for. The date of the last visit (the
|
|
39
|
+
* short lead), Hide and one move always stay: a move without its date would
|
|
40
|
+
* read as the day's. Turn off stays next, as long as a move fits beside it
|
|
41
|
+
* (the command bar's Since Last Visit has it too); then as many moves as fit,
|
|
42
|
+
* biggest first; then Hide's key; then the lead in full.
|
|
43
|
+
*/
|
|
44
|
+
function fitTerminalStrip(
|
|
45
|
+
width: number,
|
|
46
|
+
[fullLead, shortLead]: readonly [string, string],
|
|
47
|
+
chipColumns: readonly number[],
|
|
48
|
+
hideColumns: { withKey: number; bare: number },
|
|
49
|
+
turnOffColumns: number,
|
|
50
|
+
): TerminalFit {
|
|
51
|
+
const fit = (option: Omit<TerminalFit, "chips">): TerminalFit => {
|
|
52
|
+
// One cell of padding at each edge, a gap after the lead and before each action.
|
|
53
|
+
let room = width - 2 - displayWidth(option.lead) - GAP
|
|
54
|
+
- GAP - (option.hideKey ? hideColumns.withKey : hideColumns.bare)
|
|
55
|
+
- (option.turnOff ? GAP + turnOffColumns : 0);
|
|
56
|
+
let chips = 0;
|
|
57
|
+
for (const columns of chipColumns) {
|
|
58
|
+
if (columns > room) break;
|
|
59
|
+
room -= columns;
|
|
60
|
+
chips += 1;
|
|
61
|
+
}
|
|
62
|
+
return { ...option, chips };
|
|
63
|
+
};
|
|
64
|
+
const withTurnOff = [
|
|
65
|
+
fit({ lead: fullLead, hideKey: true, turnOff: true }),
|
|
66
|
+
fit({ lead: shortLead, hideKey: true, turnOff: true }),
|
|
67
|
+
fit({ lead: shortLead, hideKey: false, turnOff: true }),
|
|
68
|
+
];
|
|
69
|
+
const whole = withTurnOff.find((option) => option.chips === chipColumns.length);
|
|
70
|
+
if (whole) return whole;
|
|
71
|
+
const most = withTurnOff.reduce((best, option) => (option.chips > best.chips ? option : best));
|
|
72
|
+
return most.chips > 0 ? most : fit({ lead: shortLead, hideKey: false, turnOff: false });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The strip a returning user sees above the layout: when they were last
|
|
77
|
+
* here, then what moved most in their own portfolios and watchlists since,
|
|
78
|
+
* each a ticker chip that opens its research. Hide puts it away for this
|
|
79
|
+
* session (the notification dismiss key too); Turn off puts it away for good,
|
|
80
|
+
* until Since Last Visit in the command bar turns it on again.
|
|
81
|
+
*/
|
|
82
|
+
export function SinceLastVisitStrip({ strip }: { strip: SinceLastVisit }) {
|
|
83
|
+
useAppLanguage();
|
|
84
|
+
const colors = useThemeColors();
|
|
85
|
+
const { nativePaneChrome = false } = useUiCapabilities();
|
|
86
|
+
const { width } = useViewport();
|
|
87
|
+
const dismissKey = useActionShortcut("notification-dismiss");
|
|
88
|
+
// The chip under the pointer says its price, as ticker chips do.
|
|
89
|
+
const [hovered, setHovered] = useState<string | null>(null);
|
|
90
|
+
const recap = strip.recap;
|
|
91
|
+
const moves: readonly SinceLastVisitMove[] = recap?.moves ?? [];
|
|
92
|
+
const entries = useQuoteEntries(useMemo(() => moves.map((entry) => entry.instrument), [moves]));
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
const chips = moves.flatMap<StripChip>(({ move, instrument }) => {
|
|
95
|
+
const quote = resolveEntryData(entries.get(buildQuoteKey(instrument))) ?? null;
|
|
96
|
+
const percent = liveMovePercent(move, quote, now);
|
|
97
|
+
return percent == null ? [] : [{ move, percent, quote }];
|
|
98
|
+
});
|
|
99
|
+
const first = chips[0]?.move ?? null;
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (!first) return;
|
|
103
|
+
strip.noteShown();
|
|
104
|
+
return bindSinceLastVisitKeys({ open: () => strip.open(first), dismiss: strip.hide });
|
|
105
|
+
}, [first, strip]);
|
|
106
|
+
// Every move it named stopped comparing (a currency or a split changed under it): nothing is left to say.
|
|
107
|
+
const exhausted = !!recap && chips.length === 0;
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (exhausted) strip.hide();
|
|
110
|
+
}, [exhausted, strip]);
|
|
111
|
+
|
|
112
|
+
if (!recap || chips.length === 0) return null;
|
|
113
|
+
|
|
114
|
+
const when = formatVisitTime(recap.seenAt, now);
|
|
115
|
+
const fullLead = tf("Since your last visit, {time}", { time: when });
|
|
116
|
+
const shortLead = tf("Since {time}", { time: when });
|
|
117
|
+
const hideButton = { label: "Hide", compact: true, shortcut: dismissKey || undefined } as const;
|
|
118
|
+
const bareHideButton = { label: "Hide", compact: true } as const;
|
|
119
|
+
const turnOffButton = { label: "Turn off", compact: true } as const;
|
|
120
|
+
const chipText = (chip: StripChip) => getTickerBadgeText({ symbol: chip.move.symbol, status: "ready", quote: chip.quote, move: chip.percent });
|
|
121
|
+
|
|
122
|
+
// The desktop and the web lay the chips out in CSS: one that has no room wraps out of sight.
|
|
123
|
+
const fit: TerminalFit = nativePaneChrome
|
|
124
|
+
? { lead: width >= NATIVE_FULL_LEAD_COLUMNS ? fullLead : shortLead, chips: chips.length, hideKey: true, turnOff: true }
|
|
125
|
+
: fitTerminalStrip(
|
|
126
|
+
width,
|
|
127
|
+
[fullLead, shortLead],
|
|
128
|
+
chips.map((chip) => displayWidth(chipText(chip)) + TICKER_BADGE_CHROME_WIDTH),
|
|
129
|
+
{ withKey: terminalButtonColumns(hideButton), bare: terminalButtonColumns(bareHideButton) },
|
|
130
|
+
terminalButtonColumns(turnOffButton),
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const chipNodes = chips.slice(0, fit.chips).map((chip) => (
|
|
134
|
+
<TickerBadge
|
|
135
|
+
key={chip.move.key}
|
|
136
|
+
symbol={chip.move.symbol}
|
|
137
|
+
status="ready"
|
|
138
|
+
quote={chip.quote}
|
|
139
|
+
move={chip.percent}
|
|
140
|
+
hovered={hovered === chip.move.key}
|
|
141
|
+
onHoverStart={() => setHovered(chip.move.key)}
|
|
142
|
+
onHoverEnd={() => setHovered((current) => (current === chip.move.key ? null : current))}
|
|
143
|
+
onOpen={() => strip.open(chip.move)}
|
|
144
|
+
/>
|
|
145
|
+
));
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<Box
|
|
149
|
+
flexDirection="row"
|
|
150
|
+
height={1}
|
|
151
|
+
alignItems="center"
|
|
152
|
+
flexShrink={0}
|
|
153
|
+
backgroundColor={colors.panel}
|
|
154
|
+
data-gloom-role="since-last-visit"
|
|
155
|
+
style={nativePaneChrome ? { paddingInline: "var(--gloom-inset)", gap: "var(--gloom-space-sm)" } : undefined}
|
|
156
|
+
paddingX={nativePaneChrome ? undefined : 1}
|
|
157
|
+
>
|
|
158
|
+
<Box flexShrink={0} paddingRight={nativePaneChrome ? undefined : GAP}>
|
|
159
|
+
<Text fg={colors.textDim}>{fit.lead}</Text>
|
|
160
|
+
</Box>
|
|
161
|
+
<Box
|
|
162
|
+
flexDirection="row"
|
|
163
|
+
flexGrow={1}
|
|
164
|
+
flexShrink={1}
|
|
165
|
+
minWidth={0}
|
|
166
|
+
overflow="hidden"
|
|
167
|
+
// A chip the window has no room for wraps out of sight rather than being cut.
|
|
168
|
+
style={nativePaneChrome ? { flexWrap: "wrap", height: "100%", alignContent: "flex-start" } : undefined}
|
|
169
|
+
>
|
|
170
|
+
{chipNodes}
|
|
171
|
+
</Box>
|
|
172
|
+
<Box
|
|
173
|
+
flexDirection="row"
|
|
174
|
+
flexShrink={0}
|
|
175
|
+
paddingLeft={nativePaneChrome ? undefined : GAP}
|
|
176
|
+
style={nativePaneChrome ? { gap: "var(--gloom-space-sm)" } : undefined}
|
|
177
|
+
>
|
|
178
|
+
<Button
|
|
179
|
+
{...(fit.hideKey ? hideButton : bareHideButton)}
|
|
180
|
+
variant="plain"
|
|
181
|
+
title={t("Hide until you next open Gloom")}
|
|
182
|
+
stopPropagation
|
|
183
|
+
onPress={strip.hide}
|
|
184
|
+
/>
|
|
185
|
+
{fit.turnOff ? (
|
|
186
|
+
<Box paddingLeft={nativePaneChrome ? undefined : GAP}>
|
|
187
|
+
<Button {...turnOffButton} variant="plain" title={t("Stop showing what moved since your last visit")} stopPropagation onPress={strip.turnOff} />
|
|
188
|
+
</Box>
|
|
189
|
+
) : null}
|
|
190
|
+
</Box>
|
|
191
|
+
</Box>
|
|
192
|
+
);
|
|
193
|
+
}
|