Skip to content

fix(billing): fix payment polling and add create lease trial info#1986

Merged
baktun14 merged 2 commits intomainfrom
fix/payment-polling
Oct 1, 2025
Merged

fix(billing): fix payment polling and add create lease trial info#1986
baktun14 merged 2 commits intomainfrom
fix/payment-polling

Conversation

@baktun14
Copy link
Contributor

@baktun14 baktun14 commented Oct 1, 2025

#1967

Summary by CodeRabbit

  • New Features

    • Updated free trial experience gated by a feature flag.
    • Added a dedicated “Add Funds” path and link when trial isn’t available.
    • Refreshed iconography in trial-related UI.
  • Improvements

    • Clearer, context-aware messaging for trials, including sign-in/sign-up/add-funds guidance.
    • “Waiting for bids” messaging now shown only when relevant.
    • Smoother payment notifications: loading indicators are reliably dismissed before success messages.
    • More predictable payment polling behavior, reducing unnecessary polling in trial scenarios.

@baktun14 baktun14 requested a review from a team as a code owner October 1, 2025 11:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 1, 2025

Walkthrough

Adds a feature-flagged branch (anonymous_free_trial) to CreateLease, introduces new dependencies (useFlag, AddFundsLink, urlService), and updates trial UI/rendering conditions. In PaymentPollingProvider, centralizes snackbar cleanup, adjusts stopPolling behavior, and simplifies refetch calls by removing try-catch.

Changes

Cohort / File(s) Summary
CreateLease: Feature flag and dependencies
apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.tsx, apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.spec.tsx
Adds anonymous_free_trial flag gating for trial UI; injects useFlag and AddFundsLink into public DEPENDENCIES; uses urlService for links; updates icons and conditional rendering; test wiring updated to mock/use typed useFlag.
Payment polling: Snackbar and stop logic
apps/deploy-web/src/context/PaymentPollingProvider/PaymentPollingProvider.tsx
Introduces closeLoadingSnackbar helper; replaces inline cleanup with helper; removes try-catch around balance/wallet refetch; changes stopPolling to skip when initialTrialing; updates dependency arrays.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant CreateLease
  participant Flags as useFlag
  participant URL as urlService
  participant UI as TrialUI

  User->>CreateLease: Open CreateLease
  CreateLease->>Flags: get("anonymous_free_trial")
  alt flag = true
    CreateLease->>UI: Render minimal trial notice (no Add Funds)
  else flag = false
    CreateLease->>URL: build Add Funds / Auth links
    CreateLease->>UI: Render Add Funds prompt and guidance
  end
Loading
sequenceDiagram
  autonumber
  participant Provider as PaymentPollingProvider
  participant Snackbar
  participant Wallet as Wallet APIs
  participant Balance as Balance API

  Provider->>Snackbar: show loading
  loop poll
    Provider->>Wallet: check payment status
    alt payment complete
      Provider->>Snackbar: closeLoadingSnackbar()
      Provider->>Balance: refetch
      Provider->>Wallet: refetch managed wallet
      alt initialTrialing = false
        Provider->>Provider: stopPolling()
      else initialTrialing = true
        Note right of Provider: Keep polling
      end
      Provider->>Snackbar: show success
    else not complete
      Note right of Provider: continue polling
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • stalniy

Poem

Hop-hop, a flag flips free as air,
I twitch my nose—new links to share.
Add funds? Or glide on trial breeze—
The UI shifts with gentle ease.
Polls now hush their loading song,
Snackbars close—then scurry along.
🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly uses a conventional commit style and highlights the two core changes in this pull request—resolving payment polling issues in the billing context and introducing trial information in the CreateLease component—providing clear guidance on the primary fixes and feature additions included.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/payment-polling

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

@codecov
Copy link

codecov bot commented Oct 1, 2025

Codecov Report

❌ Patch coverage is 73.68421% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.08%. Comparing base (9050c0b) to head (9b00236).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
.../PaymentPollingProvider/PaymentPollingProvider.tsx 50.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1986      +/-   ##
==========================================
- Coverage   45.44%   45.08%   -0.36%     
==========================================
  Files        1005      995      -10     
  Lines       28499    28157     -342     
  Branches     7478     7439      -39     
==========================================
- Hits        12951    12695     -256     
+ Misses      14427    14351      -76     
+ Partials     1121     1111      -10     
Flag Coverage Δ *Carryforward flag
api 81.55% <ø> (ø) Carriedforward from 9050c0b
deploy-web 23.82% <73.68%> (+0.02%) ⬆️
log-collector ?
notifications 87.94% <ø> (ø) Carriedforward from 9050c0b
provider-console 81.48% <ø> (ø) Carriedforward from 9050c0b
provider-proxy 84.98% <ø> (ø) Carriedforward from 9050c0b

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...ponents/new-deployment/CreateLease/CreateLease.tsx 79.06% <100.00%> (+0.49%) ⬆️
.../PaymentPollingProvider/PaymentPollingProvider.tsx 83.96% <50.00%> (-0.66%) ⬇️

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
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

🧹 Nitpick comments (1)
apps/deploy-web/src/context/PaymentPollingProvider/PaymentPollingProvider.tsx (1)

62-67: Remove loadingSnackbarKeyRef from the dependency array.

The loadingSnackbarKeyRef is a ref object and should not be included in the dependency array. Refs are stable objects that don't change between renders, so including them is unnecessary and against React best practices.

Apply this diff:

-  }, [closeSnackbar, loadingSnackbarKeyRef]);
+  }, [closeSnackbar]);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9050c0b and 9b00236.

📒 Files selected for processing (3)
  • apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.spec.tsx (3 hunks)
  • apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.tsx (8 hunks)
  • apps/deploy-web/src/context/PaymentPollingProvider/PaymentPollingProvider.tsx (4 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/deploy-web/src/context/PaymentPollingProvider/PaymentPollingProvider.tsx
  • apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.tsx
  • apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.spec.tsx
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/deploy-web/src/context/PaymentPollingProvider/PaymentPollingProvider.tsx
  • apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.tsx
  • apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.spec.tsx
**/*.spec.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.spec.tsx
apps/{deploy-web,provider-console}/**/*.spec.tsx

📄 CodeRabbit inference engine (.cursor/rules/query-by-in-tests.mdc)

Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

Files:

  • apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.spec.tsx
🧬 Code graph analysis (3)
apps/deploy-web/src/context/PaymentPollingProvider/PaymentPollingProvider.tsx (1)
apps/deploy-web/src/services/analytics/analytics.service.ts (1)
  • analyticsService (278-295)
apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.tsx (2)
apps/provider-console/src/utils/styleUtils.ts (1)
  • cn (4-6)
packages/ui/components/button.tsx (1)
  • buttonVariants (46-46)
apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.spec.tsx (1)
apps/deploy-web/src/hooks/useFlag.tsx (1)
  • useFlag (8-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (4)
apps/deploy-web/src/context/PaymentPollingProvider/PaymentPollingProvider.tsx (4)

80-81: LGTM - Good refactor!

Replacing inline cleanup logic with the closeLoadingSnackbar helper improves code maintainability by centralizing the snackbar cleanup logic.


181-181: LGTM - Correct dependency array.

The dependency array correctly includes closeLoadingSnackbar since it's called within the effect.


167-178: Confirm backend trial-flag update & add polling fallback.

  • Verify that your post-payment API (e.g. in stripe.controller) sets managedWallet.isTrialing to false so the checkForTrialStatusChange effect will stop polling.
  • Add a max-duration timeout or error case in the polling loop to avoid infinite polling if the trial flag never flips.

94-95: No error handling needed for refetch calls. React Query’s refetch() does not throw by default—errors are captured in the hook’s error/isError state (use throwOnError: true to throw) (github.com)

Comment on lines +410 to +415
const mockUseFlag = jest.fn((flag: string) => {
if (flag === "anonymous_free_trial") {
return true;
}
return false;
}) as unknown as ReturnType<typeof useFlag>;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Return the boolean flag instead of the mock function

useFlag is now stubbed as () => mockUseFlag, so when the component calls d.useFlag("anonymous_free_trial") it receives the mock function object, not the boolean it expects. Because functions are always truthy, isAnonymousFreeTrialEnabled never flips to false in tests, which makes the !isAnonymousFreeTrialEnabled branch (the new “Add Funds” UI) untestable and hides regressions. Wire the mock with the real signature so the hook returns the intended boolean.

-    const mockUseFlag = jest.fn((flag: string) => {
-      if (flag === "anonymous_free_trial") {
-        return true;
-      }
-      return false;
-    }) as unknown as ReturnType<typeof useFlag>;
+    const mockUseFlag = jest.fn<typeof useFlag>(flag => flag === "anonymous_free_trial");
...
-            useFlag: () => mockUseFlag
+            useFlag: mockUseFlag as (typeof CREATE_LEASE_DEPENDENCIES)["useFlag"]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const mockUseFlag = jest.fn((flag: string) => {
if (flag === "anonymous_free_trial") {
return true;
}
return false;
}) as unknown as ReturnType<typeof useFlag>;
// Stub useFlag to directly return a boolean based on the flag name
const mockUseFlag = jest.fn<typeof useFlag>(flag => flag === "anonymous_free_trial");
// ... other setup code ...
// Inject the mockUseFlag with the correct signature
useFlag: mockUseFlag as (typeof CREATE_LEASE_DEPENDENCIES)["useFlag"],
🤖 Prompt for AI Agents
In
apps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.spec.tsx
around lines 410 to 415, the test stubs useFlag incorrectly by returning a
function object instead of a boolean, causing d.useFlag("anonymous_free_trial")
to yield a truthy function and preventing the false branch from being tested;
change the mock so the hook returns a boolean directly (e.g. provide a mock
implementation that accepts the flag string and returns true/false), and adjust
the typing/casting to match ReturnType<typeof useFlag> so the component receives
a boolean rather than a function.

@baktun14 baktun14 merged commit f6a873c into main Oct 1, 2025
62 checks passed
@baktun14 baktun14 deleted the fix/payment-polling branch October 1, 2025 12:31
ygrishajev pushed a commit that referenced this pull request Oct 6, 2025
)

* fix(billing): continue to fetch wallet for trial

* feat(deployment): add trial warning for non-anonymous
ygrishajev pushed a commit that referenced this pull request Oct 6, 2025
)

* fix(billing): continue to fetch wallet for trial

* feat(deployment): add trial warning for non-anonymous
stalniy pushed a commit that referenced this pull request Nov 20, 2025
)

* fix(billing): continue to fetch wallet for trial

* feat(deployment): add trial warning for non-anonymous
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.

2 participants

Comments