Detach wallets and delete logs on logout

This commit is contained in:
ekzyis 2024-07-07 18:23:42 +02:00
parent dddbb53792
commit 85464f93b9
3 changed files with 21 additions and 13 deletions

View File

@ -6,7 +6,7 @@ import BackArrow from '../../svgs/arrow-left-line.svg'
import { useCallback, useEffect, useState } from 'react' import { useCallback, useEffect, useState } from 'react'
import Price from '../price' import Price from '../price'
import SubSelect from '../sub-select' 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 Head from 'next/head'
import NoteIcon from '../../svgs/notification-4-fill.svg' import NoteIcon from '../../svgs/notification-4-fill.svg'
import { useMe } from '../me' import { useMe } from '../me'
@ -22,7 +22,7 @@ import SearchIcon from '../../svgs/search-line.svg'
import classNames from 'classnames' import classNames from 'classnames'
import SnIcon from '@/svgs/sn.svg' import SnIcon from '@/svgs/sn.svg'
import { useHasNewNotes } from '../use-has-new-notes' import { useHasNewNotes } from '../use-has-new-notes'
import { useWalletLogger } from '@/components/wallet-logger' import { useWallets } from '@/components/wallet'
export function Brand ({ className }) { export function Brand ({ className }) {
return ( return (
@ -256,8 +256,7 @@ export default function LoginButton ({ className }) {
export function LogoutDropdownItem () { export function LogoutDropdownItem () {
const { registration: swRegistration, togglePushSubscription } = useServiceWorker() const { registration: swRegistration, togglePushSubscription } = useServiceWorker()
// const wallet = useWallet() const wallets = useWallets()
const { deleteLogs } = useWalletLogger()
return ( return (
<Dropdown.Item <Dropdown.Item
onClick={async () => { onClick={async () => {
@ -266,12 +265,9 @@ export function LogoutDropdownItem () {
if (pushSubscription) { if (pushSubscription) {
await togglePushSubscription().catch(console.error) await togglePushSubscription().catch(console.error)
} }
// TODO: detach wallets
// await wallet.detachAll().catch(console.error) await wallets.resetClient().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 signOut({ callbackUrl: '/' }) await signOut({ callbackUrl: '/' })
}} }}
>logout >logout

View File

@ -29,7 +29,7 @@ export function useWallet (name) {
const me = useMe() const me = useMe()
const wallet = name ? getWalletByName(name) : getEnabledWallet(me) const wallet = name ? getWalletByName(name) : getEnabledWallet(me)
const { logger } = useWalletLogger(wallet) const { logger, deleteLogs } = useWalletLogger(wallet)
const [config, saveConfig, clearConfig] = useConfig(wallet) const [config, saveConfig, clearConfig] = useConfig(wallet)
const _isConfigured = isConfigured({ ...wallet, config }) const _isConfigured = isConfigured({ ...wallet, config })
@ -101,6 +101,7 @@ export function useWallet (name) {
config, config,
save, save,
delete: delete_, delete: delete_,
deleteLogs,
enable, enable,
disable, disable,
setPriority, setPriority,
@ -256,7 +257,18 @@ export function getEnabledWallet (me) {
} }
export function useWallets () { 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) { function getStorageKey (name, me) {

View File

@ -11,7 +11,7 @@ const WalletCard = dynamic(() => import('@/components/wallet-card'), { ssr: fals
export const getServerSideProps = getGetServerSideProps({ authRequired: true }) export const getServerSideProps = getGetServerSideProps({ authRequired: true })
export default function Wallet ({ ssrData }) { export default function Wallet ({ ssrData }) {
const wallets = useWallets() const { wallets } = useWallets()
const [sourceIndex, setSourceIndex] = useState() const [sourceIndex, setSourceIndex] = useState()
const [targetIndex, setTargetIndex] = useState() const [targetIndex, setTargetIndex] = useState()