fix(billing): fix payment polling and add create lease trial info#1986
fix(billing): fix payment polling and add create lease trial info#1986
Conversation
WalkthroughAdds 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
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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Comment |
Codecov Report❌ Patch coverage is
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
*This pull request uses carry forward flags. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/deploy-web/src/context/PaymentPollingProvider/PaymentPollingProvider.tsx (1)
62-67: RemoveloadingSnackbarKeyReffrom the dependency array.The
loadingSnackbarKeyRefis 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
📒 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.tsxapps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.tsxapps/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.tsxapps/deploy-web/src/components/new-deployment/CreateLease/CreateLease.tsxapps/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, usejest-mock-extendedto create mocks and pass mocks as dependencies to the service under test.
**/*.spec.{ts,tsx}: Usesetupfunction instead ofbeforeEachin test files
setupfunction must be at the bottom of the rootdescribeblock in test files
setupfunction creates an object under test and returns it
setupfunction should accept a single parameter with inline type definition
Don't use shared state insetupfunction
Don't specify return type ofsetupfunction
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
queryBymethods instead ofgetBymethods in test expectations in.spec.tsxfiles
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
closeLoadingSnackbarhelper improves code maintainability by centralizing the snackbar cleanup logic.
181-181: LGTM - Correct dependency array.The dependency array correctly includes
closeLoadingSnackbarsince 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.isTrialingtofalseso thecheckForTrialStatusChangeeffect 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’srefetch()does not throw by default—errors are captured in the hook’serror/isErrorstate (usethrowOnError: trueto throw) (github.com)
| const mockUseFlag = jest.fn((flag: string) => { | ||
| if (flag === "anonymous_free_trial") { | ||
| return true; | ||
| } | ||
| return false; | ||
| }) as unknown as ReturnType<typeof useFlag>; |
There was a problem hiding this comment.
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.
| 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.
#1967
Summary by CodeRabbit
New Features
Improvements