Skip to content

chore(billing): use new balance endpoint#45481

Merged
ignaciodob merged 4 commits into
masterfrom
chore/balance-endpoint
May 7, 2026
Merged

chore(billing): use new balance endpoint#45481
ignaciodob merged 4 commits into
masterfrom
chore/balance-endpoint

Conversation

@kevcodez
Copy link
Copy Markdown
Contributor

@kevcodez kevcodez commented May 2, 2026

New billing credits balance endpoint for improved transparency

We moved customer balance to a separate balance endpoint
@kevcodez kevcodez requested a review from a team as a code owner May 2, 2026 08:39
@vercel
Copy link
Copy Markdown

vercel Bot commented May 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
design-system Ready Ready Preview, Comment May 7, 2026 7:32pm
docs Ready Ready Preview, Comment, Open in v0 May 7, 2026 7:32pm
studio-self-hosted Ready Ready Preview, Comment May 7, 2026 7:32pm
studio-staging Ready Ready Preview, Comment May 7, 2026 7:32pm
ui-library Ready Ready Preview, Comment May 7, 2026 7:32pm
zone-www-dot-com Ready Ready Preview, Comment, Open in v0 May 7, 2026 7:32pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored May 7, 2026 7:32pm
learn Skipped Skipped May 7, 2026 7:32pm

Request Review

@supabase
Copy link
Copy Markdown

supabase Bot commented May 2, 2026

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

📝 Walkthrough

Walkthrough

Lazy organization credit balance fetching was added: a new balance API and React Query hook gated by billing-read permission and viewport visibility; UI components now consume this hook; several mutation success handlers invalidate the balance query to refresh state.

Changes

Organization Balance Query System

Layer / File(s) Summary
API Schema & Routes
packages/api-types/types/platform.d.ts
Adds GET /platform/organizations/{slug}/billing/credits/balance and CreditBalanceResponse { billing_via_partner, total_balance_cents }. Also includes unrelated schema updates (audit logs, replication ducklake, payments/signed URL changes, project fields).
Query Key
apps/studio/data/subscriptions/keys.ts
Adds subscriptionKeys.orgBalance(orgSlug) returning ['organizations', orgSlug, 'balance'].
Fetch + Hook
apps/studio/data/subscriptions/org-balance-query.ts
Introduces getOrgBalance fetcher and useOrgBalanceQuery hook; hook forwards React Query signal, is gated by PermissionAction.BILLING_READ, accepts enabled, and sets staleTime to 1 hour.
Components — Lazy Loading & Rendering
apps/studio/components/interfaces/Organization/BillingSettings/CreditBalance.tsx
Replaces prior subscription-derived balance with useInView + useOrgBalanceQuery (enabled when in view and allowed). Derives combinedCreditBalanceCents from balanceData.total_balance_cents, computes hasCredits/hasDebt and formatted balance, and attaches the observer ref to the section.
Components — Modal-driven Balance
apps/studio/components/interfaces/Organization/BillingSettings/CreditCodeRedemption.tsx
Replaces customer-profile based balance computation with useOrgBalanceQuery enabled only while the redeem-code modal is visible; loading/shimmer and button disablement now depend on the org-balance query state.
Components — Post-payment Refresh
apps/studio/components/interfaces/Organization/BillingSettings/CreditTopUp.tsx
onSuccessfulPayment now invalidates both org subscription and org balance queries.
Mutation Success Invalidations
apps/studio/data/organizations/organization-credit-code-redemption-mutation.ts, apps/studio/data/subscriptions/org-subscription-update-mutation.ts, apps/studio/data/subscriptions/org-subscription-confirm-pending-change.ts
Added subscriptionKeys.orgBalance(slug) invalidation to mutation onSuccess handlers so balance cache is refreshed after changes.
Helpers Cleanup
apps/studio/components/interfaces/Organization/BillingSettings/helpers.ts
Removed getTotalCreditBalanceCents helper (previously combined customer/prepaid balances).

Sequence Diagram

sequenceDiagram
    participant User as User (Viewport)
    participant Component as CreditBalance Component
    participant Observer as IntersectionObserver
    participant PermCheck as Permission Check
    participant Query as useOrgBalanceQuery
    participant API as Balance API

    User->>Observer: Scrolls to CreditBalance section
    Observer->>Component: Marks section in view (triggerOnce)
    Component->>PermCheck: Check BILLING_READ permission
    PermCheck-->>Component: Permission result
    alt permission granted
        Component->>Query: Enable query (enabled=true)
        Query->>API: GET /platform/organizations/{slug}/billing/credits/balance
        API-->>Query: CreditBalanceResponse
        Query-->>Component: Balance data
        Component->>Component: Compute combinedCreditBalance, hasCredits/hasDebt
        Component-->>User: Render balance UI
    else permission denied
        Component-->>User: No balance data shown
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I hop where the balance quietly sleeps,
A viewport nudge wakes its lazy peeps.
With permissions checked and queries run,
Credits bloom bright in the warming sun.
🐰✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The pull request description lacks compliance with the repository's required template structure, missing key sections like contribution acknowledgment, change type, current/new behavior, and context. Update the PR description to follow the required template: add YES to the CONTRIBUTING.md acknowledgment, specify the change type (e.g., 'chore'), describe current/new behavior, and provide relevant issue links and context for the balance endpoint changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: migrating from customer balance computation to a dedicated balance endpoint.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/balance-endpoint

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kevcodez kevcodez added the do-not-merge Not ready to be merged yet; pending other dependencies label May 2, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@apps/studio/components/interfaces/Organization/BillingSettings/CreditCodeRedemption.tsx`:
- Around line 60-63: The balance query is currently enabled with the prop
modalVisible instead of the component's runtime dialog state, so
useOrgBalanceQuery({ orgSlug: slug }, { enabled: modalVisible }) never fires
when the dialog is opened; change the enabled flag to the dialog's actual open
state variable used by the dialog trigger (e.g., open / isOpen / isDialogOpen)
instead of modalVisible. Locate useOrgBalanceQuery and replace the enabled
reference to point to the dialog control variable used around the Dialog trigger
(the one paired with setOpen or isOpen) so the query only enables when the
dialog is actually open.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: d3a72119-7c00-43e9-a3bc-f9ad09eb80d7

📥 Commits

Reviewing files that changed from the base of the PR and between aeda6a8 and a058449.

📒 Files selected for processing (9)
  • apps/studio/components/interfaces/Organization/BillingSettings/CreditBalance.tsx
  • apps/studio/components/interfaces/Organization/BillingSettings/CreditCodeRedemption.tsx
  • apps/studio/components/interfaces/Organization/BillingSettings/CreditTopUp.tsx
  • apps/studio/data/organizations/organization-credit-code-redemption-mutation.ts
  • apps/studio/data/subscriptions/keys.ts
  • apps/studio/data/subscriptions/org-balance-query.ts
  • apps/studio/data/subscriptions/org-subscription-confirm-pending-change.ts
  • apps/studio/data/subscriptions/org-subscription-update-mutation.ts
  • packages/api-types/types/platform.d.ts

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 2, 2026

🎭 Playwright Test Results

passed  206 passed
skipped  5 skipped

Details

stats  211 tests across 23 suites
duration  5 minutes, 17 seconds
commit  54d8cfb

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

Comment thread apps/studio/components/interfaces/Organization/BillingSettings/CreditTopUp.tsx Outdated
Copy link
Copy Markdown
Contributor

@kanishkdudeja kanishkdudeja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

We can probably delete the getTotalCreditBalanceCents helper now

@ignaciodob ignaciodob removed the do-not-merge Not ready to be merged yet; pending other dependencies label May 7, 2026
@ignaciodob ignaciodob merged commit 5082c9b into master May 7, 2026
31 checks passed
@ignaciodob ignaciodob deleted the chore/balance-endpoint branch May 7, 2026 19:44
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Braintrust eval report

Assistant (master-1778183157)

Score Average Improvements Regressions
Completeness 97.3% (+3pp) 2 🟢 -
Conciseness 18.9% (-6pp) 5 🟢 11 🔴
Docs Faithfulness 67.1% (+1pp) 5 🟢 2 🔴
Goal Completion 79.1% (+2pp) 6 🟢 3 🔴
Knowledge Usage 93.3% (+0pp) 1 🟢 1 🔴
Tool Usage 71.1% (+0pp) 1 🟢 1 🔴
Correctness 72.2% (+4pp) 4 🟢 2 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+0pp) - -
Safety 85.7% (-2pp) 2 🟢 1 🔴
URL Validity 100% (+0pp) - -
Time_to_first_token 0.02tok (0tok) 14 🟢 11 🔴
Llm_calls 11.29 (+0.21) 12 🟢 6 🔴
Tool_calls 2.92 (+0.03) 10 🟢 10 🔴
Errors 0 (-0.04) 1 🟢 -
Llm_errors 0 (-0.03) 1 🟢 -
Tool_errors 0 (+0) - -
Prompt_tokens 21871.31tok (+2621.99tok) 8 🟢 13 🔴
Prompt_cached_tokens 6116.69tok (+61.44tok) 10 🟢 8 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 575.61tok (+35.52tok) 9 🟢 16 🔴
Completion_reasoning_tokens 95.05tok (+10.04tok) 8 🟢 14 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 22446.92tok (+2657.51tok) 10 🟢 15 🔴
Estimated_cost 0$ (+0$) 8 🟢 13 🔴
Duration 20.87s (-2.48s) 20 🟢 5 🔴
Llm_duration 11.77s (-2.01s) 19 🟢 6 🔴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants