Skip to content

Commit

Permalink
fix: fix change account bug for wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
yeager-eren committed Nov 20, 2024
1 parent d0d149f commit 455bafc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 19 additions & 1 deletion widget/embedded/src/store/slices/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,26 @@ export const createWalletsSlice: StateCreator<
});

set((state) => {
/*
* If wallet connected before and only need to update the address we should remove the old value and then add new conncted value.
* This scenario happens when user wants to change account inside the wallet.
* So the assumption here is the wallet has only one active address for a blockchain at the moment.
*/
const connectedWalletsWithoutSameWalletAndBlockchain =
state.connectedWallets.filter((currentConnectedWallet) => {
return !newConnectedWallets.some(
(newConnectedWallet) =>
newConnectedWallet.walletType ===
currentConnectedWallet.walletType &&
newConnectedWallet.chain === currentConnectedWallet.chain
);
});

return {
connectedWallets: [...state.connectedWallets, ...newConnectedWallets],
connectedWallets: [
...connectedWalletsWithoutSameWalletAndBlockchain,
...newConnectedWallets,
],
};
});
}
Expand Down
4 changes: 4 additions & 0 deletions widget/embedded/src/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export function isFeatureHidden(feature: keyof Features, features?: Features) {
return features?.[feature] === 'hidden';
}

export function isFeatureEnabled(feature: keyof Features, features?: Features) {
return features?.[feature] === 'enabled';
}

export function isRoutingEnabled(item: keyof Routing, routing?: Routing) {
return routing?.[item] === 'enabled';
}
Expand Down

0 comments on commit 455bafc

Please sign in to comment.