From 4604a7bac9d4c5f5a951c25b329962c3af0fa299 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Mon, 14 Oct 2024 18:01:54 +0200 Subject: [PATCH] use SSR constant --- components/use-local-storage.js | 12 ++++++------ wallets/webln/client.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/use-local-storage.js b/components/use-local-storage.js index 732d9ded..c0683bda 100644 --- a/components/use-local-storage.js +++ b/components/use-local-storage.js @@ -70,13 +70,13 @@ export async function listLocalStorages ({ userId, database }) { */ function createMemBackend (userId, namespace) { const joinedNamespace = userId + ':' + namespace.join(':') - let memory = typeof window !== 'undefined' ? window?.snMemStorage?.[joinedNamespace] : null - if (!memory) { + let memory + if (SSR) { memory = {} - if (typeof window !== 'undefined') { - if (!window.snMemStorage) window.snMemStorage = {} - window.snMemStorage[joinedNamespace] = memory - } + } else { + if (!window.snMemStorage) window.snMemStorage = {} + memory = window.snMemStorage[joinedNamespace] + if (!memory) window.snMemStorage[joinedNamespace] = memory = {} } return { set: (key, value) => { memory[key] = value }, diff --git a/wallets/webln/client.js b/wallets/webln/client.js index c855cccc..f47e494c 100644 --- a/wallets/webln/client.js +++ b/wallets/webln/client.js @@ -1,6 +1,6 @@ import { useEffect } from 'react' +import { SSR } from '@/lib/constants' export * from 'wallets/webln' - export const sendPayment = async (bolt11) => { if (typeof window.webln === 'undefined') { throw new Error('WebLN provider not found') @@ -22,7 +22,7 @@ export const sendPayment = async (bolt11) => { } export function isAvailable () { - return typeof window !== 'undefined' && window?.weblnEnabled + return !SSR && window?.weblnEnabled } export function WebLnProvider ({ children }) {