Set canPay, canReceive in useWallet

This commit is contained in:
ekzyis 2024-06-20 20:16:27 +02:00
parent 6ac8785c51
commit 1a2be99027
3 changed files with 9 additions and 12 deletions

View File

@ -252,15 +252,13 @@ export const WalletLoggerProvider = ({ children }) => {
return () => idb.current?.close() return () => idb.current?.close()
}, []) }, [])
const appendLog = useCallback((walletName, level, message) => { const appendLog = useCallback((wallet, level, message) => {
const log = { wallet: walletName, level, message, ts: +new Date() } const log = { wallet: wallet.name, level, message, ts: +new Date() }
saveLog(log) saveLog(log)
setLogs((prevLogs) => [...prevLogs, log]) setLogs((prevLogs) => [...prevLogs, log])
}, [saveLog]) }, [saveLog])
const deleteLogs = useCallback(async (walletName) => { const deleteLogs = useCallback(async (wallet) => {
const wallet = walletName ? getWalletByName(walletName, me) : null
if (!wallet || wallet.canReceive) { if (!wallet || wallet.canReceive) {
await deleteServerWalletLogs({ variables: { wallet: wallet?.type } }) await deleteServerWalletLogs({ variables: { wallet: wallet?.type } })
} }
@ -302,9 +300,9 @@ export function useWalletLogger (wallet) {
// TODO: // TODO:
// also send this to us if diagnostics was enabled, // also send this to us if diagnostics was enabled,
// very similar to how the service worker logger works. // very similar to how the service worker logger works.
appendLog(wallet.name, level, message) appendLog(wallet, level, message)
console[level !== 'error' ? 'info' : 'error'](`[${wallet.name}]`, message) console[level !== 'error' ? 'info' : 'error'](`[${wallet.name}]`, message)
}, [appendLog, wallet?.name]) }, [appendLog, wallet])
const logger = useMemo(() => ({ const logger = useMemo(() => ({
ok: (...message) => log('ok')(message.join(' ')), ok: (...message) => log('ok')(message.join(' ')),
@ -312,7 +310,7 @@ export function useWalletLogger (wallet) {
error: (...message) => log('error')(message.join(' ')) error: (...message) => log('error')(message.join(' '))
}), [log, wallet?.name]) }), [log, wallet?.name])
const deleteLogs = useCallback((w) => innerDeleteLogs(w?.name || wallet?.name), [innerDeleteLogs, wallet?.name]) const deleteLogs = useCallback((w) => innerDeleteLogs(w || wallet), [innerDeleteLogs, wallet])
return { logger, deleteLogs } return { logger, deleteLogs }
} }

View File

@ -70,6 +70,8 @@ export function useWallet (name) {
disable, disable,
isConfigured: !!config, isConfigured: !!config,
status: config?.enabled ? Status.Enabled : Status.Initialized, status: config?.enabled ? Status.Enabled : Status.Initialized,
canPay: !!wallet?.sendPayment,
canReceive: !!wallet?.createInvoice,
logger logger
} }
} }
@ -81,7 +83,7 @@ export function getWalletByName (name, me) {
export function getEnabledWallet (me) { export function getEnabledWallet (me) {
// TODO: handle multiple enabled wallets // TODO: handle multiple enabled wallets
return WALLET_DEFS return WALLET_DEFS
.filter(def => def.canPay) .filter(def => !!def.sendPayment)
.find(def => { .find(def => {
const key = getStorageKey(def.name, me) const key = getStorageKey(def.name, me)
const config = SSR ? null : JSON.parse(window?.localStorage.getItem(key)) const config = SSR ? null : JSON.parse(window?.localStorage.getItem(key))

View File

@ -1,8 +1,5 @@
export const name = 'lnbits' export const name = 'lnbits'
export const canPay = true
export const canReceive = false
export const fields = [ export const fields = [
{ {
name: 'url', name: 'url',