diff --git a/wallets/client/hooks/global.js b/wallets/client/hooks/global.js index 3684b568e..354cb044a 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 75d8d3c8a..a3ced4327 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 }