openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

feat(wallet): surface multi-chain balances in Settings

Open obchain opened this issue 6 months ago • 2 comments

Summary

  • Surfaces the existing wallet.balances RPC in the UI by adding a new Settings → Account → Wallet Balances panel.
  • Multi-chain rows (EVM, BTC, Solana, Tron) with chain badges, truncated addresses, copy-to-clipboard, formatted balances, provider-status chips, and a Refresh button.
  • No behaviour change in the core — backend was already complete; this fills the UI gap.

Problem

The wallet.balances RPC has been live in the Rust core for some time and is listed as a capability in about_app/catalog.rs, but the frontend never had a caller. The only way to read multi-chain balances today is to issue a raw JSON-RPC request — inaccessible to normal users, which breaks the obvious "I set up a wallet → what is in it?" mental model and blocks the broader crypto / portfolio workflows tracked in #1394.

Solution

  1. app/src/services/walletApi.ts — adds BalanceInfo type + fetchWalletBalances() calling wallet.balances via the existing coreRpcClient, mirroring the fetchWalletStatus pattern. New tests added in the same file.
  2. app/src/components/settings/panels/WalletBalancesPanel.tsx — new self-contained panel that renders four states (loading, error with Retry, empty with Recovery Phrase hint, loaded). Loaded state renders one BalanceRow per balance with chain badge (color-coded per Tailwind palette), truncated address (first 6 + last 4 chars), copy-to-clipboard button, formatted amount + symbol, optional "provider unavailable" chip, and a Refresh button.
  3. app/src/pages/Settings.tsx — registers the new entry under Account section, routed at /settings/wallet-balances.
  4. i18n — 13 new keys in app/src/lib/i18n/en.ts plus matching English-value entries in every locale chunk (chunks/{ar,bn,de,en,es,fr,hi,id,it,ko,pt,ru,zh-CN}-4.ts) so pnpm i18n:check parity passes and translators can fill non-English values later.
  5. Capability catalog (src/openhuman/about_app/catalog.rs) — single-line update to the skills.wallet_execution how_to field pointing users at the new panel.
  6. Coverage matrix — new row in docs/TEST-COVERAGE-MATRIX.md tracking the panel.

Submission Checklist

  • [x] Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy — 9 Vitest panel tests across loading / error+retry / empty / loaded / refresh states, plus 5 walletApi tests for the new fetchWalletBalances function (14/14 passing locally).
  • [x] Diff coverage ≥ 80% — changed lines are largely the new panel + new RPC client function, both fully covered by the new test files.
  • [x] Coverage matrix updated — added row 13.1.4 ("Wallet Balances Panel") under the wallet feature group; covered count bumped 69→70.
  • [x] All affected feature IDs from the matrix are listed in the PR description under ## Related — skills.wallet_execution (UI surfacing of an existing capability — no new feature ID needed).
  • [x] No new external network dependencies introduced (mock backend used per Testing Strategy) — the new tests mock fetchWalletBalances directly; no network calls.
  • [x] Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md) — N/A: additive UI surface, no release-cut behaviour change.
  • [x] Linked issue closed via Closes #NNN in the ## Related section — Closes #2682 below.

Impact

  • Runtime / platform: pure UI addition — desktop only, no behaviour change on existing surfaces.
  • Performance: negligible — one RPC call on panel mount + on user-triggered Refresh.
  • Security / privacy: unchanged — wallet.balances only uses the public address; the recovery phrase never leaves the local core.
  • Migration / compatibility: none.

Manual visual verification

Verified locally via pnpm dev:app:

  • Setting up a fresh wallet via Settings → Recovery Phrase and then opening Settings → Wallet Balances renders all four chain rows (EVM, BTC, SOL, TRX) with the expected zero-balance loaded state.
  • Sample output observed:
    EVM   0x9B99…2660      0.000000000000000000  ETH
    BTC   1BnHT1…77G3      0.00000000            BTC
    SOL   51xrwi…aWRF      0.000000000           SOL
    TRX   TAWYnc…q4q9      0.000000              TRX
    
  • Addresses are derived correctly per chain, decimals match the chain conventions (18/8/9/6), and chain badges colour-match the Tailwind palette tokens.

Related

  • Closes: #2682
  • Parent crypto roadmap: #1394 (this PR is one slice — read-only balance surface; transfers / swaps / contract calls remain open under that parent).
  • Follow-up PR(s)/TODOs: none.

AI Authored PR Metadata (required for Codex/Linear PRs)

Keep this section for AI-authored PRs. For human-only PRs, mark each field N/A.

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: N/A
  • Commit SHA: N/A

Validation Run

  • [x] pnpm --filter openhuman-app format:check — passes (Prettier auto-fixes applied during quality-gate commit).
  • [x] pnpm typecheck — clean.
  • [x] Focused tests: pnpm test -- WalletBalancesPanel walletApi — 14/14 passed.
  • [x] Rust fmt/check (if changed): cargo check --manifest-path Cargo.toml clean for the one-line catalog.rs touch.
  • [x] Tauri fmt/check (if changed): pnpm rust:check clean.

Validation Blocked

  • command: N/A
  • error: N/A
  • impact: N/A

Behavior Changes

  • Intended behavior change: Users can now view multi-chain wallet balances inside the app instead of having to issue raw RPC calls.
  • User-visible effect: New Settings → Account → Wallet Balances panel listing per-chain balance rows.

Parity Contract

  • Legacy behavior preserved: No existing surface touched. Backend RPC unchanged.
  • Guard/fallback/dispatch parity checks: N/A — additive UI only.

Summary by CodeRabbit

  • New Features

    • Added Wallet Balances settings panel with per-chain badges, truncated addresses + copy-to-clipboard (with “copied” feedback), provider-status badge, and manual refresh with loading/disabled state.
  • Bug Fixes / Stability

    • Retry flow and error messaging for failed balance loads; refresh updates list reliably.
  • Documentation

    • Added translations for the Wallet Balances UI across multiple languages and updated settings entry text.
  • Tests

    • Added behavioral and API tests covering loading, error/retry, empty, populated, and refresh states.

Review Change Stack

obchain avatar May 26 '26 10:05 obchain

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] ▶️ Resume reviews
  • [ ] 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a Settings > Account > Wallet Balances panel that fetches multi-chain wallet balances via a new fetchWalletBalances() API, displays rows with chain badges, truncated copyable addresses, formatted balances and provider-status badges, includes request-sequencing guards, loading/error/empty states, refresh control, tests, i18n across language chunks, settings routing integration, and a separate Rust admission pipeline for generated tools with provenance/risk fields and admission logic.

Changes

Wallet Balances Feature

Layer / File(s) Summary
API Contract & Data Shape
app/src/services/walletApi.ts, app/src/services/walletApi.test.ts
Exports BalanceInfo and fetchWalletBalances() calling openhuman.wallet_balances; tests verify RPC invocation, error propagation, and empty results.
Panel Component Implementation
app/src/components/settings/panels/WalletBalancesPanel.tsx
Implements WalletBalancesPanel and BalanceRow: monotonic request-id guards to avoid stale updates, loading/error/empty/loaded UI branches, refresh button (disabled while loading) with spinner, truncated address + copy-to-clipboard with transient “copied” feedback, formatted balances and asset symbols, and provider-unavailable badge.
Panel Behavioral Tests
app/src/components/settings/panels/__tests__/WalletBalancesPanel.test.tsx
Vitest suite (mocked fetchWalletBalances and navigation hook) covering loading spinner, generic error with Retry flow, empty-state with Recovery Phrase hint, loaded rows (chain badges, balances, symbols, truncated addresses), provider-unavailable chip, and refresh-triggered reloads.
Settings Navigation & Routing
app/src/pages/Settings.tsx
Imports WalletBalancesPanel, defines WalletIcon, adds wallet-balances to accountSettingsItems with localized strings, and registers /settings/wallet-balances route rendering the panel via wrapSettingsPage.
Navigation Hook Update
app/src/components/settings/hooks/useSettingsNavigation.ts
Adds 'wallet-balances' to SettingsRoute, maps /settings/wallet-balances to that route, and reuses recovery-phrase breadcrumbs.
Multi-Language i18n Translations
app/src/lib/i18n/en.ts, app/src/lib/i18n/chunks/*-4.ts
Adds pages.settings.account.walletBalances and walletBalances.* keys (title/description, refresh/loading/retry, empty-state guidance, copy-address, provider-missing, raw-balance template, generic error) across the main English map and language chunk files.
Documentation & Capability Catalog
docs/TEST-COVERAGE-MATRIX.md, src/openhuman/about_app/catalog.rs
Adds Wallet Balances Panel (13.1.4) as covered in the test matrix and updates skills.wallet_execution how_to text to mention Settings > Wallet Balances.

Generated Tools Admission (Rust)

Layer / File(s) Summary
Structs, Enums & Public Types
src/openhuman/tools/generated.rs
Extends GeneratedToolDefinition with optional provenance/policy fields, adds GeneratedToolRisk enum, and introduces admission-related public types (GeneratedToolAdmissionConfig, GeneratedToolAdmissionRejection, GeneratedToolAdmissionReport).
Admission Entrypoint & Validation
src/openhuman/tools/generated.rs
Implements admit_generated_tool_definitions with normalization and validation helpers enforcing provenance/risk/provider/capability checks and returning admitted/rejected reports.
Admission Tests & Helpers
src/openhuman/tools/generated.rs (tests)
Expands tests to cover trusted acceptance, provider normalization, invalid-provider rejection, legacy preservation when enforcement is off, duplicate/unsafe-name rejection, missing-risk rejection, and verifies external_effect() semantics.

Sequence Diagram

sequenceDiagram
  participant User
  participant WalletBalancesPanel
  participant fetchWalletBalances
  participant CoreRPC as openhuman.wallet_balances
  User->>WalletBalancesPanel: Click Refresh
  WalletBalancesPanel->>WalletBalancesPanel: increment latestRequestId
  WalletBalancesPanel->>fetchWalletBalances: call loadBalances()
  fetchWalletBalances->>CoreRPC: call openhuman.wallet_balances
  CoreRPC-->>fetchWalletBalances: return BalanceInfo[]
  fetchWalletBalances-->>WalletBalancesPanel: Promise resolves
  WalletBalancesPanel->>WalletBalancesPanel: setState(balances)
  WalletBalancesPanel-->>User: render BalanceRow list

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • tinyhumansai/openhuman#2519: Changes to backend wallet_balances output (provider status, optional evm_network) that this UI and fetchWalletBalances consume.
  • tinyhumansai/openhuman#1858: Also modifies useSettingsNavigation.ts/Settings route handling; similar integration pattern for adding settings panels.

Suggested reviewers

  • graycyrus
  • M3gA-Mind
  • sanil-23

Poem

🐰 Hoppy code hops through the settings door,
Wallet balances shimmer, chained and pure.
Click to copy, refresh to see,
Multi-chain friends, all safe and free. ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Most changes are in-scope, but the Rust changes to src/openhuman/tools/generated.rs introducing admission pipeline for generated tools appear unrelated to wallet balances display. Clarify the relationship between generated tool admission and wallet balances, or move those Rust changes to a separate PR focused on tool security/provenance.
Docstring Coverage ⚠️ Warning Docstring coverage is 57.58% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely describes the main feature: adding a wallet balances panel to Settings UI for viewing multi-chain balances.
Linked Issues check ✅ Passed All primary objectives from #2682 are fully implemented: Settings entry, multi-chain rows with badges/addresses/copy, provider health visibility, refresh functionality, all UI states, privacy preservation, i18n coverage, and unit tests.

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


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.

coderabbitai[bot] avatar May 26 '26 10:05 coderabbitai[bot]

@graycyrus addressed both non-blocking nits in d524a5de + 1d7eb5eb:- Copy-address timer stacking: switched to a useRef-tracked timer that clears on each re-click and on unmount, so rapid clicks reset the 2s window cleanly instead of letting an older setTimeout flip copied back to false.- Dead walletBalances.addressCopied key: removed from en.ts and all 13 locale chunk-4 files. pnpm i18n:check is clean (0 missing/extra/drift). Existing Vitest suite (3551 tests) still green.

obchain avatar May 27 '26 14:05 obchain

Actionable comments posted: 0

coderabbitai[bot] avatar May 28 '26 13:05 coderabbitai[bot]

Hi @graycyrus @oxoxDev — round-4 rfix4 shepherding complete: CR comments addressed, CI green/converging, I've approved. Would appreciate a second-maintainer review when you have a moment 🙏

sanil-23 avatar May 28 '26 17:05 sanil-23

Hi @graycyrus — addressed your major finding directly: pushed 50dee06c which reverts the 3 bundled commits from pr/2549 (6226ed4, 21a7bf3, 46631365 — the 393 lines of admission-control code in src/openhuman/tools/generated.rs). Local cargo check clean; no other code referenced the reverted types. Once #2549 merges to main, the admission-control code will arrive here naturally via the next main merge. Re-requesting review.

sanil-23 avatar May 28 '26 18:05 sanil-23

@graycyrus @oxoxDev — addressed the 2 CI failures in 711e01fa: the classifies_embedding_api_invalid_token_401_as_session_expired test was failing on main itself (a regression from #2786 leaving the obsolete TAURI-RUST-T BackendUserError test contradicting the new SessionExpired classification). Fix scoped to src/core/observability.rs: guard is_embedding_backend_auth_failure so the OpenHuman-backend {"error":"Invalid token"} envelope falls through to SessionExpired; extend is_session_expired_message to match both parenthesized and bare-status wire forms; update the obsolete TAURI-RUST-T test to assert SessionExpired (now a regression guard). 121 observability tests green locally. Re-requesting review.

sanil-23 avatar May 28 '26 23:05 sanil-23

Resolved the merge conflict with main in 97b07007 — merged latest upstream db3fdc2e. The only conflict was in en.ts (our walletBalances.* keys vs upstream's new skills.dashboard.* keys); kept both. Verified locally: pnpm i18n:check parity clean (0 missing/extra/drifted across all locales), pnpm typecheck clean, cargo check clean. Branch is mergeable again.

obchain avatar May 29 '26 05:05 obchain

really great PR. merging shortly.

senamakel avatar May 29 '26 18:05 senamakel