Skip to content

fix(wallets): prevent duplicate main account labels#607

Merged
PastaPastaPasta merged 2 commits into
v1.0-devfrom
codex/fix-duplicate-main-account-label
Feb 19, 2026
Merged

fix(wallets): prevent duplicate main account labels#607
PastaPastaPasta merged 2 commits into
v1.0-devfrom
codex/fix-duplicate-main-account-label

Conversation

@PastaPastaPasta
Copy link
Copy Markdown
Member

@PastaPastaPasta PastaPastaPasta commented Feb 19, 2026

Summary

  • fix account categorization to prioritize derivation path shape over stored metadata so legacy m/0'/... paths are treated as BIP32
  • prevent BIP44 entries without a real account index from being labeled Main Account
  • align wallets account dropdown and address table categorization logic
  • normalize SPV metadata classification so legacy and BIP44 references are corrected on registration

Testing

  • cargo test --lib account_summary -- --nocapture
  • cargo test --test kittest wallets_screen -- --nocapture

This pull request was created by Codex.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved recognition and handling of BIP32 and BIP44 wallet standards
    • Enhanced account path categorization for better accuracy
    • Refined conditions for "Add Receiving Address" feature availability
  • Refactoring

    • Consolidated account path categorization logic across wallet UI components for consistency

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 19, 2026

Warning

Rate limit exceeded

@PastaPastaPasta has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

The changes enhance derivation path categorization for wallet accounts by adding explicit BIP32/BIP44 checks in the wallet lifecycle, introducing a shared categorization helper function, delegating categorization logic across modules, and tightening the condition for displaying the "Add Receiving Address" UI to require explicit index 0 instead of treating None as default.

Changes

Cohort / File(s) Summary
Wallet Lifecycle Path Classification
src/context/wallet_lifecycle.rs
Adds short-circuit checks for BIP32 and BIP44 derivation paths in classify_derivation_metadata to return explicit references instead of falling through to default behavior.
Account Categorization Logic
src/ui/wallets/account_summary.rs
Introduces categorize_account_path helper function to categorize accounts based on derivation path type; adds looks_like_bip44 detection; replaces inline categorization logic; extends label handling for BIP44 accounts without index; adds unit tests for path-based categorization overrides.
Shared Categorization Delegation
src/ui/wallets/wallets_screen/address_table.rs
Refactors categorize_path to delegate to the shared categorize_account_path function from account summary module.
Receiving Address UI Guard
src/ui/wallets/wallets_screen/mod.rs
Tightens condition for "Add Receiving Address" button to require explicit Some(0) index instead of treating None as the main account.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Hops of logic, paths refined with care,
BIP32, BIP44 everywhere!
Shared helpers now, no more duplication,
Account categorization perfection!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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(wallets): prevent duplicate main account labels' accurately captures the main fix—preventing duplicate main account labels by fixing account categorization logic to prioritize derivation path shape over stored metadata.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-duplicate-main-account-label

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.

@PastaPastaPasta
Copy link
Copy Markdown
Member Author

After

Screenshot 2026-02-18 at 20 10 09

before, both were marked as "main account"

Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (1)
src/ui/wallets/account_summary.rs (1)

273-309: Good test coverage for the new categorization logic.

The three tests cover the key scenarios: None-index labeling, legacy-path-overrides-BIP44-reference, and BIP44-path-overrides-BIP32-reference. These directly validate the fix described in the PR objectives.

One minor observation: consider adding a test for a genuine BIP44 account-0 path with a correct BIP44 reference to verify it still yields (Bip44, Some(0)) — i.e., the happy path isn't broken.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ui/wallets/account_summary.rs` around lines 273 - 309, Add a unit test
that constructs a true BIP44 account-0 derivation path (e.g., hardened 44',
hardened 1', hardened 0' followed by normal 0/1) and calls
categorize_account_path with DerivationPathReference::BIP44, then assert the
result equals (AccountCategory::Bip44, Some(0)) to ensure the happy-path BIP44
classification still works; use the existing test module and helpers
(DerivationPath, ChildNumber, categorize_account_path, AccountCategory::Bip44,
DerivationPathReference::BIP44) to locate where to add this test.
🤖 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/context/wallet_lifecycle.rs`:
- Around line 409-415: The UI and registration use inconsistent BIP44 checks:
wallet lifecycle uses DerivationPath::is_bip44(self.network) while the UI uses
looks_like_bip44(path), causing mismatched classification; choose and implement
a single validation rule and make both callers use it (either tighten
looks_like_bip44 to match is_bip44: check components[0]==Hardened(44),
components[1]==Hardened(coin_type) using network-aware coin_type and len≥4, or
relax is_bip44 and DerivationPath::is_bip44 to only check
components[0]==Hardened(44)), update the implementations in
src/model/wallet/mod.rs (is_bip44) and src/ui/wallets/account_summary.rs
(looks_like_bip44) and ensure derivation_path.is_bip44(self.network) and the UI
call both point to the same canonical helper (extract a shared function if
needed) so registration and UI classify paths identically.

---

Nitpick comments:
In `@src/ui/wallets/account_summary.rs`:
- Around line 273-309: Add a unit test that constructs a true BIP44 account-0
derivation path (e.g., hardened 44', hardened 1', hardened 0' followed by normal
0/1) and calls categorize_account_path with DerivationPathReference::BIP44, then
assert the result equals (AccountCategory::Bip44, Some(0)) to ensure the
happy-path BIP44 classification still works; use the existing test module and
helpers (DerivationPath, ChildNumber, categorize_account_path,
AccountCategory::Bip44, DerivationPathReference::BIP44) to locate where to add
this test.

Comment thread src/context/wallet_lifecycle.rs
@PastaPastaPasta PastaPastaPasta merged commit bdfbd9c into v1.0-dev Feb 19, 2026
5 checks passed
@PastaPastaPasta PastaPastaPasta deleted the codex/fix-duplicate-main-account-label branch February 19, 2026 15:26
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