Skip to content

fix: detect confirmed onchain deposits after tab switch#2092

Open
im-adithya wants to merge 2 commits intomasterfrom
fix/onchain-receive-state
Open

fix: detect confirmed onchain deposits after tab switch#2092
im-adithya wants to merge 2 commits intomasterfrom
fix/onchain-receive-state

Conversation

@im-adithya
Copy link
Member

@im-adithya im-adithya commented Feb 25, 2026

Fixes #2087

Adds logic to also check for confirmed transactions in case the user never goes to the page after copying address

Summary by CodeRabbit

  • Bug Fixes
    • Improved Bitcoin deposit and receive flows to prioritize unconfirmed transactions so pending TXs remain visible and aren't overwritten during the same update cycle.
    • When a transaction becomes confirmed, the UI now reliably updates to show the confirmed amount and clears pending state only for confirmations that occurred after the screen was opened.

@im-adithya im-adithya requested a review from rolznz February 25, 2026 16:37
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

Added a startTimeRef used to delay processing until initialized, prioritized unconfirmed UTXOs with an early return, and if none found, select confirmed UTXOs whose block_time is >= startTimeRef, updating txId/confirmedAmount and clearing pendingAmount accordingly.

Changes

Cohort / File(s) Summary
Receive / Deposit onchain logic
frontend/src/screens/onchain/DepositBitcoin.tsx, frontend/src/screens/wallet/receive/ReceiveOnchain.tsx
Introduce startTimeRef (useRef) and initialize it on mount; guard main effect to wait for startTimeRef; prioritize unconfirmed UTXO handling with an early return; if no unconfirmed UTXO, find a confirmed UTXO with block_time >= startTimeRef and set txId/confirmedAmount while clearing pendingAmount.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I waited a tick, noted the start,
Unconfirmed hops first — I guard the heart.
If none appear, I look for the light,
Confirmed steps since then make the state right.
Hooray for clear paths — a rabbit's delight! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: detecting confirmed onchain deposits after tab switching, which is the primary objective of the pull request.
Linked Issues check ✅ Passed The code changes implement the required fix by adding startTimeRef tracking and logic to detect confirmed UTXOs after their initial unconfirmed state, directly addressing issue #2087's requirement to update the Receive page for confirmed deposits when the page wasn't focused during the unconfirmed state.
Out of Scope Changes check ✅ Passed All changes are scoped to the two affected files (DepositBitcoin.tsx and ReceiveOnchain.tsx) and directly implement the temporal filtering logic to detect confirmed UTXOs, with no unrelated modifications detected.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/onchain-receive-state

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.

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.

🧹 Nitpick comments (1)
frontend/src/screens/wallet/receive/ReceiveOnchain.tsx (1)

106-110: Reset the detection baseline when the receive address changes.

startTimeRef is initialized only once (Line 106), so if onchainAddress rotates, the confirmed-UTXO filter keeps using an old timestamp window. Re-initialize per address to avoid stale matching behavior.

Proposed adjustment
-  useEffect(() => {
-    if (startTimeRef.current === 0) {
-      startTimeRef.current = Math.floor(Date.now() / 1000);
-    }
-  }, []);
+  useEffect(() => {
+    if (!onchainAddress) return;
+    startTimeRef.current = Math.floor(Date.now() / 1000);
+    setTxId("");
+    setConfirmedAmount(null);
+    setPendingAmount(null);
+  }, [onchainAddress]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/screens/wallet/receive/ReceiveOnchain.tsx` around lines 106 -
110, The current useEffect only initializes startTimeRef once so when
onchainAddress changes the confirmed-UTXO detection still uses the old
timestamp; update the effect to depend on onchainAddress and reset
startTimeRef.current to Math.floor(Date.now()/1000) whenever onchainAddress
changes. Locate the useEffect that sets startTimeRef and change it to run on
[onchainAddress] (or include onchainAddress in the dependency array) and set
startTimeRef.current = 0 or the new timestamp inside the effect so the
confirmed-UTXO filter uses a fresh baseline for each new onchainAddress.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@frontend/src/screens/wallet/receive/ReceiveOnchain.tsx`:
- Around line 106-110: The current useEffect only initializes startTimeRef once
so when onchainAddress changes the confirmed-UTXO detection still uses the old
timestamp; update the effect to depend on onchainAddress and reset
startTimeRef.current to Math.floor(Date.now()/1000) whenever onchainAddress
changes. Locate the useEffect that sets startTimeRef and change it to run on
[onchainAddress] (or include onchainAddress in the dependency array) and set
startTimeRef.current = 0 or the new timestamp inside the effect so the
confirmed-UTXO filter uses a fresh baseline for each new onchainAddress.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb4b50 and 9ecf5b9.

📒 Files selected for processing (2)
  • frontend/src/screens/onchain/DepositBitcoin.tsx
  • frontend/src/screens/wallet/receive/ReceiveOnchain.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/screens/onchain/DepositBitcoin.tsx


useEffect(() => {
if (!mempoolAddressUtxos || mempoolAddressUtxos.length === 0) {
if (startTimeRef.current === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this check needed?

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.

Bug: ReceiveToOnchain page does not update if page is not focused while TX is unconfirmed state

2 participants