@gloom-sh/terminal 0.20.8 → 0.20.10
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/auth.ts +6 -0
- package/src/api-client/data.ts +1 -0
- package/src/api-client/earnings.ts +15 -0
- package/src/api-client/futures-curve.ts +5 -1
- package/src/api-client/index.ts +14 -3
- package/src/api-client/types/account.ts +10 -0
- package/src/api-client/types/billing.ts +10 -0
- package/src/api-client/types/econ.ts +19 -7
- package/src/api-client/types/market.ts +7 -0
- package/src/api-client/types/screener.ts +2 -0
- package/src/cli/commands/market.ts +18 -8
- package/src/cli/commands/overview.ts +28 -7
- package/src/cli/commands/ticker.ts +40 -15
- package/src/cli/desktop-pane-shot.ts +39 -0
- package/src/cli/errors.ts +20 -3
- package/src/cli/fx-pair.ts +11 -2
- package/src/cli/history-rows.ts +34 -3
- package/src/cli/index.ts +1 -1
- package/src/cli/listing-arg.ts +51 -13
- package/src/cli/pane-functions/data.ts +3 -2
- package/src/cli/pane-functions/headless.ts +5 -2
- package/src/cli/pane-functions/index.ts +1 -0
- package/src/cli/pane-functions/resolver.ts +2 -1
- package/src/cli/pane-functions/screenshot-assessment.ts +73 -5
- package/src/cli/pane-functions/screenshot-types.ts +4 -0
- package/src/cli/symbol-cells.ts +6 -0
- package/src/cli/symbol-list.ts +14 -6
- package/src/cli/symbol-rows.ts +12 -5
- package/src/components/chart/composite/chart-layout.ts +7 -4
- package/src/components/chart/composite/composite-chart.tsx +6 -16
- package/src/components/chart/composite/toolbar.tsx +258 -82
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +5 -6
- package/src/components/command-bar/list/model.ts +13 -0
- package/src/components/command-bar/routes/ticker-search/actions.ts +2 -0
- package/src/components/command-bar/routes/ticker-search/results.ts +15 -8
- package/src/components/command-bar/surface/index.tsx +10 -5
- package/src/components/command-bar/workflow/alert.ts +21 -7
- package/src/components/data-table/table-pane.ts +3 -1
- package/src/components/layout/pane/footer/model.ts +26 -1
- package/src/components/metric-treemap/heat-surface.tsx +2 -1
- package/src/components/metric-treemap/index.tsx +3 -2
- package/src/components/ui/confirm-dialog.tsx +253 -7
- package/src/components/ui/data-table/index.tsx +1 -1
- package/src/components/ui/data-table/types.ts +7 -0
- package/src/components/ui/list-view.tsx +4 -3
- package/src/components/ui/page-stack-view.tsx +24 -6
- package/src/components/ui/status.tsx +9 -6
- package/src/docs/snapshot.json +36 -0
- package/src/i18n/es.ts +12 -0
- package/src/i18n/ja.ts +12 -0
- package/src/i18n/ko.ts +12 -0
- package/src/i18n/zh-cn.ts +12 -0
- package/src/i18n/zh-tw.ts +12 -0
- package/src/market-data/futures-roll-returns.ts +226 -0
- package/src/market-data/fx-closes.ts +14 -2
- package/src/market-data/market/change-basis.ts +35 -1
- package/src/market-data/market/session-close-note.ts +41 -4
- package/src/market-data/market/status.ts +37 -0
- package/src/market-data/performance.ts +4 -1
- package/src/market-data/quotes/listing-enterprise-value.ts +8 -4
- package/src/market-data/quotes/live-valuation.ts +25 -2
- package/src/market-data/realized-volatility.ts +3 -0
- package/src/market-data/us-bond-market.ts +115 -0
- package/src/plugins/builtin/account-management/invite-row.tsx +54 -0
- package/src/plugins/builtin/account-management/keyboard.ts +3 -0
- package/src/plugins/builtin/account-management/model.ts +1 -0
- package/src/plugins/builtin/account-management/pane.tsx +51 -5
- package/src/plugins/builtin/account-management/trial-cancel.ts +32 -7
- package/src/plugins/builtin/backtest/client.ts +9 -2
- package/src/plugins/builtin/backtest/pane.tsx +1 -1
- package/src/plugins/builtin/backtest/report.ts +22 -6
- package/src/plugins/builtin/backtest/window.ts +17 -9
- package/src/plugins/builtin/cloud/askg/pane-session.ts +94 -0
- package/src/plugins/builtin/cloud/askg/pane.tsx +40 -83
- package/src/plugins/builtin/congress-trades/pane.tsx +8 -2
- package/src/plugins/builtin/correlation/compute.ts +4 -3
- package/src/plugins/builtin/correlation/headless.ts +6 -2
- package/src/plugins/builtin/correlation/index.tsx +7 -3
- package/src/plugins/builtin/correlation/matrix/model.ts +15 -1
- package/src/plugins/builtin/correlation/relationship/model.ts +15 -1
- package/src/plugins/builtin/correlation/relationship/pane.tsx +4 -2
- package/src/plugins/builtin/earnings/board-model.ts +33 -0
- package/src/plugins/builtin/earnings/board-table.ts +50 -11
- package/src/plugins/builtin/earnings/board.tsx +29 -13
- package/src/plugins/builtin/earnings/calendar.tsx +15 -3
- package/src/plugins/builtin/earnings/client.ts +4 -1
- package/src/plugins/builtin/earnings/headless.ts +27 -14
- package/src/plugins/builtin/econ/calendar-source.ts +3 -0
- package/src/plugins/builtin/futures-curve/headless.ts +4 -1
- package/src/plugins/builtin/futures-curve/model.ts +24 -0
- package/src/plugins/builtin/help/index.tsx +1 -1
- package/src/plugins/builtin/ipo-calendar/model.ts +3 -3
- package/src/plugins/builtin/iv-history/headless.ts +12 -10
- package/src/plugins/builtin/kelly-sizer/headless.ts +2 -2
- package/src/plugins/builtin/kelly-sizer/history.ts +10 -3
- package/src/plugins/builtin/kelly-sizer/pane.tsx +2 -2
- package/src/plugins/builtin/kelly-sizer/sections.tsx +1 -1
- package/src/plugins/builtin/macro-day/headless.ts +15 -5
- package/src/plugins/builtin/macro-day/model.ts +17 -4
- package/src/plugins/builtin/macro-day/releases.ts +36 -15
- package/src/plugins/builtin/market-halts/model.ts +3 -2
- package/src/plugins/builtin/market-movers/headless.ts +2 -1
- package/src/plugins/builtin/market-movers/index.tsx +3 -2
- package/src/plugins/builtin/market-movers/model.ts +75 -22
- package/src/plugins/builtin/market-movers/screener.ts +2 -1
- package/src/plugins/builtin/market-movers/table.ts +7 -5
- package/src/plugins/builtin/pe-band/model.ts +4 -0
- package/src/plugins/builtin/portfolio-list/cell-version.ts +4 -4
- package/src/plugins/builtin/portfolio-list/cli/render.ts +9 -4
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +2 -1
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +24 -7
- package/src/plugins/builtin/portfolio-list/summary/totals.ts +40 -11
- package/src/plugins/builtin/portfolio-list/table.tsx +13 -1
- package/src/plugins/builtin/realized-vol/headless.ts +11 -6
- package/src/plugins/builtin/realized-vol/model.ts +14 -6
- package/src/plugins/builtin/realized-vol/pane.tsx +2 -1
- package/src/plugins/builtin/realized-vol/settings.ts +2 -1
- package/src/plugins/builtin/research/analyst-headless.ts +9 -1
- package/src/plugins/builtin/research/analyst-pane.tsx +10 -4
- package/src/plugins/builtin/research/client.ts +25 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +2 -1
- package/src/plugins/builtin/research/event-model.ts +3 -13
- package/src/plugins/builtin/research/event-sources.ts +3 -1
- package/src/plugins/builtin/seasonality/client.ts +66 -17
- package/src/plugins/builtin/seasonality/headless.ts +7 -2
- package/src/plugins/builtin/seasonality/model.ts +12 -3
- package/src/plugins/builtin/seasonality/pane.tsx +4 -2
- package/src/plugins/builtin/shared/use-quote-board.ts +28 -6
- package/src/plugins/builtin/short-interest/headless.ts +2 -0
- package/src/plugins/builtin/short-interest/publications-headless.ts +2 -0
- package/src/plugins/builtin/short-interest/watch-headless.ts +1 -0
- package/src/plugins/builtin/yield-curve/headless.ts +5 -1
- package/src/plugins/builtin/yield-curve/index.tsx +5 -0
- package/src/portfolio/column-values.ts +47 -14
- package/src/portfolio/return-metrics.ts +4 -2
- package/src/renderers/dom/desktop/controls.tsx +1 -1
- package/src/renderers/dom/host/image-surface.tsx +19 -9
- package/src/renderers/dom/host/input.tsx +4 -0
- package/src/renderers/dom/styles.css +7 -4
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +23 -1
- package/src/renderers/opentui/box-width.ts +30 -0
- package/src/sources/gloomberb-cloud/normalizers.ts +2 -0
- package/src/sources/provider-errors.ts +12 -0
- package/src/sources/provider-router/index.ts +12 -4
- package/src/state/pane-session.ts +145 -0
- package/src/tickers/search/home-listing.ts +44 -1
- package/src/tickers/search/index.ts +5 -2
- package/src/tickers/search/ranking.ts +7 -7
- package/src/tickers/us-listing.ts +11 -5
- package/src/time-series/base-series.ts +7 -1
- package/src/time-series/fundamentals/current-valuation.ts +8 -0
- package/src/time-series/fundamentals/series.ts +6 -0
- package/src/time-series/resolve.ts +1 -0
- package/src/types/financials.ts +36 -3
- package/src/types/headless.ts +15 -0
- package/src/ui/host.tsx +2 -0
- package/src/utils/exchanges.ts +13 -8
- package/src/utils/fundamentals.ts +49 -8
- package/src/utils/price-earnings.ts +17 -10
- package/src/utils/price-history-integrity.ts +15 -0
- package/src/utils/reason-codes.ts +79 -0
- package/src/utils/share-multiples.cases.json +889 -0
- package/src/utils/share-multiples.ts +254 -0
- package/src/utils/untrusted-text.ts +11 -0
|
@@ -11,7 +11,13 @@ import { futuresChangeBasis, futuresQuoteMonth, futuresSettleText, isFuturesInst
|
|
|
11
11
|
import { quoteTradingDay } from "../quotes/day-range";
|
|
12
12
|
import { splitRatioText } from "../quotes/session-split";
|
|
13
13
|
import { hasPublishedSessionCalendar, isVenueTradingDay, latestRegularSessionOpen, previousPublishedSession, sessionCalendarTimeZone } from "./freshness";
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
EXTENDED_SESSION_MARKS,
|
|
16
|
+
getActiveQuoteDisplay,
|
|
17
|
+
getRegularSessionDisplay,
|
|
18
|
+
regularSessionDisplayDate,
|
|
19
|
+
type ExtendedSession,
|
|
20
|
+
} from "./status";
|
|
15
21
|
|
|
16
22
|
const DAY_MS = 86_400_000;
|
|
17
23
|
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -406,6 +412,34 @@ export function combinedChangeBasisLabel(bases: Iterable<QuoteChangeBasis | null
|
|
|
406
412
|
return labels.size === 1 ? [...labels][0]! : MIXED_CHANGE_BASIS_LABEL;
|
|
407
413
|
}
|
|
408
414
|
|
|
415
|
+
/** An extended session as a day's move names its print in words, where there is room: "after hours vs Tue 10 Nov close". */
|
|
416
|
+
const EXTENDED_PRINT_WORDS: Record<ExtendedSession, string> = { PRE: "pre-market", POST: "after hours", OVERNIGHT: "overnight" };
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* The basis of a day's move summed over the prices a book is valued at, when
|
|
420
|
+
* some are pre-market, after-hours or overnight prints (its latest print): the
|
|
421
|
+
* session of those prints, then the close the moves are from, so the line says
|
|
422
|
+
* which print it compares with which close. `marks` gives the session as a row
|
|
423
|
+
* marks its price ("AH vs Tue 10 Nov close"), otherwise in words ("after hours
|
|
424
|
+
* vs Tue 10 Nov close"); prints from several sessions read EXT or "extended
|
|
425
|
+
* hours". Without an extended print, the close alone, as
|
|
426
|
+
* combinedChangeBasisLabel gives it; null without a basis.
|
|
427
|
+
*/
|
|
428
|
+
export function dayMoveBasisLabel(
|
|
429
|
+
bases: Iterable<QuoteChangeBasis | null | undefined>,
|
|
430
|
+
prints: Iterable<ExtendedSession | null | undefined>,
|
|
431
|
+
{ marks = false, now = Date.now() }: { marks?: boolean; now?: number } = {},
|
|
432
|
+
): string | null {
|
|
433
|
+
const basis = combinedChangeBasisLabel(bases, now);
|
|
434
|
+
const sessions = new Set<ExtendedSession>();
|
|
435
|
+
for (const print of prints) if (print) sessions.add(print);
|
|
436
|
+
if (!basis || sessions.size === 0) return basis;
|
|
437
|
+
const [session] = sessions;
|
|
438
|
+
const print = sessions.size > 1 ? (marks ? "EXT" : "extended hours")
|
|
439
|
+
: marks ? EXTENDED_SESSION_MARKS[session!] : EXTENDED_PRINT_WORDS[session!];
|
|
440
|
+
return `${print} ${basis}`;
|
|
441
|
+
}
|
|
442
|
+
|
|
409
443
|
/**
|
|
410
444
|
* The basis as `--json` gives it beside a move: the kind, the dated session
|
|
411
445
|
* (`date`), the venue's closures in between and the label and note a change
|
|
@@ -2,6 +2,8 @@ import { canonicalExchange } from "../../utils/exchanges";
|
|
|
2
2
|
import { futuresListingVenue } from "../../utils/futures-generic";
|
|
3
3
|
import { regularSessionCloseUtcMinute } from "./freshness";
|
|
4
4
|
import { PERPETUAL_EXCHANGES } from "../../tickers/perpetual-listing";
|
|
5
|
+
import { futuresContractByCode } from "../futures-board";
|
|
6
|
+
import { zonedWallClockToUtcMs } from "../../utils/zoned-date-time";
|
|
5
7
|
|
|
6
8
|
interface SessionLeg {
|
|
7
9
|
symbol: string;
|
|
@@ -23,9 +25,37 @@ function offsetText(minutes: number): string {
|
|
|
23
25
|
return [hours ? `${hours} h` : "", rest ? `${rest} min` : ""].filter(Boolean).join(" ");
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
/** Metals settle at their own times, New York minutes: gold 13:30, silver 13:25, platinum 13:05, copper and palladium 13:00. */
|
|
29
|
+
const METAL_SETTLEMENTS: Readonly<Record<string, number>> = {
|
|
30
|
+
GC: 13 * 60 + 30, MGC: 13 * 60 + 30, SI: 13 * 60 + 25, SIL: 13 * 60 + 25, PL: 13 * 60 + 5, HG: 13 * 60, PA: 13 * 60,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* When a future's daily settlement is taken, in New York minutes: the time
|
|
35
|
+
* its daily bar closes on, whatever the bar is stamped. From CME Group's and
|
|
36
|
+
* Cboe's settlement procedures: energy 14:30 (NYMEX), grains 14:15 (13:15
|
|
37
|
+
* Chicago), livestock 14:05, Treasuries and currencies 15:00, equity index
|
|
38
|
+
* and VIX futures 16:00. Null for a root whose time is not listed here
|
|
39
|
+
* (Dutch TTF, the ICE softs, lumber, aluminum), whose bar is read as stamped.
|
|
40
|
+
*/
|
|
41
|
+
function futuresSettlementMinute(root: string | null): number | null {
|
|
42
|
+
if (!root) return null;
|
|
43
|
+
if (METAL_SETTLEMENTS[root] !== undefined) return METAL_SETTLEMENTS[root]!;
|
|
44
|
+
const contract = futuresContractByCode(root);
|
|
45
|
+
switch (contract?.sector) {
|
|
46
|
+
case "energy": return contract.code === "TTF" ? null : 14 * 60 + 30;
|
|
47
|
+
case "agriculture": return contract.venue === "CBT" ? 14 * 60 + 15 : null;
|
|
48
|
+
case "livestock": return 14 * 60 + 5;
|
|
49
|
+
case "rates": case "currencies": return 15 * 60;
|
|
50
|
+
case "equity-index": case "equity-sectors": case "volatility": return 16 * 60;
|
|
51
|
+
default: return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
26
55
|
/**
|
|
27
56
|
* Where a daily bar of the listing falls on its date. A venue with a listed
|
|
28
|
-
* regular close closes at that UTC time
|
|
57
|
+
* regular close closes at that UTC time, and a future at its settlement.
|
|
58
|
+
* Crypto, FX and a future whose settlement time is not listed carry a bar
|
|
29
59
|
* dated 00:00 UTC, which closes when the next UTC day starts. A venue with
|
|
30
60
|
* neither is unknown.
|
|
31
61
|
*/
|
|
@@ -34,9 +64,16 @@ function dailyBarClose(leg: SessionLeg, time: number): { minute: number; text: s
|
|
|
34
64
|
const minute = regularSessionCloseUtcMinute(leg.exchange, time);
|
|
35
65
|
if (minute !== null) return { minute, text: `${label} closes ${clock(minute)} UTC` };
|
|
36
66
|
const exchange = canonicalExchange(leg.exchange);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
67
|
+
if (!exchange) return null;
|
|
68
|
+
const future = futuresListingVenue(leg.symbol, exchange);
|
|
69
|
+
const settles = future ? futuresSettlementMinute(future.root) : null;
|
|
70
|
+
if (settles != null) {
|
|
71
|
+
const day = new Date(time).toISOString().slice(0, 10).split("-").map(Number);
|
|
72
|
+
const at = zonedWallClockToUtcMs("America/New_York", day[0]!, day[1]!, day[2]!, Math.floor(settles / 60), settles % 60, 0);
|
|
73
|
+
const utc = Math.floor(at / 60_000) % MINUTES_PER_DAY;
|
|
74
|
+
return { minute: utc, text: `${label} settles ${clock(utc)} UTC` };
|
|
75
|
+
}
|
|
76
|
+
return future || ALWAYS_OPEN_EXCHANGES.has(exchange) ? { minute: MINUTES_PER_DAY, text: `${label} bar is ${clock(0)} UTC` } : null;
|
|
40
77
|
}
|
|
41
78
|
|
|
42
79
|
/**
|
|
@@ -331,6 +331,43 @@ export function getActiveQuoteDisplay(quote: Quote | null | undefined): ActiveQu
|
|
|
331
331
|
return { price: quote.price, change: quote.change, changePercent: quote.changePercent };
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
+
/** A price and its move, with the extended session it is a print of when it is not the regular session's. */
|
|
335
|
+
export interface SessionPriceDisplay extends ActiveQuoteDisplay {
|
|
336
|
+
/** Set when the price is a pre-market, after-hours or overnight print. */
|
|
337
|
+
session?: ExtendedSession;
|
|
338
|
+
/** That print is the midpoint of the session's bid and ask, nothing having traded in it. */
|
|
339
|
+
mark?: true;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* The latest print (getActiveQuoteDisplay), naming its session when it is a
|
|
344
|
+
* pre-market, after-hours or overnight trade rather than the regular
|
|
345
|
+
* session's price or close: the extended print `quote` shows beside Last
|
|
346
|
+
* (getExtendedSessionDisplay) at the same price. A quote that says nothing
|
|
347
|
+
* has traded in the session yet (extendedSessionPrint false) carries the
|
|
348
|
+
* close, which names none. Whatever is priced at the latest print (a
|
|
349
|
+
* position's value and day, an alert's current price) says which session the
|
|
350
|
+
* price is from with this.
|
|
351
|
+
*/
|
|
352
|
+
export function getLatestPrintDisplay(quote: Quote | null | undefined): SessionPriceDisplay | null {
|
|
353
|
+
const latest = getActiveQuoteDisplay(quote);
|
|
354
|
+
if (!latest || quote?.extendedSessionPrint === false) return latest;
|
|
355
|
+
const extended = getExtendedSessionDisplay(quote);
|
|
356
|
+
if (!extended || extended.price !== latest.price) return latest;
|
|
357
|
+
return { ...latest, session: extended.session, ...(extended.mark ? { mark: true as const } : {}) };
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* The extended session `price` is a print of: the quote's latest print's
|
|
362
|
+
* (getLatestPrintDisplay) when that is the price and a pre-market,
|
|
363
|
+
* after-hours or overnight trade. Null for a regular session's price or close,
|
|
364
|
+
* and for any other price (an option's mark, a future's settlement).
|
|
365
|
+
*/
|
|
366
|
+
export function extendedPrintSession(quote: Quote | null | undefined, price: number | null | undefined): ExtendedSession | null {
|
|
367
|
+
const latest = getLatestPrintDisplay(quote);
|
|
368
|
+
return latest?.session && price != null && latest.price === price ? latest.session : null;
|
|
369
|
+
}
|
|
370
|
+
|
|
334
371
|
function isPositive(value: number | undefined): value is number {
|
|
335
372
|
return isFiniteNumber(value) && value > 0;
|
|
336
373
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PricePoint, Quote } from "../types/financials";
|
|
2
|
-
import { pricePointIntegrity } from "../utils/price-history-integrity";
|
|
2
|
+
import { pricePointCloseCopied, pricePointIntegrity } from "../utils/price-history-integrity";
|
|
3
3
|
import { calendarMonthsBefore } from "../utils/calendar-date";
|
|
4
4
|
import { barSessionDay, isReturnPeriod, periodBaseDay, periodBaseIndex } from "./market/period-return";
|
|
5
5
|
|
|
@@ -56,6 +56,9 @@ function normalizePriceReturnHistory(points: readonly PricePoint[]): readonly Pr
|
|
|
56
56
|
for (const point of points) {
|
|
57
57
|
const date = coercePointDate(point.date as Date | string | number);
|
|
58
58
|
if (!date || (!Number.isFinite(point.close) && !pricePointIntegrity(point))) continue;
|
|
59
|
+
// A pair's close its source copied from the open, which nothing rebuilt, is no day's close: a horizon's base or end
|
|
60
|
+
// falls on the close before it, as across a holiday.
|
|
61
|
+
if (pricePointCloseCopied(point)) continue;
|
|
59
62
|
byTimestamp.set(date.getTime(), { ...point, date });
|
|
60
63
|
}
|
|
61
64
|
const history = [...byTimestamp.entries()]
|
|
@@ -130,10 +130,14 @@ function datedSheets(financials: Pick<TickerFinancials, "annualStatements" | "qu
|
|
|
130
130
|
.sort((a, b) => b.date.localeCompare(a.date));
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Total equity including minority interest less common equity, else what the company's filing tags for the date (a
|
|
135
|
+
* quarter read from the filing alone); null where the sheet gives neither.
|
|
136
|
+
*/
|
|
134
137
|
function minorityOnSheet(row: FinancialStatement | undefined): number | null {
|
|
135
138
|
const gross = row?.totalEquityGrossMinorityInterest, common = row?.commonStockEquity;
|
|
136
|
-
|
|
139
|
+
if (finite(gross) && finite(common)) return Math.max(0, gross - common);
|
|
140
|
+
return finite(row?.minorityAndPreferredEquity) ? Math.max(0, row.minorityAndPreferredEquity) : null;
|
|
137
141
|
}
|
|
138
142
|
|
|
139
143
|
/** The bridge Gloom Cloud computed beside a withdrawal, its minority interest and cash read as its balance sheet holds them. */
|
|
@@ -141,8 +145,8 @@ function checkBridge(check: EnterpriseValueCheck, financials: EnterpriseValueInp
|
|
|
141
145
|
const sheetDate = check.balanceSheetDate ?? "";
|
|
142
146
|
const row = [...financials.quarterlyStatements ?? [], ...financials.annualStatements ?? []]
|
|
143
147
|
.find((statement) => statement.date.slice(0, 10) === sheetDate);
|
|
144
|
-
// Gloom Cloud serves the line only where
|
|
145
|
-
// one that is not on file, is named: never counted as zero.
|
|
148
|
+
// Gloom Cloud serves the line only where the equity lines or the filing give a positive figure. A sheet on file
|
|
149
|
+
// without them, or one that is not on file, is named: never counted as zero.
|
|
146
150
|
const minority = finite(check.minorityAndPreferred) ? check.minorityAndPreferred : row ? minorityOnSheet(row) : null;
|
|
147
151
|
return {
|
|
148
152
|
sheetDate, marketCap: check.marketCap ?? 0, totalDebt: check.totalDebt ?? 0, leases: check.leases ?? 0, cash: check.cash ?? 0,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { AnalystResearchData, CorporateActionsData, Fundamentals, Quote } from "../../types/financials";
|
|
1
|
+
import type { AnalystResearchData, CorporateActionsData, Fundamentals, Quote, TickerFinancials } from "../../types/financials";
|
|
2
2
|
import { atRegularSessionPrice, regularSessionValuationPrice } from "./regular-session-valuation";
|
|
3
3
|
import { hasLikelyQuoteUnitMismatch, resolveCurrencyUnit } from "../../utils/currency-units";
|
|
4
4
|
import { cashInMajorUnits } from "../../utils/dividend-cash";
|
|
5
5
|
import { cashDistribution, dividendReferencePrice, trailingDividendYield, type CashDistribution } from "../../utils/trailing-dividend";
|
|
6
6
|
import { priceEarningsEps } from "../../utils/fundamentals";
|
|
7
7
|
import { selectMarketCapitalization, type MarketCapitalization } from "../../utils/market-capitalization";
|
|
8
|
-
import { priceEarningsOnEarnings, type PriceEarnings } from "../../utils/price-earnings";
|
|
8
|
+
import { NOT_MEANINGFUL, priceEarningsOnEarnings, type PriceEarnings } from "../../utils/price-earnings";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Price-derived statistics repriced at the quote's regular session price
|
|
@@ -69,16 +69,39 @@ function repriceMultiple(
|
|
|
69
69
|
* currency than the price is repriced at the rate the served P/E converted it at.
|
|
70
70
|
*/
|
|
71
71
|
export function liveTrailingPE(quote: Quote | null | undefined, fundamentals: Fundamentals | undefined): PriceEarnings | undefined {
|
|
72
|
+
// Withdrawn as no multiple of the share (utils/share-multiples).
|
|
73
|
+
if (fundamentals?.notMeaningful?.trailingPE) return NOT_MEANINGFUL;
|
|
72
74
|
const stored = pricedFundamentals(quote, fundamentals)?.trailingPE;
|
|
73
75
|
return priceEarningsOnEarnings(repriceMultiple(stored, priceEarningsEps(fundamentals), quote, fundamentals), fundamentals?.eps);
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
/** Forward P/E over the regular session price; not meaningful when the forward EPS behind it is zero or a loss. */
|
|
77
79
|
export function liveForwardPE(quote: Quote | null | undefined, fundamentals: Fundamentals | undefined): PriceEarnings | undefined {
|
|
80
|
+
if (fundamentals?.notMeaningful?.forwardPE) return NOT_MEANINGFUL;
|
|
78
81
|
const stored = pricedFundamentals(quote, fundamentals)?.forwardPE;
|
|
79
82
|
return priceEarningsOnEarnings(repriceMultiple(stored, fundamentals?.forwardEps, quote, fundamentals), fundamentals?.forwardEps);
|
|
80
83
|
}
|
|
81
84
|
|
|
85
|
+
/**
|
|
86
|
+
* `financials` at the regular session price (atRegularSessionPrice) with the trailing and forward P/E the Overview,
|
|
87
|
+
* the portfolio and EQS show (liveTrailingPE, liveForwardPE): one the source measured at an older print is the price
|
|
88
|
+
* over its EPS. A P/E with no number (N/M, or none) stays as the block has it, for its reason.
|
|
89
|
+
*/
|
|
90
|
+
export function atLivePriceEarnings<T extends Pick<TickerFinancials, "quote" | "fundamentals">>(financials: T): T {
|
|
91
|
+
const priced = atRegularSessionPrice(financials);
|
|
92
|
+
if (!priced.fundamentals) return priced;
|
|
93
|
+
const trailing = liveTrailingPE(financials.quote, financials.fundamentals);
|
|
94
|
+
const forward = liveForwardPE(financials.quote, financials.fundamentals);
|
|
95
|
+
return {
|
|
96
|
+
...priced,
|
|
97
|
+
fundamentals: {
|
|
98
|
+
...priced.fundamentals,
|
|
99
|
+
...typeof trailing === "number" ? { trailingPE: trailing } : {},
|
|
100
|
+
...typeof forward === "number" ? { forwardPE: forward } : {},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
82
105
|
/** Forward dividend yield over the regular session price, as a ratio like the stored yield. */
|
|
83
106
|
export function liveDividendYield(quote: Quote | null | undefined, fundamentals: Fundamentals | undefined): number | undefined {
|
|
84
107
|
const stored = pricedFundamentals(quote, fundamentals)?.dividendYield;
|
|
@@ -2,6 +2,7 @@ import type { PricePoint } from "../types/financials";
|
|
|
2
2
|
import { barsPerYear, type BarsPerYearInstrument } from "./bars-per-year";
|
|
3
3
|
import {
|
|
4
4
|
mergePriceHistoryIntegrity,
|
|
5
|
+
pricePointCloseCopied,
|
|
5
6
|
pricePointIntegrity,
|
|
6
7
|
pricePointOpenWithheld,
|
|
7
8
|
pricePointWicks,
|
|
@@ -113,6 +114,8 @@ function observations(points: readonly PricePoint[]): Observation[] | null {
|
|
|
113
114
|
for (const point of points) {
|
|
114
115
|
const time = new Date(point.date).getTime();
|
|
115
116
|
if (!Number.isFinite(time)) return null;
|
|
117
|
+
// A pair's close its source copied from the open, which nothing rebuilt, is no day's close: the bar is left out.
|
|
118
|
+
if (pricePointCloseCopied(point)) continue;
|
|
116
119
|
dates.set(time, point);
|
|
117
120
|
}
|
|
118
121
|
return [...dates.entries()].sort(([a], [b]) => a - b).map(([time, point]) => ({
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The US bond market's full holidays, as SIFMA recommends them: the federal
|
|
3
|
+
* holidays (Columbus Day and Veterans Day among them, when stocks trade) and
|
|
4
|
+
* Good Friday, except a Good Friday the March jobs report comes out on (the
|
|
5
|
+
* first Friday of April: 2010-04-02, 2012-04-06, 2015-04-03, 2021-04-02,
|
|
6
|
+
* 2023-04-07, 2026-04-03), when SIFMA recommends an early close instead and
|
|
7
|
+
* the Treasury curve and FRED's daily rates have the day. A Treasury curve and
|
|
8
|
+
* a FRED rate series have no observation on a full holiday. A holiday on a Sunday closes the Monday after it; one on a Saturday
|
|
9
|
+
* closes the Friday before it, except New Year's Day and Veterans Day, which
|
|
10
|
+
* close nothing then (the market traded Fri 31 Dec 2021 and Fri 10 Nov 2023).
|
|
11
|
+
* Juneteenth is a holiday from 2022. Early closes are trading days.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const DAY_MS = 86_400_000;
|
|
15
|
+
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
16
|
+
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
17
|
+
|
|
18
|
+
const isoDay = (time: number) => new Date(time).toISOString().slice(0, 10);
|
|
19
|
+
|
|
20
|
+
/** The `nth` `weekday` (0 Sunday) of a month (0 January), or its last when `nth` is -1. */
|
|
21
|
+
function nthWeekday(year: number, month: number, weekday: number, nth: number): number {
|
|
22
|
+
if (nth < 0) {
|
|
23
|
+
const last = Date.UTC(year, month + 1, 0);
|
|
24
|
+
return last - ((new Date(last).getUTCDay() - weekday + 7) % 7) * DAY_MS;
|
|
25
|
+
}
|
|
26
|
+
const first = Date.UTC(year, month, 1);
|
|
27
|
+
return first + (((weekday - new Date(first).getUTCDay() + 7) % 7) + (nth - 1) * 7) * DAY_MS;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Good Friday: Easter Sunday (the Gregorian computus) less two days. */
|
|
31
|
+
function goodFriday(year: number): number {
|
|
32
|
+
const a = year % 19, b = Math.floor(year / 100), c = year % 100;
|
|
33
|
+
const d = Math.floor(b / 4), e = b % 4, f = Math.floor((b + 8) / 25), g = Math.floor((b - f + 1) / 3);
|
|
34
|
+
const h = (19 * a + b - d - g + 15) % 30, i = Math.floor(c / 4), k = c % 4;
|
|
35
|
+
const l = (32 + 2 * e + 2 * i - h - k) % 7, m = Math.floor((a + 11 * h + 22 * l) / 451);
|
|
36
|
+
const month = Math.floor((h + l - 7 * m + 114) / 31);
|
|
37
|
+
const day = ((h + l - 7 * m + 114) % 31) + 1;
|
|
38
|
+
return Date.UTC(year, month - 1, day) - 2 * DAY_MS;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const holidaysByYear = new Map<number, ReadonlyMap<string, string>>();
|
|
42
|
+
|
|
43
|
+
/** Each closed day of a year with the holiday it is for. */
|
|
44
|
+
function holidays(year: number): ReadonlyMap<string, string> {
|
|
45
|
+
const kept = holidaysByYear.get(year);
|
|
46
|
+
if (kept) return kept;
|
|
47
|
+
const days = new Map<string, string>();
|
|
48
|
+
// A fixed date on a Sunday closes the Monday; on a Saturday the Friday, where the market moves it.
|
|
49
|
+
const fixed = (month: number, day: number, name: string, saturdayCloses = true) => {
|
|
50
|
+
const date = Date.UTC(year, month, day);
|
|
51
|
+
const weekday = new Date(date).getUTCDay();
|
|
52
|
+
if (weekday === 6 && !saturdayCloses) return;
|
|
53
|
+
days.set(isoDay(date + (weekday === 0 ? DAY_MS : weekday === 6 ? -DAY_MS : 0)), name);
|
|
54
|
+
};
|
|
55
|
+
fixed(0, 1, "New Year's Day", false);
|
|
56
|
+
days.set(isoDay(nthWeekday(year, 0, 1, 3)), "Martin Luther King Jr. Day");
|
|
57
|
+
days.set(isoDay(nthWeekday(year, 1, 1, 3)), "Washington's Birthday");
|
|
58
|
+
// A Good Friday in April's first week is the March jobs report's day: an early close, not a holiday.
|
|
59
|
+
const friday = goodFriday(year);
|
|
60
|
+
if (!(new Date(friday).getUTCMonth() === 3 && new Date(friday).getUTCDate() <= 7)) days.set(isoDay(friday), "Good Friday");
|
|
61
|
+
days.set(isoDay(nthWeekday(year, 4, 1, -1)), "Memorial Day");
|
|
62
|
+
if (year >= 2022) fixed(5, 19, "Juneteenth");
|
|
63
|
+
fixed(6, 4, "Independence Day");
|
|
64
|
+
days.set(isoDay(nthWeekday(year, 8, 1, 1)), "Labor Day");
|
|
65
|
+
days.set(isoDay(nthWeekday(year, 9, 1, 2)), "Columbus Day");
|
|
66
|
+
fixed(10, 11, "Veterans Day", false);
|
|
67
|
+
days.set(isoDay(nthWeekday(year, 10, 4, 4)), "Thanksgiving Day");
|
|
68
|
+
fixed(11, 25, "Christmas Day");
|
|
69
|
+
holidaysByYear.set(year, days);
|
|
70
|
+
return days;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The holiday a day (`YYYY-MM-DD`) closes the US bond market for, or null for a trading day or a weekend. */
|
|
74
|
+
export function usBondMarketHoliday(date: string): string | null {
|
|
75
|
+
const year = Number(date.slice(0, 4));
|
|
76
|
+
return Number.isInteger(year) ? holidays(year).get(date.slice(0, 10)) ?? null : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** `Wed 11 Nov`: a day as the closure note names it. */
|
|
80
|
+
function dayText(date: string): string {
|
|
81
|
+
const day = new Date(`${date.slice(0, 10)}T00:00:00Z`);
|
|
82
|
+
return `${WEEKDAYS[day.getUTCDay()]} ${day.getUTCDate()} ${MONTHS[day.getUTCMonth()]}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Why a day asked for shows an earlier one, for a series observed on US bond
|
|
87
|
+
* market days (the Treasury curve, FRED's daily rates): "Wed 11 Nov: US bond
|
|
88
|
+
* market closed (Veterans Day); showing Tue 10 Nov", or "Sat 7 Nov: weekend;
|
|
89
|
+
* showing Fri 6 Nov" when every day between them is a weekend or a holiday.
|
|
90
|
+
* Null when the day shown is the day asked for, or when a trading day between
|
|
91
|
+
* them has no observation either, which a closure does not explain.
|
|
92
|
+
*/
|
|
93
|
+
export function usBondMarketClosedNote(asked: string, shown: string): string | null {
|
|
94
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(asked) || !/^\d{4}-\d{2}-\d{2}$/.test(shown) || shown >= asked) return null;
|
|
95
|
+
const from = Date.parse(`${shown}T00:00:00Z`) + DAY_MS;
|
|
96
|
+
for (let time = from; time <= Date.parse(`${asked}T00:00:00Z`); time += DAY_MS) {
|
|
97
|
+
const day = isoDay(time);
|
|
98
|
+
if (new Date(time).getUTCDay() % 6 !== 0 && !usBondMarketHoliday(day)) return null;
|
|
99
|
+
}
|
|
100
|
+
const holiday = usBondMarketHoliday(asked);
|
|
101
|
+
const why = holiday ? `US bond market closed (${holiday})` : new Date(`${asked}T00:00:00Z`).getUTCDay() % 6 === 0 ? "weekend"
|
|
102
|
+
: "US bond market closed";
|
|
103
|
+
return `${dayText(asked)}: ${why}; showing ${dayText(shown)}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Whether a FRED series is observed on US bond market days: the Treasury's
|
|
108
|
+
* constant-maturity, bill and real yields and their spreads, SOFR, and the
|
|
109
|
+
* corporate yields and spreads priced off them. A stock index or an oil price
|
|
110
|
+
* trades on Veterans Day and is no such series.
|
|
111
|
+
*/
|
|
112
|
+
export function followsUsBondMarket(seriesId: string): boolean {
|
|
113
|
+
return /^(?:DGS\d+(?:MO)?|DTB\d+(?:WK)?|DTB\d+YR|DFII\d+|T\d+Y(?:\d+[MY]|FF|IE)|T5YIFR|SOFR\w*|BAML\w+|DAAA|DBAA|AAA10Y|BAA10Y)$/i
|
|
114
|
+
.test(seriesId.trim());
|
|
115
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Ref } from "react";
|
|
2
|
+
import { Button, FieldLabel } from "../../../components";
|
|
3
|
+
import { terminalButtonColumns } from "../../../components/ui/button";
|
|
4
|
+
import type { ReferralInvite } from "../../../api-client";
|
|
5
|
+
import { t, tf } from "../../../i18n";
|
|
6
|
+
import { colors } from "../../../theme/colors";
|
|
7
|
+
import { Box, Text, type BoxRenderable } from "../../../ui";
|
|
8
|
+
import { displayWidth } from "../../../utils/format";
|
|
9
|
+
|
|
10
|
+
/** The link as people read it, without the scheme; Copy gives the whole URL. */
|
|
11
|
+
function inviteLinkText(url: string): string {
|
|
12
|
+
return url.replace(/^https?:\/\//, "");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The Pro tab's Invite row: the account's invite link, selectable, a Copy
|
|
17
|
+
* button beside it (under it when the pane is too narrow for both), and the
|
|
18
|
+
* free months the link has earned so far.
|
|
19
|
+
*/
|
|
20
|
+
export function InviteRow({
|
|
21
|
+
invite,
|
|
22
|
+
active,
|
|
23
|
+
width,
|
|
24
|
+
labelWidth,
|
|
25
|
+
nodeRef,
|
|
26
|
+
onCopy,
|
|
27
|
+
onFocus,
|
|
28
|
+
}: {
|
|
29
|
+
invite: ReferralInvite;
|
|
30
|
+
active: boolean;
|
|
31
|
+
width: number;
|
|
32
|
+
labelWidth: number;
|
|
33
|
+
nodeRef: Ref<BoxRenderable>;
|
|
34
|
+
onCopy: () => void;
|
|
35
|
+
onFocus: () => void;
|
|
36
|
+
}) {
|
|
37
|
+
const link = inviteLinkText(invite.url);
|
|
38
|
+
const copyLabel = t("Copy");
|
|
39
|
+
const besideLink = displayWidth(link) + 1 + terminalButtonColumns({ label: copyLabel }) <= width - labelWidth - 1;
|
|
40
|
+
return (
|
|
41
|
+
<Box ref={nodeRef} flexDirection="row" gap={1} onMouseDown={onFocus}>
|
|
42
|
+
<FieldLabel label={t("Invite")} active={active} width={labelWidth} />
|
|
43
|
+
<Box flexDirection="column" flexShrink={1}>
|
|
44
|
+
<Box flexDirection={besideLink ? "row" : "column"} gap={besideLink ? 1 : 0} alignItems={besideLink ? "center" : "flex-start"}>
|
|
45
|
+
<Text selectable fg={colors.text}>{link}</Text>
|
|
46
|
+
<Button label={copyLabel} active={active} onPress={onCopy} />
|
|
47
|
+
</Box>
|
|
48
|
+
<Text fg={colors.textDim}>
|
|
49
|
+
{tf("Free months earned: {earned} of {cap}", { earned: invite.earned, cap: invite.cap })}
|
|
50
|
+
</Text>
|
|
51
|
+
</Box>
|
|
52
|
+
</Box>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -35,6 +35,7 @@ export function useAccountManagementKeyboard({
|
|
|
35
35
|
setDraftValue,
|
|
36
36
|
deleteAccount,
|
|
37
37
|
endTrial,
|
|
38
|
+
copyInvite,
|
|
38
39
|
turnOffEmailAlerts,
|
|
39
40
|
}: {
|
|
40
41
|
activeField: AccountFieldKey;
|
|
@@ -54,6 +55,7 @@ export function useAccountManagementKeyboard({
|
|
|
54
55
|
setDraftValue: <K extends keyof AccountDraft>(key: K, value: AccountDraft[K]) => void;
|
|
55
56
|
deleteAccount: () => Promise<void>;
|
|
56
57
|
endTrial: () => Promise<void>;
|
|
58
|
+
copyInvite: () => void;
|
|
57
59
|
turnOffEmailAlerts: () => Promise<void>;
|
|
58
60
|
}): FieldRing<AccountFieldKey> {
|
|
59
61
|
const actions: Partial<Record<AccountFieldKey, () => void>> = {
|
|
@@ -62,6 +64,7 @@ export function useAccountManagementKeyboard({
|
|
|
62
64
|
passwordAction: openPasswordDialog,
|
|
63
65
|
upgradeAction: openUpgrade,
|
|
64
66
|
cancelTrialAction: () => { void endTrial(); },
|
|
67
|
+
inviteCopyAction: copyInvite,
|
|
65
68
|
assistantsAction: openAssistants,
|
|
66
69
|
deleteAccountAction: () => { void deleteAccount(); },
|
|
67
70
|
emailAlertsOffAction: () => { void turnOffEmailAlerts(); },
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
ScrollBox,
|
|
27
27
|
Textarea,
|
|
28
28
|
TextAttributes,
|
|
29
|
+
useRendererHost,
|
|
29
30
|
useUiCapabilities,
|
|
30
31
|
type ScrollBoxRenderable,
|
|
31
32
|
type TextareaRenderable,
|
|
@@ -33,7 +34,7 @@ import {
|
|
|
33
34
|
import { useDialog, type AlertContext } from "../../../ui/dialog";
|
|
34
35
|
import type { SelectControl } from "../../../components/ui/select-button";
|
|
35
36
|
import { FRAMED_TEXTAREA_DESKTOP_STYLE, fieldFrameStyle } from "../../../components/ui/fields";
|
|
36
|
-
import { apiClient, type AccountProfile, type CloudPricing } from "../../../api-client";
|
|
37
|
+
import { apiClient, type AccountProfile, type CloudPricing, type ReferralInvite } from "../../../api-client";
|
|
37
38
|
import { chatController } from "../chat/controller";
|
|
38
39
|
import { SignInWall } from "../cloud/auth-actions";
|
|
39
40
|
import { loadUpgradeOffer } from "../../../account/upgrade-dialog";
|
|
@@ -72,6 +73,7 @@ import { DeleteAccountPasswordDialog, PasswordChangeDialog } from "./password-di
|
|
|
72
73
|
import { deleteAccountConfirmingSession } from "./delete-account";
|
|
73
74
|
import { endTrialAfterWarning } from "./trial-cancel";
|
|
74
75
|
import { CalendarAccountTab } from "./calendar-tab";
|
|
76
|
+
import { InviteRow } from "./invite-row";
|
|
75
77
|
import { useAccountManagementFooter } from "./footer";
|
|
76
78
|
import { useAccountManagementKeyboard } from "./keyboard";
|
|
77
79
|
import {
|
|
@@ -128,8 +130,8 @@ const ACCOUNT_TAB_FIELD_ORDER: Record<AccountManagementTab, AccountFieldKey[]> =
|
|
|
128
130
|
],
|
|
129
131
|
// Its actions are footer hints; the tab owns its footer.
|
|
130
132
|
calendar: [],
|
|
131
|
-
// Cancel Trial shows only while a trial runs.
|
|
132
|
-
pro: ["upgradeAction", "cancelTrialAction"],
|
|
133
|
+
// Cancel Trial shows only while a trial runs, the invite once it loaded.
|
|
134
|
+
pro: ["upgradeAction", "cancelTrialAction", "inviteCopyAction"],
|
|
133
135
|
// The Teams tab owns its own keyboard handling (a list, not form fields).
|
|
134
136
|
teams: [],
|
|
135
137
|
// Remote assistants allowed to drive this terminal; a list with its own footer.
|
|
@@ -230,6 +232,8 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
230
232
|
const [pricing, setPricing] = useState<CloudPricing | null>(null);
|
|
231
233
|
// Null until the server says; only a confirmed trial is offered.
|
|
232
234
|
const [trialAvailable, setTrialAvailable] = useState<boolean | null>(null);
|
|
235
|
+
// The Pro tab's invite link; null until it loads, and when it cannot.
|
|
236
|
+
const [invite, setInvite] = useState<ReferralInvite | null>(null);
|
|
233
237
|
const [draft, setDraft] = useState<AccountDraft>(() => profileToDraft(null));
|
|
234
238
|
const [activeTab, setActiveTab] = usePluginPaneState<AccountManagementTab>("activeTab", "profile");
|
|
235
239
|
const [activeField, setActiveField] = useState<AccountFieldKey>(
|
|
@@ -268,8 +272,9 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
268
272
|
if (field === "showLocalTime" || field === "showDesks") return chatCardSupported;
|
|
269
273
|
if (field === "desks") return chatCardSupported && draft.showDesks;
|
|
270
274
|
if (field === "cancelTrialAction") return planAccess.isTrialActive;
|
|
275
|
+
if (field === "inviteCopyAction") return invite !== null;
|
|
271
276
|
return true;
|
|
272
|
-
}), [activeTab, chatCardSupported, draft.showDesks, planAccess.isTrialActive]);
|
|
277
|
+
}), [activeTab, chatCardSupported, draft.showDesks, invite, planAccess.isTrialActive]);
|
|
273
278
|
const accountTabs = ACCOUNT_TAB_DEFS.map((tab) => ({ ...tab, label: t(tab.label) }));
|
|
274
279
|
|
|
275
280
|
const planPrice = useMemo(() => formatCloudMonthlyPrice(pricing), [language, pricing]);
|
|
@@ -519,6 +524,24 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
519
524
|
};
|
|
520
525
|
}, [sessionMarker]);
|
|
521
526
|
|
|
527
|
+
// The invite link is read when the Pro tab opens, and again for another
|
|
528
|
+
// account: one account's link must never show under another's.
|
|
529
|
+
const proTabOpen = activeTab === "pro";
|
|
530
|
+
useEffect(() => {
|
|
531
|
+
setInvite(null);
|
|
532
|
+
if (!proTabOpen || !apiClient.isSignedIn()) return;
|
|
533
|
+
let cancelled = false;
|
|
534
|
+
void apiClient.getReferralInvite()
|
|
535
|
+
.then((next) => {
|
|
536
|
+
if (!cancelled) setInvite(next);
|
|
537
|
+
})
|
|
538
|
+
// A server without invites, or a failed read, leaves the row out.
|
|
539
|
+
.catch(logFailure("account-management.pane", "Load invite link failed"));
|
|
540
|
+
return () => {
|
|
541
|
+
cancelled = true;
|
|
542
|
+
};
|
|
543
|
+
}, [proTabOpen, sessionMarker]);
|
|
544
|
+
|
|
522
545
|
useEffect(() => {
|
|
523
546
|
if (!hasSession || !apiClient.isSignedIn()) return;
|
|
524
547
|
if (syncStatus.phase !== "synced" || syncStatus.revision == null) return;
|
|
@@ -757,7 +780,7 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
757
780
|
const result = await endTrialAfterWarning(
|
|
758
781
|
dialog,
|
|
759
782
|
planAccess,
|
|
760
|
-
() => apiClient.endCloudTrial(),
|
|
783
|
+
(feedback) => apiClient.endCloudTrial(feedback),
|
|
761
784
|
() => {
|
|
762
785
|
setBusy("trial");
|
|
763
786
|
setMessage({ tone: "info", text: t("Ending trial...") });
|
|
@@ -784,6 +807,17 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
784
807
|
}
|
|
785
808
|
}, [busy, dialog, planAccess]);
|
|
786
809
|
|
|
810
|
+
const renderer = useRendererHost();
|
|
811
|
+
const copyInvite = useCallback(() => {
|
|
812
|
+
setActiveField("inviteCopyAction");
|
|
813
|
+
if (!invite) return;
|
|
814
|
+
void renderer.copyText(invite.url).then(
|
|
815
|
+
() => setMessage({ tone: "success", text: t("Link copied.") }),
|
|
816
|
+
// A terminal without clipboard access: the link is selectable on the row.
|
|
817
|
+
() => setMessage({ tone: "info", text: t("Copy failed. Select the link instead.") }),
|
|
818
|
+
);
|
|
819
|
+
}, [invite, renderer]);
|
|
820
|
+
|
|
787
821
|
useAccountManagementFooter({
|
|
788
822
|
busy,
|
|
789
823
|
// The Calendar and Agents tabs save nothing and show their own status.
|
|
@@ -799,6 +833,7 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
799
833
|
deleteAccount,
|
|
800
834
|
draftRef,
|
|
801
835
|
endTrial,
|
|
836
|
+
copyInvite,
|
|
802
837
|
fieldOrder,
|
|
803
838
|
// Behind the sign-in wall the fields are not there, and Enter is the wall's.
|
|
804
839
|
focused: focused && activeTab !== "teams" && activeTab !== "calendar" && activeTab !== "agents" && (hasSession || apiClient.isSignedIn()),
|
|
@@ -1053,6 +1088,17 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
1053
1088
|
</Box>
|
|
1054
1089
|
) : null}
|
|
1055
1090
|
</Box>
|
|
1091
|
+
{invite ? (
|
|
1092
|
+
<InviteRow
|
|
1093
|
+
invite={invite}
|
|
1094
|
+
active={activeField === "inviteCopyAction"}
|
|
1095
|
+
width={contentWidth}
|
|
1096
|
+
labelWidth={formLabelWidth}
|
|
1097
|
+
nodeRef={fieldNodeRef("inviteCopyAction")}
|
|
1098
|
+
onCopy={copyInvite}
|
|
1099
|
+
onFocus={() => setActiveField("inviteCopyAction")}
|
|
1100
|
+
/>
|
|
1101
|
+
) : null}
|
|
1056
1102
|
</>
|
|
1057
1103
|
) : null}
|
|
1058
1104
|
|