diff --git a/widget/embedded/src/store/slices/wallets.ts b/widget/embedded/src/store/slices/wallets.ts index a029824a9..53c1581de 100644 --- a/widget/embedded/src/store/slices/wallets.ts +++ b/widget/embedded/src/store/slices/wallets.ts @@ -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, + ], }; }); } diff --git a/widget/embedded/src/utils/settings.ts b/widget/embedded/src/utils/settings.ts index d921a5b12..c8e180ddb 100644 --- a/widget/embedded/src/utils/settings.ts +++ b/widget/embedded/src/utils/settings.ts @@ -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'; }