Skip to content

Conversation

@bordalix
Copy link
Collaborator

@bordalix bordalix commented Oct 15, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved wallet reload sequence to present balances, transactions, and UTXOs more consistently, reducing transient mismatches between sections.
    • Minimized UI flicker and partial updates during wallet refresh, providing a smoother, more reliable data display.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Walkthrough

The reloadWallet function in src/providers/wallet.tsx was changed from parallel fetching (Promise.all) to sequential awaits: first vtxos, then transaction history, then balance. Corresponding state updates were reordered to align with the new fetch sequence. Error handling and public interfaces were not modified.

Changes

Cohort / File(s) Summary
Wallet provider fetch sequence
src/providers/wallet.tsx
Replaced Promise.all with sequential awaits in reloadWallet: fetch vtxos → txHistory → balance; reordered setBalance/setVtxos/setTxs to match; no changes to exports or error handling logic.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant WP as WalletProvider
  participant V as VTXO Service
  participant T as TxHistory Service
  participant B as Balance Service

  User->>WP: reloadWallet()
  Note over WP: Start sequential fetch

  WP->>V: getVtxos()
  V-->>WP: vtxos
  WP->>WP: setVtxos(vtxos)

  WP->>T: getTxHistory()
  T-->>WP: txs
  WP->>WP: setTxs(txs)

  WP->>B: getBalance()
  B-->>WP: balance
  WP->>WP: setBalance(balance)

  Note over WP: Error handling unchanged
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely conveys that the pull request addresses an issue with restoring the wallet balance, which aligns with the changes made to the reloadWallet fetch sequence and state updates.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_restore

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.

@cloudflare-workers-and-pages
Copy link

Deploying wallet-signet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1ce1347
Status: ✅  Deploy successful!
Preview URL: https://2a26e2f3.wallet-23u.pages.dev
Branch Preview URL: https://fix-restore.wallet-23u.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

Deploying wallet-mutinynet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1ce1347
Status: ✅  Deploy successful!
Preview URL: https://250f6ba8.arkade-wallet.pages.dev
Branch Preview URL: https://fix-restore.arkade-wallet.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

Deploying wallet-bitcoin-v8 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1ce1347
Status: ✅  Deploy successful!
Preview URL: https://75bef00b.wallet-v8.pages.dev
Branch Preview URL: https://fix-restore.wallet-v8.pages.dev

View logs

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: 0

🧹 Nitpick comments (2)
src/providers/wallet.tsx (2)

115-117: Consider aligning state update order with fetch order for clarity.

The fetch order is vtxos → txs → balance (lines 112-114), but state updates are balance → vtxos → txs (lines 115-117). While React batches these updates, aligning the order improves code readability and makes the data flow clearer.

 const balance = await getBalance(swWallet)
-setBalance(balance)
 setVtxos(vtxos)
 setTxs(txs)
+setBalance(balance)

112-114: Parallelize vtxos and txs fetch, then await balance
Sequential awaits add ~3× latency. Instead, use:

const [vtxos, txs] = await Promise.all([
  getVtxos(swWallet),
  getTxHistory(swWallet),
]);
const balance = await getBalance(swWallet);

This ensures VTXO state is refreshed before getBalance() without degrading reload performance. Verify this still resolves the balance-restore bug.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1a8b6d and 1ce1347.

📒 Files selected for processing (1)
  • src/providers/wallet.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: bordalix
PR: arkade-os/wallet#114
File: src/lib/asp.ts:0-0
Timestamp: 2025-06-30T18:33:29.839Z
Learning: In src/lib/asp.ts, only the collaborativeExit function should accept both IWallet and ServiceWorkerWallet types. Other wallet functions (getBalance, getTxHistory, getReceivingAddresses, redeemNotes, sendOnChain, settleVtxos) should maintain their original IWallet-only signatures and not be updated for consistency.
📚 Learning: 2025-06-30T18:33:29.839Z
Learnt from: bordalix
PR: arkade-os/wallet#114
File: src/lib/asp.ts:0-0
Timestamp: 2025-06-30T18:33:29.839Z
Learning: In src/lib/asp.ts, only the collaborativeExit function should accept both IWallet and ServiceWorkerWallet types. Other wallet functions (getBalance, getTxHistory, getReceivingAddresses, redeemNotes, sendOnChain, settleVtxos) should maintain their original IWallet-only signatures and not be updated for consistency.

Applied to files:

  • src/providers/wallet.tsx
🧬 Code graph analysis (1)
src/providers/wallet.tsx (1)
src/lib/asp.ts (3)
  • getVtxos (122-131)
  • getTxHistory (86-120)
  • getBalance (80-84)

@bordalix bordalix merged commit 1596ff4 into master Oct 15, 2025
5 checks passed
@bordalix bordalix deleted the fix_restore branch October 15, 2025 13:51
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