Skip to content

fix available sats in keyboard - #224

Merged
bordalix merged 1 commit into
masterfrom
fix_available_sats_mobile
Nov 12, 2025
Merged

bordalix merged 1 commit into
masterfrom
fix_available_sats_mobile

Conversation

@bordalix

@bordalix bordalix commented Nov 12, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Updated balance calculations to reflect available balance in transaction forms for more accurate maximum amount allocation and display.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying wallet-signet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8fc7db6
Status: ✅  Deploy successful!
Preview URL: https://aecac845.wallet-23u.pages.dev
Branch Preview URL: https://fix-available-sats-mobile.wallet-23u.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying wallet-mutinynet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8fc7db6
Status: ✅  Deploy successful!
Preview URL: https://6c969478.arkade-wallet.pages.dev
Branch Preview URL: https://fix-available-sats-mobile.arkade-wallet.pages.dev

View logs

@coderabbitai

coderabbitai Bot commented Nov 12, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Changes introduce available balance state management in the Keyboard component, fetching balance via wallet service and using it for max button functionality and balance displays. A type annotation is simplified in the Send form component.

Changes

Cohort / File(s) Summary
Available Balance State Integration
src/components/Keyboard.tsx
Introduces svcWallet from WalletContext and availableBalance state. Adds effect to fetch available balance via svcWallet.getBalance() when balance changes. Updates handleMaxPress to use availableBalance for max allocation. Modifies balance display to render availableBalance instead of balance for both fiat and non-fiat paths. Includes guard against svcWallet absence before fetching.
Type Annotation Simplification
src/screens/Wallet/Send/Form.tsx
Removes explicit generic type from availableBalance state initialization, changing from useState<number>(0) to useState(0). Type is now inferred at runtime rather than explicitly declared.

Sequence Diagram

sequenceDiagram
    participant Keyboard as Keyboard Component
    participant Effect as useEffect Hook
    participant Wallet as svcWallet Service
    participant State as availableBalance State

    Keyboard->>Keyboard: balance updates
    Keyboard->>Effect: trigger effect (dependency: balance)
    Effect->>Effect: check svcWallet exists
    alt svcWallet available
        Effect->>Wallet: getBalance()
        Wallet-->>Effect: available balance
        Effect->>State: update availableBalance
    else svcWallet missing
        Effect->>Effect: guard exits, no action
    end
    Keyboard->>State: read availableBalance
    Keyboard->>Keyboard: handleMaxPress uses availableBalance
    Keyboard->>Keyboard: display uses availableBalance
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Service integration and effect setup logic in Keyboard component requires verification of correct guard conditions and dependency tracking
  • Balance display changes should be validated across both fiat and non-fiat rendering paths
  • Type annotation simplification is straightforward and low-risk

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 'fix available sats in keyboard' directly corresponds to the main change: modifying the Keyboard component to use availableBalance instead of balance for displaying and handling satoshi amounts.
✨ 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_available_sats_mobile

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

Deploying wallet-bitcoin with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8fc7db6
Status: ✅  Deploy successful!
Preview URL: https://66ad3c4f.wallet-bitcoin.pages.dev
Branch Preview URL: https://fix-available-sats-mobile.wallet-bitcoin.pages.dev

View logs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/screens/Wallet/Send/Form.tsx (1)

88-91: Add error handling for the balance fetch.

The promise from svcWallet.getBalance() lacks error handling, which could result in unhandled promise rejections if the call fails.

Apply this diff to add error handling:

 useEffect(() => {
   if (!svcWallet) return
-  svcWallet.getBalance().then((bal) => setAvailableBalance(bal.available))
+  svcWallet.getBalance()
+    .then((bal) => setAvailableBalance(bal.available))
+    .catch((err) => consoleError(err, 'error fetching available balance'))
 }, [balance])
src/components/Keyboard.tsx (1)

36-39: Add error handling for the balance fetch.

The promise from svcWallet.getBalance() lacks error handling, which could result in unhandled promise rejections if the call fails.

Apply this diff to add error handling:

 useEffect(() => {
   if (!svcWallet) return
-  svcWallet.getBalance().then((bal) => setAvailableBalance(bal.available))
+  svcWallet.getBalance()
+    .then((bal) => setAvailableBalance(bal.available))
+    .catch((err) => console.error('error fetching available balance:', err))
 }, [balance])
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b12dcb and 8fc7db6.

📒 Files selected for processing (2)
  • src/components/Keyboard.tsx (3 hunks)
  • src/screens/Wallet/Send/Form.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: bordalix
Repo: arkade-os/wallet PR: 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
Repo: arkade-os/wallet PR: 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/components/Keyboard.tsx
  • src/screens/Wallet/Send/Form.tsx
📚 Learning: 2025-07-21T18:25:36.391Z
Learnt from: bordalix
Repo: arkade-os/wallet PR: 121
File: src/screens/Init/Restore.tsx:58-58
Timestamp: 2025-07-21T18:25:36.391Z
Learning: In src/screens/Init/Restore.tsx, the Input component for private key restoration intentionally omits the `value` prop to make it uncontrolled. This is a security feature to prevent the private key from being displayed if users navigate away and return to the screen, avoiding potential exposure of sensitive data in the UI.

Applied to files:

  • src/components/Keyboard.tsx
🧬 Code graph analysis (1)
src/components/Keyboard.tsx (3)
src/providers/wallet.tsx (1)
  • WalletContext (41-55)
src/lib/constants.ts (1)
  • defaultFee (2-2)
src/lib/format.ts (1)
  • prettyAmount (27-34)
⏰ 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). (1)
  • GitHub Check: test
🔇 Additional comments (3)
src/screens/Wallet/Send/Form.tsx (1)

56-56: LGTM! Type inference handles this.

Removing the explicit type annotation is fine since TypeScript correctly infers number from the initial value.

src/components/Keyboard.tsx (2)

26-26: Good addition of available balance tracking.

Adding svcWallet from context and introducing the availableBalance state improves accuracy by tracking the actual spendable balance.

Also applies to: 29-29


49-50: Correct use of available balance for max amount and display.

The logic now correctly uses availableBalance instead of the total balance, which accurately reflects what users can actually spend and prevents confusion.

Also applies to: 60-60

@bordalix
bordalix merged commit c40be55 into master Nov 12, 2025
1 check passed
@bordalix
bordalix deleted the fix_available_sats_mobile branch November 26, 2025 14:29
@coderabbitai coderabbitai Bot mentioned this pull request Dec 17, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Jan 8, 2026
This was referenced Mar 23, 2026
@coderabbitai coderabbitai Bot mentioned this pull request May 14, 2026
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.

1 participant