[TASK-18801] fix: refresh balance on all balance-affecting websocket history entries#1765
[TASK-18801] fix: refresh balance on all balance-affecting websocket history entries#1765jjramirezn wants to merge 1 commit intodevfrom
Conversation
Previously only DIRECT_SEND and completed REQUEST triggered a balance refetch. Added explicit list of balance-affecting transaction types: DEPOSIT, WITHDRAW, BRIDGE_OFFRAMP/ONRAMP, MANTECA_OFFRAMP/ONRAMP, SEND_LINK, BANK_SEND_LINK_CLAIM, and PERK_REWARD. Non-balance-affecting types (e.g. CASHOUT, QR payments with separate flows) are excluded. REQUEST still requires COMPLETED status.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThe PR modifies the balance refresh trigger in HomeHistory's WebSocket onHistoryEntry handler by introducing a BALANCE_AFFECTING_TYPES list that defines which transaction types should refresh the balance, replacing the previous narrower condition. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment |
|
@coderabbitai review in depth. Evaluate:
Also, write a very concise testing guide for QA |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainLet me gather the code changes for this PR first. 🏁 Script executed: Length of output: 2446 Good. Let me now look at the full file and the 🏁 Script executed: Length of output: 31023 Let me check a couple more things — the 🏁 Script executed: Length of output: 13825
🔍 In-Depth Review:
|
| Scenario | Expected Behavior |
|---|---|
| Make a deposit (on-chain) | Balance updates in the Home screen in real time |
| Make a withdrawal | Balance decrements in real time |
| Complete a Bridge on-ramp | Balance updates after WS event received |
| Complete a Bridge off-ramp | Balance updates after WS event received |
| Complete a Manteca on/off-ramp | Balance updates after WS event received |
| Send a link | Balance decrements in real time |
Claim a bank send link (BANK_SEND_LINK_CLAIM) |
Balance updates after claim |
| Receive a PERK_REWARD | Balance updates in real time |
| Send a REQUEST (status = NEW) | Balance does NOT update |
| Complete a REQUEST (status = COMPLETED) | Balance does update |
| Initiate a CASHOUT | Balance does NOT update via WS (separate flow) |
| QR payment (MANTECA_QR_PAYMENT / SIMPLEFI_QR_PAYMENT) | Balance does NOT update via WS |
| Rapid burst of WS events (simulate multiple status changes) | No duplicate/hung balance fetch states |
| Balance fetch while wallet address not ready | Gracefully skipped (check console for warning) |
🧠 Learnings used
Learnt from: Hugo0
Repo: peanutprotocol/peanut-ui PR: 852
File: src/hooks/useTransactionHistory.ts:177-239
Timestamp: 2025-05-14T21:16:06.369Z
Learning: When reviewing code, pay attention to and resolve CodeRabbit comments as they can contain useful refactoring suggestions and insights.
Learnt from: Hugo0
Repo: peanutprotocol/peanut-ui PR: 594
File: src/components/Request/Pay/Views/Initial.view.tsx:188-213
Timestamp: 2024-12-31T15:08:15.640Z
Learning: Always resolve coderabbit comments when reviewing code, since they can contain useful suggestions.
Learnt from: kushagrasarathe
Repo: peanutprotocol/peanut-ui PR: 0
File: :0-0
Timestamp: 2026-03-04T18:32:51.654Z
Learning: In peanutprotocol/peanut-ui, Bridge-specific add-money and withdraw flows (`src/app/(mobile-ui)/add-money/[country]/bank/page.tsx`, `src/components/AddWithdraw/AddWithdrawCountriesList.tsx`, `src/components/Claim/Link/views/BankFlowManager.view.tsx`) have been migrated (PR `#1713`) to use the unified `isUserKycApproved` from `useKycStatus()` hook instead of per-component `liveKycStatus` + WebSocket state. The migration is complete; no more direct `bridgeKycStatus === 'approved'` checks in those files.
Learnt from: kushagrasarathe
Repo: peanutprotocol/peanut-ui PR: 1693
File: src/app/(mobile-ui)/add-money/[country]/bank/page.tsx:206-207
Timestamp: 2026-03-04T18:35:17.673Z
Learning: In Bridge-specific add-money and withdraw flows (e.g., src/app/(mobile-ui)/add-money/[country]/bank/page.tsx), liveKycStatus from WebSocket tracks real-time bridge KYC status changes, and bridgeKycStatus is the persisted status. These flows use direct bridgeKycStatus === 'approved' checks instead of the unified isUserKycVerified helper. Migrating to the unified verifier requires careful testing of WebSocket-based real-time status tracking and is deferred to follow-up work.
There was a problem hiding this comment.
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 `@src/components/Home/HomeHistory.tsx`:
- Around line 69-73: isCompleted currently treats missing status as completed
(const isCompleted = !entry.status || entry.status.toUpperCase() ===
'COMPLETED'), which causes REQUEST entries with no status to trigger
fetchBalance; change the logic so isCompleted is true only when status
explicitly equals 'COMPLETED' (e.g., use entry.status &&
entry.status.toUpperCase() === 'COMPLETED' or check entry.status?.toUpperCase()
=== 'COMPLETED') and keep the existing condition that calls fetchBalance for
BALANCE_AFFECTING_TYPES or when entry.type === EHistoryEntryType.REQUEST &&
isCompleted, so only REQUEST entries with explicit COMPLETED status invoke
fetchBalance.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aefb2bf8-4fd0-4403-b18d-7d50f939197d
📒 Files selected for processing (1)
src/components/Home/HomeHistory.tsx
| const isCompleted = !entry.status || entry.status.toUpperCase() === 'COMPLETED' | ||
| const isBalanceAffecting = BALANCE_AFFECTING_TYPES.includes(entry.type) | ||
|
|
||
| if (isBalanceAffecting || (entry.type === EHistoryEntryType.REQUEST && isCompleted)) { | ||
| fetchBalance() |
There was a problem hiding this comment.
REQUEST completion check is too permissive.
At Line 69, isCompleted treats a missing status as completed (!entry.status), so REQUEST entries without status can still call fetchBalance at Line 72. The requirement is to refresh only when REQUEST is explicitly COMPLETED.
Proposed fix
- const isCompleted = !entry.status || entry.status.toUpperCase() === 'COMPLETED'
+ const isCompleted = entry.status?.toUpperCase() === 'COMPLETED'
const isBalanceAffecting = BALANCE_AFFECTING_TYPES.includes(entry.type)
if (isBalanceAffecting || (entry.type === EHistoryEntryType.REQUEST && isCompleted)) {
fetchBalance()
}📝 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 isCompleted = !entry.status || entry.status.toUpperCase() === 'COMPLETED' | |
| const isBalanceAffecting = BALANCE_AFFECTING_TYPES.includes(entry.type) | |
| if (isBalanceAffecting || (entry.type === EHistoryEntryType.REQUEST && isCompleted)) { | |
| fetchBalance() | |
| const isCompleted = entry.status?.toUpperCase() === 'COMPLETED' | |
| const isBalanceAffecting = BALANCE_AFFECTING_TYPES.includes(entry.type) | |
| if (isBalanceAffecting || (entry.type === EHistoryEntryType.REQUEST && isCompleted)) { | |
| fetchBalance() |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/components/Home/HomeHistory.tsx` around lines 69 - 73, isCompleted
currently treats missing status as completed (const isCompleted = !entry.status
|| entry.status.toUpperCase() === 'COMPLETED'), which causes REQUEST entries
with no status to trigger fetchBalance; change the logic so isCompleted is true
only when status explicitly equals 'COMPLETED' (e.g., use entry.status &&
entry.status.toUpperCase() === 'COMPLETED' or check entry.status?.toUpperCase()
=== 'COMPLETED') and keep the existing condition that calls fetchBalance for
BALANCE_AFFECTING_TYPES or when entry.type === EHistoryEntryType.REQUEST &&
isCompleted, so only REQUEST entries with explicit COMPLETED status invoke
fetchBalance.
Previously only DIRECT_SEND and completed REQUEST triggered a balance refetch. Added explicit list of balance-affecting transaction types: DEPOSIT, WITHDRAW, BRIDGE_OFFRAMP/ONRAMP, MANTECA_OFFRAMP/ONRAMP, SEND_LINK, BANK_SEND_LINK_CLAIM, and PERK_REWARD.
Non-balance-affecting types (e.g. CASHOUT, QR payments with separate flows) are excluded. REQUEST still requires COMPLETED status.