Skip to content
TypeScript

fix(usage): use each account accent colour in limit bars (#24630)

Dan Fakkeldy8f258f02161a
diff --git a/apps/mobile/src/features/threads/ComposerUsageLimits.tsx b/apps/mobile/src/features/threads/ComposerUsageLimits.tsx
index 7044a8d70a3..ef39ef51ff4 100644
--- a/apps/mobile/src/features/threads/ComposerUsageLimits.tsx
+++ b/apps/mobile/src/features/threads/ComposerUsageLimits.tsx
@@ -44,6 +44,7 @@ export function ComposerUsageLimits({
dense
first={index === 0}
driver={account.driver}
+ accentColor={account.accentColor}
label={driverLabel}
instanceLabel={
account.instanceId
diff --git a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx
index 19e7e7e03c6..27f6912bc7c 100644
--- a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx
+++ b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx
@@ -1,6 +1,7 @@
import { useAtomValue } from "@effect/atom-react";
import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
import { EnvironmentId } from "@t3tools/contracts";
+import { normalizeProviderAccentColor } from "@t3tools/client-runtime/state/provider-instance-display";
import {
collectLimitAccounts,
collectExternalUsageLinks,
@@ -253,7 +254,7 @@ function PoolWindowCard({
<View className="absolute inset-0 overflow-hidden rounded-md">
<AccountSegment
remaining={remainingPercent(window)}
- color={color}
+ color={normalizeProviderAccentColor(account.accentColor) ?? color}
refillPercent={window.resetsAt ? member.refillPercent : 0}
/>
</View>
@@ -324,6 +325,7 @@ function PoolWindowCard({
<View>
{pool.columns.map(({ account, window }, index) => {
if (!window) return null;
+ const segmentColor = normalizeProviderAccentColor(account.accentColor) ?? color;
const credits = account.limits.resetCredits?.availableCount ?? 0;
const resetsIn = formatResetsIn(window, now);
return (
@@ -335,7 +337,12 @@ function PoolWindowCard({
onPress={() => openAccount(account)}
className="min-h-[44px] flex-row items-center gap-2 active:opacity-60"
>
- <View className="size-5 items-center justify-center overflow-hidden rounded-md bg-subtle-strong">
+ <View className="relative size-5 items-center justify-center overflow-hidden rounded-md bg-subtle-strong">
+ <View
+ pointerEvents="none"
+ className="absolute inset-0"
+ style={{ backgroundColor: segmentColor, opacity: 0.35 }}
+ />
<Text className="text-xs font-t3-medium tabular-nums text-foreground">
{index + 1}
</Text>
diff --git a/apps/mobile/src/features/usage/UsageLimitsSection.tsx b/apps/mobile/src/features/usage/UsageLimitsSection.tsx
index 3cd009cf67c..7f9c6bf28ff 100644
--- a/apps/mobile/src/features/usage/UsageLimitsSection.tsx
+++ b/apps/mobile/src/features/usage/UsageLimitsSection.tsx
@@ -1,5 +1,6 @@
import * as Dialog from "../../components/ui/Dialog";
import { RegistryContext, useAtomMount, useAtomValue } from "@effect/atom-react";
+import { normalizeProviderAccentColor } from "@t3tools/client-runtime/state/provider-instance-display";
import {
AuthProvidersManageScope,
type EnvironmentId,
@@ -157,6 +158,7 @@ function AccountInstanceLabel({ value }: { readonly value: string }) {
export function AccountLimits(props: {
readonly driver: Driver;
+ readonly accentColor?: string | undefined;
readonly label: string;
readonly instanceLabel: string;
readonly detail: string | undefined;
@@ -168,7 +170,8 @@ export function AccountLimits(props: {
readonly footer?: ReactNode;
}) {
const { limits, now, dense = false } = props;
- const color = useBarColor(props.driver);
+ const providerColor = useBarColor(props.driver);
+ const color = normalizeProviderAccentColor(props.accentColor) ?? providerColor;
if (!limits) return null;
const notice = limitsNotice(limits);
const externalUsage = limits.externalUsage;
diff --git a/apps/web/src/components/chat/ComposerUsageLimits.tsx b/apps/web/src/components/chat/ComposerUsageLimits.tsx
index 12c11d213cd..b46614a8b41 100644
--- a/apps/web/src/components/chat/ComposerUsageLimits.tsx
+++ b/apps/web/src/components/chat/ComposerUsageLimits.tsx
@@ -132,6 +132,7 @@ function UsageLimitsBannerBody({
<LimitWindows
compact
driver={account.driver}
+ accentColor={account.accentColor}
windows={account.limits.windows}
now={now}
/>
diff --git a/apps/web/src/components/usage/UsageLimits.tsx b/apps/web/src/components/usage/UsageLimits.tsx
index e34965632b0..1153b9cc74b 100644
--- a/apps/web/src/components/usage/UsageLimits.tsx
+++ b/apps/web/src/components/usage/UsageLimits.tsx
@@ -9,6 +9,7 @@ import {
UsageProviderKind,
} from "@t3tools/contracts";
import { useAtomValue } from "@effect/atom-react";
+import { normalizeProviderAccentColor } from "@t3tools/client-runtime/state/provider-instance-display";
import {
formatDuration,
formatResetsIn,
@@ -186,16 +187,18 @@ function WindowBar({
export function LimitWindows({
driver,
+ accentColor,
windows,
now,
compact = false,
}: {
readonly driver: ServerProvider["driver"];
+ readonly accentColor?: string | undefined;
readonly windows: ReadonlyArray<ServerProviderUsageWindow>;
readonly now: number;
readonly compact?: boolean;
}) {
- const color = barColor(driver);
+ const color = normalizeProviderAccentColor(accentColor) ?? barColor(driver);
return (
<div
className={
diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx
index e55f5d3857f..bc69ca4e340 100644
--- a/apps/web/src/components/usage/UsageLimitsPooled.tsx
+++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx
@@ -15,6 +15,7 @@ import {
remainingPercent,
} from "@t3tools/shared/usageLimits";
import type { Popover as PopoverPrimitive } from "@base-ui/react/popover";
+import { normalizeProviderAccentColor } from "@t3tools/client-runtime/state/provider-instance-display";
import { AlertTriangleIcon, ExternalLinkIcon, TicketIcon } from "lucide-react";
import {
createContext,
@@ -515,7 +516,7 @@ function PoolBar({
window={member.window}
reset={restores.get(member.account.key)}
refillPercent={member.refillPercent}
- color={color}
+ color={normalizeProviderAccentColor(member.account.accentColor) ?? color}
now={now}
index={position + 1}
showAccountName={pool.columns.length > 1}