Skip to content

hide custom seed toggle unless bip39 validation fails#3260

Merged
ca333 merged 7 commits intodevfrom
hide-custom-seed-option
Oct 29, 2025
Merged

hide custom seed toggle unless bip39 validation fails#3260
ca333 merged 7 commits intodevfrom
hide-custom-seed-option

Conversation

@smk762
Copy link
Copy Markdown
Collaborator

@smk762 smk762 commented Oct 27, 2025

closes #3071

To test:

  • manual input:

    • enter wallet creation form
    • attempt to create a wallet with a non-BIP39 compliant seed.
    • see use custom seed toggle when input is non-compliant
    • do not see use custom seed toggle when input is compliant
    • Multi-address mode toggle enables/disables import button as expected based on input validation.
  • Seed file input:

    • enter seed file import form
    • select a saved seed file with a non-BIP39 compliant seed.
    • Attempt to import with "multi-address mode" selected
    • See error message as below
image
  • Disable multi-address mode, but leave custom seed unchecked.
  • See error message as below
image
  • Disable multi-address mode, and check custom seed and input I understand.

  • seed file is imported successfully

  • Log out, then log back into the imported wallet

  • Successful login.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved seed validation during wallet import with enhanced error recovery options
    • Fixed custom seed option visibility to display intelligently based on wallet mode and validation status
    • Better error handling and messaging when importing with invalid seeds

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 27, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Modifies wallet import flows to conditionally display the custom seed toggle based on BIP39 validation results. The toggle is now hidden by default and revealed only when BIP39 validation fails or in specific HD mode scenarios, across two import widget files.

Changes

Cohort / File(s) Summary
BIP39 Validation & Custom Seed Toggle Logic
lib/views/wallets_manager/widgets/wallet_import_by_file.dart, lib/views/wallets_manager/widgets/wallet_simple_import.dart
Introduces computed visibility property _shouldShowCustomSeedToggle based on validation state. Replaces simple HD mode check with multi-condition logic. Refactors BIP39 validation to differentiate error handling for HD vs non-HD modes, resetting custom seed when toggling HD mode on, and clearing prior errors before import. Adds seed text listener in wallet_simple_import.dart to trigger rebuild on seed changes.

Sequence Diagram

sequenceDiagram
    participant User
    participant ImportUI
    participant Validator
    participant StateManager

    User->>ImportUI: Initiate Import
    ImportUI->>StateManager: Clear Prior Errors
    ImportUI->>Validator: Validate Seed (BIP39)
    
    alt Valid BIP39 Seed
        Validator-->>ImportUI: ✓ Valid
        ImportUI->>StateManager: Hide Custom Seed Toggle
        ImportUI->>User: Proceed with Import
    else Invalid + HD Mode
        Validator-->>ImportUI: ✗ Invalid
        ImportUI->>StateManager: Set HD-Specific Error
        ImportUI->>StateManager: Show Custom Seed Toggle
        ImportUI->>User: Display Error & Toggle
    else Invalid + Custom Seed Not Allowed
        Validator-->>ImportUI: ✗ Invalid
        ImportUI->>StateManager: Set BIP39 Error
        ImportUI->>StateManager: Show Custom Seed Toggle
        ImportUI->>User: Display Error & Toggle
    else Invalid + Custom Seed Allowed
        Validator-->>ImportUI: ✗ Invalid (but custom allowed)
        ImportUI->>User: Proceed with Custom Seed
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • State management complexity: New _shouldShowCustomSeedToggle getter and _showCustomSeedToggle flag introduce multi-condition visibility logic that requires careful verification
  • BIP39 validation branching: Three distinct error paths (HD-specific, standard BIP39, custom seed allowed) with different error handling—verify each branch is correct and mutually exclusive
  • Cross-file consistency: Similar patterns introduced in both files; ensure the computed property logic is consistent between wallet_import_by_file.dart and wallet_simple_import.dart
  • State reset behavior: Verify that resetting _allowCustomSeed = false when HD mode toggles on, and clearing _commonError before import, don't cause unintended side effects

Possibly related PRs

Suggested reviewers

  • takenagain
  • gcharang

Poem

🐰 A seed hides 'til BIP39 fails the test,
Then Custom toggles forth—the advanced guest!
HD whispers "reset," validation's the key,
State flows like lettuce, perfectly free! 🥬✨

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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "hide custom seed toggle unless bip39 validation fails" is clear, specific, and directly describes the primary change in the pull request. It accurately reflects the main objective from the linked issue #3071, which is to conditionally show the custom seed toggle only when BIP39 validation fails. The title is concise and uses descriptive language without vague terms or noise, making it easy for a teammate scanning the history to understand the purpose of the change.
Linked Issues Check ✅ Passed The changes in both modified files directly address the core requirements from issue #3071. The implementation introduces a new _shouldShowCustomSeedToggle computed property in both wallet_import_by_file.dart and wallet_simple_import.dart that controls the visibility of the custom seed toggle based on BIP39 validation results. The reworked BIP39 validation flow ensures the toggle is hidden by default and only revealed when validation fails (in HD mode or when custom seed is not allowed). These changes align with the stated objectives to hide the toggle by default and reveal it conditionally upon BIP39 validation failure.
Out of Scope Changes Check ✅ Passed All changes in the pull request are directly related to the objectives outlined in issue #3071. The modifications to both files focus exclusively on implementing the conditional visibility logic for the custom seed toggle based on BIP39 validation results, including the new toggle state management, the visibility getter logic, and the updated conditional rendering. Related changes such as HD mode handling and seed text listener attachment serve to support the primary objective and are not tangential to the scope of hiding and revealing the toggle conditionally.

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 27, 2025

Visit the preview URL for this PR (updated for commit b9ef42b):

https://walletrc--pull-3260-merge-kg7oibpe.web.app

(expires Wed, 05 Nov 2025 06:24:22 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: f66a4ff03faa546f12f0ae5a841bd9eff2714dcc

@CharlVS CharlVS requested a review from Copilot October 27, 2025 10:19
@CharlVS
Copy link
Copy Markdown
Collaborator

CharlVS commented Oct 27, 2025

@cursoragent please review

@coderabbitai please review

@cursor
Copy link
Copy Markdown

cursor bot commented Oct 27, 2025

I completed a focused review of the PR changes around the custom seed toggle, BIP39 validation, and HD (multi-address) mode flows.

Verdict

  • LGTM. The implementation matches the acceptance criteria for both manual input and seed-file import flows.

What I verified

  • Manual input form:
    • Toggle only appears when the seed is non-BIP39 and HD mode is off; hidden when compliant.
    • Button enablement updates with validation and HD toggle.
  bool get _shouldShowCustomSeedToggle {
    if (_isHdMode) return false;
    if (_allowCustomSeed) return true; // keep visible once enabled
    final seed = _seedController.text.trim();
    if (seed.isEmpty) return false;
    final validator = context.read<KomodoDefiSdk>().mnemonicValidator;
    final isBip39 = validator.validateBip39(seed);
    return !isBip39;
  }
    return switch (maybeFailedReason) {
      MnemonicFailedReason.empty =>
        LocaleKeys.walletCreationEmptySeedError.tr(),
      MnemonicFailedReason.customNotSupportedForHd =>
        _isHdMode
            ? LocaleKeys.walletCreationHdBip39SeedError.tr()
            : LocaleKeys.walletCreationBip39SeedError.tr(),
      MnemonicFailedReason.customNotAllowed =>
        LocaleKeys.customSeedWarningText.tr(),
  • Seed-file import:
    • In HD mode, non-BIP39 produces the HD-specific error and blocks import.
    • In non-HD, non-BIP39 without custom seed shows the general error and reveals the toggle; enabling custom seed proceeds.
      final bool isBip39 = _sdk.mnemonicValidator.validateBip39(decryptedSeed);
      if (!isBip39) {
        if (_isHdMode) {
          setState(() {
            _commonError = LocaleKeys.walletCreationHdBip39SeedError.tr();
            _showCustomSeedToggle = true;
          });
          return;
        }
        if (!_allowCustomSeed) {
          setState(() {
            _commonError = LocaleKeys.walletCreationBip39SeedError.tr();
            _showCustomSeedToggle = true;
          });
          return;
        }
        // Non-HD and custom seed allowed: continue without setting an error
      }
  bool get _shouldShowCustomSeedToggle {
    if (_allowCustomSeed) return true; // keep visible once enabled
    if (_showCustomSeedToggle) return true; // show after first failure, even in HD
    return false;
  }
  • Custom seed confirmation dialog is correctly enforced before enabling:
      onChanged: (newValue) async {
        if (!value && newValue) {
          final confirmed = await customSeedDialog(context);
          if (!confirmed) return;
        }
        onChanged(newValue);
      },

Minor nits (optional)

  • Consistency: Error strings say "select 'Allow custom seed'" while the UI label is "Use custom seed phrase / private key (WIF)". Consider aligning wording.
  • UX nuance: In manual input, once the user enables custom seed, the toggle remains visible even if the current input becomes BIP39 later. If you want strict adherence to “hide unless BIP39 fails,” you could auto-hide it when the input returns to compliant (and reset _allowCustomSeed), though current behavior is defensible.

All else looks good and aligns with the test steps in the PR description.


Open in Cursor Open in Web

Learn more about Cursor Agents

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the wallet import flow to conditionally show the "custom seed" toggle only when BIP39 validation fails, improving UX by hiding unnecessary options when seeds are compliant.

Key changes:

  • Custom seed toggle now appears dynamically based on BIP39 validation results
  • Enhanced error handling for non-compliant seeds in file imports
  • Added listener to rebuild UI as users type seed phrases

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/views/wallets_manager/widgets/wallet_simple_import.dart Adds dynamic validation logic to show/hide custom seed toggle based on BIP39 compliance during manual seed entry
lib/views/wallets_manager/widgets/wallet_import_by_file.dart Implements conditional toggle visibility for seed file imports with improved error messaging for non-compliant seeds

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 27, 2025

@CharlVS, I'll review the changes in this pull request now.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

♻️ Duplicate comments (1)
lib/views/wallets_manager/widgets/wallet_simple_import.dart (1)

151-160: Memory leak: Remove listener before disposing the controller.

The listener added at line 154 is never removed in the dispose method. This will cause a memory leak as the listener persists after widget disposal.

Apply this diff to fix:

 @override
 void dispose() {
+  _seedController.removeListener(_onSeedChanged);
   _nameController.dispose();
   _seedController.dispose();
   _passwordController.dispose();
   super.dispose();
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12a0e16 and b033188.

📒 Files selected for processing (2)
  • lib/views/wallets_manager/widgets/wallet_import_by_file.dart (5 hunks)
  • lib/views/wallets_manager/widgets/wallet_simple_import.dart (3 hunks)
🔇 Additional comments (5)
lib/views/wallets_manager/widgets/wallet_simple_import.dart (2)

272-272: LGTM! Conditional visibility aligned with PR objectives.

The toggle now correctly shows only when appropriate based on HD mode, custom seed state, and BIP39 validation.


436-446: LGTM! Logic correctly implements conditional visibility.

The getter appropriately hides the toggle in HD mode, keeps it visible once enabled, and reveals it when BIP39 validation fails on non-empty seeds.

lib/views/wallets_manager/widgets/wallet_import_by_file.dart (3)

151-157: LGTM! Correctly resets custom seed when HD mode is enabled.

This ensures custom seed usage is properly disabled when switching to HD mode, which doesn't support custom seeds.


220-225: LGTM! Good practice to clear previous errors.

Clearing _commonError before a new import attempt prevents stale error messages from confusing the user.


256-273: LGTM! BIP39 validation logic is clear and correct.

The validation flow properly handles HD vs non-HD cases and sets appropriate errors. The comment on line 272 helpfully clarifies the success path.

@cursor
Copy link
Copy Markdown

cursor bot commented Oct 27, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@CharlVS
Copy link
Copy Markdown
Collaborator

CharlVS commented Oct 27, 2025

@cursoragent review

@cursor
Copy link
Copy Markdown

cursor bot commented Oct 27, 2025

I reviewed the PR. Functionality matches the acceptance criteria for both manual entry and seed-file import. Two small, actionable nits below.

Must-fix

  • Remove the seed listener in dispose to avoid a leak.
  @override
  void initState() {
    super.initState();
    _seedController.addListener(_onSeedChanged);
  }

  void _onSeedChanged() {
    // Rebuild to update custom seed toggle visibility as user types
    setState(() {});
  }
  @override
  void dispose() {
    _nameController.dispose();
    _seedController.dispose();
    _passwordController.dispose();
    super.dispose();
  }

Suggested edit:

@override
void dispose() {
  _seedController.removeListener(_onSeedChanged);
  _nameController.dispose();
  _seedController.dispose();
  _passwordController.dispose();
  super.dispose();
}

Nice-to-have

  • Align toggle visibility behavior in HD mode between manual and file-import flows (either hide in HD or show disabled with guidance). Manual input hides in HD:
  bool get _shouldShowCustomSeedToggle {
    if (_isHdMode) return false;
    if (_allowCustomSeed) return true; // keep visible once enabled
    final seed = _seedController.text.trim();
    if (seed.isEmpty) return false;
    final validator = context.read<KomodoDefiSdk>().mnemonicValidator;
    final isBip39 = validator.validateBip39(seed);
    return !isBip39;
  }

File import currently shows the toggle after failure, even if still in HD:

  bool get _shouldShowCustomSeedToggle {
    if (_allowCustomSeed) return true; // keep visible once enabled
    if (_showCustomSeedToggle) return true; // show after first failure, even in HD
    return false;
  }

Optional alignment for file import:

bool get _shouldShowCustomSeedToggle {
  if (_isHdMode) return false;
  if (_allowCustomSeed) return true;
  if (_showCustomSeedToggle) return true;
  return false;
}
  • Copy consistency: error text says “select ‘Allow custom seed’,” but the UI control is “Use custom seed phrase / private key (WIF)”. Consider updating the error strings:
  "customSeedWarningText": "Custom seed phrases are generally less secure and easier to crack than a generated BIP39-compliant seed phrase. To confirm you understand and are aware of the risk, type \"I understand\" in the box below.",
  "customSeedIUnderstand": "i understand",
  "walletCreationBip39SeedError": "BIP39 seed phrase validation failed, try again or select 'Allow custom seed'",
  "walletCreationHdBip39SeedError": "Your input seed phrase is not BIP39 compliant, and can not be used in multi-address wallet mode. Please try again, or disable multi-address wallet mode and select 'Allow custom seed' to proceed.",

Suggestion: replace “Allow custom seed” with “Use custom seed.”

All core flows look good.


Open in Cursor Open in Web

Learn more about Cursor Agents

@smk762 smk762 self-assigned this Oct 28, 2025
@smk762 smk762 added the P2 Time permissive label Oct 28, 2025
@ca333 ca333 merged commit b51ee27 into dev Oct 29, 2025
7 of 13 checks passed
@ca333 ca333 mentioned this pull request Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Time permissive

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants