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) { function createMemBackend (userId, namespace) {
const joinedNamespace = userId + ':' + namespace.join(':') const joinedNamespace = userId + ':' + namespace.join(':')
let memory = typeof window !== 'undefined' ? window?.snMemStorage?.[joinedNamespace] : null let memory
if (!memory) { if (SSR) {
memory = {} memory = {}
if (typeof window !== 'undefined') { } else {
if (!window.snMemStorage) window.snMemStorage = {} if (!window.snMemStorage) window.snMemStorage = {}
window.snMemStorage[joinedNamespace] = memory memory = window.snMemStorage[joinedNamespace]
} if (!memory) window.snMemStorage[joinedNamespace] = memory = {}
} }
return { return {
set: (key, value) => { memory[key] = value }, set: (key, value) => { memory[key] = value },

View File

@ -1,6 +1,6 @@
import { useEffect } from 'react' import { useEffect } from 'react'
import { SSR } from '@/lib/constants'
export * from 'wallets/webln' export * from 'wallets/webln'
export const sendPayment = async (bolt11) => { export const sendPayment = async (bolt11) => {
if (typeof window.webln === 'undefined') { if (typeof window.webln === 'undefined') {
throw new Error('WebLN provider not found') throw new Error('WebLN provider not found')
@ -22,7 +22,7 @@ export const sendPayment = async (bolt11) => {
} }
export function isAvailable () { export function isAvailable () {
return typeof window !== 'undefined' && window?.weblnEnabled return !SSR && window?.weblnEnabled
} }
export function WebLnProvider ({ children }) { export function WebLnProvider ({ children }) {