Skip to content

Commit

Permalink
fix: only reconnect accounts for active chain during rehydration (#1356)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakehobbs authored Feb 12, 2025
1 parent 6865bd7 commit 95c6174
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions account-kit/core/src/hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,27 @@ const hydrateAccountState = (
([, cnx]) => cnx.chain
);
const initialState = createDefaultAccountState(chains);
const activeChainId = config.store.getState().chain.id;

return Object.entries(accountConfigs).reduce((acc, [chainKey, config]) => {
const chainId = Number(chainKey);
const isActiveChain = chainId === activeChainId;
const shouldReconnect = shouldReconnectAccounts && isActiveChain;
acc[chainId] = {
LightAccount:
config.LightAccount?.accountAddress && shouldReconnectAccounts
shouldReconnect && config.LightAccount?.accountAddress
? reconnectingState(config.LightAccount.accountAddress)
: defaultAccountState(),
MultiOwnerModularAccount:
config.MultiOwnerModularAccount?.accountAddress &&
shouldReconnectAccounts
shouldReconnect && config.MultiOwnerModularAccount?.accountAddress
? reconnectingState(config.MultiOwnerModularAccount.accountAddress)
: defaultAccountState(),
MultiOwnerLightAccount:
config.MultiOwnerLightAccount?.accountAddress && shouldReconnectAccounts
shouldReconnect && config.MultiOwnerLightAccount?.accountAddress
? reconnectingState(config.MultiOwnerLightAccount.accountAddress)
: defaultAccountState(),
ModularAccountV2:
config.ModularAccountV2?.accountAddress && shouldReconnectAccounts
shouldReconnect && config.ModularAccountV2?.accountAddress
? reconnectingState(config.ModularAccountV2.accountAddress)
: defaultAccountState(),
};
Expand Down

0 comments on commit 95c6174

Please sign in to comment.