fix removing server config on unsynced client vault

This commit is contained in:
k00b 2024-11-03 01:09:45 -05:00
parent 25facad5d9
commit fb65ea3ace
3 changed files with 27 additions and 5 deletions

View File

@ -33,7 +33,22 @@ function injectResolvers (resolvers) {
console.log(resolverName)
resolvers.Mutation[resolverName] = async (parent, { settings, validateLightning, vaultEntries, ...data }, { me, models }) => {
console.log('resolving', resolverName, { settings, validateLightning, vaultEntries, ...data })
const validData = await validateWallet(walletDef, { ...data, ...settings, vaultEntries }, { serverSide: true })
let existingVaultEntries
if (typeof vaultEntries === 'undefined' && data.id) {
// this mutation was sent from an unsynced client
// to pass validation, we need to add the existing vault entries for validation
// in case the client is removing the receiving config
existingVaultEntries = await models.vaultEntry.findMany({
where: {
walletId: Number(data.id)
}
})
}
const validData = await validateWallet(walletDef,
{ ...data, ...settings, vaultEntries: vaultEntries ?? existingVaultEntries },
{ serverSide: true })
if (validData) {
data && Object.keys(validData).filter(key => key in data).forEach(key => { data[key] = validData[key] })
settings && Object.keys(validData).filter(key => key in settings).forEach(key => { settings[key] = validData[key] })

View File

@ -87,8 +87,14 @@ export function useWalletConfigurator (wallet) {
if (canReceive({ def: wallet.def, config: serverConfig })) {
await _saveToServer(serverConfig, clientConfig, validateLightning)
} else if (wallet.config.id) {
// if it previously had a server config, remove it
await _detachFromServer()
// 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)
} else {
// we previously had a server config without vault entries, remove it
await _detachFromServer()
}
}
}
}, [isActive, wallet.def, _saveToServer, _saveToLocal, _validate,

View File

@ -87,7 +87,7 @@ export function WalletsProvider ({ children }) {
// the specific wallet config on the server is stored in wallet.wallet
// on the client, it's stored unnested
wallets.push({ config: { ...config, ...w.wallet }, def })
wallets.push({ config: { ...config, ...w.wallet }, def, vaultEntries })
}
setServerWallets(wallets)
@ -109,7 +109,8 @@ export function WalletsProvider ({ children }) {
value ?? merged[wallet.def.name]?.config?.[key]
])
)
}
},
vaultEntries: wallet.vaultEntries
}
}