({
displayName,
subscriptionInfo,
rateLimit,
isLoading,
fallbackToALaCarte,
})
| 183 | } |
| 184 | |
| 185 | const SubscriptionUsageSection: React.FC<SubscriptionUsageSectionProps> = ({ |
| 186 | displayName, |
| 187 | subscriptionInfo, |
| 188 | rateLimit, |
| 189 | isLoading, |
| 190 | fallbackToALaCarte, |
| 191 | }) => { |
| 192 | const theme = useTheme() |
| 193 | const updatePreference = useUpdatePreference() |
| 194 | |
| 195 | const handleToggleFallbackToALaCarte = () => { |
| 196 | updatePreference.mutate({ fallbackToALaCarte: !fallbackToALaCarte }) |
| 197 | } |
| 198 | |
| 199 | const blockPercent = useMemo(() => { |
| 200 | if (rateLimit?.blockLimit == null || rateLimit.blockUsed == null) return 100 |
| 201 | return Math.max(0, 100 - Math.round((rateLimit.blockUsed / rateLimit.blockLimit) * 100)) |
| 202 | }, [rateLimit?.blockLimit, rateLimit?.blockUsed]) |
| 203 | |
| 204 | const weeklyPercent = rateLimit ? 100 - rateLimit.weeklyPercentUsed : 100 |
| 205 | |
| 206 | return ( |
| 207 | <box style={{ flexDirection: 'column', marginBottom: 1 }}> |
| 208 | <box style={{ flexDirection: 'row', gap: 1 }}> |
| 209 | <text style={{ fg: theme.foreground }}> |
| 210 | 💪 {displayName ?? 'Strong'} subscription |
| 211 | </text> |
| 212 | {subscriptionInfo?.tier && ( |
| 213 | <text style={{ fg: theme.muted }}>${subscriptionInfo.tier}/mo</text> |
| 214 | )} |
| 215 | </box> |
| 216 | {isLoading ? ( |
| 217 | <text style={{ fg: theme.muted }}>Loading subscription data...</text> |
| 218 | ) : rateLimit ? ( |
| 219 | <box style={{ flexDirection: 'column', gap: 0 }}> |
| 220 | <box style={{ flexDirection: 'row', alignItems: 'center', gap: 0 }}> |
| 221 | <text style={{ fg: theme.muted }}>{`5-hour limit ${`${blockPercent}%`.padStart(4)} `}</text> |
| 222 | <ProgressBar value={blockPercent} width={12} showPercentage={false} /> |
| 223 | <text style={{ fg: theme.muted }}> |
| 224 | {rateLimit.blockResetsAt |
| 225 | ? ` resets in ${formatResetTime(new Date(rateLimit.blockResetsAt))}` |
| 226 | : ''} |
| 227 | </text> |
| 228 | </box> |
| 229 | <box style={{ flexDirection: 'row', alignItems: 'center', gap: 0 }}> |
| 230 | <text style={{ fg: theme.muted }}>{`Weekly limit ${`${weeklyPercent}%`.padStart(4)} `}</text> |
| 231 | <ProgressBar value={weeklyPercent} width={12} showPercentage={false} /> |
| 232 | <text style={{ fg: theme.muted }}> |
| 233 | {` resets in ${formatResetTimeLong(rateLimit.weeklyResetsAt)}`} |
| 234 | </text> |
| 235 | </box> |
| 236 | </box> |
| 237 | ) : null} |
| 238 | <box style={{ flexDirection: 'column', gap: 0, marginTop: 1 }}> |
| 239 | <box style={{ flexDirection: 'row', alignItems: 'center', gap: 1 }}> |
| 240 | <text style={{ fg: theme.muted }}>Credit spending:</text> |
| 241 | <text style={{ fg: fallbackToALaCarte ? theme.foreground : theme.warning }}> |
| 242 | {fallbackToALaCarte ? 'enabled' : 'disabled'} |
nothing calls this directly
no test coverage detected