gloomberb 0.20.13 → 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 +2 -1
- package/patches/@opentui%2Fcore@0.3.2.patch +22 -4
- package/src/account/auth-dialog.tsx +22 -4
- package/src/account/auth-form.tsx +6 -1
- package/src/account/checkout-handoff.tsx +7 -14
- package/src/account/device-signin-dialog.tsx +35 -24
- package/src/api-client/crypto-markets.ts +10 -0
- package/src/api-client/errors.ts +3 -1
- package/src/api-client/index.ts +54 -0
- package/src/api-client/install-experiments.ts +8 -7
- package/src/api-client/money-markets.ts +7 -0
- package/src/api-client/paths.ts +2 -1
- package/src/api-client/product-waitlist.ts +63 -0
- package/src/api-client/request.ts +16 -4
- 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/architecture/floating-promise-allowlist.json +0 -1
- package/src/brokers/signed-in/sign-in-dialog.tsx +38 -38
- package/src/cli/commands/market.ts +103 -27
- package/src/cli/commands/overview.ts +18 -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/errors.ts +3 -1
- package/src/cli/freshness.ts +7 -2
- package/src/cli/glossary.ts +10 -5
- package/src/cli/help.ts +1 -0
- package/src/cli/helpers.ts +8 -16
- package/src/cli/history-export.ts +4 -0
- package/src/cli/history-rows.ts +24 -0
- package/src/cli/index.ts +4 -0
- package/src/cli/known-gaps.ts +2 -2
- package/src/cli/listing-arg.ts +79 -11
- package/src/cli/not-a-ticker.ts +4 -0
- package/src/cli/options.ts +29 -1
- package/src/cli/pane-functions/catalog.ts +70 -12
- package/src/cli/pane-functions/function-help.ts +1 -1
- package/src/cli/pane-functions/headless.ts +68 -3
- package/src/cli/pane-functions/index.ts +2 -2
- package/src/cli/pane-functions/options.ts +7 -0
- package/src/cli/pane-functions/resolver.ts +104 -15
- package/src/cli/pane-functions/screenshot-payload.ts +3 -0
- package/src/cli/report-tables.ts +20 -5
- package/src/cli/result.ts +22 -4
- package/src/cli/shot-temp-dir.ts +30 -0
- package/src/cli/suffixed-listing-rows.ts +11 -0
- package/src/cli/symbol-args.ts +5 -3
- package/src/cli/symbol-list.ts +23 -10
- package/src/cli/symbol-rows.ts +135 -3
- package/src/cli/treasury-yields.ts +15 -1
- package/src/components/chart/composite/composite-chart.tsx +3 -3
- package/src/components/chart/composite/format.ts +2 -1
- package/src/components/chart/composite/panel-surface/axis-markers.ts +133 -0
- package/src/components/chart/composite/panel-surface/level-labels.tsx +78 -0
- package/src/components/chart/composite/panel-surface/overlays.ts +108 -0
- package/src/components/chart/composite/panel-surface/pan-coast.ts +54 -0
- package/src/components/chart/composite/panel-surface/panel-cursor.tsx +138 -0
- package/src/components/chart/composite/panel-surface/panel-levels.ts +47 -0
- package/src/components/chart/composite/panel-surface/plot-gestures.ts +403 -0
- package/src/components/chart/composite/panel-surface/plot-pointer.ts +65 -0
- package/src/components/chart/composite/panel-surface/plot-wheel.ts +102 -0
- package/src/components/chart/composite/panel-surface/pointer.ts +12 -0
- package/src/components/chart/composite/panel-surface/props.ts +79 -0
- package/src/components/chart/composite/panel-surface/tool-readout.ts +151 -0
- package/src/components/chart/composite/panel-surface/value-axis-gestures.ts +152 -0
- package/src/components/chart/composite/panel-surface.tsx +81 -1177
- package/src/components/command-bar/commands/collection-list.ts +1 -0
- 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 +19 -2
- package/src/components/command-bar/routes/root/runtime.ts +3 -2
- package/src/components/command-bar/routes/root/selection.ts +3 -2
- package/src/components/command-bar/routes/root/shortcuts.ts +15 -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 +16 -6
- package/src/components/layout/shell/index.tsx +5 -1
- package/src/components/layout/shell/ticker-link-menu.ts +12 -9
- package/src/components/pane-settings-dialog/tui.tsx +6 -3
- package/src/components/pane-settings-dialog.tsx +2 -1
- package/src/components/pane-template-wizard.tsx +2 -0
- 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/choice-dialog.tsx +1 -1
- package/src/components/ui/confirm-dialog.tsx +3 -2
- 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/components/ui/frame.tsx +7 -3
- package/src/components/ui/icon.tsx +4 -2
- package/src/components/ui/list-view.tsx +8 -0
- package/src/components/ui/number-prompt-dialog.tsx +2 -1
- package/src/components/use-pane-notice-footer.tsx +3 -1
- 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/docs/snapshot.json +2 -2
- package/src/i18n/es.ts +39 -0
- package/src/i18n/ja.ts +39 -0
- package/src/i18n/ko.ts +39 -0
- package/src/i18n/zh-cn.ts +39 -0
- package/src/i18n/zh-tw.ts +39 -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/format.ts +35 -1
- package/src/market-data/market/index-level.ts +19 -0
- package/src/market-data/quotes/contributions.ts +13 -0
- package/src/market-data/quotes/export-identity.ts +36 -1
- package/src/market-data/quotes/resolution.ts +16 -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/password-dialog.tsx +2 -2
- 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/analytics/risk-client.ts +12 -2
- package/src/plugins/builtin/analytics/risk-headless.ts +66 -6
- package/src/plugins/builtin/analytics/risk-math.ts +23 -6
- package/src/plugins/builtin/analytics/risk-model.ts +20 -9
- package/src/plugins/builtin/analytics/risk-pane.tsx +2 -2
- 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/chart-composer/catalog-inventory.ts +5 -2
- package/src/plugins/builtin/chart-composer/editor.tsx +1 -0
- package/src/plugins/builtin/chart-composer/pane.tsx +1 -1
- package/src/plugins/builtin/chart-composer/quick-add.tsx +4 -1
- package/src/plugins/builtin/chart-composer/series-catalog.ts +17 -1
- package/src/plugins/builtin/cloud/askg/executor.ts +2 -1
- package/src/plugins/builtin/cloud/askg/sources.ts +2 -1
- package/src/plugins/builtin/cloud/plugin.tsx +2 -0
- package/src/plugins/builtin/cloud/thesis/module.tsx +2 -0
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +6 -2
- package/src/plugins/builtin/cpi/headless.ts +6 -1
- package/src/plugins/builtin/cpi/model.ts +17 -0
- package/src/plugins/builtin/cpi/pane.tsx +4 -2
- package/src/plugins/builtin/crypto-board/client.ts +6 -1
- package/src/plugins/builtin/crypto-board/headless.ts +10 -2
- package/src/plugins/builtin/crypto-board/model.ts +89 -11
- package/src/plugins/builtin/crypto-board/pane.tsx +20 -5
- package/src/plugins/builtin/debt-maturities/model.ts +1 -1
- package/src/plugins/builtin/dividend-yield/client.ts +24 -2
- package/src/plugins/builtin/dividend-yield/headless.ts +4 -2
- package/src/plugins/builtin/dividend-yield/ranking.ts +2 -1
- package/src/plugins/builtin/dividend-yield/view.ts +5 -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 +9 -1
- package/src/plugins/builtin/earnings/index.tsx +1 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +2 -2
- package/src/plugins/builtin/earnings-ripple/index.tsx +2 -0
- package/src/plugins/builtin/econ/calendar-model.ts +17 -1
- package/src/plugins/builtin/econ/fred-catalog.ts +33 -4
- package/src/plugins/builtin/econ-statistics/headless.ts +21 -0
- 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/headless.ts +21 -10
- package/src/plugins/builtin/macro-day/model.ts +42 -3
- package/src/plugins/builtin/macro-day/pane.tsx +26 -8
- package/src/plugins/builtin/macro-day/releases.ts +24 -1
- 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/money-markets/client.ts +4 -1
- package/src/plugins/builtin/money-markets/headless.ts +15 -4
- package/src/plugins/builtin/money-markets/index.tsx +1 -1
- package/src/plugins/builtin/money-markets/pane.tsx +7 -1
- 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/bulk-symbols.ts +4 -2
- package/src/plugins/builtin/portfolio-list/cli/period-report.ts +61 -11
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +11 -3
- package/src/plugins/builtin/portfolio-list/cli/render.ts +8 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +178 -17
- package/src/plugins/builtin/portfolio-list/headless.ts +33 -6
- package/src/plugins/builtin/portfolio-list/pane/groups.tsx +220 -0
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +95 -18
- package/src/plugins/builtin/portfolio-list/pane/period-pnl.ts +24 -6
- package/src/plugins/builtin/portfolio-list/period-pnl.ts +16 -1
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +4 -1
- package/src/plugins/builtin/portfolio-list/summary/totals.ts +6 -4
- package/src/plugins/builtin/portfolio-list/table.tsx +38 -16
- 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/cloud-upgrade.ts +4 -2
- package/src/plugins/builtin/shared/cpi-year-gap.ts +67 -0
- 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/adr-pair/headless.ts +45 -2
- 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 +280 -35
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +4 -5
- package/src/plugins/builtin/ticker-detail/overview/model.ts +9 -2
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +10 -2
- 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/collection-name.ts +2 -1
- package/src/portfolio/column-values.ts +34 -12
- package/src/portfolio/listed-symbol.ts +4 -2
- package/src/portfolio/period-pnl.ts +51 -1
- 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/dialog-host.tsx +5 -5
- package/src/renderers/dom/styles.css +7 -0
- package/src/renderers/electrobun/view/remote/capability-invoker.ts +1 -1
- package/src/renderers/opentui/dialog-host.tsx +3 -4
- package/src/sources/gloomberb-cloud/normalizers.ts +5 -0
- package/src/sources/provider-router/history.ts +5 -2
- 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/test-support/plugin-persistence.ts +12 -0
- package/src/tickers/company-name-listing.ts +4 -3
- package/src/tickers/company-name.ts +19 -1
- package/src/tickers/instrument-coverage.ts +27 -0
- package/src/tickers/search/home-listing.ts +38 -1
- package/src/tickers/search/index.ts +3 -2
- package/src/tickers/search/ranking.ts +21 -2
- package/src/time-series/base-series.ts +4 -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/types.ts +5 -2
- package/src/time-series/use-chart-resolution.ts +6 -1
- package/src/types/config.ts +32 -0
- package/src/types/financials.ts +13 -0
- package/src/types/headless.ts +7 -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/ui/dialog-stack.ts +17 -0
- package/src/ui/dialog.tsx +6 -2
- package/src/utils/async-deadline.ts +2 -2
- package/src/utils/crypto-pair.ts +9 -0
- package/src/utils/csv.ts +44 -5
- package/src/utils/exchanges.ts +13 -0
- package/src/utils/financial-statements.ts +60 -3
- package/src/utils/futures-generic.ts +17 -0
- package/src/utils/trailing-dividend.ts +13 -3
|
@@ -45,21 +45,6 @@ export function isTickerLinkPeer(
|
|
|
45
45
|
return instance.paneId === TICKER_RESEARCH_PANE_ID || canFollowTickerSource(instance, panes);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/** True when `fromInstanceId`'s follow chain reaches `targetInstanceId`. */
|
|
49
|
-
export function followBindingReaches(
|
|
50
|
-
layout: LayoutConfig,
|
|
51
|
-
fromInstanceId: string,
|
|
52
|
-
targetInstanceId: string,
|
|
53
|
-
seen = new Set<string>(),
|
|
54
|
-
): boolean {
|
|
55
|
-
if (seen.has(fromInstanceId)) return false;
|
|
56
|
-
seen.add(fromInstanceId);
|
|
57
|
-
const instance = findPaneInstance(layout, fromInstanceId);
|
|
58
|
-
if (instance?.binding?.kind !== "follow") return false;
|
|
59
|
-
const next = instance.binding.sourceInstanceId;
|
|
60
|
-
return next === targetInstanceId || followBindingReaches(layout, next, targetInstanceId, seen);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
48
|
/** The visible Ticker Research pane that follows `sourceInstanceId`, if any. */
|
|
64
49
|
export function findTickerResearchFollower(
|
|
65
50
|
layout: LayoutConfig,
|
|
@@ -75,17 +60,26 @@ export function findTickerResearchFollower(
|
|
|
75
60
|
}
|
|
76
61
|
|
|
77
62
|
/**
|
|
78
|
-
* Enter
|
|
79
|
-
*
|
|
63
|
+
* Enter focuses the follower already bound to the source pane. A source without one opens the
|
|
64
|
+
* ticker in a research pane, reusing a pinned one rather than stacking another: the one the app
|
|
65
|
+
* unlinked (`PaneUnlinkedFrom.auto`), else the only one the layout has. Shift+Enter (`newPane`)
|
|
66
|
+
* opens a new pane.
|
|
80
67
|
*/
|
|
81
68
|
export function resolveTickerActivation(
|
|
82
69
|
layout: LayoutConfig,
|
|
83
70
|
sourcePaneId: string | null | undefined,
|
|
84
71
|
options?: { newPane?: boolean },
|
|
85
|
-
): { kind: "focus"; paneId: string } | { kind: "open" } {
|
|
72
|
+
): { kind: "focus"; paneId: string } | { kind: "open"; reusePaneId?: string } {
|
|
86
73
|
if (options?.newPane) return { kind: "open" };
|
|
87
74
|
const follower = findTickerResearchFollower(layout, sourcePaneId);
|
|
88
|
-
|
|
75
|
+
if (follower) return { kind: "focus", paneId: follower.instanceId };
|
|
76
|
+
const pinned = layout.instances.filter((instance) => (
|
|
77
|
+
instance.paneId === TICKER_RESEARCH_PANE_ID
|
|
78
|
+
&& instance.binding?.kind === "fixed"
|
|
79
|
+
&& isPaneInLayout(layout, instance.instanceId)
|
|
80
|
+
));
|
|
81
|
+
const reuse = pinned.find((instance) => instance.unlinkedFrom?.auto) ?? (pinned.length === 1 ? pinned[0] : undefined);
|
|
82
|
+
return reuse ? { kind: "open", reusePaneId: reuse.instanceId } : { kind: "open" };
|
|
89
83
|
}
|
|
90
84
|
|
|
91
85
|
export function resolveTickerNavigationReplacementPane(
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import type { BrokerContractRef, TickerListingRef } from "../types/instrument";
|
|
9
9
|
import type { PaneDef } from "../types/plugin";
|
|
10
10
|
import { tickerInstrumentLabel } from "../tickers/instrument-label";
|
|
11
|
-
import { pinnedTitle } from "./pane-follow";
|
|
11
|
+
import { pinnedTitle, userUnlinkedFrom } from "./pane-follow";
|
|
12
12
|
import { isPaneInLayout } from "./pane-manager";
|
|
13
13
|
import { isTickerLinkPeer } from "./ticker-navigation";
|
|
14
14
|
|
|
@@ -79,7 +79,8 @@ export function retargetTickerPane(
|
|
|
79
79
|
};
|
|
80
80
|
const research = target.paneId === TICKER_RESEARCH_PANE_ID;
|
|
81
81
|
const title = research ? tickerInstrumentLabel(symbol, instrument) : pinnedTitle(target, symbol);
|
|
82
|
-
const
|
|
82
|
+
const unlinkedFrom = userUnlinkedFrom(target, layout);
|
|
83
|
+
const pinned: PaneInstanceConfig = { ...target, binding, ...(title ? { title } : {}), ...(unlinkedFrom ? { unlinkedFrom } : {}) };
|
|
83
84
|
const next = paneDef?.retargetTicker?.(pinned, symbol, previous) ?? pinned;
|
|
84
85
|
return {
|
|
85
86
|
...layout,
|
|
@@ -644,9 +644,14 @@ export function stablePriceFractionDigits(context: StablePriceContext): number {
|
|
|
644
644
|
digits = 2;
|
|
645
645
|
}
|
|
646
646
|
if (kind !== "crypto" && reference !== undefined) digits = Math.max(digits, tinyPriceFractionDigits(reference));
|
|
647
|
+
// A coin's session prices raise its decimals only to six significant figures: a composite's close is computed,
|
|
648
|
+
// and one written to eight decimals (0.99880666) would pad every price, bid and range to eight as well.
|
|
649
|
+
const sessionCeiling = kind === "crypto" && reference !== undefined
|
|
650
|
+
? Math.min(ceiling, Math.max(digits, 5 - Math.floor(Math.log10(reference))))
|
|
651
|
+
: ceiling;
|
|
647
652
|
for (const price of context.sessionPrices ?? []) {
|
|
648
653
|
const magnitude = positiveMagnitude(price);
|
|
649
|
-
if (magnitude !== undefined) digits = Math.max(digits, writtenFractionDigits(magnitude,
|
|
654
|
+
if (magnitude !== undefined) digits = Math.max(digits, writtenFractionDigits(magnitude, sessionCeiling));
|
|
650
655
|
}
|
|
651
656
|
return digits;
|
|
652
657
|
}
|
|
@@ -751,6 +756,35 @@ export function formatMarketPriceWithCurrency(
|
|
|
751
756
|
return `${hasNonZeroDigit(body) ? sign : ""}${prefix}${body}${suffix}`;
|
|
752
757
|
}
|
|
753
758
|
|
|
759
|
+
const writtenDecimals = (text: string) => /\.(\d+)\D*$/.exec(text)?.[1]!.length ?? 0;
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* A range's low and high, both to one number of decimals, with `currency`'s
|
|
763
|
+
* sign when given. A coin's ends are rounded to its price's decimals first
|
|
764
|
+
* (stablePriceFractionDigits' six significant figures): a composite's low of
|
|
765
|
+
* 0.9989128 beside a high of 0.998990 is a float's tail, not a finer trade the
|
|
766
|
+
* price's decimals must keep.
|
|
767
|
+
*/
|
|
768
|
+
export function formatMarketPriceRange(
|
|
769
|
+
low: number,
|
|
770
|
+
high: number,
|
|
771
|
+
options: MarketFormatOptions = {},
|
|
772
|
+
currency?: string,
|
|
773
|
+
): [string, string] {
|
|
774
|
+
const format = (value: number, digits?: number) => {
|
|
775
|
+
const shown = digits === undefined ? options : { ...options, fixedFractionDigits: digits };
|
|
776
|
+
return currency === undefined ? formatMarketPrice(value, shown) : formatMarketPriceWithCurrency(value, currency, shown);
|
|
777
|
+
};
|
|
778
|
+
const coinDigits = resolveAssetDisplayKind(options) === "crypto" ? options.fixedFractionDigits : undefined;
|
|
779
|
+
const round = (value: number) => coinDigits === undefined || !Number.isFinite(value) ? value : Number(value.toFixed(coinDigits));
|
|
780
|
+
const ends = [round(low), round(high)] as const;
|
|
781
|
+
const texts: [string, string] = [format(ends[0]), format(ends[1])];
|
|
782
|
+
const digits = texts.map(writtenDecimals);
|
|
783
|
+
if (digits[0] === digits[1]) return texts;
|
|
784
|
+
const shared = Math.max(digits[0]!, digits[1]!);
|
|
785
|
+
return [format(ends[0], shared), format(ends[1], shared)];
|
|
786
|
+
}
|
|
787
|
+
|
|
754
788
|
export function formatMarketCostWithCurrency(
|
|
755
789
|
value: number | undefined,
|
|
756
790
|
currency = "USD",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { classifyInstrumentType, isCryptoVenuePerpetual } from "../../tickers/instrument-kind";
|
|
2
2
|
import type { PriceBasis } from "../../types/instrument";
|
|
3
3
|
import type { MarketState, Quote } from "../../types/financials";
|
|
4
|
+
import { isRoundTheClockCoin } from "../../utils/crypto-pair";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* The unit an index level is in, as a chart's axis and series name it. A
|
|
@@ -89,3 +90,21 @@ export function reportedQuoteVolume(
|
|
|
89
90
|
if (volume === 0 && (isIndexLevel(quote!.instrumentType) || isCryptoVenuePerpetual(quote!.instrumentType, quote!.name))) return null;
|
|
90
91
|
return volume;
|
|
91
92
|
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The currency a quote's volume is a value in, where it is one: a coin's is
|
|
96
|
+
* the value traded in its quote currency (BTC-USD's in US dollars), whether it
|
|
97
|
+
* is the composite's or one exchange's day, as its bars' and the crypto
|
|
98
|
+
* board's are, never a count of coins. Null for a listing that counts shares
|
|
99
|
+
* or contracts, and for a quote that names no currency. `symbol` and
|
|
100
|
+
* `exchange` stand in for a quote that names no listing.
|
|
101
|
+
*/
|
|
102
|
+
export function quoteVolumeCurrency(
|
|
103
|
+
quote: { symbol?: string | null; exchangeName?: string | null; currency?: string | null } | null | undefined,
|
|
104
|
+
symbol?: string,
|
|
105
|
+
exchange?: string,
|
|
106
|
+
): string | null {
|
|
107
|
+
const currency = quote?.currency?.trim();
|
|
108
|
+
if (!currency) return null;
|
|
109
|
+
return isRoundTheClockCoin(quote?.symbol || symbol, quote?.exchangeName || exchange) ? currency : null;
|
|
110
|
+
}
|
|
@@ -240,6 +240,17 @@ export function mergeQuoteContribution(
|
|
|
240
240
|
else delete merged.yearRangeBasis;
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
// What a coin's day range and volume measure goes with the range the merge keeps, as the 52-week range's does:
|
|
244
|
+
// a tick relaying the same range keeps the word, one with another range says its own or none.
|
|
245
|
+
if (next.high !== undefined || next.low !== undefined) {
|
|
246
|
+
const relayed = next.statsBasis === undefined && next.high === current.high && next.low === current.low;
|
|
247
|
+
const basis = relayed ? current.statsBasis : next.statsBasis;
|
|
248
|
+
if (basis) merged.statsBasis = basis;
|
|
249
|
+
else delete merged.statsBasis;
|
|
250
|
+
if (relayed ? current.rangeWidened : next.rangeWidened) merged.rangeWidened = true;
|
|
251
|
+
else delete merged.rangeWidened;
|
|
252
|
+
}
|
|
253
|
+
|
|
243
254
|
// What this observation's move is from, when not its previous close (a coin's
|
|
244
255
|
// 24 hours), is said with each one: a quote back on its
|
|
245
256
|
// previous close drops an earlier "24h", and one on 24 hours drops the
|
|
@@ -263,6 +274,8 @@ export function mergeQuoteContribution(
|
|
|
263
274
|
}
|
|
264
275
|
// So is a close its daily closes could not date: the next reading says it again.
|
|
265
276
|
if (next.previousCloseUndated === undefined) delete merged.previousCloseUndated;
|
|
277
|
+
// And the exchange whose own trade the price is: a composite or streamed tick after it names none.
|
|
278
|
+
if (next.priceVenue === undefined) delete merged.priceVenue;
|
|
266
279
|
|
|
267
280
|
if (isOtherTradingDay(current, next)) {
|
|
268
281
|
const record = merged as unknown as Record<string, unknown>;
|
|
@@ -3,6 +3,7 @@ import { isYieldIndexSymbol } from "../../tickers/index-roots";
|
|
|
3
3
|
import { currencyPairCode } from "../../utils/currency-pair";
|
|
4
4
|
import { parsePublicTickerKey } from "../../utils/exchanges";
|
|
5
5
|
import { INDEX_POINTS_EXPORT_UNIT, isIndexLevel, YIELD_INDEX_EXPORT_UNIT } from "../market/index-level";
|
|
6
|
+
import { delayedFeedLagMs } from "../market/freshness";
|
|
6
7
|
import { quoteHeadlineTime, quoteSessionStateLabel } from "../market/status";
|
|
7
8
|
import { isQuoteStaleForCurrentSession } from "./freshness";
|
|
8
9
|
|
|
@@ -43,12 +44,46 @@ export type BrokerNameOf = (providerId: string) => string | null | undefined;
|
|
|
43
44
|
* the broker whose feed it is, by its name. Blank for a source with no name
|
|
44
45
|
* to give, never its internal id.
|
|
45
46
|
*/
|
|
46
|
-
export function quoteSourceName(quote: Pick<Quote, "providerId"> | null | undefined, brokerName?: BrokerNameOf): string {
|
|
47
|
+
export function quoteSourceName(quote: Pick<Quote, "providerId" | "priceVenue"> | null | undefined, brokerName?: BrokerNameOf): string {
|
|
47
48
|
if (!quote) return "";
|
|
49
|
+
// A coin priced by one exchange's own trade is that exchange's price, not the composite's.
|
|
50
|
+
if (quote.priceVenue && (!quote.providerId || quote.providerId === CLOUD_PROVIDER_ID)) return quote.priceVenue;
|
|
48
51
|
if (!quote.providerId || quote.providerId === CLOUD_PROVIDER_ID) return CLOUD_SOURCE;
|
|
49
52
|
return brokerName?.(quote.providerId)?.trim() || "";
|
|
50
53
|
}
|
|
51
54
|
|
|
55
|
+
/**
|
|
56
|
+
* What a coin's day range and volume measure, as said beside them: `composite` (across exchanges), `composite +
|
|
57
|
+
* Coinbase` when the range was widened to take in the exchange's price, or `1 exchange` (one exchange's own day).
|
|
58
|
+
* Empty when the service does not say, as for anything but a coin.
|
|
59
|
+
*/
|
|
60
|
+
export function quoteStatsBasisText(quote: Pick<Quote, "statsBasis" | "rangeWidened" | "priceVenue"> | null | undefined, range = true): string {
|
|
61
|
+
if (quote?.statsBasis === "exchange") return "1 exchange";
|
|
62
|
+
if (quote?.statsBasis !== "composite") return "";
|
|
63
|
+
return range && quote.rangeWidened && quote.priceVenue ? `composite + ${quote.priceVenue}` : "composite";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const UTC_WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Where a coin's price is from and when, as its header says it: the exchange whose own trade it is and that trade's
|
|
70
|
+
* time (`Coinbase · 21:53:40 UTC`), the composite of several exchanges and its time, or `composite · 15m delayed`
|
|
71
|
+
* when it is held back. A time from another UTC day leads with its weekday. Empty for a quote Gloom Cloud does not
|
|
72
|
+
* price, such as a broker's.
|
|
73
|
+
*/
|
|
74
|
+
export function coinPriceVenueText(
|
|
75
|
+
quote: Pick<Quote, "providerId" | "priceVenue" | "dataSource" | "lastUpdated"> | null | undefined,
|
|
76
|
+
now = Date.now(),
|
|
77
|
+
): string {
|
|
78
|
+
if (!quote || (quote.providerId && quote.providerId !== CLOUD_PROVIDER_ID)) return "";
|
|
79
|
+
const venue = quote.priceVenue ?? "composite";
|
|
80
|
+
if (!quote.priceVenue && quote.dataSource === "delayed") return `${venue} · ${delayedFeedLagMs("CCC") / 60_000}m delayed`;
|
|
81
|
+
if (!Number.isFinite(quote.lastUpdated) || quote.lastUpdated <= 0) return venue;
|
|
82
|
+
const at = new Date(quote.lastUpdated);
|
|
83
|
+
const day = Math.floor(quote.lastUpdated / 86_400_000) === Math.floor(now / 86_400_000) ? "" : `${UTC_WEEKDAYS[at.getUTCDay()]} `;
|
|
84
|
+
return `${venue} · ${day}${at.toISOString().slice(11, 19)} UTC`;
|
|
85
|
+
}
|
|
86
|
+
|
|
52
87
|
/** Whether a quote's feed is live, delayed or stale, as the Feed cell of `quote` says it. */
|
|
53
88
|
export function quoteExportFeed(quote: Quote | null | undefined, now = Date.now()): string {
|
|
54
89
|
if (!quote) return "";
|
|
@@ -146,6 +146,19 @@ function sessionConfidenceRank(confidence?: SessionConfidence): number {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
/**
|
|
150
|
+
* What a coin's day range measures, said of the range, so it comes with the
|
|
151
|
+
* provider whose range it is; and whether the service widened it to take in
|
|
152
|
+
* its exchange's price.
|
|
153
|
+
*/
|
|
154
|
+
function dayRangeBasis(contributions: readonly QuoteContribution[], resolved: Partial<Quote>): Pick<Quote, "statsBasis" | "rangeWidened"> {
|
|
155
|
+
const source = contributions.find((quote) => quote.high === resolved.high && quote.low === resolved.low);
|
|
156
|
+
return {
|
|
157
|
+
...(source?.statsBasis ? { statsBasis: source.statsBasis } : {}),
|
|
158
|
+
...(source?.rangeWidened ? { rangeWidened: true } : {}),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
149
162
|
function toProvenance(quote: QuoteContribution | undefined): QuoteFieldProvenance | undefined {
|
|
150
163
|
if (!quote?.providerId) return undefined;
|
|
151
164
|
return {
|
|
@@ -512,6 +525,7 @@ export function resolveCanonicalQuote(
|
|
|
512
525
|
low52w: resolved.low52w as Quote["low52w"],
|
|
513
526
|
// Said of the range, so it comes with the provider whose range it is.
|
|
514
527
|
yearRangeBasis: contributions.find((quote) => quote.high52w === resolved.high52w && quote.low52w === resolved.low52w)?.yearRangeBasis,
|
|
528
|
+
...dayRangeBasis(contributions, resolved),
|
|
515
529
|
// Said of the price, so it comes with it.
|
|
516
530
|
dailyClose: priceProvider?.dailyClose,
|
|
517
531
|
marketCap: resolved.marketCap as Quote["marketCap"],
|
|
@@ -547,6 +561,8 @@ export function resolveCanonicalQuote(
|
|
|
547
561
|
indexSession: priceProvider?.indexSession,
|
|
548
562
|
// A listing that no longer trades: the price is its last trade.
|
|
549
563
|
delisting: priceProvider?.delisting,
|
|
564
|
+
// The one exchange whose own trade or book the price is, when it is one's.
|
|
565
|
+
...(priceProvider?.priceVenue ? { priceVenue: priceProvider.priceVenue } : {}),
|
|
550
566
|
// A perpetual's funding, open interest and premium are of the reading that gave its price.
|
|
551
567
|
...(priceProvider?.perpetual ? { perpetual: priceProvider.perpetual } : {}),
|
|
552
568
|
bid: resolved.bid as Quote["bid"],
|
|
@@ -37,6 +37,8 @@ export function useAccountManagementKeyboard({
|
|
|
37
37
|
endTrial,
|
|
38
38
|
copyInvite,
|
|
39
39
|
turnOffEmailAlerts,
|
|
40
|
+
yearlyPlanAction,
|
|
41
|
+
dismissYearlyReview,
|
|
40
42
|
}: {
|
|
41
43
|
activeField: AccountFieldKey;
|
|
42
44
|
cyclePortfolio: (delta: number) => void;
|
|
@@ -57,6 +59,10 @@ export function useAccountManagementKeyboard({
|
|
|
57
59
|
endTrial: () => Promise<void>;
|
|
58
60
|
copyInvite: () => void;
|
|
59
61
|
turnOffEmailAlerts: () => Promise<void>;
|
|
62
|
+
/** The yearly row's action: review, pay or open the invoice. */
|
|
63
|
+
yearlyPlanAction: () => void;
|
|
64
|
+
/** Closes the yearly review while it is open, else null. */
|
|
65
|
+
dismissYearlyReview: (() => void) | null;
|
|
60
66
|
}): FieldRing<AccountFieldKey> {
|
|
61
67
|
const actions: Partial<Record<AccountFieldKey, () => void>> = {
|
|
62
68
|
sharedPortfolioId: () => { void openPortfolioDialog(); },
|
|
@@ -68,6 +74,8 @@ export function useAccountManagementKeyboard({
|
|
|
68
74
|
assistantsAction: openAssistants,
|
|
69
75
|
deleteAccountAction: () => { void deleteAccount(); },
|
|
70
76
|
emailAlertsOffAction: () => { void turnOffEmailAlerts(); },
|
|
77
|
+
yearlyPlanAction,
|
|
78
|
+
yearlyPlanDismissAction: () => dismissYearlyReview?.(),
|
|
71
79
|
};
|
|
72
80
|
for (const key of TOGGLE_FIELDS) actions[key] = () => setDraftValue(key, !draftRef.current[key]);
|
|
73
81
|
|
|
@@ -91,6 +99,12 @@ export function useAccountManagementKeyboard({
|
|
|
91
99
|
void saveProfile();
|
|
92
100
|
return;
|
|
93
101
|
}
|
|
102
|
+
// Esc closes the yearly review, as Cancel does a form.
|
|
103
|
+
if (dismissYearlyReview && !event.targetEditable && isPlainKey(event, "escape")) {
|
|
104
|
+
consume();
|
|
105
|
+
dismissYearlyReview();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
94
108
|
if (event.targetEditable || activeField !== "sharedPortfolioId") return;
|
|
95
109
|
if (isPlainKey(event, "left", "h", "[")) {
|
|
96
110
|
consume();
|
|
@@ -74,6 +74,8 @@ import { deleteAccountConfirmingSession } from "./delete-account";
|
|
|
74
74
|
import { endTrialAfterWarning } from "./trial-cancel";
|
|
75
75
|
import { CalendarAccountTab } from "./calendar-tab";
|
|
76
76
|
import { InviteRow } from "./invite-row";
|
|
77
|
+
import { PaymentRecoveryRow, usePaymentRecovery } from "./payment-recovery-row";
|
|
78
|
+
import { YearlyPlanRow, useYearlyPlan } from "./yearly-plan-row";
|
|
77
79
|
import { useAccountManagementFooter } from "./footer";
|
|
78
80
|
import { useAccountManagementKeyboard } from "./keyboard";
|
|
79
81
|
import {
|
|
@@ -130,8 +132,9 @@ const ACCOUNT_TAB_FIELD_ORDER: Record<AccountManagementTab, AccountFieldKey[]> =
|
|
|
130
132
|
],
|
|
131
133
|
// Its actions are footer hints; the tab owns its footer.
|
|
132
134
|
calendar: [],
|
|
133
|
-
// Cancel Trial shows only while a trial runs, the
|
|
134
|
-
|
|
135
|
+
// Cancel Trial shows only while a trial runs, the yearly row while it has
|
|
136
|
+
// an action, Not Now while its review is open, the invite once it loaded.
|
|
137
|
+
pro: ["upgradeAction", "cancelTrialAction", "yearlyPlanAction", "yearlyPlanDismissAction", "inviteCopyAction"],
|
|
135
138
|
// The Teams tab owns its own keyboard handling (a list, not form fields).
|
|
136
139
|
teams: [],
|
|
137
140
|
// Remote assistants allowed to drive this terminal; a list with its own footer.
|
|
@@ -241,6 +244,7 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
241
244
|
);
|
|
242
245
|
const [message, setMessage] = useState<{ tone: "info" | "success" | "error"; text: string } | null>(null);
|
|
243
246
|
const [busy, setBusy] = useState<AccountBusy>(null);
|
|
247
|
+
const paymentRecovery = usePaymentRecovery(hasSession && activeTab === "pro", sessionMarker);
|
|
244
248
|
|
|
245
249
|
// A requested tab switches the open pane; one requested before it mounted wins over the restored tab once.
|
|
246
250
|
useEffect(() => subscribeRequestedAccountManagementTab((tab) => {
|
|
@@ -268,13 +272,33 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
268
272
|
// Chat's card settings show once the server keeps them; the desks only while showing them is on.
|
|
269
273
|
const chatCardSupported = profile?.showLocalTime !== undefined;
|
|
270
274
|
const planAccess = useMemo(() => resolvePlanAccess(profile), [profile]);
|
|
275
|
+
// A paid switch changes the plan on the server: the session and the tab follow it.
|
|
276
|
+
const refreshAfterYearlySwitch = useCallback(() => {
|
|
277
|
+
void chatController.refreshSession().catch(logFailure("account-management.pane", "Refresh yearly account session failed"));
|
|
278
|
+
void apiClient.getAccountProfile().then(
|
|
279
|
+
(nextProfile) => { if (nextProfile) setProfile(nextProfile); },
|
|
280
|
+
logFailure("account-management.pane", "Refresh yearly account profile failed"),
|
|
281
|
+
);
|
|
282
|
+
}, []);
|
|
283
|
+
// An opened review lands on Not Now, in the same update that draws it: no
|
|
284
|
+
// render ever has Pay active on open, so a held Enter never pays.
|
|
285
|
+
const focusYearlyDismiss = useCallback(() => setActiveField("yearlyPlanDismissAction"), []);
|
|
286
|
+
// Only a paying Pro subscriber is asked; the server decides who may switch.
|
|
287
|
+
const yearlyPlan = useYearlyPlan(
|
|
288
|
+
hasSession && activeTab === "pro" && planAccess.isPayingPro && !paymentRecovery.visible && !paymentRecovery.checking,
|
|
289
|
+
sessionMarker,
|
|
290
|
+
refreshAfterYearlySwitch,
|
|
291
|
+
focusYearlyDismiss,
|
|
292
|
+
);
|
|
271
293
|
const fieldOrder = useMemo(() => ACCOUNT_TAB_FIELD_ORDER[activeTab].filter((field) => {
|
|
272
294
|
if (field === "showLocalTime" || field === "showDesks") return chatCardSupported;
|
|
273
295
|
if (field === "desks") return chatCardSupported && draft.showDesks;
|
|
274
296
|
if (field === "cancelTrialAction") return planAccess.isTrialActive;
|
|
297
|
+
if (field === "yearlyPlanAction") return yearlyPlan.primary !== null;
|
|
298
|
+
if (field === "yearlyPlanDismissAction") return yearlyPlan.reviewing;
|
|
275
299
|
if (field === "inviteCopyAction") return invite !== null;
|
|
276
300
|
return true;
|
|
277
|
-
}), [activeTab, chatCardSupported, draft.showDesks, invite, planAccess.isTrialActive]);
|
|
301
|
+
}), [activeTab, chatCardSupported, draft.showDesks, invite, planAccess.isTrialActive, yearlyPlan.primary, yearlyPlan.reviewing]);
|
|
278
302
|
const accountTabs = ACCOUNT_TAB_DEFS.map((tab) => ({ ...tab, label: t(tab.label) }));
|
|
279
303
|
|
|
280
304
|
const planPrice = useMemo(() => formatCloudMonthlyPrice(pricing), [language, pricing]);
|
|
@@ -722,6 +746,11 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
722
746
|
const startUpgrade = useCloudUpgradeAction("acm");
|
|
723
747
|
const openUpgrade = useCallback(() => {
|
|
724
748
|
setActiveField("upgradeAction");
|
|
749
|
+
if (paymentRecovery.checking) return;
|
|
750
|
+
if (paymentRecovery.visible) {
|
|
751
|
+
paymentRecovery.pay();
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
725
754
|
if (busy) return;
|
|
726
755
|
let opening = false;
|
|
727
756
|
void startUpgrade({
|
|
@@ -735,7 +764,7 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
735
764
|
setBusy(null);
|
|
736
765
|
setMessage(null);
|
|
737
766
|
});
|
|
738
|
-
}, [busy, startUpgrade]);
|
|
767
|
+
}, [busy, startUpgrade, paymentRecovery.visible, paymentRecovery.pay, paymentRecovery.checking]);
|
|
739
768
|
|
|
740
769
|
const deleteAccount = useCallback(async () => {
|
|
741
770
|
setActiveField("deleteAccountAction");
|
|
@@ -848,6 +877,16 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
848
877
|
setActiveField,
|
|
849
878
|
setDraftValue,
|
|
850
879
|
turnOffEmailAlerts,
|
|
880
|
+
yearlyPlanAction: () => {
|
|
881
|
+
setActiveField("yearlyPlanAction");
|
|
882
|
+
yearlyPlan.primary?.();
|
|
883
|
+
},
|
|
884
|
+
dismissYearlyReview: yearlyPlan.reviewing
|
|
885
|
+
? () => {
|
|
886
|
+
yearlyPlan.dismiss();
|
|
887
|
+
setActiveField("yearlyPlanAction");
|
|
888
|
+
}
|
|
889
|
+
: null,
|
|
851
890
|
});
|
|
852
891
|
|
|
853
892
|
const textField = (key: "username" | "name" | "company" | "title" | "publicEmail" | "xAccount", label: string, placeholder: string) => (
|
|
@@ -1067,14 +1106,24 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
1067
1106
|
width={contentWidth}
|
|
1068
1107
|
activePlan={planAccess.hasProAccess ? "pro" : "free"}
|
|
1069
1108
|
/>
|
|
1070
|
-
|
|
1109
|
+
{paymentRecovery.visible ? (
|
|
1110
|
+
<PaymentRecoveryRow
|
|
1111
|
+
active={activeField === "upgradeAction"}
|
|
1112
|
+
busy={paymentRecovery.busy}
|
|
1113
|
+
message={paymentRecovery.message}
|
|
1114
|
+
labelWidth={formLabelWidth}
|
|
1115
|
+
nodeRef={fieldNodeRef("upgradeAction")}
|
|
1116
|
+
onPay={openUpgrade}
|
|
1117
|
+
onFocus={() => setActiveField("upgradeAction")}
|
|
1118
|
+
/>
|
|
1119
|
+
) : <Box flexDirection="row" gap={1}>
|
|
1071
1120
|
<Box ref={fieldNodeRef("upgradeAction")} flexDirection="row">
|
|
1072
1121
|
<Button
|
|
1073
1122
|
label={planAccess.isPayingPro ? t("Manage Pro") : busy === "billing" ? t("Opening...") : t("Upgrade to Pro")}
|
|
1074
1123
|
variant={planAccess.isPayingPro ? "secondary" : "primary"}
|
|
1075
1124
|
active={activeField === "upgradeAction"}
|
|
1076
1125
|
onPress={openUpgrade}
|
|
1077
|
-
disabled={!!busy}
|
|
1126
|
+
disabled={!!busy || paymentRecovery.checking}
|
|
1078
1127
|
/>
|
|
1079
1128
|
</Box>
|
|
1080
1129
|
{planAccess.isTrialActive ? (
|
|
@@ -1088,7 +1137,30 @@ export function AccountManagementPane({ focused, width, height }: PaneProps) {
|
|
|
1088
1137
|
/>
|
|
1089
1138
|
</Box>
|
|
1090
1139
|
) : null}
|
|
1091
|
-
</Box>
|
|
1140
|
+
</Box>}
|
|
1141
|
+
{paymentRecovery.visible ? null : (
|
|
1142
|
+
<YearlyPlanRow
|
|
1143
|
+
view={yearlyPlan.view}
|
|
1144
|
+
busy={yearlyPlan.busy}
|
|
1145
|
+
message={yearlyPlan.message}
|
|
1146
|
+
width={contentWidth}
|
|
1147
|
+
labelWidth={formLabelWidth}
|
|
1148
|
+
primaryActive={activeField === "yearlyPlanAction"}
|
|
1149
|
+
dismissActive={activeField === "yearlyPlanDismissAction"}
|
|
1150
|
+
primaryRef={fieldNodeRef("yearlyPlanAction")}
|
|
1151
|
+
dismissRef={fieldNodeRef("yearlyPlanDismissAction")}
|
|
1152
|
+
onPrimary={yearlyPlan.primary ? () => {
|
|
1153
|
+
setActiveField("yearlyPlanAction");
|
|
1154
|
+
yearlyPlan.primary?.();
|
|
1155
|
+
} : null}
|
|
1156
|
+
onDismiss={() => {
|
|
1157
|
+
yearlyPlan.dismiss();
|
|
1158
|
+
setActiveField("yearlyPlanAction");
|
|
1159
|
+
}}
|
|
1160
|
+
onFocusPrimary={() => setActiveField("yearlyPlanAction")}
|
|
1161
|
+
onFocusDismiss={() => setActiveField("yearlyPlanDismissAction")}
|
|
1162
|
+
/>
|
|
1163
|
+
)}
|
|
1092
1164
|
{invite ? (
|
|
1093
1165
|
<InviteRow
|
|
1094
1166
|
invite={invite}
|
|
@@ -60,7 +60,7 @@ export function DeleteAccountPasswordDialog({
|
|
|
60
60
|
|
|
61
61
|
const fieldWidth = 42;
|
|
62
62
|
return (
|
|
63
|
-
<DialogFrame title={t("Delete Account")}>
|
|
63
|
+
<DialogFrame title={t("Delete Account")} onClose={dismiss}>
|
|
64
64
|
<Box flexDirection="column" gap={1}>
|
|
65
65
|
<ClippedText text={t("Enter your password to delete your account.")} width={fieldWidth} cut={truncateWithEllipsis} wrap />
|
|
66
66
|
<TextField
|
|
@@ -152,7 +152,7 @@ export function PasswordChangeDialog({
|
|
|
152
152
|
|
|
153
153
|
const fieldWidth = 42;
|
|
154
154
|
return (
|
|
155
|
-
<DialogFrame title={t("Change Password")}>
|
|
155
|
+
<DialogFrame title={t("Change Password")} onClose={dismiss}>
|
|
156
156
|
<Box flexDirection="column" gap={1}>
|
|
157
157
|
<TextField
|
|
158
158
|
label={t("Current Password")}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState, type Ref } from "react";
|
|
2
|
+
import { apiClient } from "../../../api-client";
|
|
3
|
+
import { Button, FieldLabel } from "../../../components";
|
|
4
|
+
import { t } from "../../../i18n";
|
|
5
|
+
import { colors } from "../../../theme/colors";
|
|
6
|
+
import { Box, Text, useRendererHost, type BoxRenderable } from "../../../ui";
|
|
7
|
+
|
|
8
|
+
export function usePaymentRecovery(enabled: boolean, sessionMarker: string) {
|
|
9
|
+
const renderer = useRendererHost();
|
|
10
|
+
const [status, setStatus] = useState<string | null>(null);
|
|
11
|
+
const [message, setMessage] = useState<string | null>(null);
|
|
12
|
+
const [busy, setBusy] = useState(false);
|
|
13
|
+
const [loaded, setLoaded] = useState(false);
|
|
14
|
+
const generation = useRef(0);
|
|
15
|
+
const opening = useRef<number | null>(null);
|
|
16
|
+
const refreshSequence = useRef(0);
|
|
17
|
+
const visible = status === "past_due" || status === "unpaid";
|
|
18
|
+
|
|
19
|
+
const refresh = useCallback(async (current: number) => {
|
|
20
|
+
if (generation.current !== current) return;
|
|
21
|
+
const sequence = ++refreshSequence.current;
|
|
22
|
+
try {
|
|
23
|
+
const plan = await apiClient.getCloudAccountPlan();
|
|
24
|
+
if (generation.current === current && refreshSequence.current === sequence) setStatus(plan.subscription?.status ?? null);
|
|
25
|
+
} catch {
|
|
26
|
+
if (generation.current === current && refreshSequence.current === sequence) setMessage(t("Could not refresh your account. Try again."));
|
|
27
|
+
} finally {
|
|
28
|
+
if (generation.current === current && refreshSequence.current === sequence) setLoaded(true);
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const current = ++generation.current;
|
|
34
|
+
setStatus(null);
|
|
35
|
+
setMessage(null);
|
|
36
|
+
setBusy(false);
|
|
37
|
+
setLoaded(false);
|
|
38
|
+
if (enabled) void refresh(current).catch(() => setMessage(t("Could not refresh your account. Try again.")));
|
|
39
|
+
return () => { generation.current++; };
|
|
40
|
+
}, [enabled, sessionMarker, refresh]);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!enabled || !visible) return;
|
|
44
|
+
const current = generation.current;
|
|
45
|
+
const timer = setInterval(() => { void refresh(current).catch(() => setMessage(t("Could not refresh your account. Try again."))); }, 5_000);
|
|
46
|
+
return () => clearInterval(timer);
|
|
47
|
+
}, [enabled, visible, refresh]);
|
|
48
|
+
|
|
49
|
+
const pay = useCallback(async () => {
|
|
50
|
+
if (opening.current === generation.current || !enabled || !visible) return;
|
|
51
|
+
opening.current = generation.current;
|
|
52
|
+
setBusy(true);
|
|
53
|
+
setMessage(null);
|
|
54
|
+
const current = generation.current;
|
|
55
|
+
try {
|
|
56
|
+
const { url } = await apiClient.createInvoicePayment();
|
|
57
|
+
if (generation.current !== current) return;
|
|
58
|
+
const opened = await renderer.openExternal(url);
|
|
59
|
+
if (generation.current === current) {
|
|
60
|
+
setMessage(opened === false ? t("Could not open invoice payment. Try again.") : t("Invoice opened in your browser."));
|
|
61
|
+
}
|
|
62
|
+
} catch {
|
|
63
|
+
if (generation.current === current) setMessage(t("Could not open invoice payment. Try again."));
|
|
64
|
+
} finally {
|
|
65
|
+
await refresh(current);
|
|
66
|
+
if (opening.current === current) opening.current = null;
|
|
67
|
+
if (generation.current === current) setBusy(false);
|
|
68
|
+
}
|
|
69
|
+
}, [enabled, visible, renderer, refresh]);
|
|
70
|
+
|
|
71
|
+
const openPayment = useCallback(() => {
|
|
72
|
+
void pay().catch(() => setMessage(t("Could not open invoice payment. Try again.")));
|
|
73
|
+
}, [pay]);
|
|
74
|
+
|
|
75
|
+
return { visible, busy, message, pay: openPayment, checking: enabled && !loaded };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function PaymentRecoveryRow({ active, busy, message, labelWidth, nodeRef, onPay, onFocus }: {
|
|
79
|
+
active: boolean;
|
|
80
|
+
busy: boolean;
|
|
81
|
+
message: string | null;
|
|
82
|
+
labelWidth: number;
|
|
83
|
+
nodeRef?: Ref<BoxRenderable>;
|
|
84
|
+
onPay: () => void;
|
|
85
|
+
onFocus: () => void;
|
|
86
|
+
}) {
|
|
87
|
+
return (
|
|
88
|
+
<Box ref={nodeRef} flexDirection="row" gap={1} onMouseDown={onFocus}>
|
|
89
|
+
<FieldLabel label={t("Payment")} active={active} width={labelWidth} />
|
|
90
|
+
<Box flexDirection="column" flexShrink={1} minWidth={0} gap={1}>
|
|
91
|
+
<Text fg={colors.text} wrapMode="word">{t("Your Pro payment did not go through.")}</Text>
|
|
92
|
+
<Button label={busy ? t("Opening...") : t("Pay invoice")} active={active} disabled={busy} onPress={onPay} />
|
|
93
|
+
{message ? <Text fg={colors.textDim} wrapMode="word">{message}</Text> : null}
|
|
94
|
+
</Box>
|
|
95
|
+
</Box>
|
|
96
|
+
);
|
|
97
|
+
}
|