feat: add out-of-credits warning to sidebar plan badge#637
Open
prakhar1605 wants to merge 1 commit into
Open
Conversation
Show a warning state + popover on the sidebar plan badge when the user is out of credits, prompting them to upgrade. Detection comes from two existing signals: the /v1/me billing payload (daily or monthly bucket exhausted, the same data the Settings usage bars use) and the existing 'not enough credits' API-error path. The warning clears on a successful cost-incurring call (LLM finish-step or a successful voice synth) and re-fetches /me once, only when the warning was actually showing -- no polling. Popover auto-opens on first detection and can be dismissed while the indicator persists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Sidebar plan badge (Free / Starter / Pro) now shows an out-of-credits warning — a red badge state ("Out of credits" +⚠️ ) with an upgrade popover ("You've run out of credits → Upgrade now"), matching the POC. It clears automatically when credits are available again.
Detection (both signals you mentioned)
/v1/mebilling payload — warning turns on when the daily or monthly bucket is exhausted (availableCredits <= 0). Same data the Settings usage bars use; no new API work.matchBillingError"not enough credits" path also flips it on, covering the case where cached billing is stale.Both feed a single warning state, so there's one source of truth.
Clearing (no polling)
finish-step(with usage) or a successful voice synth./meonce, and only if the warning was actually showing — so normal runs don't trigger any extra/mecalls.How it's wired
lib/credit-status.ts—isOutOfCredits(billing)helper + two window events (credit:exhausted/credit:replenished) with dispatch helpers (single source for the condition + event names).App.tsxdispatchesexhaustedon anot_enough_creditsbilling error, andreplenishedon a successful LLMfinish-step.useVoiceTTS.tsdispatchesreplenishedon a successful synth.sidebar-content.tsxowns the warning UI + listens to both events (billing stays authoritative; events flip it in between).billing-error.ts— added akinddiscriminator so we only react to the credits error, not other billing errors.ui/popover.tsx— addedPopoverArrow(for the popover pointer).Files
lib/credit-status.ts(new)App.tsx,components/sidebar-content.tsx,hooks/useVoiceTTS.ts,lib/billing-error.ts,components/ui/popover.tsxTesting
isOutOfCredits → true: badge + popover render correctly; X dismisses popover while the indicator stays; "Upgrade now" / "Upgrade" open?intent=upgrade.credit:exhausted/credit:replenishedfrom devtools: warning toggles;/mere-fetch fires only on clear-after-warning, and a normal run after that fires no extra/me.tsc --noEmitclean across renderer.Note
The existing billing-error modal still shows alongside the new sidebar warning — per your call that they're two separate things. No change to the modal.