Skip to content

Commit

Permalink
fix: not connected accounts on evm instance return empty array instea…
Browse files Browse the repository at this point in the history
…d of null
  • Loading branch information
yeager-eren committed Dec 21, 2024
1 parent fed9b28 commit f5eadf8
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions wallets/core/src/namespaces/evm/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,23 @@ export function changeAccountSubscriber(
const [, setState] = context.state();

eventCallback = async (accounts) => {
const chainId = await evmInstance.request({ method: 'eth_chainId' });

const formatAccounts = accounts.map((account) =>
AccountId.format({
address: account,
chainId: {
namespace: CAIP_NAMESPACE,
reference: chainId,
},
})
);

setState('accounts', formatAccounts);
// Phantom's intance on switching account to a not-connected account, will return empty array.
if (!accounts || accounts.length === 0) {
setState('accounts', null);
} else {
const chainId = await evmInstance.request({ method: 'eth_chainId' });
const formatAccounts = accounts.map((account) =>
AccountId.format({
address: account,
chainId: {
namespace: CAIP_NAMESPACE,
reference: chainId,
},
})
);

setState('accounts', formatAccounts);
}
};
evmInstance.on('accountsChanged', eventCallback);
},
Expand Down

0 comments on commit f5eadf8

Please sign in to comment.