Skip to content

Commit

Permalink
fix: check for window in next.js
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Aug 14, 2024
1 parent 3f38139 commit d873c49
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/wallet-management/src/createDefaultWagmiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit d873c49

Please sign in to comment.