Skip to content

Commit 28e60b0

Browse files
committed
refactor: convert WebLnProvider into hook
1 parent 8c045c5 commit 28e60b0

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

wallets/client/hooks/global.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useMe } from '@/components/me'
1616
import { useIndexedDB } from '@/components/use-indexeddb'
1717
import { FAILED_INVOICES } from '@/fragments/invoice'
1818
import { isTemplate, isWallet } from '@/wallets/lib/util'
19-
import { WebLnProvider } from '@/wallets/lib/protocols/webln'
19+
import { useWeblnEvents } from '@/wallets/lib/protocols/webln'
2020
import { useWalletsQuery } from '@/wallets/client/hooks/query'
2121
import { useWalletPayment } from '@/wallets/client/hooks/payment'
2222
import { useGenerateRandomKey, useSetKey, useIsWrongKey, useDeleteOldDb } from '@/wallets/client/hooks/crypto'
@@ -87,9 +87,7 @@ export function WalletsProvider ({ children }) {
8787
<WalletsContext.Provider value={state}>
8888
<WalletsDispatchContext.Provider value={dispatch}>
8989
<WalletHooks>
90-
<WebLnProvider>
91-
{children}
92-
</WebLnProvider>
90+
{children}
9391
</WalletHooks>
9492
</WalletsDispatchContext.Provider>
9593
</WalletsContext.Provider>
@@ -101,6 +99,7 @@ function WalletHooks ({ children }) {
10199
useAutomatedRetries()
102100
useKeyInit()
103101
useDeleteLocalWallets()
102+
useWeblnEvents()
104103

105104
return children
106105
}

wallets/lib/protocols/webln.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export default {
1212
isAvailable: () => window?.weblnEnabled
1313
}
1414

15-
export function WebLnProvider ({ children }) {
15+
// this hook is used to check if the lightning browser extension is still enabled
16+
// in which case we will also not attempt to use WebLN
17+
// for payments using the `isAvailable` function above
18+
export function useWeblnEvents () {
1619
useEffect(() => {
1720
const onEnable = () => {
1821
window.weblnEnabled = true
@@ -33,6 +36,4 @@ export function WebLnProvider ({ children }) {
3336
window.removeEventListener('webln:disabled', onDisable)
3437
}
3538
}, [])
36-
37-
return children
3839
}

0 commit comments

Comments
 (0)