Skip to content

Commit 73f5c76

Browse files
authored
fix: [lw-12781] set proper blockchain on add/restore wallet (#1871)
1 parent 2e2ef40 commit 73f5c76

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

apps/browser-extension-wallet/src/components/MainMenu/DropdownMenuOverlay/components/UserInfo.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { AnyBip32Wallet, AnyWallet, Bip32WalletAccount, ScriptWallet, WalletType
1717
import { Wallet } from '@lace/cardano';
1818
import { Separator } from './Separator';
1919
import { getUiWalletType } from '@src/utils/get-ui-wallet-type';
20+
import { isScriptWallet } from '@lace/core';
21+
import { useCurrentBlockchain } from '@src/multichain';
2022

2123
const ADRESS_FIRST_PART_LENGTH = 10;
2224
const ADRESS_LAST_PART_LENGTH = 5;
@@ -65,6 +67,7 @@ export const UserInfo = ({
6567
const [lastActiveAccount, setLastActiveAccount] = useState<number>(0);
6668
const [handle] = useGetHandles();
6769
const { activeWalletAvatar, getAvatar } = useWalletAvatar();
70+
const { blockchain } = useCurrentBlockchain();
6871

6972
const handleName = handle?.nftMetadata?.name;
7073

@@ -153,6 +156,9 @@ export const UserInfo = ({
153156
duration: TOAST_DEFAULT_DURATION,
154157
text: t('multiWallet.activated.wallet', { walletName: wallet.metadata.name })
155158
});
159+
// reload if we switch from, to or between btc wallet(s)
160+
if ((!isScriptWallet(wallet) && wallet.blockchainName === 'Bitcoin') || blockchain === 'bitcoin')
161+
window.location.reload();
156162
}}
157163
type={walletType}
158164
profile={
@@ -180,7 +186,8 @@ export const UserInfo = ({
180186
onOpenWalletAccounts,
181187
setIsDropdownMenuOpen,
182188
activeWalletId,
183-
t
189+
t,
190+
blockchain
184191
]
185192
);
186193

apps/browser-extension-wallet/src/hooks/__tests__/useWalletManager.test.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ describe('Testing useWalletManager hook', () => {
403403

404404
describe('createWallet', () => {
405405
test('should store wallet in repository', async () => {
406+
const setBackgroundStorage = jest.fn();
406407
const walletId = 'walletId';
407408
(walletApiUi.walletRepository as any).addWallet = jest.fn().mockResolvedValue(walletId);
408409
(walletApiUi.walletManager as any).activate = jest.fn().mockResolvedValue(undefined);
@@ -432,7 +433,13 @@ describe('Testing useWalletManager hook', () => {
432433
current: { createWallet }
433434
}
434435
} = renderHook(() => useWalletManager(), {
435-
wrapper: getWrapper({})
436+
wrapper: getWrapper({
437+
backgroundService: {
438+
clearBackgroundStorage: jest.fn(),
439+
getBackgroundStorage: jest.fn().mockResolvedValue({ activeBlockchain: 'cardano' }),
440+
setBackgroundStorage
441+
} as unknown as BackgroundServiceAPIProviderProps['value']
442+
})
436443
});
437444

438445
expect(createWallet).toBeDefined();
@@ -453,6 +460,8 @@ describe('Testing useWalletManager hook', () => {
453460
expect(walletApiUi.walletRepository.addWallet).toBeCalledTimes(1);
454461
expect(walletApiUi.walletManager.activate).toBeCalledTimes(1);
455462
expect(mockUseSecrets.clearSecrets).toBeCalledTimes(1);
463+
expect(setBackgroundStorage).toBeCalledTimes(1);
464+
expect(setBackgroundStorage).toBeCalledWith({ activeBlockchain: 'cardano' });
456465
});
457466
});
458467

apps/browser-extension-wallet/src/hooks/useWalletManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,10 @@ export const useWalletManager = (): UseWalletManager => {
822822
accountIndex
823823
});
824824

825+
await backgroundService.setBackgroundStorage({
826+
activeBlockchain: 'cardano'
827+
});
828+
825829
// Needed for reset password flow
826830
saveValueInLocalStorage({ key: 'wallet', value: { name } });
827831

@@ -842,7 +846,7 @@ export const useWalletManager = (): UseWalletManager => {
842846
}
843847
};
844848
},
845-
[getCurrentChainId, clearSecrets]
849+
[getCurrentChainId, backgroundService, clearSecrets]
846850
);
847851

848852
/**

0 commit comments

Comments
 (0)