Skip to content

Fix account switch sync thrash#2056

Merged
prxt6529 merged 3 commits intomainfrom
fix-account-switch-sync-thrash
Mar 5, 2026
Merged

Fix account switch sync thrash#2056
prxt6529 merged 3 commits intomainfrom
fix-account-switch-sync-thrash

Conversation

@prxt6529
Copy link
Copy Markdown
Collaborator

@prxt6529 prxt6529 commented Mar 5, 2026

Summary by CodeRabbit

  • New Features

    • Auto-switching to a stored active wallet address and consolidated wallet state management with improved error signaling.
  • Bug Fixes

    • Better synchronization between stored accounts and live provider addresses, stricter validation to avoid premature switches, and stronger security logging for wallet operations.
  • Tests

    • Added comprehensive tests covering multiple wallet account synchronization scenarios.

prxt6529 added 2 commits March 5, 2026 10:24
Signed-off-by: prxt6529 <prxt@6529.io>
Signed-off-by: prxt6529 <prxt@6529.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2247732e-12f1-4f37-8ab3-a600335684a4

📥 Commits

Reviewing files that changed from the base of the PR and between ef3f81b and e009984.

📒 Files selected for processing (1)
  • __tests__/components/auth/SeizeConnectContext.switch-sync.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/components/auth/SeizeConnectContext.switch-sync.test.tsx

📝 Walkthrough

Walkthrough

Adds tests for SeizeConnectContext address-sync behavior and updates SeizeConnectContext to prefer a validated stored active wallet address when appropriate, introduces consolidated wallet state management, internal wallet/auth error classes, and stricter validation, logging, and switching guards.

Changes

Cohort / File(s) Summary
New Test Suite for SeizeConnectContext
__tests__/components/auth/SeizeConnectContext.switch-sync.test.tsx
Adds tests covering three sync scenarios between live provider addresses and stored wallet accounts; mocks AppKit, viem, and auth utilities; includes AddressProbe and buildStoredAccount helpers; uses render/rerender to validate dynamic switching.
Core Component Enhancements
components/auth/SeizeConnectContext.tsx
Implements activeStoredAddress auto-switch flow, consolidated wallet state via useConsolidatedWalletState, new internal errors (WalletConnectionError, WalletDisconnectionError, AuthenticationError), stricter address validation/normalization, expanded security logging, and guarded account-switching/add-account logic.

Sequence Diagram

sequenceDiagram
    participant Client
    participant SeizeConnectContext
    participant AuthUtils as Auth Utilities
    participant AppKit as AppKit Provider

    Client->>SeizeConnectContext: mount / provider update
    SeizeConnectContext->>AuthUtils: getWalletAddress()
    AuthUtils-->>SeizeConnectContext: storedAddress

    alt storedAddress exists & differs from live
        SeizeConnectContext->>AuthUtils: getConnectedWalletAccounts()
        AuthUtils-->>SeizeConnectContext: storedAccounts
        SeizeConnectContext->>AuthUtils: isAddress()/getAddress() validation
        AuthUtils-->>SeizeConnectContext: validatedAddress
        alt validatedAddress in storedAccounts
            SeizeConnectContext->>AuthUtils: setActiveWalletAccount(validatedAddress)
            AuthUtils-->>SeizeConnectContext: confirm
            SeizeConnectContext->>AppKit: update active connection
            AppKit-->>Client: context updates (switched address)
        else not found
            SeizeConnectContext->>Client: keep live provider address
        end
    else single account or match
        SeizeConnectContext->>Client: use existing active address
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Mint for me - profile wallet selection #1925: Modifies SeizeConnectContext address-resolution and debounced account-update flow; overlaps with stored-active-account switching changes.
  • safe login init #1834: Adjusts wallet-state logic in SeizeConnectContext (walletInfo/isSafeWallet injection), related to consolidated wallet state refactor.

Suggested reviewers

  • ragnep

Poem

🐰 I sniffed the stored key in a moonlit groove,
I hopped through checksums, found the address to move,
Guards on my paws, consolidated state in tow,
Tests that verify where the connections go,
A little rabbit cheer — click switch, and off we go!

🚥 Pre-merge checks | ✅ 3
✅ 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 directly addresses the main change: fixing account switch synchronization issues. It clearly references the primary objective shown in the PR details and reflects the core functionality changes in SeizeConnectContext.tsx.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-account-switch-sync-thrash

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.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@__tests__/components/auth/SeizeConnectContext.switch-sync.test.tsx`:
- Around line 57-62: The mock builder buildStoredAccount produces objects that
lack required fields from the ConnectedWalletAccount contract; update
buildStoredAccount to include refreshToken (a non-empty string) and jwt (string
or null) so the objects match the type expected by getConnectedWalletAccounts(),
ensuring refreshToken is populated (e.g., dummy token) and jwt is either a
string or null to mirror real connected account shape.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fd9a0a01-d32b-456e-bc30-20757abacaf3

📥 Commits

Reviewing files that changed from the base of the PR and between 7dc1299 and ef3f81b.

📒 Files selected for processing (2)
  • __tests__/components/auth/SeizeConnectContext.switch-sync.test.tsx
  • components/auth/SeizeConnectContext.tsx

Comment thread __tests__/components/auth/SeizeConnectContext.switch-sync.test.tsx Outdated
Signed-off-by: prxt6529 <prxt@6529.io>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 5, 2026

@prxt6529 prxt6529 merged commit 3ec59b2 into main Mar 5, 2026
7 checks passed
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