Fix recv wallet deleted on logout (#1398)

* Fix recv wallet deleted on logout

* Fix wallet logs on server deleted on logout

* Remove unused option in deleteLogs to override wallet
This commit is contained in:
ekzyis 2024-09-12 20:06:13 +02:00 committed by GitHub
parent a6713f9793
commit 24aacd8839
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 10 deletions

View File

@ -209,8 +209,8 @@ export const WalletLoggerProvider = ({ children }) => {
setLogs((prevLogs) => [log, ...prevLogs]) setLogs((prevLogs) => [log, ...prevLogs])
}, [saveLog]) }, [saveLog])
const deleteLogs = useCallback(async (wallet) => { const deleteLogs = useCallback(async (wallet, options) => {
if (!wallet || wallet.walletType) { if ((!wallet || wallet.walletType) && !options?.clientOnly) {
await deleteServerWalletLogs({ variables: { wallet: wallet?.walletType } }) await deleteServerWalletLogs({ variables: { wallet: wallet?.walletType } })
} }
if (!wallet || wallet.sendPayment) { if (!wallet || wallet.sendPayment) {
@ -262,7 +262,9 @@ 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 || wallet), [innerDeleteLogs, wallet]) const deleteLogs = useCallback((options) => {
return innerDeleteLogs(wallet, options)
}, [innerDeleteLogs, wallet])
return { logger, deleteLogs } return { logger, deleteLogs }
} }

View File

@ -77,9 +77,9 @@ export function useWallet (name) {
}, [saveConfig, me, logger]) }, [saveConfig, me, logger])
// delete is a reserved keyword // delete is a reserved keyword
const delete_ = useCallback(async () => { const delete_ = useCallback(async (options) => {
try { try {
await clearConfig({ logger }) await clearConfig({ logger, ...options })
} catch (err) { } catch (err) {
const message = err.message || err.toString?.() const message = err.message || err.toString?.()
logger.error(message) logger.error(message)
@ -87,6 +87,11 @@ export function useWallet (name) {
} }
}, [clearConfig, logger, disablePayments]) }, [clearConfig, logger, disablePayments])
const deleteLogs_ = useCallback(async (options) => {
// first argument is to override the wallet
return await deleteLogs(options)
}, [deleteLogs])
if (!wallet) return null if (!wallet) return null
// Assign everything to wallet object so every function that is passed this wallet object in this // Assign everything to wallet object so every function that is passed this wallet object in this
@ -102,7 +107,7 @@ export function useWallet (name) {
wallet.config = config wallet.config = config
wallet.save = save wallet.save = save
wallet.delete = delete_ wallet.delete = delete_
wallet.deleteLogs = deleteLogs wallet.deleteLogs = deleteLogs_
wallet.setPriority = setPriority wallet.setPriority = setPriority
wallet.hasConfig = hasConfig wallet.hasConfig = hasConfig
wallet.status = status wallet.status = status
@ -237,13 +242,13 @@ function useConfig (wallet) {
} }
}, [hasClientConfig, hasServerConfig, setClientConfig, setServerConfig, wallet]) }, [hasClientConfig, hasServerConfig, setClientConfig, setServerConfig, wallet])
const clearConfig = useCallback(async ({ logger }) => { const clearConfig = useCallback(async ({ logger, clientOnly }) => {
if (hasClientConfig) { if (hasClientConfig) {
clearClientConfig() clearClientConfig()
wallet.disablePayments() wallet.disablePayments()
logger.ok('wallet detached for payments') logger.ok('wallet detached for payments')
} }
if (hasServerConfig) await clearServerConfig() if (hasServerConfig && !clientOnly) await clearServerConfig()
}, [hasClientConfig, hasServerConfig, clearClientConfig, clearServerConfig, wallet]) }, [hasClientConfig, hasServerConfig, clearClientConfig, clearServerConfig, wallet])
return [config, saveConfig, clearConfig] return [config, saveConfig, clearConfig]
@ -404,9 +409,9 @@ export function useWallets () {
const resetClient = useCallback(async (wallet) => { const resetClient = useCallback(async (wallet) => {
for (const w of wallets) { for (const w of wallets) {
if (w.canSend) { if (w.canSend) {
await w.delete() await w.delete({ clientOnly: true })
} }
await w.deleteLogs() await w.deleteLogs({ clientOnly: true })
} }
}, [wallets]) }, [wallets])