From 38caef8f939539da173cbfffd39bf356ff912731 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Mon, 16 Dec 2024 14:26:34 +0100 Subject: [PATCH] Fix missing logs on save --- api/resolvers/wallet.js | 6 +++--- wallets/config.js | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js index a794eb4be..8766e1929 100644 --- a/api/resolvers/wallet.js +++ b/api/resolvers/wallet.js @@ -551,7 +551,7 @@ const resolvers = { const logger = walletLogger({ wallet, models }) await models.wallet.delete({ where: { userId: me.id, id: Number(id) } }) - logger.info('wallet detached') + logger.info('details for receiving deleted') return true }, @@ -871,7 +871,7 @@ async function upsertWallet ( userId: me.id, wallet: wallet.type, level: 'SUCCESS', - message: id ? 'wallet details updated' : 'wallet attached' + message: id ? 'details for receiving updated' : 'details for receiving saved' } }), models.walletLog.create({ @@ -879,7 +879,7 @@ async function upsertWallet ( userId: me.id, wallet: wallet.type, level: enabled ? 'SUCCESS' : 'INFO', - message: enabled ? 'wallet enabled' : 'wallet disabled' + message: enabled ? 'receiving enabled' : 'receiving disabled' } }) ) diff --git a/wallets/config.js b/wallets/config.js index 49e47c905..a1853a440 100644 --- a/wallets/config.js +++ b/wallets/config.js @@ -76,33 +76,52 @@ export function useWalletConfigurator (wallet) { }, [me?.id, wallet.def.name, reloadLocalWallets]) const save = useCallback(async (newConfig, validateLightning = true) => { - const { clientConfig, serverConfig } = await _validate(newConfig, validateLightning) + const { clientWithShared: oldClientConfig } = siftConfig(wallet.def.fields, wallet.config) + const { clientConfig: newClientConfig, serverConfig: newServerConfig } = await _validate(newConfig, validateLightning) + + const oldCanSend = canSend({ def: wallet.def, config: oldClientConfig }) + const newCanSend = canSend({ def: wallet.def, config: newClientConfig }) // if vault is active, encrypt and send to server regardless of wallet type if (isActive) { - await _saveToServer(serverConfig, clientConfig, validateLightning) + await _saveToServer(newServerConfig, newClientConfig, validateLightning) await _detachFromLocal() } else { - if (canSend({ def: wallet.def, config: clientConfig })) { - await _saveToLocal(clientConfig) + if (newCanSend) { + await _saveToLocal(newClientConfig) } else { // if it previously had a client config, remove it await _detachFromLocal() } - if (canReceive({ def: wallet.def, config: serverConfig })) { - await _saveToServer(serverConfig, clientConfig, validateLightning) + if (canReceive({ def: wallet.def, config: newServerConfig })) { + await _saveToServer(newServerConfig, newClientConfig, validateLightning) } else if (wallet.config.id) { // we previously had a server config if (wallet.vaultEntries.length > 0) { // we previously had a server config with vault entries, save it - await _saveToServer(serverConfig, clientConfig, validateLightning) + await _saveToServer(newServerConfig, newClientConfig, validateLightning) } else { // we previously had a server config without vault entries, remove it await _detachFromServer() } } } - }, [isActive, wallet.def, _saveToServer, _saveToLocal, _validate, + + if (newCanSend) { + if (oldCanSend) { + logger.ok('details for sending updated') + } else { + logger.ok('details for sending saved') + } + if (newConfig.enabled) { + logger.ok('sending enabled') + } else { + logger.info('sending disabled') + } + } else if (oldCanSend) { + logger.info('details for sending deleted') + } + }, [isActive, wallet.def, wallet.config, _saveToServer, _saveToLocal, _validate, _detachFromLocal, _detachFromServer]) const detach = useCallback(async () => { @@ -117,7 +136,9 @@ export function useWalletConfigurator (wallet) { // if vault is not active and has a client config, delete from local storage await _detachFromLocal() } - }, [isActive, _detachFromServer, _detachFromLocal]) + + logger.info('details for sending deleted') + }, [logger, isActive, _detachFromServer, _detachFromLocal]) return { save, detach } }