From fbbfeaecfb4eb9d077f2e299cc87ba86727dfd8d Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Thu, 18 Apr 2024 10:45:21 +0200 Subject: [PATCH] check for window --- src/lib/WalletProviderSelector/index.tsx | 4 +++- src/lib/WalletProviderSelector/utils.ts | 2 +- src/lib/utils.ts | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/WalletProviderSelector/index.tsx b/src/lib/WalletProviderSelector/index.tsx index 70e7783..4c8a80d 100644 --- a/src/lib/WalletProviderSelector/index.tsx +++ b/src/lib/WalletProviderSelector/index.tsx @@ -67,6 +67,7 @@ export function WalletProviderSelector() { const triggerFadeOut = () => setIsVisible(false); function handleCancelClick() { + if (typeof window === "undefined") return; const event = new CustomEvent(cancel, { bubbles: true, composed: true, @@ -88,7 +89,7 @@ export function WalletProviderSelector() { } return; } - + if (typeof window === "undefined") return; const event = new CustomEvent(select, { detail: walletId, bubbles: true, @@ -165,6 +166,7 @@ export function WalletProviderSelector() { } onCleanup(() => { + if (typeof window === "undefined") return; window.removeEventListener(open, handleOpen); window.removeEventListener(close, handleClose); }); diff --git a/src/lib/WalletProviderSelector/utils.ts b/src/lib/WalletProviderSelector/utils.ts index 6d7f122..0c97be2 100644 --- a/src/lib/WalletProviderSelector/utils.ts +++ b/src/lib/WalletProviderSelector/utils.ts @@ -7,6 +7,6 @@ export function openAppStore(option: TWalletProviderOption) { console.error("No install prompt URL found for", option.id); return; } - + if (typeof window === "undefined") return; window.open(url, "_blank"); } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 233c70e..f7b3bb5 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -74,6 +74,7 @@ export function selectWalletProvider(config: Config): Promise { } function cleanup() { + if (typeof window === "undefined") return; window.removeEventListener(select, handleWalletSelectorSelectEvent); window.removeEventListener(cancel, handleWalletSelectorCancelEvent); @@ -101,6 +102,7 @@ export function selectWalletProvider(config: Config): Promise { } export function walletOpen(wallet: string) { + if (typeof window === "undefined") return; const event = new CustomEvent(walletOpenEventName, { detail: wallet, }); @@ -108,11 +110,13 @@ export function walletOpen(wallet: string) { } export function walletClose() { + if (typeof window === "undefined") return; const event = new CustomEvent(walletCloseEventName); window.dispatchEvent(event); } export function close() { + if (typeof window === "undefined") return; const event = new CustomEvent(closeEventName); window.dispatchEvent(event); }