From d873c49110c2be58cf06d83cbabc2e9817528a4c Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Wed, 14 Aug 2024 15:33:48 +0200 Subject: [PATCH] fix: check for window in next.js --- .../wallet-management/src/createDefaultWagmiConfig.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/wallet-management/src/createDefaultWagmiConfig.ts b/packages/wallet-management/src/createDefaultWagmiConfig.ts index bb5e22a72..020f19b97 100644 --- a/packages/wallet-management/src/createDefaultWagmiConfig.ts +++ b/packages/wallet-management/src/createDefaultWagmiConfig.ts @@ -121,10 +121,13 @@ export function createDefaultWagmiConfig( ...props?.wagmiConfig, }); + const localStorage = + typeof window !== 'undefined' ? window.localStorage : undefined; + // Check if WalletConnect properties exist in the props if (props?.walletConnect) { // Retrieve the ID of the most recently connected wallet connector from storage - const recentConnectorId = (window as any)?.localStorage.getItem( + const recentConnectorId = localStorage?.getItem( `${config.storage?.key}.recentConnectorId`, ); // If WalletConnect is the most recently connected wallet or lazy loading is disabled, @@ -135,7 +138,7 @@ export function createDefaultWagmiConfig( } if (!props?.lazy && props?.coinbase && !isWalletInstalled('coinbase')) { - const recentConnectorId = (window as any)?.localStorage.getItem( + const recentConnectorId = localStorage?.getItem( `${config.storage?.key}.recentConnectorId`, ); if (recentConnectorId?.includes?.('coinbaseWalletSDK') || !props.lazy) { @@ -144,7 +147,7 @@ export function createDefaultWagmiConfig( } if (props?.metaMask && !isWalletInstalled('metaMask')) { - const recentConnectorId = (window as any)?.localStorage.getItem( + const recentConnectorId = localStorage?.getItem( `${config.storage?.key}.recentConnectorId`, ); if (recentConnectorId?.includes?.('metaMaskSDK') || !props.lazy) {