Skip to content

Commit

Permalink
check for window
Browse files Browse the repository at this point in the history
  • Loading branch information
m-aboelenein committed Apr 18, 2024
1 parent b5296fa commit fbbfeae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/lib/WalletProviderSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -88,7 +89,7 @@ export function WalletProviderSelector() {
}
return;
}

if (typeof window === "undefined") return;
const event = new CustomEvent(select, {
detail: walletId,
bubbles: true,
Expand Down Expand Up @@ -165,6 +166,7 @@ export function WalletProviderSelector() {
}

onCleanup(() => {
if (typeof window === "undefined") return;
window.removeEventListener(open, handleOpen);
window.removeEventListener(close, handleClose);
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/WalletProviderSelector/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
4 changes: 4 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export function selectWalletProvider(config: Config): Promise<string> {
}

function cleanup() {
if (typeof window === "undefined") return;
window.removeEventListener(select, handleWalletSelectorSelectEvent);

window.removeEventListener(cancel, handleWalletSelectorCancelEvent);
Expand Down Expand Up @@ -101,18 +102,21 @@ export function selectWalletProvider(config: Config): Promise<string> {
}

export function walletOpen(wallet: string) {
if (typeof window === "undefined") return;
const event = new CustomEvent(walletOpenEventName, {
detail: wallet,
});
window.dispatchEvent(event);
}

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);
}

0 comments on commit fbbfeae

Please sign in to comment.