Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

UsageLimitsPooled.tsx

730 lines28.3 KB

1import { useAtomValue } from "@effect/atom-react";
2import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
3import { EnvironmentId } from "@t3tools/contracts";
4import { providerClients } from "@t3tools/client-runtime/provider-clients";
5import { normalizeProviderAccentColor } from "@t3tools/client-runtime/state/provider-instance-display";
6import {
7 collectHttpQuotaSources,
8 collectLimitAccounts,
9 collectLimitPools,
10 displayLimitWindows,
11 paceRemainingPercent,
12 remainingPercent,
13 type LimitAccount,
14 type LimitPoolWindow,
15} from "@t3tools/shared/usageLimits";
16import {
17 collectExternalUsageLinks,
18 collectLimitNotices,
19 cursorUsageWindowDetails,
20} from "@t3tools/shared/usageLimitsCopy";
21import { msg, T, useGT, useMessages, Var, plural, part } from "gt-react-native";
22import { Fragment, type ReactNode, use, useId, useState } from "react";
23import { Pressable, View } from "react-native";
24import { useNowMinuteMs } from "../../lib/clock";
25import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
26import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
27import { Defs, Path, Pattern, Rect, Svg } from "react-native-svg";
28import { useSafeAreaInsets } from "react-native-safe-area-context";
29​
30import { SymbolView } from "../../components/ui/AppSymbol";
31import { AppText as Text } from "../../components/ui/AppText";
32import { ProviderIcon } from "../../components/ProviderIcon";
33import type { MessageResolver } from "../../i18n/messages";
34import { SettingsScreen } from "../settings/components/SettingsScreen";
35import { environmentPresentations } from "../../state/presentation";
36import { NativeWorkspaceTabActivityContext } from "../../native/v5-workspace-context";
37import { useAtomValueWhileVisible } from "../home/home-route-visibility";
38import { refillLabel, ResetCredits, resetLabels } from "./UsageLimitsSection";
39import { usageProviderKind, useProviderColors } from "./usageProviders";
40​
41const PACE_LABEL = {
42 ahead: msg("Ahead of pace"),
43 on: msg("On pace"),
44 under: msg("Under pace"),
45} as const;
46​
47function accountName(account: LimitAccount, resolve: MessageResolver) {
48 if (account.displayName) return account.displayName;
49 if (!account.email) return providerClients.get(account.driver)?.label ?? account.driver;
50 return (
51 emailInitials(account.email) || resolve(msg({ context: "fallback account name" })`Account`)
52 );
54​
55function emailInitials(email: string) {
56 const [local = "", domain = ""] = email.split("@");
57 return `${local[0] ?? ""}${domain[0] ?? ""}`.toUpperCase();
59​
60function accountHue(email: string) {
61 let hash = 0;
62 for (let index = 0; index < email.length; index += 1) {
63 hash = (hash * 31 + email.charCodeAt(index)) | 0;
64 }
65 return Math.abs(hash) % 360;
67​
68// Same hashed hue as the web account chip, so an account keeps its color across clients.
69function AccountChip({ email }: { readonly email: string }) {
70 const hue = accountHue(email);
71 return (
72 <View
73 className="size-5 items-center justify-center rounded-full"
74 style={{ backgroundColor: `hsl(${hue}, 45%, 82%)` }}
75 >
76 <Text className="text-[9px] font-t3-bold" style={{ color: `hsl(${hue}, 45%, 28%)` }}>
77 {emailInitials(email)}
78 </Text>
79 </View>
80 );
82​
83// Same gap-and-tick as the Limits rows: two clipped copies of the segment leave a see-through gap.
84function PaceGap({
85 timeLeft,
86 children,
87}: {
88 readonly timeLeft: number | null;
89 readonly children: ReactNode;
90}) {
91 const [width, setWidth] = useState(0);
92 const tickX =
93 timeLeft === null || width < 6
94 ? null
95 : Math.min(Math.max((width * timeLeft) / 100, 3), width - 3);
96 return (
97 <View
98 pointerEvents="none"
99 className="absolute inset-0"
100 onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
101 >
102 {tickX === null
103 ? children
104 : (
105 [
106 [0, tickX - 3],
107 [tickX + 3, width],
108 ] as const
109 ).map(([start, end]) => (
110 <View
111 key={start}
112 className="absolute top-0 bottom-0 overflow-hidden"
113 style={{ left: start, width: end - start }}
114 >
115 <View className="absolute top-0 bottom-0" style={{ left: -start, width }}>
116 {children}
117 </View>
118 </View>
119 ))}
120 {tickX !== null ? (
121 <View
122 className="absolute top-0.5 bottom-0.5 w-0.5 rounded-full bg-foreground"
123 style={{ left: tickX - 1 }}
124 />
125 ) : null}
126 </View>
127 );
129​
130function AccountSegment({
131 remaining,
132 color,
133 refillPercent,
134}: {
135 readonly remaining: number;
136 readonly color: string;
137 readonly refillPercent: number;
138}) {
139 const patternId = useId().replace(/:/g, "");
140 const [size, setSize] = useState({ width: 0, height: 0 });
141 return (
142 <View
143 pointerEvents="none"
144 className="absolute inset-0"
145 onLayout={(event) => {
146 const { width, height } = event.nativeEvent.layout;
147 setSize((previous) =>
148 previous.width === width && previous.height === height ? previous : { width, height },
149 );
150 }}
151 >
152 {size.width > 0 && size.height > 0 ? (
153 // Numeric canvas dimensions clear Android SVG geometry cached before a segment resized.
154 <Svg width={size.width} height={size.height} accessible={false}>
155 <Defs>
156 <Pattern id={patternId} width={6} height={6} patternUnits="userSpaceOnUse">
157 <Path d="M-1 1L1 -1M0 6L6 0M5 7L7 5" stroke={color} strokeWidth={1} opacity={0.22} />
158 </Pattern>
159 </Defs>
160 {refillPercent > 0 ? (
161 <Rect
162 x={`${100 - Math.min(100 - remaining, refillPercent)}%`}
163 width={`${Math.min(100 - remaining, refillPercent)}%`}
164 height="100%"
165 fill={`url(#${patternId})`}
166 />
167 ) : null}
168 <Rect width={`${remaining}%`} height="100%" fill={color} opacity={0.35} />
169 </Svg>
170 ) : null}
171 </View>
172 );
174​
175function PoolWindowCard({
176 pool,
177 color,
178 now,
179 environmentIds,
180 label,
181 description,
182 wide,
183}: {
184 readonly pool: LimitPoolWindow;
185 readonly color: string;
186 readonly now: number;
187 readonly environmentIds: readonly string[] | null;
188 readonly label?: string | null;
189 readonly description?: string;
190 readonly wide: boolean;
191}) {
192 const navigation = useNavigation();
193 const gt = useGT();
194 const m = useMessages();
195 const [barWidth, setBarWidth] = useState(0);
196 // Each segment needs room for its account, percent and reset to label itself.
197 const segmentWidth = barWidth / Math.max(pool.columns.length, 1);
198 const inlineLabels = wide && segmentWidth >= 96;
199 const inlineReset = wide && segmentWidth >= 150;
200 const inlineName = wide && segmentWidth >= 220;
201 const nextRefill = pool.resets.find((reset) => reset.at > now && reset.restoresPercent > 0);
202 const openAccount = (account: LimitAccount) =>
203 navigation.navigate("SettingsUsageAccount", {
204 accountKey: account.key,
205 windowId: pool.id,
206 windowKind: pool.kind,
207 environmentIds,
208 });
209 const summary = (
210 <>
211 <View className={wide ? "gap-1" : "flex-row items-start justify-between gap-3"}>
212 <View className="gap-1">
213 {label !== null ? (
214 <Text className="text-sm font-t3-medium text-foreground">{label ?? pool.label}</Text>
215 ) : null}
216 <View className="flex-row items-baseline gap-1.5">
217 <Text className="text-sm leading-(--text-3xl--line-height) text-foreground-muted">
218 <T>
219 <Text className="text-3xl font-t3-bold tabular-nums text-foreground">
220 <Var>{pool.remainingPercent}</Var>%
221 </Text>{" "}
222 left
223 </T>
224 </Text>
225 </View>
226 </View>
227 {pool.pace ? (
228 <Text className="text-xs text-foreground-tertiary">{m(PACE_LABEL[pool.pace])}</Text>
229 ) : null}
230 </View>
231 {description ? <Text className="text-xs text-foreground-muted">{description}</Text> : null}
232 {nextRefill ? (
233 <Text className="text-xs tabular-nums text-foreground-muted">
234 {refillLabel(nextRefill.member.window, now, nextRefill.restoresPercent, m)}
235 </Text>
236 ) : null}
237 </>
238 );
239 const bar = (
240 <View
241 className="flex-row gap-1"
242 onLayout={(event) => setBarWidth(event.nativeEvent.layout.width)}
243 >
244 {pool.columns.map((member, index) => {
245 if (!member.window)
246 return (
247 <View
248 key={member.account.key}
249 className={wide ? "h-9 min-w-0 flex-1" : "h-7 min-w-0 flex-1"}
250 />
251 );
252 const { account, window } = member;
253 const timeLeft = paceRemainingPercent(window, now);
254 const credits = account.limits.resetCredits?.availableCount ?? 0;
255 const resetsIn = resetLabels(window, now, m)?.compact;
256 return (
257 <Pressable
258 key={account.key}
259 accessibilityRole="button"
260 accessibilityLabel={
261 timeLeft === null
262 ? gt`Segment ${{ index: index + 1 }}, ${{ account: accountName(account, m) }}, ${{ remaining: remainingPercent(window) }}% left`
263 : gt`Segment ${{ index: index + 1 }}, ${{ account: accountName(account, m) }}, ${{ remaining: remainingPercent(window) }}% left, ${{ timeLeft }}% of the window left`
264 }
265 accessibilityHint={gt`Show account details`}
266 onPress={() => openAccount(account)}
267 className={wide ? "h-9 min-w-0 flex-1 rounded-md" : "h-7 min-w-0 flex-1 rounded-md"}
268 >
269 <PaceGap timeLeft={timeLeft}>
270 <View className="absolute inset-0 rounded-md bg-subtle" />
271 <View className="absolute inset-0 overflow-hidden rounded-md">
272 <AccountSegment
273 remaining={remainingPercent(window)}
274 color={normalizeProviderAccentColor(account.accentColor) ?? color}
275 refillPercent={window.resetsAt ? member.refillPercent : 0}
276 />
277 </View>
278 </PaceGap>
279 {inlineLabels ? (
280 <View
281 pointerEvents="none"
282 className="absolute inset-0 flex-row items-center justify-between gap-2 overflow-hidden rounded-md px-2"
283 >
284 <View className="min-w-0 shrink flex-row items-center gap-1.5">
285 {account.email ? <AccountChip email={account.email} /> : null}
286 {account.email && !(account.displayName && inlineName) ? null : (
287 <Text
288 numberOfLines={1}
289 className="min-w-0 shrink text-xs font-t3-medium text-foreground"
290 >
291 {accountName(account, m)}
292 </Text>
293 )}
294 <Text className="text-sm font-t3-bold tabular-nums text-foreground">
295 {remainingPercent(window)}%
296 </Text>
297 </View>
298 {inlineReset && (resetsIn || credits) ? (
299 <View className="shrink-0 flex-row items-center gap-1 rounded bg-grouped-card/85 px-1.5 py-0.5">
300 {resetsIn ? (
301 <>
302 <SymbolView
303 name="arrow.clockwise"
304 size={11}
305 tintColorClassName="accent-foreground-muted"
306 />
307 <Text className="text-xs tabular-nums text-foreground-muted">
308 {resetsIn}
309 </Text>
310 </>
311 ) : null}
312 {credits ? (
313 <>
314 <SymbolView name="ticket" size={12} tintColorClassName="accent-icon" />
315 <Text className="text-xs font-t3-medium tabular-nums text-foreground">
316 {credits}
317 </Text>
318 </>
319 ) : null}
320 </View>
321 ) : null}
322 </View>
323 ) : (
324 <View
325 pointerEvents="none"
326 className="absolute inset-0 items-center justify-center overflow-hidden rounded-md"
327 >
328 <Text
329 numberOfLines={1}
330 className="max-w-full shrink text-xs font-t3-medium tabular-nums text-foreground"
331 >
332 {index + 1}
333 </Text>
334 </View>
335 )}
336 </Pressable>
337 );
338 })}
339 </View>
340 );
341 const legend = (
342 <View>
343 {pool.columns.map(({ account, window }, index) => {
344 if (!window) return null;
345 const segmentColor = normalizeProviderAccentColor(account.accentColor) ?? color;
346 const credits = account.limits.resetCredits?.availableCount ?? 0;
347 const reset = resetLabels(window, now, m);
348 const resetsIn = reset?.full;
349 return (
350 <Pressable
351 key={account.key}
352 accessibilityRole="button"
353 accessibilityLabel={
354 resetsIn && credits
355 ? gt`Segment ${{ index: index + 1 }}, ${{ account: accountName(account, m) }}, ${{ remaining: remainingPercent(window) }}% left, ${{ resetsIn }}, ${plural(
356 { credits },
357 {
358 one: part`${{ credits }} reset credit banked`,
359 other: part`${{ credits }} reset credits banked`,
360 },
361 )}`
362 : resetsIn
363 ? gt`Segment ${{ index: index + 1 }}, ${{ account: accountName(account, m) }}, ${{ remaining: remainingPercent(window) }}% left, ${{ resetsIn }}`
364 : credits
365 ? gt`Segment ${{ index: index + 1 }}, ${{ account: accountName(account, m) }}, ${{ remaining: remainingPercent(window) }}% left, ${plural(
366 { credits },
367 {
368 one: part`${{ credits }} reset credit banked`,
369 other: part`${{ credits }} reset credits banked`,
370 },
371 )}`
372 : gt`Segment ${{ index: index + 1 }}, ${{ account: accountName(account, m) }}, ${{ remaining: remainingPercent(window) }}% left`
373 }
374 accessibilityHint={gt`Show account details`}
375 onPress={() => openAccount(account)}
376 className="min-h-[44px] flex-row items-center gap-2 active:opacity-60"
377 >
378 <View className="relative size-5 items-center justify-center overflow-hidden rounded-md bg-subtle-strong">
379 <View
380 pointerEvents="none"
381 className="absolute inset-0"
382 style={{ backgroundColor: segmentColor, opacity: 0.35 }}
383 />
384 <Text className="text-xs font-t3-medium tabular-nums text-foreground">
385 {index + 1}
386 </Text>
387 </View>
388 <Text
389 numberOfLines={1}
390 className="min-w-0 flex-1 text-sm font-t3-medium text-foreground"
391 >
392 {accountName(account, m)}
393 </Text>
394 <Text className="text-sm font-t3-medium tabular-nums text-foreground">
395 {remainingPercent(window)}%
396 </Text>
397 <View className="flex-row items-center gap-1">
398 {resetsIn ? (
399 <>
400 <SymbolView
401 name="arrow.clockwise"
402 size={12}
403 tintColorClassName="accent-foreground-muted"
404 />
405 <Text className="text-xs tabular-nums text-foreground-muted">
406 {reset?.compact}
407 </Text>
408 </>
409 ) : null}
410 {credits ? (
411 <>
412 {resetsIn ? <Text className="text-xs text-foreground-tertiary">·</Text> : null}
413 <SymbolView name="ticket" size={13} tintColorClassName="accent-icon" />
414 <Text className="text-xs font-t3-medium tabular-nums text-foreground">
415 {credits}
416 </Text>
417 </>
418 ) : null}
419 </View>
420 </Pressable>
421 );
422 })}
423 </View>
424 );
425 if (wide) {
426 return (
427 <View className="flex-row items-center gap-6 rounded-[24px] border-continuous bg-grouped-card p-4">
428 <View className="w-44 gap-1">{summary}</View>
429 <View className="min-w-0 flex-1 gap-1">
430 {bar}
431 {inlineLabels ? null : legend}
432 </View>
433 </View>
434 );
435 }
436 return (
437 <View className="gap-3 rounded-[24px] border-continuous bg-grouped-card p-4">
438 {summary}
439 {bar}
440 {legend}
441 </View>
442 );
444​
445export function UsageLimitsSection({
446 now,
447 failedLabels,
448 selectedEnvironmentIds,
449 wide = false,
450}: {
451 readonly now: number;
452 readonly failedLabels: readonly string[];
453 readonly selectedEnvironmentIds: ReadonlySet<EnvironmentId> | null;
454 readonly wide?: boolean;
455}) {
456 const presentations = useAtomValueWhileVisible(
457 environmentPresentations.presentationsWithProvidersAtom,
458 use(NativeWorkspaceTabActivityContext)?.active ?? true,
459 );
460 const selected =
461 selectedEnvironmentIds === null
462 ? presentations
463 : new Map([...presentations].filter(([id]) => selectedEnvironmentIds.has(id)));
464 const pools = collectLimitPools(collectLimitAccounts(selected), now);
465 const quotaSources = collectHttpQuotaSources(selected);
466 const m = useMessages();
467 const notices = collectLimitNotices(selected, m);
468 const externalLinks = collectExternalUsageLinks(selected, m);
469 const colors = useProviderColors();
470 const gt = useGT();
471 return (
472 <View className="gap-6">
473 {pools.length === 0 &&
474 notices.length === 0 &&
475 failedLabels.length === 0 &&
476 externalLinks.length === 0 &&
477 quotaSources.length === 0 ? (
478 <Text className="py-12 text-center text-base text-foreground-muted">
479 {selected.size === 0
480 ? gt`Select an environment to see limits.`
481 : gt`No provider on the selected environments reports subscription limits.`}
482 </Text>
483 ) : null}
484 {quotaSources.map((source) => (
485 <View key={source.key} className="gap-3 rounded-[24px] bg-grouped-card p-4">
486 <Text className="text-base font-t3-medium text-foreground">{source.label}</Text>
487 {source.quotaAccounts?.map((account) => (
488 <View key={account.id} className="gap-1">
489 <Text className="text-sm font-t3-medium text-foreground">{account.label}</Text>
490 {account.windows.map((window) => {
491 const reset = resetLabels(window, now, m);
492 return (
493 <View key={window.id} className="flex-row justify-between gap-3">
494 <Text className="shrink text-sm text-foreground-muted">{window.label}</Text>
495 <Text className="text-sm text-foreground-muted">
496 {gt`${{ remaining: remainingPercent(window) }}% left`}
497 {reset ? ` · ${reset.compact}` : ""}
498 </Text>
499 </View>
500 );
501 })}
502 </View>
503 ))}
504 </View>
505 ))}
506 {pools.map((pool) => {
507 const windows = displayLimitWindows(pool);
508 return (
509 <Fragment key={pool.driver}>
510 <View className="gap-3">
511 <View className="flex-row items-center gap-2 px-1">
512 <ProviderIcon provider={pool.driver} size={18} />
513 <Text className="text-base font-t3-medium text-foreground">
514 {providerClients.get(pool.driver)?.label ?? pool.driver}
515 </Text>
516 </View>
517 {windows.map((window) => {
518 const details =
519 pool.driver === "cursor"
520 ? cursorUsageWindowDetails(window.id, pool, m)
521 : undefined;
522 return (
523 <PoolWindowCard
524 key={`${window.kind}:${window.id}`}
525 pool={window}
526 color={colors[usageProviderKind(pool.driver) ?? "codex"]}
527 now={now}
528 environmentIds={
529 selectedEnvironmentIds === null ? null : [...selectedEnvironmentIds]
530 }
531 label={details?.label}
532 description={details?.description}
533 wide={wide}
534 />
535 );
536 })}
537 </View>
538 </Fragment>
539 );
540 })}
541 {externalLinks.map((link) => (
542 <View key={link.url} className="gap-3 rounded-xl border border-border-subtle p-4">
543 <Text className="text-base font-t3-medium text-foreground">{link.label}</Text>
544 <Text className="text-xs text-foreground-muted">{link.accounts.join(", ")}</Text>
545 {link.message ? (
546 <Text className="text-sm text-foreground-muted">{link.message}</Text>
547 ) : null}
548 <Pressable
549 accessibilityRole="link"
550 className="min-h-11 justify-center"
551 onPress={() => void tryOpenExternalUrl(link.url)}
552 >
553 <Text className="text-sm font-t3-medium text-primary">
554 <T>Manage usage</T>
555 </Text>
556 </Pressable>
557 </View>
558 ))}
559 {notices.length > 0 || failedLabels.length > 0 ? (
560 <View
561 accessible
562 accessibilityRole="alert"
563 accessibilityLiveRegion="polite"
564 className="flex-row items-start gap-2 rounded-xl border border-warning-border bg-warning px-3.5 py-3"
565 >
566 <SymbolView
567 name="exclamationmark.triangle"
568 size={16}
569 tintColorClassName="accent-warning-foreground"
570 />
571 <View className="min-w-0 flex-1 gap-0.5">
572 {notices.map((notice) => (
573 <Text key={notice} className="text-sm font-t3-medium text-warning-foreground">
574 {notice}
575 </Text>
576 ))}
577 {failedLabels.length > 0 ? (
578 <Text className="text-sm font-t3-medium text-warning-foreground">
579 <T>
580 <Var>{failedLabels.join(", ")}</Var> could not refresh limits. Showing the last
581 known values.
582 </T>
583 </Text>
584 ) : null}
585 </View>
586 </View>
587 ) : null}
588 </View>
589 );
591​
592type AccountScreenProps = StaticScreenProps<{
593 accountKey: string;
594 windowId: string;
595 windowKind: LimitPoolWindow["kind"];
596 environmentIds: readonly string[] | null;
597}>;
598​
599export function UsageLimitAccountScreen({ route }: AccountScreenProps) {
600 const insets = useSafeAreaInsets();
601 const presentations = useAtomValue(environmentPresentations.presentationsWithProvidersAtom);
602 const { accountKey, windowId, windowKind, environmentIds } = route.params;
603 const now = useNowMinuteMs();
604 const selectedIds =
605 environmentIds === null ? null : new Set(environmentIds.map((id) => EnvironmentId.make(id)));
606 const selected =
607 selectedIds === null
608 ? presentations
609 : new Map([...presentations].filter(([id]) => selectedIds.has(id)));
610 const accounts = collectLimitAccounts(selected);
611 const account = accounts.find((candidate) => candidate.key === accountKey);
612 const pool = collectLimitPools(accounts, now)
613 .find((candidate) => candidate.driver === account?.driver)
614 ?.windows.find((candidate) => candidate.id === windowId && candidate.kind === windowKind);
615 const window = pool?.members.find((member) => member.account.key === accountKey)?.window;
616 const evenPace = window ? paceRemainingPercent(window, now) : null;
617 const reset = pool?.resets.find((candidate) => candidate.member.account.key === accountKey);
618 const [revealed, setRevealed] = useState(false);
619 const gt = useGT();
620 return (
621 <SettingsScreen title={gt({ context: "screen title" })`Account`}>
622 <ScrollView
623 contentInsetAdjustmentBehavior="automatic"
624 contentContainerClassName="gap-5 p-5"
625 contentContainerStyle={{ paddingBottom: insets.bottom + 24 }}
626 >
627 {!account || !window ? (
628 <Text className="text-base text-foreground-muted">
629 <T>This account is no longer reporting limits on the selected environments.</T>
630 </Text>
631 ) : (
632 <>
633 <View className="gap-2">
634 <View className="flex-row items-center gap-2">
635 <ProviderIcon provider={account.driver} size={24} />
636 <Text className="flex-1 text-xl font-t3-bold text-foreground">
637 {account.displayName ??
638 providerClients.get(account.driver)?.label ??
639 account.driver}
640 </Text>
641 </View>
642 {account.email ? (
643 <Pressable
644 accessibilityRole="button"
645 accessibilityLabel={revealed ? gt`Hide account email` : gt`Reveal account email`}
646 onPress={() => setRevealed((value) => !value)}
647 className="min-h-[44px] justify-center"
648 >
649 <Text className="text-sm text-foreground-muted">
650 {revealed ? account.email : "••••••@••••••"}
651 </Text>
652 </Pressable>
653 ) : null}
654 {account.plan ? (
655 <Text selectable className="text-sm text-foreground-muted">
656 {account.plan}
657 </Text>
658 ) : null}
659 </View>
660 <View className="gap-3 rounded-[24px] border-continuous bg-grouped-card p-4">
661 <Text className="text-sm font-t3-medium text-foreground">{window.label}</Text>
662 <Text className="text-3xl font-t3-bold tabular-nums text-foreground">
663 <T>
664 <Var>{remainingPercent(window)}</Var>% left
665 </T>
666 </Text>
667 {window.resetsAt ? (
668 <Text selectable className="text-sm text-foreground-muted">
669 <T>
670 Resets{" "}
671 <Var>
672 {new Date(window.resetsAt).toLocaleString(undefined, {
673 dateStyle: "medium",
674 timeStyle: "short",
675 })}
676 </Var>
677 </T>
678 </Text>
679 ) : null}
680 {evenPace !== null ? (
681 <Text className="text-sm text-foreground-muted">
682 <T>
683 Even pace: <Var>{evenPace}</Var>% left by now
684 </T>
685 </Text>
686 ) : null}
687 {reset && reset.restoresPercent > 0 ? (
688 <Text className="text-sm text-foreground-muted">
689 <T>
690 Restores <Var>{reset.restoresPercent}</Var>% of the pool
691 </T>
692 </Text>
693 ) : null}
694 </View>
695 <View className="gap-2 rounded-[24px] border-continuous bg-grouped-card p-4">
696 <Text className="text-sm font-t3-medium text-foreground">
697 {account.environments.length
698 ? gt({ context: "heading for environments signed in to the account" })`Signed in`
699 : gt({ context: "heading for where account limits come from" })`Source`}
700 </Text>
701 {account.environments.length ? (
702 account.environments.map((environment) => (
703 <Text key={environment.environmentId} className="text-sm text-foreground-muted">
704 {environment.label}
705 </Text>
706 ))
707 ) : (
708 <Text className="text-sm text-foreground-muted">{account.sourceLabel}</Text>
709 )}
710 </View>
711 {account.redeem && account.limits.resetCredits ? (
712 <View className="gap-3 rounded-[24px] border-continuous bg-grouped-card p-4">
713 <Text className="text-sm font-t3-medium text-foreground">
714 <T>Reset credits</T>
715 </Text>
716 <ResetCredits
717 key={account.key}
718 environmentId={account.redeem.environmentId}
719 input={account.redeem.input}
720 credits={account.limits.resetCredits}
721 now={now}
722 />
723 </View>
724 ) : null}
725 </>
726 )}
727 </ScrollView>
728 </SettingsScreen>
729 );