ensure that wallets are configured to send and/or receive

This commit is contained in:
Riccardo Balbo 2024-10-16 12:48:05 +02:00 committed by k00b
parent 0263aa8372
commit de0eb8a52c
2 changed files with 17 additions and 9 deletions

View File

@ -48,6 +48,7 @@ function injectResolvers (resolvers) {
} }
} }
if (!canReceive && !canSend) throw new GqlInputError('wallet must be able to send or receive')
return await upsertWallet({ return await upsertWallet({
wallet: { wallet: {
field: field:

View File

@ -313,6 +313,8 @@ function useConfig (walletDef) {
} }
// set server config (will create wallet if it doesn't exist) (it is also testing receive config) // set server config (will create wallet if it doesn't exist) (it is also testing receive config)
if (!isReadyToSend && !isReadyToReceive) throw new Error('wallet should be configured to send or receive payments')
const mutation = generateMutation(walletDef) const mutation = generateMutation(walletDef)
const variables = { const variables = {
...newServerConfig, ...newServerConfig,
@ -321,7 +323,7 @@ function useConfig (walletDef) {
autoWithdrawThreshold: Number(autoWithdrawThreshold == null ? autowithdrawSettings.autoWithdrawThreshold : autoWithdrawThreshold), autoWithdrawThreshold: Number(autoWithdrawThreshold == null ? autowithdrawSettings.autoWithdrawThreshold : autoWithdrawThreshold),
autoWithdrawMaxFeePercent: Number(autoWithdrawMaxFeePercent == null ? autowithdrawSettings.autoWithdrawMaxFeePercent : autoWithdrawMaxFeePercent), autoWithdrawMaxFeePercent: Number(autoWithdrawMaxFeePercent == null ? autowithdrawSettings.autoWithdrawMaxFeePercent : autoWithdrawMaxFeePercent),
priority, priority,
enabled: enabled && (isReadyToSend || isReadyToReceive) enabled
}, },
canSend: isReadyToSend, canSend: isReadyToSend,
canReceive: isReadyToReceive, canReceive: isReadyToReceive,
@ -503,15 +505,20 @@ export function WalletProvider ({ children }) {
const userKeys = migratableKeys.filter(k => k.endsWith(`:${userId}`)) const userKeys = migratableKeys.filter(k => k.endsWith(`:${userId}`))
;(async () => { ;(async () => {
for (const key of userKeys) { for (const key of userKeys) {
const walletType = key.substring('wallet:'.length, key.length - userId.length - 1) try {
const walletConfig = JSON.parse(window.localStorage.getItem(key)) const walletType = key.substring('wallet:'.length, key.length - userId.length - 1)
const wallet = wallets.find(w => w.def.name === walletType) const walletConfig = JSON.parse(window.localStorage.getItem(key))
if (wallet) { const wallet = wallets.find(w => w.def.name === walletType)
console.log('Migrating', walletType, walletConfig) if (wallet) {
await wallet.save(walletConfig) console.log('Migrating', walletType, walletConfig)
await wallet.save(walletConfig)
window.localStorage.removeItem(key)
} else {
console.warn('No wallet found for', walletType, wallets)
}
} catch (e) {
window.localStorage.removeItem(key) window.localStorage.removeItem(key)
} else { console.error('Failed to migrate wallet', key, e)
console.warn('No wallet found for', walletType, wallets)
} }
} }
})() })()