From 1614dd9f777625bb4b11a72ac10031f2d25d55e4 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 11 Oct 2025 17:55:58 +0200 Subject: [PATCH] refactor: convert WebLnProvider into hook --- wallets/client/hooks/global.js | 7 +++---- wallets/lib/protocols/webln.js | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wallets/client/hooks/global.js b/wallets/client/hooks/global.js index 3684b568e8..354cb044a0 100644 --- a/wallets/client/hooks/global.js +++ b/wallets/client/hooks/global.js @@ -16,7 +16,7 @@ import { useMe } from '@/components/me' import { useIndexedDB } from '@/components/use-indexeddb' import { FAILED_INVOICES } from '@/fragments/invoice' import { isTemplate, isWallet } from '@/wallets/lib/util' -import { WebLnProvider } from '@/wallets/lib/protocols/webln' +import { useWeblnEvents } from '@/wallets/lib/protocols/webln' import { useWalletsQuery } from '@/wallets/client/hooks/query' import { useWalletPayment } from '@/wallets/client/hooks/payment' import { useGenerateRandomKey, useSetKey, useIsWrongKey, useDeleteOldDb } from '@/wallets/client/hooks/crypto' @@ -87,9 +87,7 @@ export function WalletsProvider ({ children }) { - - {children} - + {children} @@ -101,6 +99,7 @@ function WalletHooks ({ children }) { useAutomatedRetries() useKeyInit() useDeleteLocalWallets() + useWeblnEvents() return children } diff --git a/wallets/lib/protocols/webln.js b/wallets/lib/protocols/webln.js index 75d8d3c8aa..a3ced43279 100644 --- a/wallets/lib/protocols/webln.js +++ b/wallets/lib/protocols/webln.js @@ -12,7 +12,10 @@ export default { isAvailable: () => window?.weblnEnabled } -export function WebLnProvider ({ children }) { +// this hook is used to check if the lightning browser extension is still enabled +// in which case we will also not attempt to use WebLN +// for payments using the `isAvailable` function above +export function useWeblnEvents () { useEffect(() => { const onEnable = () => { window.weblnEnabled = true @@ -33,6 +36,4 @@ export function WebLnProvider ({ children }) { window.removeEventListener('webln:disabled', onDisable) } }, []) - - return children }