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