@gloom-sh/terminal 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
|
@@ -5,7 +5,9 @@ import {
|
|
|
5
5
|
import { canonicalExchange } from "../../../utils/exchanges";
|
|
6
6
|
import { hasValidQuoteObservationTime } from "../../../market-data/quotes/freshness";
|
|
7
7
|
import { quoteMonitorColumns, quoteMonitorRow, QUOTE_MONITOR_BASE_COLUMNS, QUOTE_MONITOR_ROW_KEYS } from "./quote-monitor/rows";
|
|
8
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
HeadlessPaneColumn, HeadlessPaneContext, HeadlessPaneDefinition, HeadlessPaneFreshness, HeadlessPaneOptionValues, HeadlessRowsResult,
|
|
10
|
+
} from "../../../types/headless";
|
|
9
11
|
import type { TimeRange } from "../../../time-series/range";
|
|
10
12
|
import { MISSING_VALUE, formatNumber } from "../../../utils/format";
|
|
11
13
|
import { formatPriceObservation, penceFigure, quoteFormatOptions } from "../../../market-data/market/format";
|
|
@@ -15,8 +17,8 @@ import {
|
|
|
15
17
|
} from "../../../utils/price-history-integrity";
|
|
16
18
|
import { indexBarVolume } from "../../../market-data/market/index-level";
|
|
17
19
|
import {
|
|
18
|
-
buildFinancialTableModel, financialStatementCurrency, financialStatementDateNotice, financialStatementLimitations,
|
|
19
|
-
financialReportHeader, financialStatementPeriods, financialSubTabFields, isPerShareFinancialRow, receiptShareCountLabel,
|
|
20
|
+
buildFinancialTableModel, financialColumnLabel, financialStatementCurrency, financialStatementDateNotice, financialStatementLimitations,
|
|
21
|
+
financialReportHeader, financialStatementPeriods, financialSubTabFields, formatFinancialAmount, isPerShareFinancialRow, receiptShareCountLabel,
|
|
20
22
|
} from "./financials/model";
|
|
21
23
|
import { fiscalYearEndMonth } from "../../../utils/fiscal-period";
|
|
22
24
|
import type { FinancialStatement } from "../../../types/financials";
|
|
@@ -25,7 +27,8 @@ import { paneSchemas } from "./headless-schema";
|
|
|
25
27
|
import { loadPeriodEndHistory } from "./financials/period-end-history";
|
|
26
28
|
import { loadExchangeResultsNotes } from "./financials/exchange-results";
|
|
27
29
|
import { latestBalanceSheetDate, loadOfferingNote } from "./financials/offerings";
|
|
28
|
-
import { reportsShortTermTotal, runwayMethod } from "../../../utils/cash-runway";
|
|
30
|
+
import { formatRunwayMonths, reportsShortTermTotal, runwayMethod } from "../../../utils/cash-runway";
|
|
31
|
+
import { formatPerShareNumber } from "../../../utils/reported-money";
|
|
29
32
|
import { logFailure } from "../../../utils/log-failure";
|
|
30
33
|
import {
|
|
31
34
|
RATIO_GAP_TEXT,
|
|
@@ -108,12 +111,189 @@ function pastWindowFreshness(window: PriceWindow, size: HistoryBarSize, observed
|
|
|
108
111
|
export const financialStatementsHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
109
112
|
...paneSchemas["financial-analysis-pane"],
|
|
110
113
|
shape: "rows",
|
|
111
|
-
// Dated by the latest reported period; earlier periods are the statement's history.
|
|
112
|
-
freshness: { ...REPORTED_DATA, basis: "financial statements", observedKey: "
|
|
113
|
-
description: "Annual or quarterly financial statement rows for one ticker: the income statement, balance sheet, cash flow, or a ratio table.",
|
|
114
|
-
describe: ({ symbols, options }) => `Financial Statements | ${symbols
|
|
114
|
+
// Dated by the latest reported period (each row's `periodEnd`); earlier periods are the statement's history.
|
|
115
|
+
freshness: { ...REPORTED_DATA, basis: "financial statements", observedKey: "periodEnd", oldest: null, retrievedToo: true },
|
|
116
|
+
description: "Annual or quarterly financial statement rows for one ticker, or several in one long table: the income statement, balance sheet, cash flow, or a ratio table.",
|
|
117
|
+
describe: ({ symbols, options }) => `Financial Statements | ${symbols.join(", ")} | ${options.period} | ${options.statement}`,
|
|
115
118
|
async load({ symbols, options }, ctx) {
|
|
116
|
-
|
|
119
|
+
if (financialReportLayout(symbols, options) === "long") return loadLongFinancialReport(symbols, options, ctx);
|
|
120
|
+
return loadFinancialReport(symbols[0]!, options, ctx);
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Wide, one column per period, for one ticker; long, a row per ticker, period and metric, for several or when
|
|
126
|
+
* `--layout long` asks for it. Several tickers have no shared columns, so they are never laid out wide.
|
|
127
|
+
*/
|
|
128
|
+
function financialReportLayout(symbols: readonly string[], options: HeadlessPaneOptionValues): "wide" | "long" {
|
|
129
|
+
if (options.layout === "wide" && symbols.length > 1) {
|
|
130
|
+
throw new Error(`--layout wide is one ticker's periods as columns; ${symbols.length} tickers have no shared columns. Leave --layout out for one long table, or run FA once per ticker.`);
|
|
131
|
+
}
|
|
132
|
+
return options.layout === "long" || symbols.length > 1 ? "long" : "wide";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** How a figure of an FA row reads: the kind of number it is, which names its unit and draws it. */
|
|
136
|
+
type FigureFormat = "money" | "count" | "perShare" | "percent" | "multiple" | "days" | "months";
|
|
137
|
+
|
|
138
|
+
const DIVISOR_WORDS: Record<number, string> = { 1e3: "k", 1e6: "mn", 1e9: "bn", 1e12: "tn" };
|
|
139
|
+
|
|
140
|
+
/** The unit a figure of this kind is in, as exports name it in `currency_or_unit`: `USD bn`, `%`, `USD per share`, `bn shares`. */
|
|
141
|
+
function figureUnit(format: FigureFormat, currency: string | null, divisor: number, shares = "shares"): string {
|
|
142
|
+
const scale = DIVISOR_WORDS[divisor] ?? "";
|
|
143
|
+
switch (format) {
|
|
144
|
+
case "money": return [currency, scale].filter(Boolean).join(" ");
|
|
145
|
+
case "count": return [scale, shares].filter(Boolean).join(" ");
|
|
146
|
+
case "perShare": return currency ? `${currency} per ${shares === "shares" ? "share" : "ADR"}` : "per share";
|
|
147
|
+
case "percent": return "%";
|
|
148
|
+
case "multiple": return "x";
|
|
149
|
+
case "days": return "days";
|
|
150
|
+
case "months": return "months";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** A figure as FA's table draws it, from the row's kind and unit: what the text prints and an export reads the scale of. */
|
|
155
|
+
function drawFigure(format: FigureFormat, value: number, divisor: number, ratio = false): string {
|
|
156
|
+
if (format === "percent") return ratio ? formatRatioValue("percent", value) : `${formatNumber(value * 100, 1)}%`;
|
|
157
|
+
if (format === "perShare") return formatPerShareNumber(value);
|
|
158
|
+
if (format === "money" || format === "count") return ratio ? formatRatioInput("money", value, divisor) : formatFinancialAmount(value, divisor);
|
|
159
|
+
return format === "days" && !ratio ? formatNumber(value, 1) : formatRatioValue(format, value);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** A statement row's kind of figure. */
|
|
163
|
+
function statementFigure(row: { format: "compact" | "eps" | "percent"; moneyUnit: string | null }): FigureFormat {
|
|
164
|
+
return row.format === "percent" ? "percent" : row.format === "eps" ? "perShare" : row.moneyUnit == null ? "count" : "money";
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A period column of a wide FA table: the cell as the table drew it, its growth beside it in text. The figure is
|
|
169
|
+
* drawn from the value it is handed, so an export reads its scale, and a reason drawn in place of a missing one
|
|
170
|
+
* (`needs prior period`, `N/M`) goes to the `status` column rather than into a column of numbers.
|
|
171
|
+
*/
|
|
172
|
+
function financialPeriodColumn(date: string, header: string, index: number, withGrowth: boolean): HeadlessPaneColumn {
|
|
173
|
+
type Cell = { formatted: string; growthFormatted?: string };
|
|
174
|
+
const cellOf = (row: Record<string, unknown>) => (row.cells as Cell[] | undefined)?.[index];
|
|
175
|
+
const draw = (value: unknown, row: Record<string, unknown>) => {
|
|
176
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return cellOf(row)?.formatted ?? MISSING_VALUE;
|
|
177
|
+
const format = row.figure as FigureFormat | undefined;
|
|
178
|
+
return format ? drawFigure(format, value, Number(row.divisor) || 1, row.kind === "ratio" || row.kind === "input") : value.toFixed(2);
|
|
179
|
+
};
|
|
180
|
+
return {
|
|
181
|
+
key: date, header, align: "right",
|
|
182
|
+
// Exports write the amount alone, every digit; its growth (or N/M) is in the JSON and on the text table.
|
|
183
|
+
format: draw,
|
|
184
|
+
...withGrowth ? {
|
|
185
|
+
textFormat: (value: unknown, row: Record<string, unknown>) => [draw(value, row), cellOf(row)?.growthFormatted].filter(Boolean).join(" "),
|
|
186
|
+
} : {},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The newest period end of a table's columns, which dates every row of it. */
|
|
191
|
+
function newestPeriodEnd(columns: ReadonlyArray<{ periodEnd: string }>): string | null {
|
|
192
|
+
return columns.map(({ periodEnd }) => periodEnd).filter(Boolean).sort().at(-1) ?? null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** A figure of the long layout as the text prints it: the number in the row's unit, which the Unit column names. */
|
|
196
|
+
function drawLongFigure(format: FigureFormat, value: number, divisor: number): string {
|
|
197
|
+
switch (format) {
|
|
198
|
+
case "percent": return formatNumber(value * 100, 1);
|
|
199
|
+
case "money": case "count": return formatFinancialAmount(value, divisor);
|
|
200
|
+
case "perShare": return formatPerShareNumber(value);
|
|
201
|
+
case "multiple": return formatNumber(value, Math.abs(value) < 10 ? 2 : 1);
|
|
202
|
+
case "days": return formatNumber(value, 1);
|
|
203
|
+
case "months": return formatRunwayMonths(value, "");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The figure in its long-layout unit: a percent as percent, money and share counts in their unit, the rest as they are. */
|
|
208
|
+
function longFigureValue(format: FigureFormat, value: number, divisor: number): number {
|
|
209
|
+
return format === "percent" ? value * 100 : format === "money" || format === "count" ? value / divisor : value;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const mostCommon = (values: readonly number[]): number | undefined => {
|
|
213
|
+
const counts = new Map<number, number>();
|
|
214
|
+
for (const value of values) counts.set(value, (counts.get(value) ?? 0) + 1);
|
|
215
|
+
return [...counts].sort((left, right) => right[1] - left[1] || right[0] - left[0])[0]?.[0];
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Text columns of the long layout. The export keeps Ticker to Value: each row's unit is its `currency_or_unit`,
|
|
220
|
+
* its period end its `as_of`, and a reason a figure is missing its `status`.
|
|
221
|
+
*/
|
|
222
|
+
const LONG_FINANCIAL_COLUMNS: HeadlessPaneColumn[] = [
|
|
223
|
+
{ key: "ticker", header: "Ticker" },
|
|
224
|
+
{ key: "period", header: "Period" },
|
|
225
|
+
{ key: "periodEnd", header: "Period End" },
|
|
226
|
+
{ key: "metric", header: "Metric" },
|
|
227
|
+
{ key: "value", header: "Value", align: "right", unitKey: "unit",
|
|
228
|
+
format: (value, row) => typeof value === "number" && Number.isFinite(value) ? String(row.formatted) : String(row.gap ?? MISSING_VALUE) },
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* FA for several tickers, or one with `--layout long`: a row per ticker, fiscal period and metric (Ticker, Period,
|
|
233
|
+
* Period End, Metric, Value, Unit), each ticker's table as `fn FA <ticker>` reads it. Money is in the one unit most
|
|
234
|
+
* of the tables' money rows take, so a figure pasted beside another ticker's needs no conversion; a ratio's input
|
|
235
|
+
* that several ratios share (Net Income under ROE, ROA and Net Margin) is one row.
|
|
236
|
+
*/
|
|
237
|
+
async function loadLongFinancialReport(symbols: string[], options: HeadlessPaneOptionValues, ctx: HeadlessPaneContext): Promise<HeadlessRowsResult> {
|
|
238
|
+
const loaded = await loadHeadlessSymbols(symbols, ctx, (symbol) => loadFinancialReport(symbol, options, ctx));
|
|
239
|
+
type WideRow = { kind: string; label: string; figure: FigureFormat; divisor: number;
|
|
240
|
+
cells: Array<{ value: number | null; formatted: string; gap?: string | null }> };
|
|
241
|
+
type WideColumn = { period: string; periodEnd: string; currency: string | null };
|
|
242
|
+
const tables = loaded.entries.map(({ symbol, data }) => ({
|
|
243
|
+
symbol, data, rows: data.rows as unknown as WideRow[], columns: (data.metadata?.columns ?? []) as WideColumn[],
|
|
244
|
+
}));
|
|
245
|
+
const divisor = mostCommon(tables.flatMap(({ rows }) => rows.filter((row) => row.figure === "money").map((row) => row.divisor))) ?? 1;
|
|
246
|
+
const rows = tables.flatMap(({ symbol, rows: wide, columns }) => {
|
|
247
|
+
const said = new Set<string>();
|
|
248
|
+
return wide.flatMap((row) => {
|
|
249
|
+
// An input is named without the operator that joins it to its ratio, and once.
|
|
250
|
+
const metric = row.kind === "input" ? row.label.replace(/^[÷+−-]\s*/, "") : row.label;
|
|
251
|
+
if (said.has(metric)) return [];
|
|
252
|
+
said.add(metric);
|
|
253
|
+
const rowDivisor = row.figure === "money" ? divisor : row.divisor;
|
|
254
|
+
return columns.map((column, index) => {
|
|
255
|
+
const cell = row.cells[index];
|
|
256
|
+
const value = typeof cell?.value === "number" && Number.isFinite(cell.value) ? cell.value : null;
|
|
257
|
+
return {
|
|
258
|
+
ticker: symbol, period: column.period, periodEnd: column.periodEnd, metric,
|
|
259
|
+
value: value == null ? null : longFigureValue(row.figure, value, rowDivisor),
|
|
260
|
+
unit: figureUnit(row.figure, column.currency, rowDivisor),
|
|
261
|
+
formatted: value == null ? null : drawLongFigure(row.figure, value, rowDivisor),
|
|
262
|
+
gap: value == null ? cell?.gap ?? (cell?.formatted && cell.formatted !== MISSING_VALUE ? cell.formatted : null) : null,
|
|
263
|
+
};
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
// A note every table makes is said once; one only some make names the ticker. The headers' date sources are
|
|
268
|
+
// not in this layout's columns, so neither is what they mean.
|
|
269
|
+
const kept = (note: string) => note !== SEC_DATE_NOTE && note !== PROVIDER_DATE_NOTE;
|
|
270
|
+
for (const table of tables) table.data = { ...table.data, notes: (table.data.notes ?? []).filter(kept) };
|
|
271
|
+
const notes = tables.flatMap(({ data }) => data.notes ?? []);
|
|
272
|
+
const shared = (note: string) => tables.every(({ data }) => (data.notes ?? []).includes(note));
|
|
273
|
+
const ownNotes = tables.flatMap(({ symbol, data }) => (data.notes ?? []).filter((note) => !shared(note)).map((note) => `${symbol}: ${note}`));
|
|
274
|
+
const empty = tables.filter(({ rows: wide }) => wide.length === 0);
|
|
275
|
+
const first = tables[0]?.data.metadata ?? {};
|
|
276
|
+
return {
|
|
277
|
+
rows,
|
|
278
|
+
columns: LONG_FINANCIAL_COLUMNS,
|
|
279
|
+
textColumns: [...LONG_FINANCIAL_COLUMNS, { key: "unit", header: "Unit" }],
|
|
280
|
+
rowUnitKey: "unit", rowSymbolKey: "ticker", rowAsOfKey: "periodEnd",
|
|
281
|
+
interval: options.period === "quarterly" ? "quarterly" : "annual",
|
|
282
|
+
unavailableSymbols: [...loaded.unavailableSymbols, ...empty.flatMap(({ data }) => data.unavailableSymbols ?? [])],
|
|
283
|
+
errors: [...loaded.errors, ...tables.flatMap(({ symbol, data }) => (data.errors ?? []).map((error) => error.startsWith(symbol) ? error : `${symbol}: ${error}`))],
|
|
284
|
+
notes: [...new Set([...notes.filter(shared), ...ownNotes])],
|
|
285
|
+
metadata: {
|
|
286
|
+
symbols, layout: "long", statement: first.statement ?? options.statement, statementLabel: first.statementLabel ?? null,
|
|
287
|
+
period: options.period === "quarterly" ? "quarterly" : "annual",
|
|
288
|
+
notices: [...new Set(tables.flatMap(({ data }) => (data.metadata?.notices ?? []) as string[]))],
|
|
289
|
+
limitations: [...new Set(tables.flatMap(({ data }) => (data.metadata?.limitations ?? []) as string[]))],
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** One ticker's statement or ratio table, its periods as columns. */
|
|
295
|
+
async function loadFinancialReport(symbol: string, options: HeadlessPaneOptionValues, ctx: HeadlessPaneContext): Promise<HeadlessRowsResult> {
|
|
296
|
+
{
|
|
117
297
|
const financials = await loadHeadlessFinancials(ctx, symbol);
|
|
118
298
|
const requestedPeriod = options.period === "quarterly" ? "quarterly" : "annual";
|
|
119
299
|
const hasRequestedStatements = (requestedPeriod === "quarterly"
|
|
@@ -164,29 +344,30 @@ export const financialStatementsHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
164
344
|
dateSource: date === "TTM" ? "derived" : dateSource ?? "provider",
|
|
165
345
|
providerDate: date === "TTM" ? null : providerDate ?? null,
|
|
166
346
|
dateEvidence: date === "TTM" || dateSource !== "sec" ? null : dateEvidence ?? null,
|
|
167
|
-
//
|
|
347
|
+
// The fiscal period as the pane names it, and the day it ends, which the long layout and exports date it by.
|
|
348
|
+
period: financialColumnLabel(statement, requestedPeriod, yearEndMonth),
|
|
349
|
+
periodEnd: ratioPeriodEnd(statement),
|
|
350
|
+
// Rows in the table's one money unit do not name it, so the header does.
|
|
168
351
|
label: financialReportHeader(statement, [currency ?? statementCurrency, table.unit].filter(Boolean).join(" ") || undefined, requestedPeriod, yearEndMonth, listRows),
|
|
169
352
|
};
|
|
170
353
|
}) ?? [];
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
354
|
+
const asOf = newestPeriodEnd(dates);
|
|
355
|
+
const rows = table?.rows.map((row) => {
|
|
356
|
+
const figure = statementFigure(row);
|
|
357
|
+
return {
|
|
358
|
+
id: row.id, kind: row.kind, metric: allReceipts ? receiptShareCountLabel(row) : row.unitLabel, label: row.label,
|
|
359
|
+
// What the figures are in, which exports name in `currency_or_unit`, and the newest period they run to.
|
|
360
|
+
figure, divisor: row.divisor, unit: figureUnit(figure, statementCurrency ?? null, row.divisor, allReceipts ? "ADRs" : "shares"), periodEnd: asOf,
|
|
361
|
+
cells: row.cells.map((cell, index) => ({
|
|
362
|
+
date: dates[index]?.date ?? "", value: cell.value ?? null,
|
|
363
|
+
growth: cell.growth ?? null, formatted: cell.valueText.trim(), growthFormatted: cell.growthText.trim(),
|
|
364
|
+
})),
|
|
365
|
+
...Object.fromEntries(row.cells.map((cell, index) => [dates[index]!.date, cell.value ?? null])),
|
|
366
|
+
};
|
|
367
|
+
}) ?? [];
|
|
179
368
|
const columns: HeadlessPaneColumn[] = [
|
|
180
369
|
{ key: "metric", header: "Metric" },
|
|
181
|
-
...dates.map(({ date, label }, index) => (
|
|
182
|
-
key: date, header: label, align: "right" as const,
|
|
183
|
-
// Exports write the amount alone, every digit; its growth (or N/M) is in the JSON and on the text table.
|
|
184
|
-
format: (_value: unknown, row: Record<string, unknown>) => (row.cells as Array<{ formatted: string }>)[index]!.formatted,
|
|
185
|
-
textFormat: (_value: unknown, row: Record<string, unknown>) => {
|
|
186
|
-
const cell = (row.cells as Array<{ formatted: string; growthFormatted: string }>)[index]!;
|
|
187
|
-
return [cell.formatted, cell.growthFormatted].filter(Boolean).join(" ");
|
|
188
|
-
},
|
|
189
|
-
})),
|
|
370
|
+
...dates.map(({ date, label }, index) => financialPeriodColumn(date, label, index, true)),
|
|
190
371
|
];
|
|
191
372
|
// The balance sheet's cash, when an offering since is not in it yet.
|
|
192
373
|
const offering = table?.subTab.key === "balance" ? await reportOfferingNote(ctx, symbol, financials) : null;
|
|
@@ -202,9 +383,12 @@ export const financialStatementsHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
202
383
|
return {
|
|
203
384
|
rows, columns, unavailableSymbols: rows.length ? [] : [symbol],
|
|
204
385
|
...(missing ? { errors: [missing] } : {}),
|
|
386
|
+
// Each exported row names its unit, the statements' period and the newest period end it runs to.
|
|
387
|
+
rowUnitKey: "unit", rowAsOfKey: "periodEnd", interval: requestedPeriod,
|
|
205
388
|
// The report closes with how old its latest period is, how far back its periods go, and how to read further.
|
|
206
389
|
notes: [...announced, ...stale ? [stale] : [], ...filled ? [filled] : [], ...offering ? [offering] : [],
|
|
207
|
-
...statementHistoryNotes(requestedPeriod, periodDates, symbol, await reportOlderStatements(ctx, symbol, requestedPeriod, periodDates))
|
|
390
|
+
...statementHistoryNotes(requestedPeriod, periodDates, symbol, await reportOlderStatements(ctx, symbol, requestedPeriod, periodDates)),
|
|
391
|
+
...table?.subTab.key === "cashflow" ? [CASH_FLOW_NOTE] : [], ...dateSourceNotes(dates)],
|
|
208
392
|
metadata: {
|
|
209
393
|
symbol, name: financials.quote?.name ?? symbol, currency: statementCurrency ?? null, unit: table?.unit ?? null, quoteCurrency: financials.quote?.currency ?? null,
|
|
210
394
|
statement: table?.subTab.key ?? options.statement, statementLabel: table?.subTab.name ?? null,
|
|
@@ -218,11 +402,34 @@ export const financialStatementsHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
218
402
|
dateProvenance: financialStatementDateNotice(table?.statements ?? []),
|
|
219
403
|
},
|
|
220
404
|
};
|
|
221
|
-
}
|
|
222
|
-
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
223
407
|
|
|
224
408
|
const reportAmount = (amount: RatioAmount) => (typeof amount === "number" ? amount : null);
|
|
225
409
|
|
|
410
|
+
/** What the profitability tab's figures are, said under it, as docs/financial-ratios.md defines them. */
|
|
411
|
+
const PROFITABILITY_NOTES = [
|
|
412
|
+
"ROIC is NOPAT / average (equity + total debt), cash not netted; ROIC ex Cash takes cash and short-term investments out of that capital.",
|
|
413
|
+
"NOPAT is operating income x (1 - tax provision / pretax income), the rate held between 0% and 100%; a pretax loss pays no tax.",
|
|
414
|
+
"Margins and NOPAT are GAAP, as the income statement reports them, not the company's adjusted (non-GAAP) figures.",
|
|
415
|
+
];
|
|
416
|
+
|
|
417
|
+
const NEEDS_OPENING_NOTE = "needs prior period: an average of the opening and closing balance has no opening balance sheet on file, the period before the column's (the prior year end for a year, the prior quarter end for a quarter, the quarter a year earlier for TTM), as for the oldest column or a year whose prior year is missing.";
|
|
418
|
+
|
|
419
|
+
/** What the cash flow table works out of its own lines. */
|
|
420
|
+
const CASH_FLOW_NOTE = "CapEx / Revenue is capex over revenue; Reinvestment Rate is capex plus acquisitions less D&A, over NOPAT.";
|
|
421
|
+
|
|
422
|
+
const SEC_DATE_NOTE = "SEC date: the period end the company's 10-K or 10-Q states.";
|
|
423
|
+
const PROVIDER_DATE_NOTE = "provider date: the period end as the statements source dates it, which can be a few days off the company's own.";
|
|
424
|
+
|
|
425
|
+
/** What a column header's `(SEC date)` and `(provider date)` mean, for the ones the table has. */
|
|
426
|
+
function dateSourceNotes(columns: ReadonlyArray<{ dateSource: string }>): string[] {
|
|
427
|
+
return [
|
|
428
|
+
...columns.some(({ dateSource }) => dateSource === "sec") ? [SEC_DATE_NOTE] : [],
|
|
429
|
+
...columns.some(({ dateSource }) => dateSource === "provider") ? [PROVIDER_DATE_NOTE] : [],
|
|
430
|
+
];
|
|
431
|
+
}
|
|
432
|
+
|
|
226
433
|
/**
|
|
227
434
|
* What a table of quarters says its growth is measured against; a half filled
|
|
228
435
|
* from a results announcement is measured against the same half a year earlier.
|
|
@@ -315,11 +522,15 @@ async function loadRatioReport(
|
|
|
315
522
|
const yearEndMonth = fiscalYearEndMonth(financials.annualStatements);
|
|
316
523
|
const dates = table?.periods.map(({ statement }) => ({
|
|
317
524
|
date: statement.date,
|
|
525
|
+
// The fiscal period as the pane names it, and the day it ends.
|
|
526
|
+
period: financialColumnLabel(statement, period, yearEndMonth),
|
|
318
527
|
periodEnd: ratioPeriodEnd(statement),
|
|
319
528
|
currency: statement.currency ?? statementCurrency ?? null,
|
|
529
|
+
dateSource: statement.date === "TTM" ? "derived" : statement.dateSource ?? "provider",
|
|
320
530
|
label: financialReportHeader(statement, statement.currency ?? statementCurrency, period, yearEndMonth,
|
|
321
531
|
period === "quarterly" ? financials.quarterlyStatements : financials.annualStatements),
|
|
322
532
|
})) ?? [];
|
|
533
|
+
const asOf = newestPeriodEnd(dates);
|
|
323
534
|
const rows = table?.rows.map((row) => {
|
|
324
535
|
const cells = table.cells.get(row.def.id)!.map((cell, index) => {
|
|
325
536
|
const amount = row.kind === "ratio" ? cell.value : cell.inputs[row.index]!;
|
|
@@ -332,19 +543,23 @@ async function loadRatioReport(
|
|
|
332
543
|
: formatRatioInput(row.def.inputs[row.index]!.format, amount, row.divisor),
|
|
333
544
|
};
|
|
334
545
|
});
|
|
546
|
+
const figure: FigureFormat = row.kind === "ratio" ? row.def.format : row.def.inputs[row.index]!.format;
|
|
547
|
+
const divisor = row.kind === "ratio" ? 1 : row.divisor;
|
|
335
548
|
return {
|
|
336
549
|
id: row.id, kind: row.kind, metric: row.kind === "ratio" ? row.label : row.unitLabel,
|
|
550
|
+
label: row.kind === "ratio" ? row.label : row.unitLabel.replace(/ \([a-z]+\)$/, ""),
|
|
551
|
+
// What the figures are in, which exports name in `currency_or_unit`, and the newest period they run to.
|
|
552
|
+
figure, divisor, unit: figureUnit(figure, statementCurrency ?? null, divisor), periodEnd: asOf,
|
|
337
553
|
cells,
|
|
338
554
|
...Object.fromEntries(cells.map((cell) => [cell.date, cell.value])),
|
|
339
555
|
};
|
|
340
556
|
}) ?? [];
|
|
341
557
|
const columns: HeadlessPaneColumn[] = [
|
|
342
558
|
{ key: "metric", header: "Ratio" },
|
|
343
|
-
...dates.map(({ date, label }, index) => (
|
|
344
|
-
key: date, header: label, align: "right" as const,
|
|
345
|
-
format: (_value: unknown, row: Record<string, unknown>) => (row.cells as Array<{ formatted: string }>)[index]!.formatted,
|
|
346
|
-
})),
|
|
559
|
+
...dates.map(({ date, label }, index) => financialPeriodColumn(date, label, index, false)),
|
|
347
560
|
];
|
|
561
|
+
// An average with no opening balance sheet on file (the oldest column, a year after a missing one, TTM) says what it needs.
|
|
562
|
+
const needsOpening = rows.some((row) => row.cells.some((cell) => cell.gap === RATIO_GAP_TEXT["no-opening"]));
|
|
348
563
|
// Liquidity's runway says how it counts months, and that the cash predates an offering since.
|
|
349
564
|
const liquidity = tab.key === "liquidity" && table;
|
|
350
565
|
const runwayShown = liquidity && table.ratios.some((def) => def.format === "months"
|
|
@@ -356,12 +571,17 @@ async function loadRatioReport(
|
|
|
356
571
|
rows, columns, unavailableSymbols: rows.length ? [] : [symbol],
|
|
357
572
|
...(missing ? { errors: [missing] } : {}),
|
|
358
573
|
...(tab.key === "valuation" && hasRequestedStatements && !history?.length ? { complete: false } : {}),
|
|
574
|
+
// Each exported row names its unit, the statements' period and the newest period end it runs to.
|
|
575
|
+
rowUnitKey: "unit", rowAsOfKey: "periodEnd", interval: period,
|
|
359
576
|
notes: [
|
|
360
577
|
...[stalePeriodNote(dates.map(({ periodEnd }) => ({ date: periodEnd, lead: true })))].filter((note): note is string => !!note),
|
|
361
578
|
...[filledPeriodsNote(table?.periods.map(({ statement }) => statement) ?? [])].filter((note): note is string => !!note),
|
|
362
579
|
...offering ? [offering] : [],
|
|
363
580
|
...runwayShown ? [runwayMethod(reportsShortTermTotal([...financials.quarterlyStatements, ...financials.annualStatements]))] : [],
|
|
364
581
|
...statementHistoryNotes(period, periodDates, symbol, await reportOlderStatements(ctx, symbol, period, periodDates)),
|
|
582
|
+
...tab.key === "profitability" && rows.length ? PROFITABILITY_NOTES : [],
|
|
583
|
+
...needsOpening ? [NEEDS_OPENING_NOTE] : [],
|
|
584
|
+
...dateSourceNotes(dates),
|
|
365
585
|
],
|
|
366
586
|
metadata: {
|
|
367
587
|
symbol, name: financials.quote?.name ?? symbol, currency: statementCurrency ?? null,
|
|
@@ -27,7 +27,8 @@ import {
|
|
|
27
27
|
formatMarketQuantity,
|
|
28
28
|
withCurrencyMinorDigits,
|
|
29
29
|
} from "../../../../market-data/market/format";
|
|
30
|
-
import { reportedQuoteVolume } from "../../../../market-data/market/index-level";
|
|
30
|
+
import { quoteVolumeCurrency, reportedQuoteVolume } from "../../../../market-data/market/index-level";
|
|
31
|
+
import { formatChartLegendValue } from "../../../../components/chart/composite/format";
|
|
31
32
|
import type { OverviewFunctionLink, PositionTableRow, StatField } from "./types";
|
|
32
33
|
import type { OverviewDividendState } from "./dividend";
|
|
33
34
|
import { lapseValue } from "../../../../utils/forward-dividend";
|
|
@@ -211,9 +212,12 @@ export function buildOverviewStats({
|
|
|
211
212
|
const volume = reportedQuoteVolume(quote);
|
|
212
213
|
if (volume != null) {
|
|
213
214
|
// Live figures keep their decimals (12.30M, not 12.3M) so the digits hold still.
|
|
214
|
-
// A coin's volume is the
|
|
215
|
+
// A coin's volume is the value it traded in its quote currency, written as the chart's volume reads ($47.94B),
|
|
216
|
+
// and the composite's or one exchange's own day, said beside it as its range's is.
|
|
215
217
|
const basis = quoteStatsBasisText(quote, false);
|
|
216
|
-
|
|
218
|
+
const currency = quoteVolumeCurrency(quote);
|
|
219
|
+
const value = currency ? formatChartLegendValue(volume, currency, "volume") : formatCompact(volume, { fixedDecimals: true });
|
|
220
|
+
stats.push({ label: "Volume", value, ...(basis ? { detail: basis } : {}) });
|
|
217
221
|
}
|
|
218
222
|
// Price-derived statistics follow the quote; see live-valuation for when a stored figure is kept.
|
|
219
223
|
// Market cap and EV read in the currency they are reported in, as the revenue and income beside them do, with
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CompanyProfile } from "../../../../types/financials";
|
|
2
|
+
import type { TickerInstrumentKind } from "../../../../types/instrument";
|
|
3
|
+
|
|
4
|
+
/** The Signals tab's id: what `?tab=`, `--tab` and a saved layout name it by. */
|
|
5
|
+
export const PHARMA_SIGNALS_TAB_ID = "pharma-signals";
|
|
6
|
+
|
|
7
|
+
/** The profile's industries of drug developers: Biotechnology, Drug Manufacturers - General, - Specialty & Generic. */
|
|
8
|
+
const DRUG_INDUSTRY = /^(?:biotechnology|drug manufacturers\b.*)$/i;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* SEC codes of drug makers, for a US filer whose profile names no industry:
|
|
12
|
+
* medicinal chemicals (2833), pharmaceutical preparations (2834) and
|
|
13
|
+
* biological products (2836). Diagnostic substances (2835) are not drugs.
|
|
14
|
+
*/
|
|
15
|
+
const DRUG_SIC = new Set(["2833", "2834", "2836"]);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Whether a listing gets the Signals tab: a company share whose profile says
|
|
19
|
+
* it develops or makes drugs. Other healthcare (devices, services, insurers,
|
|
20
|
+
* tools), funds such as a biotech ETF, and a listing whose profile has not
|
|
21
|
+
* loaded do not: the tab shows once the profile says so, never on a guess
|
|
22
|
+
* from the name.
|
|
23
|
+
*/
|
|
24
|
+
export function isPharmaSignalsListing(
|
|
25
|
+
instrumentKind: TickerInstrumentKind,
|
|
26
|
+
profile: Pick<CompanyProfile, "industry" | "sic"> | null | undefined,
|
|
27
|
+
): boolean {
|
|
28
|
+
if (instrumentKind !== "equity" || !profile) return false;
|
|
29
|
+
const industry = profile.industry?.trim();
|
|
30
|
+
if (industry) return DRUG_INDUSTRY.test(industry);
|
|
31
|
+
return DRUG_SIC.has(profile.sic?.trim() ?? "");
|
|
32
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createContext, useCallback, useContext, useRef, useSyncExternalStore } from "react";
|
|
2
|
+
import { requestAuthDialog } from "../../../../account/auth-dialog";
|
|
3
|
+
import { apiClient } from "../../../../api-client";
|
|
4
|
+
import { usePlanAccess } from "../../../../api-client/plan-access";
|
|
5
|
+
import { isEmailVerificationRequired } from "../../../../api-client/product-waitlist";
|
|
6
|
+
import { Button, confirmDialog, PaneStatusBody, usePaneStatusFooter } from "../../../../components";
|
|
7
|
+
import { usePaneRefreshKey } from "../../../../components/data-table/table-pane";
|
|
8
|
+
import { t } from "../../../../i18n";
|
|
9
|
+
import { usePluginAppActions } from "../../../../public/react";
|
|
10
|
+
import { colors } from "../../../../theme/colors";
|
|
11
|
+
import type { TickerResearchTabProps } from "../../../../types/plugin";
|
|
12
|
+
import { Box, Text, TextAttributes } from "../../../../ui";
|
|
13
|
+
import { useOptionalDialog } from "../../../../ui/dialog";
|
|
14
|
+
import { logFailure } from "../../../../utils/log-failure";
|
|
15
|
+
import { useProductWaitlist, type WaitlistClient } from "./waitlist";
|
|
16
|
+
|
|
17
|
+
export const PharmaWaitlistClientContext = createContext<WaitlistClient | null>(null);
|
|
18
|
+
|
|
19
|
+
const PRODUCT = "pharma-signals";
|
|
20
|
+
const PLANNED = "Planned: alerts the day a trial's endpoint, enrollment, dates or status change, and cash runway against the next catalyst.";
|
|
21
|
+
const RESEND_VERIFICATION = "Resend Verification Email";
|
|
22
|
+
|
|
23
|
+
function subscribeAccount(onChange: () => void): () => void {
|
|
24
|
+
return apiClient.subscribeCurrentUser(onChange);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function currentAccount(): string | null {
|
|
28
|
+
return apiClient.getCurrentUser()?.id ?? null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The consent itself: what joining costs (nothing now) and the one email it allows. */
|
|
32
|
+
function JoinDialogBody() {
|
|
33
|
+
return (
|
|
34
|
+
<Box flexDirection="column">
|
|
35
|
+
<Text fg={colors.text} wrapText>{t("Planned price: $50/month on top of Pro, once it launches.")}</Text>
|
|
36
|
+
<Box height={1} />
|
|
37
|
+
<Text fg={colors.positive} attributes={TextAttributes.BOLD} wrapText>{t("Nothing is charged now. No card needed.")}</Text>
|
|
38
|
+
<Box height={1} />
|
|
39
|
+
<Text fg={colors.textDim} wrapText>{t("We email you once, only if it launches. Nothing else.")}</Text>
|
|
40
|
+
</Box>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The Signals tab of a drug developer's research pane: an add-on that is not
|
|
46
|
+
* built, said plainly, with a no-charge waitlist. Nothing in it is data, so
|
|
47
|
+
* it shows no rows, real or made up. Joining asks first, every time, and
|
|
48
|
+
* never happens at sign-in: signed out, the button only opens the sign-in.
|
|
49
|
+
* The launch email goes to the account's address, so an unverified one is
|
|
50
|
+
* asked to verify it first: the app sends nothing for an address it knows is
|
|
51
|
+
* unverified, and says the same when the service refuses one it thought was.
|
|
52
|
+
*/
|
|
53
|
+
export function PharmaSignalsResearchTab({ width, height, focused }: TickerResearchTabProps) {
|
|
54
|
+
const client = useContext(PharmaWaitlistClientContext) ?? apiClient;
|
|
55
|
+
const account = useSyncExternalStore(subscribeAccount, currentAccount, currentAccount);
|
|
56
|
+
const access = usePlanAccess();
|
|
57
|
+
const waitlist = useProductWaitlist(client, PRODUCT, account && access.emailVerified ? account : null);
|
|
58
|
+
const needsVerification = !!account && (!access.emailVerified || waitlist.unverified);
|
|
59
|
+
const { change, retry } = waitlist;
|
|
60
|
+
const dialog = useOptionalDialog();
|
|
61
|
+
const { openCommandBar, notify } = usePluginAppActions();
|
|
62
|
+
// The join dialog is open: the key or press that answered it does not open another.
|
|
63
|
+
const asking = useRef(false);
|
|
64
|
+
|
|
65
|
+
usePaneRefreshKey(retry, { focused });
|
|
66
|
+
usePaneStatusFooter({ registrationId: "pharma-signals", loading: waitlist.loading, error: waitlist.error });
|
|
67
|
+
|
|
68
|
+
const failed = useCallback((message: string, unverifiedMessage: string, error: unknown) => {
|
|
69
|
+
if (isEmailVerificationRequired(error)) {
|
|
70
|
+
notify({ body: t(unverifiedMessage), type: "error", desktop: "never" });
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
logFailure("pharma-signals", message)(error);
|
|
74
|
+
notify({ body: t(message), type: "error", desktop: "never" });
|
|
75
|
+
}, [notify]);
|
|
76
|
+
|
|
77
|
+
const join = useCallback(() => {
|
|
78
|
+
if (!account) {
|
|
79
|
+
if (!requestAuthDialog({ mode: "login" })) openCommandBar("Log In");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!dialog || asking.current) return;
|
|
83
|
+
asking.current = true;
|
|
84
|
+
// The account the person decides as: a sign-in elsewhere while the dialog is open sends nothing.
|
|
85
|
+
const decidedAs = account;
|
|
86
|
+
confirmDialog(dialog, {
|
|
87
|
+
title: t("Join the pharma signals waitlist"),
|
|
88
|
+
body: <JoinDialogBody />,
|
|
89
|
+
confirmLabel: t("Join waitlist"),
|
|
90
|
+
cancelLabel: t("Not now"),
|
|
91
|
+
confirmVariant: "primary",
|
|
92
|
+
// An opt-in: a stray Enter answers Not now; only `y` or the button joins.
|
|
93
|
+
defaultAction: "cancel",
|
|
94
|
+
})
|
|
95
|
+
.then((confirmed) => {
|
|
96
|
+
// Released a turn after the answer, once the key that gave it has gone everywhere it goes.
|
|
97
|
+
setTimeout(() => { asking.current = false; }, 0);
|
|
98
|
+
return confirmed ? change(true, decidedAs) : null;
|
|
99
|
+
})
|
|
100
|
+
.catch((error: unknown) => failed("Couldn't join the waitlist. Try again.", "Verify your email to join the waitlist.", error));
|
|
101
|
+
}, [account, change, dialog, failed, openCommandBar]);
|
|
102
|
+
|
|
103
|
+
const leave = useCallback(() => {
|
|
104
|
+
if (!account) return;
|
|
105
|
+
change(false, account)
|
|
106
|
+
.catch((error: unknown) => failed("Couldn't leave the waitlist. Try again.", "Verify your email to leave the waitlist.", error));
|
|
107
|
+
}, [account, change, failed]);
|
|
108
|
+
|
|
109
|
+
if (needsVerification) {
|
|
110
|
+
return (
|
|
111
|
+
<PaneStatusBody
|
|
112
|
+
empty
|
|
113
|
+
width={width}
|
|
114
|
+
height={height}
|
|
115
|
+
emptyTitle={t("Verify your email to join the pharma signals waitlist.")}
|
|
116
|
+
emptyMessage={t(PLANNED)}
|
|
117
|
+
actions={<Button label={t(RESEND_VERIFICATION)} onPress={() => openCommandBar(RESEND_VERIFICATION)} />}
|
|
118
|
+
/>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (waitlist.joined) {
|
|
123
|
+
return (
|
|
124
|
+
<PaneStatusBody
|
|
125
|
+
empty
|
|
126
|
+
width={width}
|
|
127
|
+
height={height}
|
|
128
|
+
emptyTitle={t("You're on the pharma signals waitlist.")}
|
|
129
|
+
emptyMessage={t("We email you once, only if it launches. Nothing is charged.")}
|
|
130
|
+
actions={(
|
|
131
|
+
<Button
|
|
132
|
+
label={t("Leave waitlist")}
|
|
133
|
+
variant="secondary"
|
|
134
|
+
pending={waitlist.pending === "leave"}
|
|
135
|
+
pendingLabel={t("Leaving…")}
|
|
136
|
+
onPress={leave}
|
|
137
|
+
/>
|
|
138
|
+
)}
|
|
139
|
+
/>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const known = !account || waitlist.joined === false;
|
|
144
|
+
return (
|
|
145
|
+
<PaneStatusBody
|
|
146
|
+
empty
|
|
147
|
+
width={width}
|
|
148
|
+
height={height}
|
|
149
|
+
emptyTitle={t("Pharma signals are not available yet.")}
|
|
150
|
+
emptyMessage={t(PLANNED)}
|
|
151
|
+
retry={waitlist.error ? { onRetry: retry } : undefined}
|
|
152
|
+
actions={known ? (
|
|
153
|
+
<Button
|
|
154
|
+
label={account ? t("Join waitlist") : t("Log in to join")}
|
|
155
|
+
pending={waitlist.pending === "join"}
|
|
156
|
+
pendingLabel={t("Joining…")}
|
|
157
|
+
onPress={join}
|
|
158
|
+
/>
|
|
159
|
+
) : undefined}
|
|
160
|
+
/>
|
|
161
|
+
);
|
|
162
|
+
}
|