@gloom-sh/terminal 0.20.11 → 0.20.12
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/src/api-client/awards.ts +16 -0
- package/src/api-client/central-bank-rates.ts +5 -0
- package/src/api-client/data.ts +55 -2
- package/src/api-client/index.ts +18 -1
- package/src/api-client/request.ts +86 -3
- package/src/api-client/socket-connection.ts +12 -1
- package/src/api-client/socket.ts +21 -3
- package/src/api-client/supply-chain-graph.ts +4 -2
- package/src/api-client/supply-chain.ts +8 -0
- package/src/api-client/types/econ.ts +10 -7
- package/src/api-client/types/filings-and-calls.ts +8 -0
- package/src/app/global-shortcuts.ts +2 -1
- package/src/app/keybindings/actions.ts +19 -0
- package/src/app/pane-runtime/index.tsx +18 -3
- package/src/app/pane-runtime/layout-placement.ts +63 -0
- package/src/app/pane-runtime/ticker-open-runtime.ts +10 -2
- package/src/capabilities/chart-series.ts +4 -1
- package/src/cli/board-coins.ts +10 -1
- package/src/cli/commands/crypto-hints.ts +3 -2
- package/src/cli/commands/fred-series.ts +0 -54
- package/src/cli/commands/market.ts +209 -31
- package/src/cli/commands/overview.ts +47 -14
- package/src/cli/commands/search.ts +37 -8
- package/src/cli/commands/ticker.ts +15 -4
- package/src/cli/desktop-pane-shot.ts +27 -2
- package/src/cli/fx-quote-rate.ts +1 -1
- package/src/cli/glossary.ts +14 -5
- package/src/cli/history-catalog-series.ts +85 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/list-progress.ts +45 -0
- package/src/cli/listing-arg.ts +71 -7
- package/src/cli/name-entries.ts +8 -4
- package/src/cli/not-a-ticker.ts +2 -2
- package/src/cli/pane-functions/freshness.ts +50 -3
- package/src/cli/pane-functions/index.ts +7 -4
- package/src/cli/pane-functions/market-session.ts +66 -14
- package/src/cli/pane-functions/options.ts +5 -0
- package/src/cli/pane-functions/resolver.ts +9 -2
- package/src/cli/pane-functions/screenshot-assessment.ts +28 -3
- package/src/cli/pane-functions/screenshot-types.ts +6 -0
- package/src/cli/quote-answer.ts +49 -10
- package/src/cli/quote-list-reads.ts +87 -0
- package/src/cli/report-tables.ts +70 -13
- package/src/cli/result.ts +24 -2
- package/src/cli/symbol-list.ts +31 -4
- package/src/cli/terminal-code-hints.ts +83 -0
- package/src/cli/ticker-resolution.ts +2 -1
- package/src/cli/treasury-yields.ts +5 -0
- package/src/components/command-bar/action-runtime.ts +2 -0
- package/src/components/command-bar/routing/launch-request.ts +2 -1
- package/src/components/command-bar/routing/navigation-state.ts +4 -2
- package/src/components/command-bar/workflow/types.ts +6 -0
- package/src/components/layout/detached-pane-shell.tsx +3 -0
- package/src/components/layout/double-escape-close.ts +34 -3
- package/src/components/layout/floating-pane.tsx +10 -4
- package/src/components/layout/pane/cycle-order.ts +66 -2
- package/src/components/layout/pane/header.tsx +140 -31
- package/src/components/layout/pane/sidebar.tsx +13 -5
- package/src/components/layout/pane/status-footer.ts +3 -1
- package/src/components/layout/shell/drag/runtime.ts +5 -0
- package/src/components/layout/shell/index.tsx +25 -0
- package/src/components/layout/shell/menu.ts +9 -0
- package/src/components/layout/shell/pane/actions.ts +36 -0
- package/src/components/layout/shell/pane/management-shortcuts.ts +27 -3
- package/src/components/layout/shell/pane-occlusion.ts +40 -0
- package/src/components/layout/shell/shortcuts.ts +17 -1
- package/src/components/layout/shell/terminal-pointer-runtime.ts +39 -6
- package/src/components/layout/shell/window-mode/index.ts +5 -16
- package/src/components/layout/shell/window-mode/overlays.tsx +3 -1
- package/src/components/market-board/index.tsx +14 -5
- package/src/components/metric-treemap/index.tsx +3 -1
- package/src/components/ui/button.tsx +48 -4
- package/src/components/ui/data-table/opentui/index.tsx +24 -9
- package/src/components/ui/data-table/types.ts +7 -0
- package/src/components/ui/inline-quick-add.tsx +19 -3
- package/src/components/ui/list-view.tsx +11 -5
- package/src/components/ui/query-bar.tsx +16 -1
- package/src/components/ui/selection-fill.ts +39 -0
- package/src/core/state/app/layout-reducer.ts +2 -1
- package/src/core/state/app/pane-choices.ts +68 -0
- package/src/core/state/app/state.ts +14 -6
- package/src/core/state/app/types.ts +8 -0
- package/src/layout/pane-manager/dock-tree.ts +19 -0
- package/src/layout/pane-manager/index.ts +3 -0
- package/src/market-data/market/freshness.ts +33 -0
- package/src/market-data/market/status.ts +5 -1
- package/src/market-data/quotes/contributions.ts +10 -0
- package/src/market-data/quotes/freshness.ts +19 -0
- package/src/market-data/quotes/live-valuation.ts +31 -4
- package/src/market-data/quotes/resolution.ts +4 -0
- package/src/market-data/quotes/time.ts +0 -14
- package/src/plugins/builtin/account-management/index.tsx +1 -0
- package/src/plugins/builtin/awards/detail.tsx +12 -4
- package/src/plugins/builtin/awards/headless.ts +29 -8
- package/src/plugins/builtin/awards/model.ts +36 -2
- package/src/plugins/builtin/awards/pane.tsx +7 -4
- package/src/plugins/builtin/broker-manager/index.tsx +1 -0
- package/src/plugins/builtin/broker-trading/index.tsx +1 -1
- package/src/plugins/builtin/central-bank-rates/headless.ts +6 -6
- package/src/plugins/builtin/central-bank-rates/index.tsx +1 -1
- package/src/plugins/builtin/central-bank-rates/model.ts +21 -3
- package/src/plugins/builtin/central-bank-rates/pane.tsx +15 -5
- package/src/plugins/builtin/chart-composer/headless.ts +5 -1
- package/src/plugins/builtin/chart-composer/pane.tsx +1 -0
- package/src/plugins/builtin/chat/content/handle-prompt.tsx +4 -0
- package/src/plugins/builtin/chat/controller/realtime.ts +17 -1
- package/src/plugins/builtin/chat/message/terminal.tsx +4 -1
- package/src/plugins/builtin/chat/sidebar.tsx +3 -4
- package/src/plugins/builtin/cloud/askg/pane.tsx +4 -0
- package/src/plugins/builtin/cloud/plugin.tsx +1 -0
- package/src/plugins/builtin/cloud/team/module.tsx +1 -0
- package/src/plugins/builtin/cloud/thesis/detail.tsx +9 -4
- package/src/plugins/builtin/commodity-balances/pane.tsx +13 -5
- package/src/plugins/builtin/company-kpis/model.ts +3 -3
- package/src/plugins/builtin/connections/index.ts +1 -0
- package/src/plugins/builtin/credit-boards/cdx-pane.tsx +9 -5
- package/src/plugins/builtin/credit-boards/client.ts +5 -0
- package/src/plugins/builtin/credit-boards/headless.ts +1 -6
- package/src/plugins/builtin/credit-boards/model.ts +0 -6
- package/src/plugins/builtin/credit-boards/series.ts +19 -8
- package/src/plugins/builtin/credit-boards/sovr-pane.tsx +9 -5
- package/src/plugins/builtin/crypto-etf-flows/headless.ts +23 -13
- package/src/plugins/builtin/crypto-etf-flows/pane.tsx +8 -3
- package/src/plugins/builtin/debt-maturities/headless.ts +16 -7
- package/src/plugins/builtin/debt-maturities/model.ts +9 -15
- package/src/plugins/builtin/debt-maturities/pane.tsx +9 -10
- package/src/plugins/builtin/earnings/board-model.ts +33 -4
- package/src/plugins/builtin/earnings/board.tsx +15 -3
- package/src/plugins/builtin/earnings/calendar.tsx +10 -6
- package/src/plugins/builtin/earnings/client.ts +0 -9
- package/src/plugins/builtin/earnings/headless.ts +10 -7
- package/src/plugins/builtin/earnings/history.tsx +21 -14
- package/src/plugins/builtin/earnings-calls/data.ts +24 -4
- package/src/plugins/builtin/earnings-calls/format.ts +23 -5
- package/src/plugins/builtin/earnings-calls/headless.ts +23 -3
- package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
- package/src/plugins/builtin/earnings-calls/model.ts +11 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +2 -5
- package/src/plugins/builtin/econ/calendar-model.ts +27 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +3 -0
- package/src/plugins/builtin/econ/index.tsx +9 -2
- package/src/plugins/builtin/econ-statistics/headless.ts +3 -1
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -1
- package/src/plugins/builtin/fear-greed/headless.ts +16 -13
- package/src/plugins/builtin/fear-greed/pane.tsx +12 -4
- package/src/plugins/builtin/filing-events/index.tsx +1 -0
- package/src/plugins/builtin/fx-matrix/index.tsx +30 -19
- package/src/plugins/builtin/insider/table.tsx +10 -7
- package/src/plugins/builtin/insider/tickers.tsx +1 -1
- package/src/plugins/builtin/iv-history/headless.ts +9 -8
- package/src/plugins/builtin/jobs/index.tsx +1 -0
- package/src/plugins/builtin/macro-day/headless.ts +3 -3
- package/src/plugins/builtin/macro-day/model.ts +1 -1
- package/src/plugins/builtin/macro-day/releases.ts +25 -16
- package/src/plugins/builtin/market-movers/index.tsx +20 -8
- package/src/plugins/builtin/market-movers/model.ts +5 -0
- package/src/plugins/builtin/market-movers/session-body.tsx +2 -1
- package/src/plugins/builtin/money-markets/headless.ts +12 -2
- package/src/plugins/builtin/money-markets/pane.tsx +10 -1
- package/src/plugins/builtin/options/view.tsx +1 -0
- package/src/plugins/builtin/options-positioning/pane.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +4 -31
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +6 -1
- package/src/plugins/builtin/portfolio-list/quick-add/index.tsx +22 -8
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +6 -8
- package/src/plugins/builtin/portfolio-list/table.tsx +10 -1
- package/src/plugins/builtin/realized-vol/headless.ts +28 -2
- package/src/plugins/builtin/risk-factors/index.tsx +1 -0
- package/src/plugins/builtin/shared/source-footer.ts +70 -0
- package/src/plugins/builtin/short-interest/publications-pane.tsx +5 -1
- package/src/plugins/builtin/short-volume/pane.tsx +5 -1
- package/src/plugins/builtin/social-mentions/outliers.tsx +10 -1
- package/src/plugins/builtin/social-mentions/pane.tsx +7 -0
- package/src/plugins/builtin/supply-chain/client.ts +3 -1
- package/src/plugins/builtin/supply-chain/flow.tsx +25 -8
- package/src/plugins/builtin/supply-chain/graph-client.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-evidence.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-model.ts +12 -1
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +9 -8
- package/src/plugins/builtin/supply-chain/graph.tsx +12 -6
- package/src/plugins/builtin/supply-chain/headless.ts +13 -7
- package/src/plugins/builtin/supply-chain/model.ts +68 -11
- package/src/plugins/builtin/supply-chain/pane.tsx +9 -6
- package/src/plugins/builtin/supply-chain/row-evidence.tsx +5 -5
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +14 -1
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +2 -0
- package/src/plugins/builtin/ticker-detail/pane.tsx +48 -24
- package/src/plugins/builtin/ticker-detail/quote-footer.ts +5 -0
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +6 -3
- package/src/plugins/builtin/treasury-auctions/after.ts +50 -23
- package/src/plugins/builtin/treasury-auctions/cache.ts +23 -5
- package/src/plugins/builtin/treasury-auctions/headless.ts +226 -37
- package/src/plugins/builtin/treasury-auctions/hk-headless.ts +11 -5
- package/src/plugins/builtin/treasury-auctions/hk-view.tsx +27 -25
- package/src/plugins/builtin/treasury-auctions/hk.ts +60 -8
- package/src/plugins/builtin/treasury-auctions/index.tsx +3 -0
- package/src/plugins/builtin/treasury-auctions/keys.ts +27 -0
- package/src/plugins/builtin/treasury-auctions/like.ts +137 -0
- package/src/plugins/builtin/treasury-auctions/model.ts +100 -22
- package/src/plugins/builtin/treasury-auctions/pane.tsx +39 -11
- package/src/plugins/builtin/vol-surface/heat-grid.tsx +4 -2
- package/src/plugins/builtin/vol-surface/pane.tsx +5 -2
- package/src/plugins/runtime/index.tsx +1 -0
- package/src/plugins/runtime/state.ts +20 -0
- package/src/portfolio/column-values.ts +8 -2
- package/src/public/__snapshots__/public-api.test.ts.snap +5 -0
- package/src/public/react.ts +7 -0
- package/src/react/auto-refresh.ts +29 -0
- package/src/renderers/browser/deeplink-bridge.ts +24 -3
- package/src/renderers/dom/desktop/query-bar.tsx +229 -60
- package/src/renderers/dom/host/overflow-fade-px.ts +2 -0
- package/src/renderers/dom/host/overflow-fade.ts +1 -2
- package/src/renderers/dom/styles.css +25 -5
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +2 -1
- package/src/series/types.ts +2 -0
- package/src/sources/gloomberb-cloud/fred-attribution.ts +86 -0
- package/src/sources/gloomberb-cloud/index.ts +25 -1
- package/src/sources/gloomberb-cloud/normalizers.ts +22 -3
- package/src/sources/provider-errors.ts +64 -1
- package/src/sources/provider-router/batches.ts +19 -0
- package/src/sources/provider-router/index.ts +7 -1
- package/src/state/app/context/index.tsx +24 -1
- package/src/state/pane-unsent-work.ts +47 -0
- package/src/test-support/shell-pane-keys.tsx +5 -0
- package/src/test-support/telemetry-guard.ts +83 -0
- package/src/test-support/test-env.ts +12 -0
- package/src/theme/colors.ts +17 -1
- package/src/theme/ui-tokens.ts +50 -1
- package/src/tickers/listing-venues.ts +11 -1
- package/src/tickers/search/japanese-names.json +1 -0
- package/src/tickers/search/japanese-names.ts +152 -0
- package/src/tickers/terminal-codes.ts +55 -6
- package/src/time-series/base-series.ts +3 -0
- package/src/types/data-provider.ts +6 -0
- package/src/types/financials.ts +11 -0
- package/src/types/plugin-contributions.ts +7 -0
- package/src/types/plugin-panes.ts +7 -0
- package/src/ui/host.tsx +6 -0
- package/src/utils/double-escape-close.ts +42 -0
- package/src/utils/fx-status.ts +30 -7
- package/src/utils/network-failure.ts +23 -0
|
@@ -33,6 +33,8 @@ import { isBankOrInsurerIndustry, withStatementEbitda } from "../../utils/ebitda
|
|
|
33
33
|
import { parseListingDelisting } from "../../market-data/quotes/delisting";
|
|
34
34
|
import { readIntradayBar, readStaleReason } from "../../market-data/quotes/intraday-bar";
|
|
35
35
|
import { readSessionSplit } from "../../market-data/quotes/session-split";
|
|
36
|
+
import { isIndexLevel } from "../../market-data/market/index-level";
|
|
37
|
+
import { isYieldIndexSymbol } from "../../tickers/index-roots";
|
|
36
38
|
|
|
37
39
|
export const GLOOMBERB_CLOUD_PROVIDER_ID = "gloomberb-cloud" as const;
|
|
38
40
|
|
|
@@ -109,6 +111,13 @@ export function mapQuote(
|
|
|
109
111
|
const priceBasis = quote.priceBasis === "nav"
|
|
110
112
|
? "per-unit"
|
|
111
113
|
: futuresBasis ?? quote.priceBasis;
|
|
114
|
+
// An index's 0 open or day range is none (^BVSP before B3 opens served Open 0.00, Day Range 0.00 - 0.00): no level
|
|
115
|
+
// is 0. A Treasury yield index's is (^IRX read 0.00 in 2020), and its levels stand.
|
|
116
|
+
const index = isIndexLevel(quote.instrumentType) && !isYieldIndexSymbol(quote.symbol ?? "");
|
|
117
|
+
const sessionPrice = (value: number | undefined) => {
|
|
118
|
+
const price = normalizePriceValueByDivisor(value, divisor);
|
|
119
|
+
return index && price != null && price <= 0 ? undefined : price;
|
|
120
|
+
};
|
|
112
121
|
return withoutUndefinedFields(reconcileQuoteDayRange({
|
|
113
122
|
...quote,
|
|
114
123
|
retrievedAt: serviceRetrievedAt(quote.retrievedAt),
|
|
@@ -132,11 +141,15 @@ export function mapQuote(
|
|
|
132
141
|
: undefined,
|
|
133
142
|
high52w: normalizePriceValueByDivisor(quote.high52w, divisor),
|
|
134
143
|
low52w: normalizePriceValueByDivisor(quote.low52w, divisor),
|
|
144
|
+
// The service read the 52-week range from its stored daily bars, its source's being unusable.
|
|
145
|
+
yearRangeBasis: quote.yearRangeBasis === "daily-bars" ? "daily-bars" : undefined,
|
|
146
|
+
// No live quote: the close of the latest daily bar of this session.
|
|
147
|
+
dailyClose: readDailyClose(quote.dailyClose),
|
|
135
148
|
bid: normalizePriceValueByDivisor(quote.bid, divisor),
|
|
136
149
|
ask: normalizePriceValueByDivisor(quote.ask, divisor),
|
|
137
|
-
open:
|
|
138
|
-
high:
|
|
139
|
-
low:
|
|
150
|
+
open: sessionPrice(quote.open),
|
|
151
|
+
high: sessionPrice(quote.high),
|
|
152
|
+
low: sessionPrice(quote.low),
|
|
140
153
|
mark: normalizePriceValueByDivisor(quote.mark, divisor),
|
|
141
154
|
lastTradePrice: normalizePriceValueByDivisor(quote.lastTradePrice, divisor),
|
|
142
155
|
preMarketPrice: normalizePriceValueByDivisor(quote.preMarketPrice, divisor),
|
|
@@ -195,6 +208,12 @@ export function mapQuote(
|
|
|
195
208
|
}));
|
|
196
209
|
}
|
|
197
210
|
|
|
211
|
+
/** A daily close's session, an exchange-local `YYYY-MM-DD`; anything else is no daily close. */
|
|
212
|
+
function readDailyClose(value: unknown): Quote["dailyClose"] {
|
|
213
|
+
const session = value && typeof value === "object" ? (value as { session?: unknown }).session : undefined;
|
|
214
|
+
return typeof session === "string" && /^\d{4}-\d{2}-\d{2}$/.test(session) ? { session } : undefined;
|
|
215
|
+
}
|
|
216
|
+
|
|
198
217
|
/**
|
|
199
218
|
* JSON has no undefined, so a field the server left out must stay absent here
|
|
200
219
|
* too; the desktop window only ever sees the JSON form. Whether an omitted
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataServiceUnreachableError, isNetworkFailure } from "../utils/network-failure";
|
|
2
|
-
import { wasAskedTwice } from "../api-client/errors";
|
|
2
|
+
import { ApiRequestError, wasAskedTwice } from "../api-client/errors";
|
|
3
3
|
|
|
4
4
|
// Registered, so a miss raised by another copy of this module (a plugin that
|
|
5
5
|
// resolved `gloomberb/market-data` from the source tree) is still recognized.
|
|
@@ -163,9 +163,22 @@ export function noProviderError(message: string, note: ProviderMissNote | undefi
|
|
|
163
163
|
return note!.failure instanceof DataServiceUnreachableError ? note!.failure : new DataServiceUnreachableError(note!.failure);
|
|
164
164
|
}
|
|
165
165
|
if (wasAskedTwice(note?.failure)) return new NoProviderError(serviceDidNotAnswerMessage(symbol), note!.failure);
|
|
166
|
+
if (note?.failure instanceof ApiRequestError && note.failure.status === 429) {
|
|
167
|
+
return new NoProviderError(rateLimitedMessage(symbol, note.failure.retryAfterMs), note.failure);
|
|
168
|
+
}
|
|
166
169
|
return new NoProviderError(message, note?.failure);
|
|
167
170
|
}
|
|
168
171
|
|
|
172
|
+
/**
|
|
173
|
+
* What a read says when Gloom's data service refused it for its request limit
|
|
174
|
+
* (429): not that the listing has no data, and when to ask again. "for SYMBOL"
|
|
175
|
+
* closes the first sentence, as `serviceDidNotAnswerMessage` words it.
|
|
176
|
+
*/
|
|
177
|
+
export function rateLimitedMessage(symbol?: string, retryAfterMs?: number): string {
|
|
178
|
+
const wait = retryAfterMs && retryAfterMs > 0 ? `in ${Math.ceil(retryAfterMs / 1000)} s` : "in a minute";
|
|
179
|
+
return `Gloom's data service is at its request limit${symbol ? ` for ${symbol}` : ""}. Try again ${wait}.`;
|
|
180
|
+
}
|
|
181
|
+
|
|
169
182
|
/**
|
|
170
183
|
* The router's answer that no source served a read because one failed (a
|
|
171
184
|
* timeout, a rate limit, a refused session), not because none has it: asked
|
|
@@ -212,3 +225,53 @@ export function shouldLogProviderError(error: unknown): boolean {
|
|
|
212
225
|
const message = error instanceof Error ? error.message : String(error);
|
|
213
226
|
return !EXPECTED_PROVIDER_MISS.test(message);
|
|
214
227
|
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The data service's refusal of a read for its request limit (429), however
|
|
231
|
+
* it reached the caller: as itself, as the failure behind the router's "No
|
|
232
|
+
* quote provider available", or as the cause of a busy search. Null for any
|
|
233
|
+
* other failure.
|
|
234
|
+
*/
|
|
235
|
+
function rateLimitRefusal(error: unknown, depth = 0): ApiRequestError | null {
|
|
236
|
+
if (!error || typeof error !== "object" || depth > 4) return null;
|
|
237
|
+
if (error instanceof ApiRequestError) return error.status === 429 ? error : null;
|
|
238
|
+
if (error instanceof NoProviderError) return rateLimitRefusal(error.failure, depth + 1);
|
|
239
|
+
return rateLimitRefusal((error as { cause?: unknown }).cause, depth + 1);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Whether a read was refused for the data service's request limit, including
|
|
244
|
+
* one whose message alone crossed a bridge ("... at its request limit for
|
|
245
|
+
* AAPL. Try again in 40 s."). Never asked again: asking is more of what it
|
|
246
|
+
* refused, so the row keeps when to try.
|
|
247
|
+
*/
|
|
248
|
+
export function isRateLimited(error: unknown): boolean {
|
|
249
|
+
if (error == null) return false;
|
|
250
|
+
if (rateLimitRefusal(error)) return true;
|
|
251
|
+
const message = (error instanceof Error ? error.message : String(error)).trim();
|
|
252
|
+
return message.startsWith(rateLimitedMessage().split(".")[0]!);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* A read refused for the request limit, worded as a single read of `symbol`
|
|
257
|
+
* says it: "Gloom's data service is at its request limit for AAPL. Try again
|
|
258
|
+
* in 40 s.". The error itself when it says so already.
|
|
259
|
+
*/
|
|
260
|
+
export function rateLimitedError(error: unknown, symbol: string): unknown {
|
|
261
|
+
const refusal = rateLimitRefusal(error);
|
|
262
|
+
return refusal ? new NoProviderError(rateLimitedMessage(symbol, refusal.retryAfterMs), refusal) : error;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Whether a failure says nothing of what was asked, so asked again in a
|
|
267
|
+
* moment it may be answered: no connection, no answer from the data service,
|
|
268
|
+
* or a busy moment. A source's own answer (Not a ticker, a delisting) is not
|
|
269
|
+
* one, and neither is the request limit (`isRateLimited`), which is never
|
|
270
|
+
* asked again.
|
|
271
|
+
*/
|
|
272
|
+
export function isTransientServiceFailure(error: unknown): boolean {
|
|
273
|
+
if (error == null || isRateLimited(error)) return false;
|
|
274
|
+
if (isNetworkFailure(error) || isProviderBusy(error)) return true;
|
|
275
|
+
const message = (error instanceof Error ? error.message : String(error)).trim();
|
|
276
|
+
return message.startsWith(serviceDidNotAnswerMessage().split(".")[0]!);
|
|
277
|
+
}
|
|
@@ -27,6 +27,8 @@ import {
|
|
|
27
27
|
type CachedFinancialsSelection,
|
|
28
28
|
} from "./financials";
|
|
29
29
|
import type { ProviderRouterCoreDeps } from "./route-types";
|
|
30
|
+
import { isRateLimited, rateLimitedError } from "../provider-errors";
|
|
31
|
+
import { quoteServedFromSavedCopy } from "../../data/saved-copies";
|
|
30
32
|
import { isNetworkFailure } from "../../utils/network-failure";
|
|
31
33
|
import { withRetrievedAt } from "./retrieved-at";
|
|
32
34
|
|
|
@@ -62,6 +64,8 @@ export class ProviderRouterBatchRoutes {
|
|
|
62
64
|
const results = new Array<QuoteBatchResult | null>(targets.length).fill(null);
|
|
63
65
|
// A dated price the batch answered that is not current: shown, flagged stale, when asking alone brings none.
|
|
64
66
|
const lastKnown = new Array<Quote | null>(targets.length).fill(null);
|
|
67
|
+
// The data service's copy each listing has saved here, which answers for it when the service refuses the batch.
|
|
68
|
+
const saved = new Array<{ value: Quote; fetchedAt: number } | null>(targets.length).fill(null);
|
|
65
69
|
const misses: Array<{ index: number; target: QuoteSubscriptionTarget }> = [];
|
|
66
70
|
|
|
67
71
|
targets.forEach((target, index) => {
|
|
@@ -88,6 +92,7 @@ export class ProviderRouterBatchRoutes {
|
|
|
88
92
|
return;
|
|
89
93
|
}
|
|
90
94
|
// Revalidated, a fresh copy is still what the quote route answers when no source does.
|
|
95
|
+
if (cached && !brokerSourceKeys.includes(cached.sourceKey)) saved[index] = cached;
|
|
91
96
|
misses.push({ index, target });
|
|
92
97
|
});
|
|
93
98
|
|
|
@@ -95,6 +100,8 @@ export class ProviderRouterBatchRoutes {
|
|
|
95
100
|
const providerMisses = misses.filter(({ target }) => !this.deps.hasBrokerContext(target.context));
|
|
96
101
|
const providerIndexes = new Map<string, Array<{ index: number; target: QuoteSubscriptionTarget }>>();
|
|
97
102
|
let batchFailure: unknown = null;
|
|
103
|
+
// Listings the service refused for its request limit, by batch key, with the refusal.
|
|
104
|
+
const limited = new Map<string, unknown>();
|
|
98
105
|
if (batchProvider && providerMisses.length > 0) {
|
|
99
106
|
for (const entry of providerMisses) {
|
|
100
107
|
const key = this.quoteBatchKey(entry.target);
|
|
@@ -111,6 +118,7 @@ export class ProviderRouterBatchRoutes {
|
|
|
111
118
|
for (const answered of batchResults) {
|
|
112
119
|
const item = { ...answered, quote: withRetrievedAt(answered.quote, answeredAt) };
|
|
113
120
|
const key = this.quoteBatchKey(item.target);
|
|
121
|
+
if (!item.quote && isRateLimited(item.error)) limited.set(key, item.error);
|
|
114
122
|
if (!isProviderQuoteUsableForCurrentSession(item.quote, item.target.exchange, item.target.symbol, { recentAnswer: true })) {
|
|
115
123
|
const fallback = lastKnownProviderQuote(item.quote, item.target.exchange, item.target.symbol);
|
|
116
124
|
if (fallback) for (const entry of providerIndexes.get(key) ?? []) lastKnown[entry.index] = fallback;
|
|
@@ -126,6 +134,17 @@ export class ProviderRouterBatchRoutes {
|
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
|
|
137
|
+
// Refused for the request limit, a listing is never asked again alone: that is a request each, more of what was
|
|
138
|
+
// refused. Its saved copy answers, as a single read's would, else the row says when to try again.
|
|
139
|
+
for (const { index, target } of providerMisses) {
|
|
140
|
+
const refusal = isRateLimited(batchFailure) ? batchFailure : limited.get(this.quoteBatchKey(target));
|
|
141
|
+
if (results[index] || refusal === undefined) continue;
|
|
142
|
+
const copy = saved[index];
|
|
143
|
+
results[index] = copy ? { target, quote: quoteServedFromSavedCopy(withRetrievedAt(copy.value, copy.fetchedAt), copy.fetchedAt) }
|
|
144
|
+
: lastKnown[index] ? { target, quote: lastKnown[index] }
|
|
145
|
+
: { target, quote: null, error: rateLimitedError(refusal, target.symbol) };
|
|
146
|
+
}
|
|
147
|
+
|
|
129
148
|
// The batch never reached the data service: a copy saved a moment ago is still a saved copy, not the
|
|
130
149
|
// service's answer, so each is asked for as a refresh, which fails at once and says it answers from that copy.
|
|
131
150
|
const unreached = isNetworkFailure(batchFailure) ? new Set(providerMisses.map(({ index }) => index)) : null;
|
|
@@ -33,6 +33,8 @@ import { assertTimeRange, type TimeRange } from "../../time-series/range";
|
|
|
33
33
|
import type { ChartResolutionSupport, ManualChartResolution } from "../../time-series/resolution";
|
|
34
34
|
import { debugLog } from "../../utils/debug-log";
|
|
35
35
|
import { errorMessage } from "../../utils/errors";
|
|
36
|
+
import { isProviderBusy, isRateLimited, isSourceFailure } from "../provider-errors";
|
|
37
|
+
import { isNetworkFailure } from "../../utils/network-failure";
|
|
36
38
|
import { isPastPreCloseRefetch } from "../../utils/exchange-rate-snapshot";
|
|
37
39
|
import { ProviderRouterBatchRoutes } from "./batches";
|
|
38
40
|
import { createSignedInRealtimeCloudAccess, type RealtimeCloudAccess } from "./realtime-access";
|
|
@@ -259,7 +261,11 @@ export class AssetDataRouter implements DataProvider {
|
|
|
259
261
|
// Error into {} and its reason into "[object Object]" on the board.
|
|
260
262
|
return targets.map((target) => {
|
|
261
263
|
const result = restored.get(target) ?? { target, quote: null };
|
|
262
|
-
|
|
264
|
+
if (result.error == null) return result;
|
|
265
|
+
// The request limit is no moment's failure: asked again it is more of what was refused (`isRateLimited`).
|
|
266
|
+
const transient = !isRateLimited(result.error)
|
|
267
|
+
&& (isSourceFailure(result.error) || isNetworkFailure(result.error) || isProviderBusy(result.error));
|
|
268
|
+
return { ...result, error: errorMessage(result.error), ...transient ? { transient } : {} };
|
|
263
269
|
});
|
|
264
270
|
}
|
|
265
271
|
|
|
@@ -26,6 +26,7 @@ import { setPaneSetting, setPaneSettings, updatePaneInstance } from "../../../pa
|
|
|
26
26
|
import { useTickerFinancials } from "../../../market-data/hooks";
|
|
27
27
|
import { hasAmbiguousTickerContracts, resolveInstrumentForPane, resolveListingForPane, tickerForInstrument } from "../../../core/state/app/instrument";
|
|
28
28
|
import { materializeDetachedLayouts } from "../../../core/state/app/layout";
|
|
29
|
+
import { isPaneChoice, withAllPaneChoices } from "../../../core/state/app/pane-choices";
|
|
29
30
|
import {
|
|
30
31
|
APP_SESSION_ID,
|
|
31
32
|
APP_SESSION_SCHEMA_VERSION,
|
|
@@ -339,6 +340,21 @@ export function usePaneStateValue<T>(key: string, fallback: T, paneId?: string):
|
|
|
339
340
|
return [value, setValue];
|
|
340
341
|
}
|
|
341
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Whether this pane's `key` was chosen in this session rather than restored
|
|
345
|
+
* with the workspace, and the call for a pick that may leave the value as it
|
|
346
|
+
* is (see `pane-choices.ts`). Any write of the key already counts.
|
|
347
|
+
*/
|
|
348
|
+
export function usePaneChoice(key: string, paneId?: string): [chosen: boolean, choose: () => void] {
|
|
349
|
+
const dispatch = useAppDispatch();
|
|
350
|
+
const scopedPaneId = useScopedPaneId(paneId);
|
|
351
|
+
const chosen = useAppSelector((state) => isPaneChoice(state, scopedPaneId, key));
|
|
352
|
+
const choose = useCallback(() => {
|
|
353
|
+
dispatch({ type: "CHOOSE_PANE_STATE", paneId: scopedPaneId, key });
|
|
354
|
+
}, [dispatch, key, scopedPaneId]);
|
|
355
|
+
return [chosen, choose];
|
|
356
|
+
}
|
|
357
|
+
|
|
342
358
|
export function usePaneSettingValue<T>(
|
|
343
359
|
key: string,
|
|
344
360
|
fallback: T,
|
|
@@ -445,6 +461,7 @@ export function AppProvider({
|
|
|
445
461
|
desktopBridge,
|
|
446
462
|
desktopSnapshot = null,
|
|
447
463
|
initialThemePreview = null,
|
|
464
|
+
paneStateChosen = false,
|
|
448
465
|
}: {
|
|
449
466
|
config: AppConfig;
|
|
450
467
|
children: ReactNode;
|
|
@@ -453,6 +470,11 @@ export function AppProvider({
|
|
|
453
470
|
desktopBridge?: DesktopWindowBridge;
|
|
454
471
|
desktopSnapshot?: DesktopSharedStateSnapshot | null;
|
|
455
472
|
initialThemePreview?: DesktopThemePreviewState | null;
|
|
473
|
+
/**
|
|
474
|
+
* The pane state it starts with was asked for now (a pane function's
|
|
475
|
+
* capture), not restored with a workspace: see `pane-choices.ts`.
|
|
476
|
+
*/
|
|
477
|
+
paneStateChosen?: boolean;
|
|
456
478
|
}) {
|
|
457
479
|
const [state, rawDispatch] = useReducer(
|
|
458
480
|
appReducer,
|
|
@@ -470,9 +492,10 @@ export function AppProvider({
|
|
|
470
492
|
initialThemePreview: initialDesktopThemePreview,
|
|
471
493
|
} = initialState;
|
|
472
494
|
const baseState = createInitialState(initialConfig, initialSessionSnapshot);
|
|
473
|
-
const
|
|
495
|
+
const hydratedState = initialDesktopSnapshot
|
|
474
496
|
? appReducer(baseState, { type: "HYDRATE_DESKTOP_SNAPSHOT", snapshot: initialDesktopSnapshot })
|
|
475
497
|
: baseState;
|
|
498
|
+
const nextState = paneStateChosen ? withAllPaneChoices(hydratedState) : hydratedState;
|
|
476
499
|
return initialDesktopThemePreview
|
|
477
500
|
? appReducer(nextState, { type: "PREVIEW_THEME", theme: initialDesktopThemePreview.theme })
|
|
478
501
|
: nextState;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { useOptionalPaneInstanceId } from "./app/context";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Panes holding something an Esc must not throw away: a draft not sent, an
|
|
6
|
+
* answer still coming in. Esc, one press or two, never closes such a pane; a
|
|
7
|
+
* deliberate close (Ctrl+W, the close button, the pane menu) still does.
|
|
8
|
+
*
|
|
9
|
+
* A pane whose draft outlives it (saved with the chat channel, a note saved
|
|
10
|
+
* when editing ends) has nothing to report. Neither has a form that takes its
|
|
11
|
+
* own Esc as Cancel: that Esc never reaches the close.
|
|
12
|
+
*/
|
|
13
|
+
const holders = new Map<string, Set<symbol>>();
|
|
14
|
+
|
|
15
|
+
export function paneHoldsUnsentWork(paneId: string | null | undefined): boolean {
|
|
16
|
+
return !!paneId && (holders.get(paneId)?.size ?? 0) > 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Marks a pane as holding unsent work until the returned release is called. */
|
|
20
|
+
export function holdPaneUnsentWork(paneId: string): () => void {
|
|
21
|
+
const token = Symbol(paneId);
|
|
22
|
+
let entry = holders.get(paneId);
|
|
23
|
+
if (!entry) {
|
|
24
|
+
entry = new Set();
|
|
25
|
+
holders.set(paneId, entry);
|
|
26
|
+
}
|
|
27
|
+
const held = entry;
|
|
28
|
+
held.add(token);
|
|
29
|
+
return () => {
|
|
30
|
+
held.delete(token);
|
|
31
|
+
if (held.size === 0 && holders.get(paneId) === held) holders.delete(paneId);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Reports that the pane holds work an Esc must not throw away while `holds`
|
|
37
|
+
* is true: a composer with text in it, an answer still streaming. The pane is
|
|
38
|
+
* the one in context, or `paneId` where the caller names it.
|
|
39
|
+
*/
|
|
40
|
+
export function usePaneUnsentWork(holds: boolean, paneId?: string): void {
|
|
41
|
+
const contextPaneId = useOptionalPaneInstanceId();
|
|
42
|
+
const target = paneId ?? contextPaneId;
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!holds || !target) return undefined;
|
|
45
|
+
return holdPaneUnsentWork(target);
|
|
46
|
+
}, [holds, target]);
|
|
47
|
+
}
|
|
@@ -14,6 +14,7 @@ export function TestShellPaneKeys(options: Partial<ShellPaneKeyOptions> & { focu
|
|
|
14
14
|
askAboutFocusedPane: none,
|
|
15
15
|
cancelActiveDrag: () => {},
|
|
16
16
|
closeAllFloatingPanes: none,
|
|
17
|
+
closeFocusedFloatingPane: none,
|
|
17
18
|
closeFocusedPane: none,
|
|
18
19
|
copyFocusedPaneScreenshot: none,
|
|
19
20
|
exportFocusedPaneCsv: none,
|
|
@@ -26,11 +27,15 @@ export function TestShellPaneKeys(options: Partial<ShellPaneKeyOptions> & { focu
|
|
|
26
27
|
overlayOpen: false,
|
|
27
28
|
popOutFocusedPane: none,
|
|
28
29
|
shareFocusedPane: none,
|
|
30
|
+
showAdjacentStackTab: none,
|
|
29
31
|
startWindowMode: () => {},
|
|
30
32
|
toggleFocusedPaneFullscreen: none,
|
|
31
33
|
toggleFocusedPaneFloating: none,
|
|
32
34
|
toggleFocusedPaneNewLayout: none,
|
|
33
35
|
...options,
|
|
36
|
+
// Esc Esc closes as the shell's close does unless the test passes its own.
|
|
37
|
+
closeFocusedPaneOnEscape: options.closeFocusedPaneOnEscape
|
|
38
|
+
?? (options.closeFocusedPane ? () => options.closeFocusedPane!({ focusNextFloating: true }) : none),
|
|
34
39
|
});
|
|
35
40
|
return null;
|
|
36
41
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { afterAll, afterEach, beforeEach } from "bun:test";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The paths a running app reports itself on: crash reports and usage counts
|
|
5
|
+
* (`/telemetry/`), research activity (`/activity/`) and command-search reports
|
|
6
|
+
* (`/assist/searches`). The web app reaches them under `/api`.
|
|
7
|
+
*/
|
|
8
|
+
const TELEMETRY_PATH = /^(?:\/api)?\/(?:telemetry\/|activity\/|assist\/searches$)/;
|
|
9
|
+
|
|
10
|
+
/** Whether a request is one the app sends about itself, on any host but the machine's own. */
|
|
11
|
+
function isTelemetryRequest(input: RequestInfo | URL): boolean {
|
|
12
|
+
try {
|
|
13
|
+
const url = new URL(input instanceof Request ? input.url : String(input));
|
|
14
|
+
if (url.hostname === "127.0.0.1" || url.hostname === "localhost" || url.hostname === "[::1]") return false;
|
|
15
|
+
return TELEMETRY_PATH.test(url.pathname);
|
|
16
|
+
} catch {
|
|
17
|
+
// Intentional ignore: a relative or malformed URL names no telemetry endpoint.
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const attempts: string[] = [];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Tests never send usage counts or crash reports: `test-env.ts` turns them off
|
|
26
|
+
* for the whole process and for every process a test starts. A test that
|
|
27
|
+
* checks telemetry itself opts in and stubs the transport
|
|
28
|
+
* (`setCloudApiFetchTransport`), so nothing reaches `globalThis.fetch`.
|
|
29
|
+
*
|
|
30
|
+
* This is the net under that: a telemetry request that does reach the real
|
|
31
|
+
* `fetch` is refused and fails the test running when it was made (a fire and
|
|
32
|
+
* forget caller swallows the refusal, so throwing alone would pass), or the
|
|
33
|
+
* run's final check when it was made after the last test.
|
|
34
|
+
*/
|
|
35
|
+
const realFetch = globalThis.fetch;
|
|
36
|
+
const guardedFetch = Object.assign(
|
|
37
|
+
(input: RequestInfo | URL, init?: RequestInit) => {
|
|
38
|
+
if (isTelemetryRequest(input)) {
|
|
39
|
+
const url = input instanceof Request ? input.url : String(input);
|
|
40
|
+
attempts.push(`${init?.method ?? (input instanceof Request ? input.method : "GET")} ${url}`);
|
|
41
|
+
return Promise.reject(new Error(`Telemetry request blocked in tests: ${url}`));
|
|
42
|
+
}
|
|
43
|
+
return realFetch(input, init);
|
|
44
|
+
},
|
|
45
|
+
realFetch,
|
|
46
|
+
) as typeof fetch;
|
|
47
|
+
globalThis.fetch = guardedFetch;
|
|
48
|
+
|
|
49
|
+
function failOnAttempts(): void {
|
|
50
|
+
if (attempts.length === 0) return;
|
|
51
|
+
const sent = attempts.splice(0);
|
|
52
|
+
throw new Error(
|
|
53
|
+
`A test sent telemetry to the real service: ${sent.join(", ")}. Tests run with telemetry off; `
|
|
54
|
+
+ "a test that exercises telemetry must stub the Cloud API transport (setCloudApiFetchTransport).",
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
afterEach(failOnAttempts);
|
|
59
|
+
afterAll(failOnAttempts);
|
|
60
|
+
|
|
61
|
+
const OPT_OUT_ENV = ["GLOOMBERB_NO_TELEMETRY", "DO_NOT_TRACK"] as const;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* For a test file, or a `describe`, that checks what the app sends about
|
|
65
|
+
* itself: clears the opt-out `test-env.ts` sets for each test and restores it
|
|
66
|
+
* after. Stub where the report goes (`setCloudApiFetchTransport`, the host's
|
|
67
|
+
* `send`, the `apiClient` method) as well: a report that reaches the real
|
|
68
|
+
* `fetch` fails the test.
|
|
69
|
+
*/
|
|
70
|
+
export function allowTelemetryInTests(): void {
|
|
71
|
+
let saved: Array<string | undefined> = [];
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
saved = OPT_OUT_ENV.map((name) => process.env[name]);
|
|
74
|
+
for (const name of OPT_OUT_ENV) delete process.env[name];
|
|
75
|
+
});
|
|
76
|
+
afterEach(() => {
|
|
77
|
+
OPT_OUT_ENV.forEach((name, index) => {
|
|
78
|
+
const value = saved[index];
|
|
79
|
+
if (value === undefined) delete process.env[name];
|
|
80
|
+
else process.env[name] = value;
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -5,3 +5,15 @@
|
|
|
5
5
|
* first in bunfig.toml's preload, so it runs before anything imports React.
|
|
6
6
|
*/
|
|
7
7
|
process.env.NODE_ENV = "test";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Tests never send crash reports or usage counts. Each test home looks like a
|
|
11
|
+
* brand-new install to the service, so a run that reached it would count dozens
|
|
12
|
+
* of installs that exist for the length of one test. Set here, the opt-out also
|
|
13
|
+
* reaches every process a test starts with the inherited environment (a CLI
|
|
14
|
+
* run, a packaged entry), which the in-process guard in `telemetry-guard.ts`
|
|
15
|
+
* cannot see. A test that checks telemetry itself calls `allowTelemetryInTests`
|
|
16
|
+
* from that file and stubs where the report goes.
|
|
17
|
+
*/
|
|
18
|
+
process.env.GLOOMBERB_NO_TELEMETRY = "1";
|
|
19
|
+
process.env.DO_NOT_TRACK = "1";
|
package/src/theme/colors.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { blendForContrast, blendForContrastOnSurfaces, blendHex, higherContrast } from "./color-utils";
|
|
2
2
|
import { getTheme, DEFAULT_THEME, type Theme } from "./themes";
|
|
3
|
-
import { hoverColour, placeholderColour, themeCssVariables } from "./ui-tokens";
|
|
3
|
+
import { hoverColour, inactiveSelectionColour, inactiveSelectionTextColour, placeholderColour, themeCssVariables } from "./ui-tokens";
|
|
4
4
|
|
|
5
5
|
export type ThemeColors = Readonly<Omit<Theme, "name" | "description">>;
|
|
6
6
|
|
|
@@ -94,6 +94,22 @@ export function hoverBg(palette: ThemeColors = colors): string {
|
|
|
94
94
|
return hoverColour(palette);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* The chosen row of a list or table in a pane that is not focused (ui-tokens
|
|
99
|
+
* `inactiveSelectionColour`); the focused pane's chosen row is `selected`.
|
|
100
|
+
*/
|
|
101
|
+
export function inactiveSelectedBg(palette: ThemeColors = colors): string {
|
|
102
|
+
return inactiveSelectionColour(palette);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Text on the inactive selection (`inactiveSelectedBg`): the row's own colour,
|
|
107
|
+
* lifted where it would not read there (ui-tokens `inactiveSelectionTextColour`).
|
|
108
|
+
*/
|
|
109
|
+
export function inactiveSelectedText(color: string, palette: ThemeColors = colors): string {
|
|
110
|
+
return inactiveSelectionTextColour(color, palette);
|
|
111
|
+
}
|
|
112
|
+
|
|
97
113
|
/**
|
|
98
114
|
* Placeholder text in a field (ui-tokens `placeholderColour`); `surface` is
|
|
99
115
|
* what the field sits on when that is not the page or a panel.
|
package/src/theme/ui-tokens.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { blendForContrast, blendHex, higherContrast } from "./color-utils";
|
|
1
|
+
import { blendForContrast, blendHex, contrastRatio, higherContrast } from "./color-utils";
|
|
2
2
|
import { SUBTLE_TEXT_MIN, type Theme } from "./themes";
|
|
3
3
|
|
|
4
4
|
type Palette = Readonly<Omit<Theme, "name" | "description">>;
|
|
@@ -74,6 +74,55 @@ export function hoverColour(palette: Palette): string {
|
|
|
74
74
|
return blendHex(palette.bg, palette.selected, 0.5);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* The least contrast the inactive selection keeps with the page and with a
|
|
79
|
+
* panel, either of which a list sits on: below it the row reads as a shadow
|
|
80
|
+
* in a theme whose selection sits close to its background (high contrast,
|
|
81
|
+
* blue, midnight).
|
|
82
|
+
*/
|
|
83
|
+
export const INACTIVE_SELECTION_MIN = 1.3;
|
|
84
|
+
/** The least contrast any text keeps on the inactive selection, tones and muted text included. */
|
|
85
|
+
export const INACTIVE_SELECTION_TEXT_MIN = 3;
|
|
86
|
+
/** How far from the panel toward the selection the inactive selection starts, steps and stops. */
|
|
87
|
+
const INACTIVE_SELECTION_BLEND = { from: 0.35, step: 0.01, to: 0.6 } as const;
|
|
88
|
+
|
|
89
|
+
const inactiveSelectionCache = new Map<string, string>();
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The chosen row of a list or table whose pane does not have the keyboard:
|
|
93
|
+
* from a third of the way from the panel to the selection, as far on as it
|
|
94
|
+
* takes to stand apart from the page and a panel (INACTIVE_SELECTION_MIN),
|
|
95
|
+
* and never past 0.6, so the row still says where the cursor is without
|
|
96
|
+
* reading as the one the keys move.
|
|
97
|
+
*/
|
|
98
|
+
export function inactiveSelectionColour(palette: Palette): string {
|
|
99
|
+
const key = `${palette.panel}|${palette.bg}|${palette.selected}`;
|
|
100
|
+
const cached = inactiveSelectionCache.get(key);
|
|
101
|
+
if (cached) return cached;
|
|
102
|
+
const { from, step, to } = INACTIVE_SELECTION_BLEND;
|
|
103
|
+
let fill = blendHex(palette.panel, palette.selected, to);
|
|
104
|
+
for (let ratio = from; ratio < to; ratio = Math.round((ratio + step) * 100) / 100) {
|
|
105
|
+
const candidate = blendHex(palette.panel, palette.selected, ratio);
|
|
106
|
+
if (contrastRatio(candidate, palette.bg) >= INACTIVE_SELECTION_MIN && contrastRatio(candidate, palette.panel) >= INACTIVE_SELECTION_MIN) {
|
|
107
|
+
fill = candidate;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (inactiveSelectionCache.size > 64) inactiveSelectionCache.clear();
|
|
112
|
+
inactiveSelectionCache.set(key, fill);
|
|
113
|
+
return fill;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A row's text colour on the inactive selection: as it is where it reads at
|
|
118
|
+
* INACTIVE_SELECTION_TEXT_MIN, lifted toward black or white only as far as
|
|
119
|
+
* it takes where it does not (a muted label, a theme's down tone).
|
|
120
|
+
*/
|
|
121
|
+
export function inactiveSelectionTextColour(color: string, palette: Palette): string {
|
|
122
|
+
const fill = inactiveSelectionColour(palette);
|
|
123
|
+
return blendForContrast(color, fill, higherContrast("#000000", "#ffffff", fill), INACTIVE_SELECTION_TEXT_MIN);
|
|
124
|
+
}
|
|
125
|
+
|
|
77
126
|
/**
|
|
78
127
|
* The colour roles the palette names indirectly, as `--gloom-*` variables:
|
|
79
128
|
* styles.css and inline styles read these, never a blend of their own.
|
|
@@ -15,6 +15,7 @@ import { currencyPairSpelling } from "../utils/currency-pair";
|
|
|
15
15
|
import { savedAbroadForBareSymbol } from "./search/bare-symbol";
|
|
16
16
|
import { parseListingWithdrawal, withdrawalLabel } from "../market-data/quotes/delisting";
|
|
17
17
|
import type { ListingWithdrawal } from "../types/financials";
|
|
18
|
+
import { isRateLimited, isTransientServiceFailure } from "../sources/provider-errors";
|
|
18
19
|
|
|
19
20
|
export interface ListingStore {
|
|
20
21
|
loadTicker(symbol: string): Promise<TickerRecord | null>;
|
|
@@ -59,7 +60,15 @@ function ownSymbol(listed: string | undefined, asked: string): { symbol: string
|
|
|
59
60
|
* every command names; whether a venue it leaves out trades the symbol is the
|
|
60
61
|
* listing's own quote's to say (`quotedOnVenue`).
|
|
61
62
|
*/
|
|
62
|
-
export async function listingVenues(
|
|
63
|
+
export async function listingVenues(
|
|
64
|
+
symbol: string,
|
|
65
|
+
{ store, dataProvider }: ListingDeps,
|
|
66
|
+
/**
|
|
67
|
+
* Throw a search failure that says nothing of the symbol (a busy moment, the
|
|
68
|
+
* request limit, no connection) rather than answer that no venue lists it.
|
|
69
|
+
*/
|
|
70
|
+
{ failTransient = false }: { failTransient?: boolean } = {},
|
|
71
|
+
): Promise<ListingVenue[]> {
|
|
63
72
|
const query = `${symbol}:`;
|
|
64
73
|
if (!listingChoiceQuery(query)) return [];
|
|
65
74
|
const tickers = new Map((await store.loadAllTickers()).map((ticker) => [ticker.metadata.ticker.toUpperCase(), ticker] as const));
|
|
@@ -77,6 +86,7 @@ export async function listingVenues(symbol: string, { store, dataProvider }: Lis
|
|
|
77
86
|
};
|
|
78
87
|
venues = only?.exchange ? [{ ...only, exchange: canonicalExchange(only.exchange) }] : [];
|
|
79
88
|
} catch (error) {
|
|
89
|
+
if (failTransient && (isTransientServiceFailure(error) || isRateLimited(error))) throw error;
|
|
80
90
|
// One listing settles the picker; several are its choices.
|
|
81
91
|
if (!(error instanceof AmbiguousTickerError) || error instanceof AmbiguousContractError) return [];
|
|
82
92
|
venues = error.listings.flatMap((listing) => {
|