Only provide WebLN if enabled (#1115)

Co-authored-by: ekzyis <ekzyis@ekzy.is>
This commit is contained in:
ekzyis 2024-04-28 18:03:07 +02:00 committed by GitHub
parent b8e153a4be
commit 0f95eb6c36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 2 deletions

View File

@ -7,9 +7,11 @@ import { LNCProvider, useLNC } from './lnc'
const WebLNContext = createContext({})
const isEnabled = p => [Status.Enabled, Status.Locked].includes(p?.status)
const syncProvider = (array, provider) => {
const idx = array.findIndex(({ name }) => provider.name === name)
const enabled = [Status.Enabled, Status.Locked].includes(provider.status)
const enabled = isEnabled(provider)
if (idx === -1) {
// add provider to end if enabled
return enabled ? [...array, provider] : array
@ -113,7 +115,7 @@ function RawWebLNProvider ({ children }) {
}, [setEnabledProviders])
return (
<WebLNContext.Provider value={{ provider: provider ? { sendPayment: sendPaymentWithToast } : null, enabledProviders, setProvider }}>
<WebLNContext.Provider value={{ provider: isEnabled(provider) ? { sendPayment: sendPaymentWithToast } : null, enabledProviders, setProvider }}>
{children}
</WebLNContext.Provider>
)