use SSR constant

This commit is contained in:
Riccardo Balbo 2024-10-14 18:01:54 +02:00 committed by k00b
parent 49cf1f2e23
commit 4604a7bac9
2 changed files with 8 additions and 8 deletions

View File

@ -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 },

View File

@ -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 }) {