diff --git a/components/nav/common.js b/components/nav/common.js index d04cf3f2..30bec234 100644 --- a/components/nav/common.js +++ b/components/nav/common.js @@ -6,7 +6,7 @@ import BackArrow from '../../svgs/arrow-left-line.svg' import { useCallback, useEffect, useState } from 'react' import Price from '../price' import SubSelect from '../sub-select' -import { USER_ID, BALANCE_LIMIT_MSATS, Wallet } from '../../lib/constants' +import { USER_ID, BALANCE_LIMIT_MSATS } from '../../lib/constants' import Head from 'next/head' import NoteIcon from '../../svgs/notification-4-fill.svg' import { useMe } from '../me' @@ -22,7 +22,7 @@ import SearchIcon from '../../svgs/search-line.svg' import classNames from 'classnames' import SnIcon from '@/svgs/sn.svg' import { useHasNewNotes } from '../use-has-new-notes' -import { useWalletLogger } from '@/components/wallet-logger' +import { useWallets } from '@/components/wallet' export function Brand ({ className }) { return ( @@ -256,8 +256,7 @@ export default function LoginButton ({ className }) { export function LogoutDropdownItem () { const { registration: swRegistration, togglePushSubscription } = useServiceWorker() - // const wallet = useWallet() - const { deleteLogs } = useWalletLogger() + const wallets = useWallets() return ( { @@ -266,12 +265,9 @@ export function LogoutDropdownItem () { if (pushSubscription) { await togglePushSubscription().catch(console.error) } - // TODO: detach wallets - // await wallet.detachAll().catch(console.error) - // delete client wallet logs to prevent leak of private data if a shared device was used - await deleteLogs(Wallet.NWC).catch(console.error) - await deleteLogs(Wallet.LNbits).catch(console.error) - await deleteLogs(Wallet.LNC).catch(console.error) + + await wallets.resetClient().catch(console.error) + await signOut({ callbackUrl: '/' }) }} >logout diff --git a/components/wallet/index.js b/components/wallet/index.js index ad5b26a7..25c2d64b 100644 --- a/components/wallet/index.js +++ b/components/wallet/index.js @@ -29,7 +29,7 @@ export function useWallet (name) { const me = useMe() const wallet = name ? getWalletByName(name) : getEnabledWallet(me) - const { logger } = useWalletLogger(wallet) + const { logger, deleteLogs } = useWalletLogger(wallet) const [config, saveConfig, clearConfig] = useConfig(wallet) const _isConfigured = isConfigured({ ...wallet, config }) @@ -101,6 +101,7 @@ export function useWallet (name) { config, save, delete: delete_, + deleteLogs, enable, disable, setPriority, @@ -256,7 +257,18 @@ export function getEnabledWallet (me) { } export function useWallets () { - return WALLET_DEFS.map(def => useWallet(def.name)) + const wallets = WALLET_DEFS.map(def => useWallet(def.name)) + + const resetClient = useCallback(async (wallet) => { + for (const w of wallets) { + if (w.sendPayment) { + await w.delete() + } + await w.deleteLogs() + } + }, [wallets]) + + return { wallets, resetClient } } function getStorageKey (name, me) { diff --git a/pages/settings/wallets/index.js b/pages/settings/wallets/index.js index d67491d4..b5519a25 100644 --- a/pages/settings/wallets/index.js +++ b/pages/settings/wallets/index.js @@ -11,7 +11,7 @@ const WalletCard = dynamic(() => import('@/components/wallet-card'), { ssr: fals export const getServerSideProps = getGetServerSideProps({ authRequired: true }) export default function Wallet ({ ssrData }) { - const wallets = useWallets() + const { wallets } = useWallets() const [sourceIndex, setSourceIndex] = useState() const [targetIndex, setTargetIndex] = useState()