From 6517a5b681c8fc0677358a5f1c2390698c4b7495 Mon Sep 17 00:00:00 2001 From: mehmetkr-31 Date: Sun, 7 Jun 2026 09:57:39 +0300 Subject: [PATCH] fix(signer): sanitize chain state on reconnect to prevent stale address When a Signer is reconstructed after cleanup (e.g., reconnect), the constructor reads account.chain from the store. If the store was cleared, account.chain is undefined and the fallback used params.metadata.appChainIds which could be stale or missing, defaulting to chain id 1 (mainnet). This caused two problems: 1. Incorrect public address returned after reconnect on Base (chain id 8453) 2. handleGetCapabilitiesRequest failing because accounts array was empty until the next successful handshake The fix prefers the chains array already registered in the store before falling back to metadata, ensuring the correct chain context is preserved across reconnect cycles. --- packages/account-sdk/src/sign/base-account/Signer.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/account-sdk/src/sign/base-account/Signer.ts b/packages/account-sdk/src/sign/base-account/Signer.ts index 1cffe605..bf38f0d4 100644 --- a/packages/account-sdk/src/sign/base-account/Signer.ts +++ b/packages/account-sdk/src/sign/base-account/Signer.ts @@ -94,7 +94,7 @@ export class Signer { const { account, chains } = this.storeInstance.getState(); this.accounts = account.accounts ?? []; - this.chain = account.chain ?? { + this.chain = account.chain ?? chains?.[0] ?? { id: params.metadata.appChainIds?.[0] ?? 1, }; @@ -433,7 +433,8 @@ export class Signer { // reset the signer this.accounts = []; - this.chain = { + const chains = this.storeInstance.getState().chains; + this.chain = chains?.[0] ?? { id: metadata?.appChainIds?.[0] ?? 1, }; }