Fix missing logs on save (#1729)

* Fix missing logs on save

* fix receive logs wrt device sync

---------

Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: k00b <k00b@stacker.news>
This commit is contained in:
ekzyis 2024-12-17 00:37:31 +01:00 committed by GitHub
parent 62a922247d
commit 6098d39574
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 57 additions and 30 deletions

View File

@ -22,7 +22,7 @@ import { lnAddrOptions } from '@/lib/lnurl'
import { GqlAuthenticationError, GqlAuthorizationError, GqlInputError } from '@/lib/error' import { GqlAuthenticationError, GqlAuthorizationError, GqlInputError } from '@/lib/error'
import { getNodeSockets, getOurPubkey } from '../lnd' import { getNodeSockets, getOurPubkey } from '../lnd'
import validateWallet from '@/wallets/validate' import validateWallet from '@/wallets/validate'
import { canReceive } from '@/wallets/common' import { canReceive, getWalletByType } from '@/wallets/common'
import performPaidAction from '../paidAction' import performPaidAction from '../paidAction'
import performPayingAction from '../payingAction' import performPayingAction from '../payingAction'
import { timeoutSignal, withTimeout } from '@/lib/time' import { timeoutSignal, withTimeout } from '@/lib/time'
@ -65,6 +65,7 @@ function injectResolvers (resolvers) {
return await upsertWallet({ return await upsertWallet({
wallet, wallet,
walletDef,
testCreateInvoice: testCreateInvoice:
walletDef.testCreateInvoice && validateLightning && canReceive({ def: walletDef, config: data }) walletDef.testCreateInvoice && validateLightning && canReceive({ def: walletDef, config: data })
? (data) => withTimeout( ? (data) => withTimeout(
@ -558,7 +559,10 @@ const resolvers = {
const logger = walletLogger({ wallet, models }) const logger = walletLogger({ wallet, models })
await models.wallet.delete({ where: { userId: me.id, id: Number(id) } }) await models.wallet.delete({ where: { userId: me.id, id: Number(id) } })
logger.info('wallet detached')
if (canReceive({ def: getWalletByType(wallet.type), config: wallet.wallet })) {
logger.info('details for receiving deleted')
}
return true return true
}, },
@ -766,7 +770,7 @@ export const walletLogger = ({ wallet, models }) => {
} }
async function upsertWallet ( async function upsertWallet (
{ wallet, testCreateInvoice }, { settings, data, vaultEntries }, { logger, me, models }) { { wallet, walletDef, testCreateInvoice }, { settings, data, vaultEntries }, { logger, me, models }) {
if (!me) { if (!me) {
throw new GqlAuthenticationError() throw new GqlAuthenticationError()
} }
@ -872,24 +876,26 @@ async function upsertWallet (
) )
} }
txs.push( if (canReceive({ def: walletDef, config: walletData })) {
models.walletLog.createMany({ txs.push(
data: { models.walletLog.createMany({
userId: me.id, data: {
wallet: wallet.type, userId: me.id,
level: 'SUCCESS', wallet: wallet.type,
message: id ? 'wallet details updated' : 'wallet attached' level: 'SUCCESS',
} message: id ? 'details for receiving updated' : 'details for receiving saved'
}), }
models.walletLog.create({ }),
data: { models.walletLog.create({
userId: me.id, data: {
wallet: wallet.type, userId: me.id,
level: enabled ? 'SUCCESS' : 'INFO', wallet: wallet.type,
message: enabled ? 'wallet enabled' : 'wallet disabled' level: enabled ? 'SUCCESS' : 'INFO',
} message: enabled ? 'receiving enabled' : 'receiving disabled'
}) }
) })
)
}
const [upsertedWallet] = await models.$transaction(txs) const [upsertedWallet] = await models.$transaction(txs)
return upsertedWallet return upsertedWallet

View File

@ -84,33 +84,52 @@ export function useWalletConfigurator (wallet) {
}, [me?.id, wallet.def.name, reloadLocalWallets]) }, [me?.id, wallet.def.name, reloadLocalWallets])
const save = useCallback(async (newConfig, validateLightning = true) => { 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 vault is active, encrypt and send to server regardless of wallet type
if (isActive) { if (isActive) {
await _saveToServer(serverConfig, clientConfig, validateLightning) await _saveToServer(newServerConfig, newClientConfig, validateLightning)
await _detachFromLocal() await _detachFromLocal()
} else { } else {
if (canSend({ def: wallet.def, config: clientConfig })) { if (newCanSend) {
await _saveToLocal(clientConfig) await _saveToLocal(newClientConfig)
} else { } else {
// if it previously had a client config, remove it // if it previously had a client config, remove it
await _detachFromLocal() await _detachFromLocal()
} }
if (canReceive({ def: wallet.def, config: serverConfig })) { if (canReceive({ def: wallet.def, config: newServerConfig })) {
await _saveToServer(serverConfig, clientConfig, validateLightning) await _saveToServer(newServerConfig, newClientConfig, validateLightning)
} else if (wallet.config.id) { } else if (wallet.config.id) {
// we previously had a server config // we previously had a server config
if (wallet.vaultEntries.length > 0) { if (wallet.vaultEntries.length > 0) {
// we previously had a server config with vault entries, save it // we previously had a server config with vault entries, save it
await _saveToServer(serverConfig, clientConfig, validateLightning) await _saveToServer(newServerConfig, newClientConfig, validateLightning)
} else { } else {
// we previously had a server config without vault entries, remove it // we previously had a server config without vault entries, remove it
await _detachFromServer() 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]) _detachFromLocal, _detachFromServer])
const detach = useCallback(async () => { const detach = useCallback(async () => {
@ -125,7 +144,9 @@ export function useWalletConfigurator (wallet) {
// if vault is not active and has a client config, delete from local storage // if vault is not active and has a client config, delete from local storage
await _detachFromLocal() await _detachFromLocal()
} }
}, [isActive, _detachFromServer, _detachFromLocal])
logger.info('details for sending deleted')
}, [logger, isActive, _detachFromServer, _detachFromLocal])
return { save, detach } return { save, detach }
} }