gloomberb 0.20.17 → 0.20.18
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 +3 -1
- package/src/account/auth-dialog.tsx +19 -1
- package/src/account/billing.ts +2 -1
- package/src/account/heard-from-question.tsx +235 -0
- package/src/account/heard-from.ts +97 -0
- package/src/api-client/data.ts +3 -2
- package/src/api-client/heard-from.ts +72 -0
- package/src/api-client/index.ts +63 -6
- package/src/api-client/mna.ts +18 -0
- package/src/api-client/supply-chain.ts +9 -0
- package/src/api-client/types/billing.ts +35 -1
- package/src/app/global-shortcuts.ts +5 -3
- package/src/app/pro-welcome/keys.ts +27 -0
- package/src/app/pro-welcome/model.ts +158 -0
- package/src/app/pro-welcome/row.tsx +176 -0
- package/src/app/pro-welcome/use-pro-welcome.ts +156 -0
- package/src/app/runtime/external-profile-changes.ts +135 -0
- package/src/app.tsx +33 -2
- package/src/architecture/core-builtin-allowlist.json +1 -1
- package/src/architecture/floating-promise-allowlist.json +0 -1
- package/src/architecture/shortcut-labels-allowlist.json +1 -0
- package/src/cli/alert-listing.ts +98 -0
- package/src/cli/commands/market.ts +138 -22
- package/src/cli/commands/overview.ts +7 -1
- package/src/cli/commands/plugins.ts +3 -2
- package/src/cli/commands/search.ts +30 -6
- package/src/cli/context.ts +16 -5
- package/src/cli/csv-export.ts +2 -1
- package/src/cli/desktop-pane-shot.ts +72 -9
- package/src/cli/glossary.ts +64 -10
- package/src/cli/history-demergers.ts +117 -0
- package/src/cli/history-rows.ts +6 -2
- package/src/cli/index.ts +1 -0
- package/src/cli/known-gaps.ts +16 -0
- package/src/cli/known-us-stocks.ts +18 -0
- package/src/cli/listing-arg.ts +105 -15
- package/src/cli/pane-functions/catalog-snapshot-build.ts +83 -0
- package/src/cli/pane-functions/catalog-snapshot.json +866 -0
- package/src/cli/pane-functions/catalog-snapshot.ts +62 -0
- package/src/cli/pane-functions/catalog.ts +50 -16
- package/src/cli/pane-functions/data.ts +16 -4
- package/src/cli/pane-functions/dom.ts +24 -6
- package/src/cli/pane-functions/freshness.ts +17 -1
- package/src/cli/pane-functions/index.ts +100 -42
- package/src/cli/pane-functions/resolver.ts +8 -5
- package/src/cli/pane-functions/screenshot-assessment.ts +30 -7
- package/src/cli/pane-functions/screenshot-payload.ts +21 -0
- package/src/cli/pane-functions/screenshot-render.ts +3 -1
- package/src/cli/quote-answer.ts +32 -16
- package/src/cli/registry.ts +22 -2
- package/src/cli/result.ts +5 -4
- package/src/cli/series-search.ts +45 -6
- package/src/cli/shot-temp-dir.ts +4 -9
- package/src/components/chart/composite/legend.tsx +43 -18
- package/src/components/chart/composite/panel-surface/panel-cursor.tsx +3 -3
- package/src/components/chart/composite/price-axis-labels.tsx +7 -5
- package/src/components/chart-table/header.tsx +9 -0
- package/src/components/chart-table/layout.ts +11 -11
- package/src/components/command-bar/pane-templates/items.ts +17 -1
- package/src/components/command-bar/routes/root/provider-search.ts +10 -1
- package/src/components/command-bar/routes/root/results.ts +34 -2
- package/src/components/command-bar/routes/root/runtime.ts +8 -1
- package/src/components/command-bar/routes/ticker-search/route.ts +5 -0
- package/src/components/command-bar/workflow/alert.ts +19 -8
- package/src/components/data-table/view.tsx +15 -2
- package/src/components/form-modal/content.tsx +9 -4
- package/src/components/index.ts +1 -1
- package/src/components/layout/header.tsx +9 -5
- package/src/components/layout/pane/capture-status.ts +6 -0
- package/src/components/layout/pane/footer/index.tsx +2 -0
- package/src/components/layout/pane/footer/model.ts +113 -15
- package/src/components/layout/pane/header.tsx +16 -2
- package/src/components/market-board/index.tsx +4 -2
- package/src/components/onboarding/onboarding-frame.tsx +6 -2
- package/src/components/onboarding/onboarding-keyboard.ts +7 -1
- package/src/components/onboarding/onboarding-wizard.tsx +3 -1
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +24 -15
- package/src/components/onboarding/setup-cards.ts +36 -0
- package/src/components/onboarding/use-onboarding-progress.ts +22 -1
- package/src/components/onboarding/wizard-account.ts +6 -1
- package/src/components/onboarding/wizard-model.ts +32 -6
- package/src/components/onboarding/wizard-positions.ts +1 -1
- package/src/components/sign-in-gate.tsx +3 -1
- package/src/components/toggle-list.tsx +6 -8
- package/src/components/ui/confirm-dialog.tsx +47 -7
- package/src/components/ui/data-table/types.ts +8 -0
- package/src/components/ui/display.tsx +17 -2
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/stat-grid.tsx +4 -0
- package/src/components/ui/status.tsx +13 -1
- package/src/components/ui/table-layout.ts +2 -1
- package/src/components/use-pane-notice-footer.tsx +16 -3
- package/src/data/config/store/index.ts +31 -0
- package/src/data/config/store/node.ts +61 -11
- package/src/data/config/store/normalize.ts +4 -6
- package/src/data/config/store/shared-file.ts +309 -0
- package/src/data/profile-merge.ts +299 -0
- package/src/data/sqlite/checkpointer.ts +11 -1
- package/src/data/sqlite/database.ts +1 -1
- package/src/data/ticker-repository.ts +134 -10
- package/src/data/ticker-store.ts +67 -0
- package/src/data/ticker-writes.ts +5 -0
- package/src/i18n/es.ts +27 -0
- package/src/i18n/ja.ts +27 -0
- package/src/i18n/ko.ts +27 -0
- package/src/i18n/zh-cn.ts +27 -0
- package/src/i18n/zh-tw.ts +27 -0
- package/src/layout-marketplace/gallery-desktop.tsx +2 -2
- package/src/market-data/ah-pair.ts +103 -0
- package/src/market-data/depositary-pair.ts +6 -2
- package/src/market-data/hooks.tsx +33 -2
- package/src/market-data/market/change-basis.ts +2 -1
- package/src/market-data/market/header-market.ts +11 -0
- package/src/market-data/split-terms.ts +28 -0
- package/src/plugins/builtin/account-management/footer.ts +1 -1
- package/src/plugins/builtin/account-management/keyboard.ts +4 -0
- package/src/plugins/builtin/account-management/model.ts +1 -0
- package/src/plugins/builtin/account-management/pane.tsx +75 -7
- package/src/plugins/builtin/account-management/payment-recovery-row.tsx +12 -5
- package/src/plugins/builtin/account-management/pro-cancel.tsx +197 -0
- package/src/plugins/builtin/account-management/trial-cancel.ts +1 -1
- package/src/plugins/builtin/alerts/cli-move.ts +2 -2
- package/src/plugins/builtin/alerts/cli.ts +36 -30
- package/src/plugins/builtin/alerts/constants.ts +10 -0
- package/src/plugins/builtin/alerts/earnings-listing.ts +20 -0
- package/src/plugins/builtin/alerts/format.ts +24 -8
- package/src/plugins/builtin/alerts/index.tsx +38 -9
- package/src/plugins/builtin/alerts/move-checks.ts +7 -0
- package/src/plugins/builtin/alerts/pane.tsx +1 -1
- package/src/plugins/builtin/alerts/quotes.ts +26 -2
- package/src/plugins/builtin/alerts/scheduled.ts +6 -1
- package/src/plugins/builtin/alerts/types.ts +7 -0
- package/src/plugins/builtin/analytics/manual-value.ts +61 -0
- package/src/plugins/builtin/analytics/risk-book.ts +7 -7
- package/src/plugins/builtin/analytics/risk-client.ts +26 -13
- package/src/plugins/builtin/analytics/risk-headless.ts +13 -8
- package/src/plugins/builtin/analytics/risk-model.ts +92 -4
- package/src/plugins/builtin/analytics/risk-pane.tsx +85 -38
- package/src/plugins/builtin/awards/pane.tsx +1 -1
- package/src/plugins/builtin/broker-trading/orders.tsx +2 -2
- package/src/plugins/builtin/central-bank-rates/model.ts +8 -2
- package/src/plugins/builtin/central-bank-rates/pane.tsx +5 -3
- package/src/plugins/builtin/chart-composer/cli-options.ts +4 -2
- package/src/plugins/builtin/chart-composer/data-catalog-pane.tsx +2 -6
- package/src/plugins/builtin/chart-composer/pane.tsx +5 -2
- package/src/plugins/builtin/cloud/auth-actions.tsx +11 -6
- package/src/plugins/builtin/cloud/company-picker.tsx +5 -3
- package/src/plugins/builtin/cloud/upgrade-command.ts +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +9 -4
- package/src/plugins/builtin/company-kpis/latest.ts +45 -0
- package/src/plugins/builtin/company-kpis/model.ts +38 -8
- package/src/plugins/builtin/company-kpis/pane.tsx +22 -8
- package/src/plugins/builtin/composite/alt-data.ts +20 -0
- package/src/plugins/builtin/composite/application.ts +14 -0
- package/src/plugins/builtin/composite/broker.ts +12 -0
- package/src/plugins/builtin/composite/credit.ts +33 -0
- package/src/plugins/builtin/composite/crypto.ts +10 -0
- package/src/plugins/builtin/composite/earnings.ts +12 -0
- package/src/plugins/builtin/composite/filings.ts +13 -0
- package/src/plugins/builtin/composite/futures-commodities.ts +23 -0
- package/src/plugins/builtin/composite/global-markets.ts +12 -0
- package/src/plugins/builtin/composite/options-volatility.ts +23 -0
- package/src/plugins/builtin/composite/ownership.ts +23 -0
- package/src/plugins/builtin/composite/portfolio.ts +10 -0
- package/src/plugins/builtin/composite/quant.ts +15 -0
- package/src/plugins/builtin/composite/rates-macro.ts +30 -0
- package/src/plugins/builtin/composite/screeners.ts +11 -0
- package/src/plugins/builtin/composite/shared.ts +11 -0
- package/src/plugins/builtin/composite/ticker-core.ts +36 -0
- package/src/plugins/builtin/congress-trades/headless.ts +31 -3
- package/src/plugins/builtin/correlation/index.tsx +13 -17
- package/src/plugins/builtin/correlation/matrix/model.ts +18 -0
- package/src/plugins/builtin/dividend-yield/client.ts +57 -16
- package/src/plugins/builtin/dividend-yield/headless.ts +17 -11
- package/src/plugins/builtin/dividend-yield/model.ts +4 -3
- package/src/plugins/builtin/dividend-yield/pane.tsx +22 -18
- package/src/plugins/builtin/dividend-yield/ranking.ts +1 -1
- package/src/plugins/builtin/dividend-yield/types.ts +4 -0
- package/src/plugins/builtin/dividend-yield/view.ts +23 -12
- package/src/plugins/builtin/earnings/fiscal-quarter.ts +39 -0
- package/src/plugins/builtin/earnings/headless.ts +7 -4
- package/src/plugins/builtin/earnings/history-model.ts +6 -4
- package/src/plugins/builtin/earnings/history-table.ts +4 -3
- package/src/plugins/builtin/earnings-calls/pane.tsx +8 -2
- package/src/plugins/builtin/econ/calendar-model.ts +16 -0
- package/src/plugins/builtin/econ/index.tsx +3 -0
- package/src/plugins/builtin/equity-screener/headless.ts +4 -1
- package/src/plugins/builtin/equity-screener/model.ts +7 -6
- package/src/plugins/builtin/estimate-revisions/headless.ts +1 -1
- package/src/plugins/builtin/exposure/model.ts +10 -0
- package/src/plugins/builtin/exposure/pane.tsx +10 -3
- package/src/plugins/builtin/fx-matrix/amount.ts +15 -1
- package/src/plugins/builtin/fx-matrix/headless.ts +12 -6
- package/src/plugins/builtin/fx-matrix/index.tsx +23 -5
- package/src/plugins/builtin/fx-matrix/settings.ts +9 -4
- package/src/plugins/builtin/kelly-sizer/pane.tsx +9 -4
- package/src/plugins/builtin/market-valuation/pane.tsx +22 -10
- package/src/plugins/builtin/mna/detail.tsx +67 -6
- package/src/plugins/builtin/mna/headless.ts +128 -13
- package/src/plugins/builtin/mna/model.ts +219 -16
- package/src/plugins/builtin/mna/pane.tsx +34 -6
- package/src/plugins/builtin/money-markets/model.ts +14 -5
- package/src/plugins/builtin/money-markets/pane.tsx +4 -3
- package/src/plugins/builtin/news/wire/news/footer.ts +3 -8
- package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +22 -6
- package/src/plugins/builtin/options-scenario/csp-screen.ts +39 -12
- package/src/plugins/builtin/options-scenario/strategy-screen.ts +7 -5
- package/src/plugins/builtin/pe-band/client.ts +13 -1
- package/src/plugins/builtin/pe-band/headless.ts +2 -2
- package/src/plugins/builtin/pe-band/model.ts +63 -10
- package/src/plugins/builtin/pe-band/pane.tsx +5 -5
- package/src/plugins/builtin/portfolio-list/allocation-rows.ts +26 -7
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +66 -13
- package/src/plugins/builtin/portfolio-list/cli/render.ts +76 -33
- package/src/plugins/builtin/portfolio-list/headless.ts +69 -22
- package/src/plugins/builtin/portfolio-list/pane/data.ts +3 -3
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +29 -14
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +2 -2
- package/src/plugins/builtin/relative-rotation/pane.tsx +2 -3
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +5 -1
- package/src/plugins/builtin/research/event-model.ts +31 -13
- package/src/plugins/builtin/research/headless.ts +8 -1
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +19 -17
- package/src/plugins/builtin/sectors/index.tsx +6 -9
- package/src/plugins/builtin/shared/cloud-upgrade.ts +1 -1
- package/src/plugins/builtin/shared/earnings-report.ts +19 -4
- package/src/plugins/builtin/shared/report-freshness.ts +2 -3
- package/src/plugins/builtin/supply-chain/client.ts +34 -9
- package/src/plugins/builtin/supply-chain/evidence.ts +3 -2
- package/src/plugins/builtin/supply-chain/flow.tsx +4 -3
- package/src/plugins/builtin/supply-chain/graph-model.ts +14 -7
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +3 -1
- package/src/plugins/builtin/supply-chain/graph.tsx +6 -3
- package/src/plugins/builtin/supply-chain/headless.ts +19 -4
- package/src/plugins/builtin/supply-chain/model.ts +50 -6
- package/src/plugins/builtin/supply-chain/pane.tsx +76 -16
- package/src/plugins/builtin/ticker-detail/adr-pair/ah.ts +62 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +119 -20
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +51 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +25 -14
- package/src/plugins/builtin/ticker-detail/overview/model.ts +17 -1
- package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -0
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +9 -2
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +9 -2
- package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +5 -2
- package/src/plugins/builtin/volatility/model.ts +17 -0
- package/src/plugins/builtin/volatility/pane.tsx +13 -4
- package/src/plugins/builtin/world-indices/index.tsx +2 -0
- package/src/plugins/builtin/world-indices/table.tsx +15 -0
- package/src/plugins/builtin/world-venue-map/evidence.ts +3 -2
- package/src/plugins/builtin/world-venue-map/headless.ts +28 -16
- package/src/plugins/builtin/world-venue-map/index.ts +19 -6
- package/src/plugins/builtin/world-venue-map/layered-pane.tsx +9 -5
- package/src/plugins/builtin/world-venue-map/layers.ts +33 -11
- package/src/plugins/builtin/world-venue-map/map.tsx +12 -0
- package/src/plugins/builtin/world-venue-map/pane.tsx +35 -6
- package/src/plugins/builtin/world-venue-map/place.ts +119 -0
- package/src/plugins/catalog-data.ts +20 -0
- package/src/plugins/catalog-lazy.ts +51 -0
- package/src/plugins/catalog-ui.ts +16 -18
- package/src/plugins/host-smoke.ts +5 -2
- package/src/portfolio/allocation.ts +79 -19
- package/src/portfolio/cash-balances.ts +76 -0
- package/src/portfolio/mutations.ts +43 -8
- package/src/public/__snapshots__/public-api.test.ts.snap +1 -0
- package/src/renderers/desktop/window-layouts.ts +14 -0
- package/src/renderers/dom/data-table/row.tsx +2 -0
- package/src/renderers/dom/host/tabs.tsx +57 -8
- package/src/renderers/dom/styles.css +13 -5
- package/src/renderers/electrobun/bun/desktop/backend-requests.ts +4 -0
- package/src/renderers/electrobun/bun/desktop/backend.ts +22 -1
- package/src/renderers/electrobun/bun/window/native-min-size.ts +6 -1
- package/src/renderers/electrobun/shared/protocol.ts +4 -0
- package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +50 -12
- package/src/renderers/electrobun/view/remote/ticker-repository.ts +10 -0
- package/src/series/standalone-catalog.ts +5 -4
- package/src/series/standalone.ts +13 -7
- package/src/sources/gloomberb-cloud/index.ts +14 -3
- package/src/sources/gloomberb-cloud/perpetuals.ts +60 -3
- package/src/sources/provider-router/financials.ts +20 -13
- package/src/sources/provider-router/index.ts +4 -0
- package/src/sources/provider-router/search.ts +1 -0
- package/src/sync/collections-contributor.ts +3 -1
- package/src/sync/config-merge.ts +10 -1
- package/src/sync/sanitize.ts +26 -2
- package/src/tickers/company-name-listing.ts +16 -2
- package/src/tickers/listing-fate.ts +12 -8
- package/src/tickers/renamed-listings.ts +43 -10
- package/src/tickers/search/home-listing.ts +28 -0
- package/src/tickers/search/index.ts +19 -7
- package/src/tickers/terminal-codes.ts +11 -1
- package/src/time-series/resolve.ts +3 -1
- package/src/time-series/spec.ts +2 -2
- package/src/time-series/types.ts +1 -1
- package/src/types/data-provider.ts +11 -0
- package/src/types/financials.ts +39 -3
- package/src/types/ticker.ts +10 -2
- package/src/utils/cli-output.ts +1 -1
- package/src/utils/declared-dividends.ts +13 -1
- package/src/utils/dividend-cash.ts +5 -1
- package/src/utils/forward-dividend.ts +4 -3
- package/src/utils/remove-folder.ts +37 -0
- package/src/utils/trailing-dividend.ts +1 -1
- package/src/plugins/builtin/composite-plugins.ts +0 -285
|
@@ -3,6 +3,8 @@ export type SupplyTier = 1 | 2 | 3 | 4 | 5 | 6;
|
|
|
3
3
|
export type SupplyTierFilter = "sec" | "company" | "call" | "reported" | "unconfirmed";
|
|
4
4
|
type SupplyClaim = "disclosed" | "company_confirmed" | "reported" | "rumored";
|
|
5
5
|
export interface SupplyOptions { tiers?: SupplyTierFilter[]; includeLeads?: boolean; }
|
|
6
|
+
/** A read of the disclosures: the trust filters, and the day they were known by (YYYY-MM-DD), when one is asked for. */
|
|
7
|
+
export type SupplyRead = SupplyOptions & { asOf?: string };
|
|
6
8
|
export interface SupplyEvidenceItem {
|
|
7
9
|
id: string;
|
|
8
10
|
tier: SupplyTier;
|
|
@@ -47,6 +49,13 @@ export interface SupplyRow {
|
|
|
47
49
|
direction: "in" | "out" | "mutual";
|
|
48
50
|
pctOfRevenue: number | null;
|
|
49
51
|
pctScope: string | null;
|
|
52
|
+
/**
|
|
53
|
+
* For a share tagged with a business segment, what the filing's sentence
|
|
54
|
+
* makes it a share of: "total" for the whole company's revenue the segment
|
|
55
|
+
* earns (NVDA's 16% of total revenue, from Compute & Networking), "segment"
|
|
56
|
+
* for the segment's own. Absent while unread, and from older servers.
|
|
57
|
+
*/
|
|
58
|
+
pctScopeBasis?: "total" | "segment" | null;
|
|
50
59
|
pctBasis: "revenue" | "receivables" | "cost" | "purchases" | null;
|
|
51
60
|
usd: number | null;
|
|
52
61
|
usdBasis: "disclosed" | "derived" | null;
|
|
@@ -38,12 +38,46 @@ interface CloudPricingTier {
|
|
|
38
38
|
|
|
39
39
|
/** `/account/cloud`, reduced to the plan fields the apps read. */
|
|
40
40
|
export interface CloudAccountPlan {
|
|
41
|
-
subscription
|
|
41
|
+
/** The account's own Cloud subscription; Pro through a team is never here. */
|
|
42
|
+
subscription?: {
|
|
43
|
+
status: string | null;
|
|
44
|
+
/** Paid or trialing now. */
|
|
45
|
+
active?: boolean;
|
|
46
|
+
/** ISO end of the period paid for: the renewal, or the end once cancelled. */
|
|
47
|
+
currentPeriodEnd?: string | null;
|
|
48
|
+
/** A cancel is scheduled for the period end. */
|
|
49
|
+
cancelAtPeriodEnd?: boolean;
|
|
50
|
+
};
|
|
42
51
|
effectivePlan?: "free" | "pro";
|
|
43
52
|
/** Whether a checkout started now comes with the free trial attached. */
|
|
44
53
|
trialAvailable?: boolean;
|
|
45
54
|
/** The last charge failed; checkout opens the unpaid invoice instead. */
|
|
46
55
|
paymentFailed?: boolean;
|
|
56
|
+
/** The team whose plan gives this account Pro, when its own plan does not. */
|
|
57
|
+
proTeam?: { id: string; name: string } | null;
|
|
58
|
+
/**
|
|
59
|
+
* ISO time the account first paid for Pro, while its own subscription is
|
|
60
|
+
* paid; null on a trial, through a team, or when unknown. Older servers
|
|
61
|
+
* leave it out.
|
|
62
|
+
*/
|
|
63
|
+
firstChargeAt?: string | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The one save offer the cancel flow can make, as the server decides it. */
|
|
67
|
+
export type CloudRetentionOffer = "trial_extension" | "discount";
|
|
68
|
+
|
|
69
|
+
/** The subscriber's price when it is below what a new subscriber pays, in integer cents. */
|
|
70
|
+
export interface CloudKeptPrice {
|
|
71
|
+
amount: number;
|
|
72
|
+
listAmount: number;
|
|
73
|
+
interval: "month" | "year";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** What the cancel flow offers this subscription, read as it opens. */
|
|
77
|
+
export interface CloudRetentionOfferAnswer {
|
|
78
|
+
offer: CloudRetentionOffer | null;
|
|
79
|
+
extendedTrialEndsAt: string | null;
|
|
80
|
+
keptPrice: CloudKeptPrice | null;
|
|
47
81
|
}
|
|
48
82
|
|
|
49
83
|
/** Moving a monthly Pro subscription to yearly billing, in integer cents. */
|
|
@@ -19,6 +19,7 @@ import { registerPaneDocsHandler } from "../docs/requests";
|
|
|
19
19
|
import { isMoveDownShortcut, isMoveUpShortcut } from "../components/command-bar/keyboard-handlers";
|
|
20
20
|
import { pressStarPromptKey } from "./star-prompt/runtime";
|
|
21
21
|
import { pressSinceLastVisitKey } from "./since-last-visit/keys";
|
|
22
|
+
import { pressProWelcomeKey } from "./pro-welcome/keys";
|
|
22
23
|
import {
|
|
23
24
|
copyActiveSelection,
|
|
24
25
|
isCopyShortcut,
|
|
@@ -177,8 +178,9 @@ export function useAppGlobalShortcuts({
|
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
// Toasts float above everything, so their keys work over a dialog too.
|
|
180
|
-
// The since-last-visit strip, then the
|
|
181
|
-
// the same keys once no toast does, but only over
|
|
181
|
+
// The since-last-visit strip, then the Pro row under it, then the status
|
|
182
|
+
// bar's star line, answer the same keys once no toast does, but only over
|
|
183
|
+
// the workspace itself.
|
|
182
184
|
if (action === "notification-action" || action === "notification-dismiss") {
|
|
183
185
|
if (ranAlready(action)) return;
|
|
184
186
|
const toastHandled = action === "notification-action"
|
|
@@ -190,7 +192,7 @@ export function useAppGlobalShortcuts({
|
|
|
190
192
|
&& !state.commandBarOpen
|
|
191
193
|
&& !state.inputCaptured
|
|
192
194
|
&& !isDetachedWindow
|
|
193
|
-
&& (pressSinceLastVisitKey(kind) || pressStarPromptKey(kind))
|
|
195
|
+
&& (pressSinceLastVisitKey(kind) || pressProWelcomeKey(kind) || pressStarPromptKey(kind))
|
|
194
196
|
);
|
|
195
197
|
if (handled) {
|
|
196
198
|
event.preventDefault();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface ProWelcomeKeyHandlers {
|
|
2
|
+
open(): void;
|
|
3
|
+
dismiss(): void;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** What the notification keys do while the row shows; null otherwise. */
|
|
7
|
+
let keyHandlers: ProWelcomeKeyHandlers | null = null;
|
|
8
|
+
|
|
9
|
+
/** Hands the notification keys to the row while it shows; returns the release. */
|
|
10
|
+
export function bindProWelcomeKeys(handlers: ProWelcomeKeyHandlers): () => void {
|
|
11
|
+
keyHandlers = handlers;
|
|
12
|
+
return () => {
|
|
13
|
+
if (keyHandlers === handlers) keyHandlers = null;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Runs the row's open (its first function) or dismiss for the notification
|
|
19
|
+
* keys. False when the row is not showing, so the key goes on to whatever
|
|
20
|
+
* else wants it.
|
|
21
|
+
*/
|
|
22
|
+
export function pressProWelcomeKey(kind: "open" | "dismiss"): boolean {
|
|
23
|
+
if (!keyHandlers) return false;
|
|
24
|
+
if (kind === "open") keyHandlers.open();
|
|
25
|
+
else keyHandlers.dismiss();
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { CloudAccountPlan } from "../../api-client";
|
|
2
|
+
import type { PlanAccess } from "../../api-client/plan-rules";
|
|
3
|
+
import { kindFromListingSyntax, resolveTickerInstrumentKind } from "../../tickers/instrument-kind";
|
|
4
|
+
import type { AppConfig } from "../../types/config";
|
|
5
|
+
import type { TickerInstrumentKind } from "../../types/instrument";
|
|
6
|
+
import type { TickerRecord } from "../../types/ticker";
|
|
7
|
+
import { trackedListings } from "../since-last-visit/model";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The row a new Pro payer sees in their first two weeks: a few Pro functions
|
|
11
|
+
* they have not opened yet, each on one of their own tickers. Everything it
|
|
12
|
+
* reads is already on this machine (the command bar's recent runs, the
|
|
13
|
+
* layouts, the portfolios, watchlists and recently viewed tickers) except the
|
|
14
|
+
* first charge's date, which the account's own plan answer carries. Nothing
|
|
15
|
+
* about it is kept per account or sent anywhere.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const DAY_MS = 86_400_000;
|
|
19
|
+
/** Days after the first paid charge the row may show: day 0 (the charge) through this one. */
|
|
20
|
+
const PRO_WELCOME_LAST_DAY = 14;
|
|
21
|
+
/** Fewer unopened functions than this and the row has nothing worth a row. */
|
|
22
|
+
const MIN_FUNCTIONS = 2;
|
|
23
|
+
const MAX_FUNCTIONS = 3;
|
|
24
|
+
|
|
25
|
+
/** A Pro function the row can name: its command, what it is, and the tickers it has data for. */
|
|
26
|
+
export interface ProWelcomeFunction {
|
|
27
|
+
templateId: string;
|
|
28
|
+
/** The command bar's mnemonic (`CALLS`), which the button's tooltip teaches. */
|
|
29
|
+
shortcut: string;
|
|
30
|
+
/** What it is, ahead of the ticker: "Earnings calls" AAPL. */
|
|
31
|
+
label: string;
|
|
32
|
+
kinds: readonly TickerInstrumentKind[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Pro's functions that open on a ticker, in the order the upgrade sheet
|
|
37
|
+
* sells them: earnings calls, then options flow and X, then the rest.
|
|
38
|
+
*/
|
|
39
|
+
const PRO_WELCOME_FUNCTIONS: readonly ProWelcomeFunction[] = [
|
|
40
|
+
{ templateId: "earnings-calls-pane", shortcut: "CALLS", label: "Earnings calls", kinds: ["equity"] },
|
|
41
|
+
{ templateId: "scanner-flow-pane", shortcut: "FLOW", label: "Options flow", kinds: ["equity", "fund"] },
|
|
42
|
+
{ templateId: "social-mentions-pane", shortcut: "BUZZ", label: "X mentions", kinds: ["equity", "fund", "crypto"] },
|
|
43
|
+
{ templateId: "jobs-pane", shortcut: "JOBS", label: "Hiring", kinds: ["equity"] },
|
|
44
|
+
{ templateId: "filing-events-pane", shortcut: "EK", label: "8-K events", kinds: ["equity"] },
|
|
45
|
+
{ templateId: "risk-factors-pane", shortcut: "RISK", label: "Risk factors", kinds: ["equity"] },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
/** One button on the row: a function on one of the user's tickers. */
|
|
49
|
+
export interface ProWelcomeChip {
|
|
50
|
+
fn: ProWelcomeFunction;
|
|
51
|
+
symbol: string;
|
|
52
|
+
/** The saved ticker, when the symbol is one; the pane opens on it. */
|
|
53
|
+
ticker: TickerRecord | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ProWelcomeEligibility {
|
|
57
|
+
access: Pick<PlanAccess, "isPayingPro" | "isTrialActive">;
|
|
58
|
+
/** The account's plan answer; null until it came. */
|
|
59
|
+
plan: Pick<CloudAccountPlan, "firstChargeAt" | "proTeam"> | null;
|
|
60
|
+
/** Dismissed for good on this machine. */
|
|
61
|
+
dismissed: boolean;
|
|
62
|
+
now: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A payer of their own Pro plan from the day of their first paid charge
|
|
67
|
+
* through day 14. Not on a trial (no charge yet), not with Pro through a team
|
|
68
|
+
* seat, not once dismissed, and not when the server gave no first charge.
|
|
69
|
+
*/
|
|
70
|
+
export function proWelcomeEligible({ access, plan, dismissed, now }: ProWelcomeEligibility): boolean {
|
|
71
|
+
if (dismissed || !access.isPayingPro || access.isTrialActive) return false;
|
|
72
|
+
if (!plan || plan.proTeam) return false;
|
|
73
|
+
const firstCharge = Date.parse(plan.firstChargeAt ?? "");
|
|
74
|
+
if (!Number.isFinite(firstCharge)) return false;
|
|
75
|
+
// A charge a moment ahead of this machine's clock is today's.
|
|
76
|
+
const day = Math.floor(Math.max(0, now - firstCharge) / DAY_MS);
|
|
77
|
+
return day <= PRO_WELCOME_LAST_DAY;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type LayoutsConfig = Pick<AppConfig, "layout" | "layouts" | "recentCommands">;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The pane templates this machine shows the user opened: run from the
|
|
84
|
+
* command bar lately, or open in a layout (saved ones too).
|
|
85
|
+
*/
|
|
86
|
+
export function openedFunctions(
|
|
87
|
+
config: LayoutsConfig,
|
|
88
|
+
paneIdOf: (templateId: string) => string | null,
|
|
89
|
+
functions: readonly ProWelcomeFunction[] = PRO_WELCOME_FUNCTIONS,
|
|
90
|
+
): Set<string> {
|
|
91
|
+
const paneIds = new Set<string>();
|
|
92
|
+
for (const layout of [config.layout, ...config.layouts.map((saved) => saved.layout)]) {
|
|
93
|
+
for (const instance of layout?.instances ?? []) paneIds.add(instance.paneId);
|
|
94
|
+
}
|
|
95
|
+
const ran = new Set((config.recentCommands ?? []).map((command) => command.id));
|
|
96
|
+
const opened = new Set<string>();
|
|
97
|
+
for (const fn of functions) {
|
|
98
|
+
const paneId = paneIdOf(fn.templateId);
|
|
99
|
+
if (ran.has(`pane-template:${fn.templateId}`) || (paneId && paneIds.has(paneId))) opened.add(fn.templateId);
|
|
100
|
+
}
|
|
101
|
+
return opened;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface OwnTicker {
|
|
105
|
+
symbol: string;
|
|
106
|
+
ticker: TickerRecord | null;
|
|
107
|
+
kind: TickerInstrumentKind;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The user's own tickers, best first: holdings, then watchlists (team
|
|
112
|
+
* collections and imported portfolios are not their own), and with none of
|
|
113
|
+
* those the tickers they viewed most recently.
|
|
114
|
+
*/
|
|
115
|
+
export function ownTickers(
|
|
116
|
+
config: Pick<AppConfig, "portfolios" | "watchlists">,
|
|
117
|
+
tickers: ReadonlyMap<string, TickerRecord>,
|
|
118
|
+
recentTickers: readonly string[],
|
|
119
|
+
): OwnTicker[] {
|
|
120
|
+
const tracked = trackedListings(config, tickers).map(({ symbol }) => symbol);
|
|
121
|
+
const symbols = tracked.length > 0 ? tracked : recentTickers;
|
|
122
|
+
const seen = new Set<string>();
|
|
123
|
+
const own: OwnTicker[] = [];
|
|
124
|
+
for (const symbol of symbols) {
|
|
125
|
+
if (!symbol || seen.has(symbol)) continue;
|
|
126
|
+
seen.add(symbol);
|
|
127
|
+
const ticker = tickers.get(symbol) ?? null;
|
|
128
|
+
const kind = ticker ? resolveTickerInstrumentKind(ticker) : kindFromListingSyntax(symbol) ?? "equity";
|
|
129
|
+
own.push({ symbol, ticker, kind });
|
|
130
|
+
}
|
|
131
|
+
return own;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Two or three functions the user has not opened, each on one of their own
|
|
136
|
+
* tickers it has data for, a different one each while there are enough;
|
|
137
|
+
* empty when fewer than two can be named. `available` leaves out a function
|
|
138
|
+
* whose plugin is off or missing.
|
|
139
|
+
*/
|
|
140
|
+
export function pickProWelcomeChips(
|
|
141
|
+
own: readonly OwnTicker[],
|
|
142
|
+
opened: ReadonlySet<string>,
|
|
143
|
+
available: (templateId: string) => boolean,
|
|
144
|
+
functions: readonly ProWelcomeFunction[] = PRO_WELCOME_FUNCTIONS,
|
|
145
|
+
): ProWelcomeChip[] {
|
|
146
|
+
const chips: ProWelcomeChip[] = [];
|
|
147
|
+
const used = new Set<string>();
|
|
148
|
+
for (const fn of functions) {
|
|
149
|
+
if (chips.length >= MAX_FUNCTIONS) break;
|
|
150
|
+
if (opened.has(fn.templateId) || !available(fn.templateId)) continue;
|
|
151
|
+
const fits = own.filter((entry) => fn.kinds.includes(entry.kind));
|
|
152
|
+
const pick = fits.find((entry) => !used.has(entry.symbol)) ?? fits[0];
|
|
153
|
+
if (!pick) continue;
|
|
154
|
+
used.add(pick.symbol);
|
|
155
|
+
chips.push({ fn, symbol: pick.symbol, ticker: pick.ticker });
|
|
156
|
+
}
|
|
157
|
+
return chips.length >= MIN_FUNCTIONS ? chips : [];
|
|
158
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { Box, Text, useActionShortcut, useUiCapabilities } from "../../ui";
|
|
3
|
+
import { Button, terminalButtonColumns } from "../../components/ui/button";
|
|
4
|
+
import { DesktopPaneLinkChip, TerminalPaneLinkChip } from "../../components/ui/pane-link-chip";
|
|
5
|
+
import { t, tf } from "../../i18n";
|
|
6
|
+
import { useAppLanguage } from "../../i18n/react";
|
|
7
|
+
import { useViewport } from "../../react/input";
|
|
8
|
+
import { useThemeColors } from "../../theme/theme-context";
|
|
9
|
+
import { displayWidth } from "../../utils/format";
|
|
10
|
+
import { bindProWelcomeKeys } from "./keys";
|
|
11
|
+
import type { ProWelcomeChip } from "./model";
|
|
12
|
+
import type { ProWelcome } from "./use-pro-welcome";
|
|
13
|
+
|
|
14
|
+
/** Cells between the lead and the chips, and before Dismiss. */
|
|
15
|
+
const GAP = 2;
|
|
16
|
+
/** A window this wide (in cells) says the lead and the functions in full on the desktop and the web. */
|
|
17
|
+
const NATIVE_FULL_COLUMNS = 110;
|
|
18
|
+
|
|
19
|
+
interface RowFit {
|
|
20
|
+
lead: string;
|
|
21
|
+
/** Functions by their mnemonic (`CALLS · AAPL`) rather than their name. */
|
|
22
|
+
short: boolean;
|
|
23
|
+
chips: number;
|
|
24
|
+
dismissKey: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** What a chip says: the function and the ticker it opens on, short as the command itself (`CALLS AAPL`). */
|
|
28
|
+
function chipText(chip: ProWelcomeChip, short: boolean): string {
|
|
29
|
+
return short ? `${chip.fn.shortcut} ${chip.symbol}` : `${t(chip.fn.label)} · ${chip.symbol}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The chip's lead square: the function's letter, as its pane's chip has. */
|
|
33
|
+
function chipIcon(chip: ProWelcomeChip): string {
|
|
34
|
+
return chip.fn.shortcut.slice(0, 1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A terminal chip's cells: its square, its words and the space after them, then one between chips. */
|
|
38
|
+
function terminalChipColumns(chip: ProWelcomeChip, short: boolean): number {
|
|
39
|
+
return displayWidth(` ${chipIcon(chip)} `) + displayWidth(chipText(chip, short)) + 1 + 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* What the terminal's one row has room for: a lead and Dismiss always; then
|
|
44
|
+
* every function by its name, else by its command, else as many as fit;
|
|
45
|
+
* then Dismiss's key; then the lead in full. A window too narrow for any
|
|
46
|
+
* function says the least lead and one command when one fits.
|
|
47
|
+
*/
|
|
48
|
+
function fitTerminalRow(
|
|
49
|
+
width: number,
|
|
50
|
+
chips: readonly ProWelcomeChip[],
|
|
51
|
+
[fullLead, shortLead, tinyLead]: readonly [string, string, string],
|
|
52
|
+
dismissColumns: { withKey: number; bare: number },
|
|
53
|
+
): RowFit {
|
|
54
|
+
const fit = (option: Omit<RowFit, "chips">): RowFit => {
|
|
55
|
+
let room = width - 2 - displayWidth(option.lead) - GAP - GAP
|
|
56
|
+
- (option.dismissKey ? dismissColumns.withKey : dismissColumns.bare);
|
|
57
|
+
let count = 0;
|
|
58
|
+
for (const chip of chips) {
|
|
59
|
+
const columns = terminalChipColumns(chip, option.short);
|
|
60
|
+
if (columns > room) break;
|
|
61
|
+
room -= columns;
|
|
62
|
+
count += 1;
|
|
63
|
+
}
|
|
64
|
+
return { ...option, chips: count };
|
|
65
|
+
};
|
|
66
|
+
const options = [
|
|
67
|
+
fit({ lead: fullLead, short: false, dismissKey: true }),
|
|
68
|
+
fit({ lead: shortLead, short: false, dismissKey: true }),
|
|
69
|
+
fit({ lead: shortLead, short: true, dismissKey: true }),
|
|
70
|
+
fit({ lead: shortLead, short: true, dismissKey: false }),
|
|
71
|
+
fit({ lead: tinyLead, short: true, dismissKey: false }),
|
|
72
|
+
];
|
|
73
|
+
const whole = options.find((option) => option.chips === chips.length);
|
|
74
|
+
if (whole) return whole;
|
|
75
|
+
const most = options.reduce((best, option) => (option.chips > best.chips ? option : best));
|
|
76
|
+
return most.chips > 0 ? most : options.at(-1)!;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The row a new Pro payer sees under the header in their first two weeks: a
|
|
81
|
+
* few Pro functions they have not opened, each a chip that opens it on one
|
|
82
|
+
* of their own tickers. Dismiss puts it away for good on this machine (the
|
|
83
|
+
* notification dismiss key too; the notification action key opens the first).
|
|
84
|
+
*/
|
|
85
|
+
export function ProWelcomeRow({ welcome }: { welcome: ProWelcome }) {
|
|
86
|
+
useAppLanguage();
|
|
87
|
+
const colors = useThemeColors();
|
|
88
|
+
const { nativePaneChrome = false } = useUiCapabilities();
|
|
89
|
+
const { width } = useViewport();
|
|
90
|
+
const dismissKey = useActionShortcut("notification-dismiss");
|
|
91
|
+
const chips = welcome.chips ?? [];
|
|
92
|
+
const first = chips[0] ?? null;
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!first) return;
|
|
96
|
+
return bindProWelcomeKeys({ open: () => welcome.open(first), dismiss: welcome.dismiss });
|
|
97
|
+
}, [first, welcome]);
|
|
98
|
+
|
|
99
|
+
if (chips.length === 0) return null;
|
|
100
|
+
|
|
101
|
+
const fullLead = t("Try Pro on your tickers");
|
|
102
|
+
const shortLead = t("Try Pro");
|
|
103
|
+
const tinyLead = "Pro";
|
|
104
|
+
const dismissButton = { label: "Dismiss", compact: true, shortcut: dismissKey || undefined } as const;
|
|
105
|
+
const bareDismissButton = { label: "Dismiss", compact: true } as const;
|
|
106
|
+
const wide = width >= NATIVE_FULL_COLUMNS;
|
|
107
|
+
// The desktop and the web lay the chips out in CSS: one that has no room wraps out of sight.
|
|
108
|
+
const fit: RowFit = nativePaneChrome
|
|
109
|
+
? { lead: wide ? fullLead : shortLead, short: !wide, chips: chips.length, dismissKey: true }
|
|
110
|
+
: fitTerminalRow(
|
|
111
|
+
width,
|
|
112
|
+
chips,
|
|
113
|
+
[fullLead, shortLead, tinyLead],
|
|
114
|
+
{ withKey: terminalButtonColumns(dismissButton), bare: terminalButtonColumns(bareDismissButton) },
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const chipNodes = chips.slice(0, fit.chips).map((chip) => {
|
|
118
|
+
const command = `${chip.fn.shortcut} ${chip.symbol}`;
|
|
119
|
+
return nativePaneChrome ? (
|
|
120
|
+
<DesktopPaneLinkChip
|
|
121
|
+
key={chip.fn.templateId}
|
|
122
|
+
content={{ title: chipText(chip, fit.short), detail: "", icon: chipIcon(chip) }}
|
|
123
|
+
variant="inline"
|
|
124
|
+
onOpen={() => welcome.open(chip)}
|
|
125
|
+
tooltip={tf("Open {command}", { command })}
|
|
126
|
+
role="pro-welcome-chip"
|
|
127
|
+
linkKey={`pro-welcome:${chip.fn.shortcut}`}
|
|
128
|
+
/>
|
|
129
|
+
) : (
|
|
130
|
+
<Box key={chip.fn.templateId} paddingRight={1}>
|
|
131
|
+
<TerminalPaneLinkChip
|
|
132
|
+
content={{ title: chipText(chip, fit.short), detail: "", icon: chipIcon(chip) }}
|
|
133
|
+
width={terminalChipColumns(chip, fit.short) - 1}
|
|
134
|
+
onOpen={() => welcome.open(chip)}
|
|
135
|
+
/>
|
|
136
|
+
</Box>
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<Box
|
|
142
|
+
flexDirection="row"
|
|
143
|
+
height={1}
|
|
144
|
+
alignItems="center"
|
|
145
|
+
flexShrink={0}
|
|
146
|
+
backgroundColor={colors.panel}
|
|
147
|
+
data-gloom-role="pro-welcome"
|
|
148
|
+
style={nativePaneChrome ? { paddingInline: "var(--gloom-inset)", gap: "var(--gloom-space-sm)" } : undefined}
|
|
149
|
+
paddingX={nativePaneChrome ? undefined : 1}
|
|
150
|
+
>
|
|
151
|
+
<Box flexShrink={0} paddingRight={nativePaneChrome ? undefined : GAP}>
|
|
152
|
+
<Text fg={colors.textDim}>{fit.lead}</Text>
|
|
153
|
+
</Box>
|
|
154
|
+
<Box
|
|
155
|
+
flexDirection="row"
|
|
156
|
+
flexGrow={1}
|
|
157
|
+
flexShrink={1}
|
|
158
|
+
minWidth={0}
|
|
159
|
+
overflow="hidden"
|
|
160
|
+
// A chip the window has no room for wraps out of sight rather than being cut.
|
|
161
|
+
style={nativePaneChrome ? { flexWrap: "wrap", height: "100%", alignContent: "flex-start", alignItems: "center", gap: "var(--gloom-space-sm)" } : undefined}
|
|
162
|
+
>
|
|
163
|
+
{chipNodes}
|
|
164
|
+
</Box>
|
|
165
|
+
<Box flexDirection="row" flexShrink={0} paddingLeft={nativePaneChrome ? undefined : GAP}>
|
|
166
|
+
<Button
|
|
167
|
+
{...(fit.dismissKey ? dismissButton : bareDismissButton)}
|
|
168
|
+
variant="plain"
|
|
169
|
+
title={t("Stop suggesting Pro functions")}
|
|
170
|
+
stopPropagation
|
|
171
|
+
onPress={welcome.dismiss}
|
|
172
|
+
/>
|
|
173
|
+
</Box>
|
|
174
|
+
</Box>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { apiClient, type CloudAccountPlan } from "../../api-client";
|
|
3
|
+
import { usePlanAccess } from "../../api-client/plan-access";
|
|
4
|
+
import { getPaneTemplateDisplayLabel } from "../../components/command-bar/pane-templates/items";
|
|
5
|
+
import type { AppPluginStateStorePort } from "../../core/app-service-ports";
|
|
6
|
+
import type { PluginRegistry } from "../../plugins/registry";
|
|
7
|
+
import { useAppDispatch, useAppSelector } from "../../state/app/context";
|
|
8
|
+
import { recordFunctionOpen } from "../../telemetry/usage-counts";
|
|
9
|
+
import { logFailure } from "../../utils/log-failure";
|
|
10
|
+
import {
|
|
11
|
+
openedFunctions,
|
|
12
|
+
ownTickers,
|
|
13
|
+
pickProWelcomeChips,
|
|
14
|
+
proWelcomeEligible,
|
|
15
|
+
type ProWelcomeChip,
|
|
16
|
+
} from "./model";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether the row was dismissed lives in the app's local state store (SQLite
|
|
20
|
+
* in the terminal and the desktop app, browser storage on the web), for this
|
|
21
|
+
* machine, never in config.json, cloud sync or anything sent anywhere.
|
|
22
|
+
*/
|
|
23
|
+
const STATE_OWNER = "core.pro-welcome";
|
|
24
|
+
const DISMISSED_KEY = "dismissed";
|
|
25
|
+
|
|
26
|
+
export interface ProWelcome {
|
|
27
|
+
/** The functions the row names while it shows; null otherwise. */
|
|
28
|
+
chips: ProWelcomeChip[] | null;
|
|
29
|
+
/** Opens a function on its ticker, as the command bar would run it. */
|
|
30
|
+
open(chip: ProWelcomeChip): void;
|
|
31
|
+
/** Puts the row away for good on this machine. */
|
|
32
|
+
dismiss(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface UseProWelcomeOptions {
|
|
36
|
+
/** This window shows the row: the main window, with no setup or sign-in in front of the workspace. */
|
|
37
|
+
active: boolean;
|
|
38
|
+
pluginState: Pick<AppPluginStateStorePort, "get" | "set">;
|
|
39
|
+
pluginRegistry: Pick<PluginRegistry, "paneTemplates" | "createPaneFromTemplateAsync">;
|
|
40
|
+
/** Settles once every plugin has registered: the functions and the account are known by then. */
|
|
41
|
+
pluginsReady?: Promise<unknown>;
|
|
42
|
+
/** Defaults to the Cloud API client's `/account/cloud`. */
|
|
43
|
+
loadPlan?: () => Promise<CloudAccountPlan>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function readDismissed(pluginState: Pick<AppPluginStateStorePort, "get">): boolean {
|
|
47
|
+
try {
|
|
48
|
+
return pluginState.get<boolean>(STATE_OWNER, DISMISSED_KEY)?.value === true;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
logFailure("pro-welcome", "Reading whether the Pro row was dismissed failed")(error);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The first-weeks Pro row's session (see `./model.ts` for who sees it and
|
|
57
|
+
* what it names). The account's plan is asked for once a session, and only
|
|
58
|
+
* for a paying Pro account that has not dismissed the row.
|
|
59
|
+
*/
|
|
60
|
+
export function useProWelcome({
|
|
61
|
+
active,
|
|
62
|
+
pluginState,
|
|
63
|
+
pluginRegistry,
|
|
64
|
+
pluginsReady,
|
|
65
|
+
loadPlan = () => apiClient.getCloudAccountPlan(),
|
|
66
|
+
}: UseProWelcomeOptions): ProWelcome {
|
|
67
|
+
const dispatch = useAppDispatch();
|
|
68
|
+
const initialized = useAppSelector((state) => state.initialized);
|
|
69
|
+
const layout = useAppSelector((state) => state.config.layout);
|
|
70
|
+
const layouts = useAppSelector((state) => state.config.layouts);
|
|
71
|
+
const recentCommands = useAppSelector((state) => state.config.recentCommands);
|
|
72
|
+
const portfolios = useAppSelector((state) => state.config.portfolios);
|
|
73
|
+
const watchlists = useAppSelector((state) => state.config.watchlists);
|
|
74
|
+
const disabledPlugins = useAppSelector((state) => state.config.disabledPlugins);
|
|
75
|
+
const tickers = useAppSelector((state) => state.tickers);
|
|
76
|
+
const recentTickers = useAppSelector((state) => state.recentTickers);
|
|
77
|
+
const access = usePlanAccess();
|
|
78
|
+
const accountId = access.signedIn ? apiClient.getCurrentUser()?.id ?? null : null;
|
|
79
|
+
|
|
80
|
+
const [ready, setReady] = useState(!pluginsReady);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (!pluginsReady) return;
|
|
83
|
+
let live = true;
|
|
84
|
+
const done = () => {
|
|
85
|
+
if (live) setReady(true);
|
|
86
|
+
};
|
|
87
|
+
pluginsReady.then(done, done);
|
|
88
|
+
return () => {
|
|
89
|
+
live = false;
|
|
90
|
+
};
|
|
91
|
+
}, [pluginsReady]);
|
|
92
|
+
|
|
93
|
+
const [dismissed, setDismissed] = useState(() => readDismissed(pluginState));
|
|
94
|
+
const [plan, setPlan] = useState<{ accountId: string; plan: CloudAccountPlan } | null>(null);
|
|
95
|
+
const asked = useRef(new Set<string>());
|
|
96
|
+
const loadPlanRef = useRef(loadPlan);
|
|
97
|
+
loadPlanRef.current = loadPlan;
|
|
98
|
+
const wanted = active && initialized && ready && !dismissed && access.isPayingPro && !!accountId;
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (!wanted || !accountId || asked.current.has(accountId)) return;
|
|
102
|
+
asked.current.add(accountId);
|
|
103
|
+
// Kept under the account it is for: one that signed in since never reads it.
|
|
104
|
+
loadPlanRef.current().then(
|
|
105
|
+
(next) => setPlan({ accountId, plan: next }),
|
|
106
|
+
// The row is a nicety: without an answer it stays away until the next launch.
|
|
107
|
+
logFailure("pro-welcome", "Loading the account's plan failed"),
|
|
108
|
+
);
|
|
109
|
+
}, [accountId, wanted]);
|
|
110
|
+
|
|
111
|
+
const eligible = wanted && plan?.accountId === accountId && proWelcomeEligible({
|
|
112
|
+
access,
|
|
113
|
+
plan: plan.plan,
|
|
114
|
+
dismissed,
|
|
115
|
+
now: Date.now(),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const chips = useMemo(() => {
|
|
119
|
+
if (!eligible) return null;
|
|
120
|
+
const paneIdOf = (templateId: string) => pluginRegistry.paneTemplates.get(templateId)?.paneId ?? null;
|
|
121
|
+
const opened = openedFunctions({ layout, layouts, recentCommands }, paneIdOf);
|
|
122
|
+
const own = ownTickers({ portfolios, watchlists }, tickers, recentTickers);
|
|
123
|
+
const picked = pickProWelcomeChips(own, opened, (templateId) => pluginRegistry.paneTemplates.has(templateId));
|
|
124
|
+
return picked.length > 0 ? picked : null;
|
|
125
|
+
// The templates follow the plugins turned on and off.
|
|
126
|
+
}, [disabledPlugins, eligible, layout, layouts, pluginRegistry, portfolios, recentCommands, recentTickers, tickers, watchlists]);
|
|
127
|
+
|
|
128
|
+
const open = useCallback((chip: ProWelcomeChip) => {
|
|
129
|
+
const template = pluginRegistry.paneTemplates.get(chip.fn.templateId);
|
|
130
|
+
if (!template) return;
|
|
131
|
+
// Kept as the command bar keeps its runs, so the row stops naming it.
|
|
132
|
+
dispatch({
|
|
133
|
+
type: "RECORD_COMMAND",
|
|
134
|
+
id: `pane-template:${template.id}`,
|
|
135
|
+
label: getPaneTemplateDisplayLabel(template),
|
|
136
|
+
arg: chip.symbol,
|
|
137
|
+
});
|
|
138
|
+
recordFunctionOpen({ shortcut: chip.fn.shortcut, externalPluginId: null });
|
|
139
|
+
pluginRegistry.createPaneFromTemplateAsync(template.id, {
|
|
140
|
+
arg: chip.symbol,
|
|
141
|
+
symbol: chip.symbol,
|
|
142
|
+
...(chip.ticker ? { ticker: chip.ticker } : {}),
|
|
143
|
+
}).catch(logFailure("pro-welcome", "Opening a Pro function from the row failed"));
|
|
144
|
+
}, [dispatch, pluginRegistry]);
|
|
145
|
+
|
|
146
|
+
const dismiss = useCallback(() => {
|
|
147
|
+
setDismissed(true);
|
|
148
|
+
try {
|
|
149
|
+
pluginState.set(STATE_OWNER, DISMISSED_KEY, true);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
logFailure("pro-welcome", "Saving the Pro row's dismissal failed")(error);
|
|
152
|
+
}
|
|
153
|
+
}, [pluginState]);
|
|
154
|
+
|
|
155
|
+
return useMemo(() => ({ chips, open, dismiss }), [chips, dismiss, open]);
|
|
156
|
+
}
|