Skip wallet tests on priority update (#1327)
* Skip wallet connection tests if only priority is changed * Fix server priority overrides client priority * Also add priorityOnly as last argument in generateMutation
This commit is contained in:
parent
382f16643d
commit
66cf97e832
@ -22,18 +22,20 @@ function injectResolvers (resolvers) {
|
|||||||
const resolverName = generateResolverName(w.walletField)
|
const resolverName = generateResolverName(w.walletField)
|
||||||
console.log(resolverName)
|
console.log(resolverName)
|
||||||
|
|
||||||
resolvers.Mutation[resolverName] = async (parent, { settings, ...data }, { me, models }) => {
|
resolvers.Mutation[resolverName] = async (parent, { settings, priorityOnly, ...data }, { me, models }) => {
|
||||||
// allow transformation of the data on validation (this is optional ... won't do anything if not implemented)
|
// allow transformation of the data on validation (this is optional ... won't do anything if not implemented)
|
||||||
|
if (!priorityOnly) {
|
||||||
const validData = await walletValidate(w, { ...data, ...settings })
|
const validData = await walletValidate(w, { ...data, ...settings })
|
||||||
if (validData) {
|
if (validData) {
|
||||||
Object.keys(validData).filter(key => key in data).forEach(key => { data[key] = validData[key] })
|
Object.keys(validData).filter(key => key in data).forEach(key => { data[key] = validData[key] })
|
||||||
Object.keys(validData).filter(key => key in settings).forEach(key => { settings[key] = validData[key] })
|
Object.keys(validData).filter(key => key in settings).forEach(key => { settings[key] = validData[key] })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return await upsertWallet({
|
return await upsertWallet({
|
||||||
wallet: { field: w.walletField, type: w.walletType },
|
wallet: { field: w.walletField, type: w.walletType },
|
||||||
testCreateInvoice: (data) => w.testCreateInvoice(data, { me, models })
|
testCreateInvoice: (data) => w.testCreateInvoice(data, { me, models })
|
||||||
}, { settings, data }, { me, models })
|
}, { settings, data, priorityOnly }, { me, models })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.groupEnd()
|
console.groupEnd()
|
||||||
@ -571,13 +573,13 @@ export const addWalletLog = async ({ wallet, level, message }, { models }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function upsertWallet (
|
async function upsertWallet (
|
||||||
{ wallet, testCreateInvoice }, { settings, data }, { me, models }) {
|
{ wallet, testCreateInvoice }, { settings, data, priorityOnly }, { me, models }) {
|
||||||
if (!me) {
|
if (!me) {
|
||||||
throw new GraphQLError('you must be logged in', { extensions: { code: 'UNAUTHENTICATED' } })
|
throw new GraphQLError('you must be logged in', { extensions: { code: 'UNAUTHENTICATED' } })
|
||||||
}
|
}
|
||||||
assertApiKeyNotPermitted({ me })
|
assertApiKeyNotPermitted({ me })
|
||||||
|
|
||||||
if (testCreateInvoice) {
|
if (testCreateInvoice && !priorityOnly) {
|
||||||
try {
|
try {
|
||||||
await testCreateInvoice(data)
|
await testCreateInvoice(data)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -17,7 +17,7 @@ function mutationTypeDefs () {
|
|||||||
args += w.fields
|
args += w.fields
|
||||||
.filter(isServerField)
|
.filter(isServerField)
|
||||||
.map(fieldToGqlArg).join(', ')
|
.map(fieldToGqlArg).join(', ')
|
||||||
args += ', settings: AutowithdrawSettings!'
|
args += ', settings: AutowithdrawSettings!, priorityOnly: Boolean'
|
||||||
const resolverName = generateResolverName(w.walletField)
|
const resolverName = generateResolverName(w.walletField)
|
||||||
const typeDef = `${resolverName}(${args}): Boolean`
|
const typeDef = `${resolverName}(${args}): Boolean`
|
||||||
console.log(typeDef)
|
console.log(typeDef)
|
||||||
|
@ -71,7 +71,7 @@ export function useWallet (name) {
|
|||||||
const setPriority = useCallback(async (priority) => {
|
const setPriority = useCallback(async (priority) => {
|
||||||
if (_isConfigured && priority !== config.priority) {
|
if (_isConfigured && priority !== config.priority) {
|
||||||
try {
|
try {
|
||||||
await saveConfig({ ...config, priority }, { logger })
|
await saveConfig({ ...config, priority }, { logger, priorityOnly: true })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toaster.danger(`failed to change priority of ${wallet.name} wallet: ${err.message}`)
|
toaster.danger(`failed to change priority of ${wallet.name} wallet: ${err.message}`)
|
||||||
}
|
}
|
||||||
@ -161,16 +161,19 @@ function useConfig (wallet) {
|
|||||||
let config = {}
|
let config = {}
|
||||||
if (hasClientConfig) config = clientConfig
|
if (hasClientConfig) config = clientConfig
|
||||||
if (hasServerConfig) {
|
if (hasServerConfig) {
|
||||||
const { enabled } = config || {}
|
const { enabled, priority } = config || {}
|
||||||
config = {
|
config = {
|
||||||
...config,
|
...config,
|
||||||
...serverConfig
|
...serverConfig
|
||||||
}
|
}
|
||||||
// wallet is enabled if enabled is set in client or server config
|
// wallet is enabled if enabled is set in client or server config
|
||||||
config.enabled ||= enabled
|
config.enabled ||= enabled
|
||||||
|
// priority might only be set on client or server
|
||||||
|
// ie. if send+recv is available but only one is configured
|
||||||
|
config.priority ||= priority
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveConfig = useCallback(async (newConfig, { logger }) => {
|
const saveConfig = useCallback(async (newConfig, { logger, priorityOnly }) => {
|
||||||
// NOTE:
|
// NOTE:
|
||||||
// verifying the client/server configuration before saving it
|
// verifying the client/server configuration before saving it
|
||||||
// prevents unsetting just one configuration if both are set.
|
// prevents unsetting just one configuration if both are set.
|
||||||
@ -189,6 +192,9 @@ function useConfig (wallet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
if (priorityOnly) {
|
||||||
|
setClientConfig(newConfig)
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
// XXX: testSendPayment can return a new config (e.g. lnc)
|
// XXX: testSendPayment can return a new config (e.g. lnc)
|
||||||
const newerConfig = await wallet.testSendPayment?.(newConfig, { me, logger })
|
const newerConfig = await wallet.testSendPayment?.(newConfig, { me, logger })
|
||||||
@ -206,6 +212,8 @@ function useConfig (wallet) {
|
|||||||
else wallet.disablePayments()
|
else wallet.disablePayments()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (hasServerConfig) {
|
if (hasServerConfig) {
|
||||||
let newServerConfig = extractServerConfig(wallet.fields, newConfig)
|
let newServerConfig = extractServerConfig(wallet.fields, newConfig)
|
||||||
|
|
||||||
@ -216,7 +224,7 @@ function useConfig (wallet) {
|
|||||||
valid = false
|
valid = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid) await setServerConfig(newServerConfig)
|
if (valid) await setServerConfig(newServerConfig, { priorityOnly })
|
||||||
}
|
}
|
||||||
}, [hasClientConfig, hasServerConfig, setClientConfig, setServerConfig, wallet])
|
}, [hasClientConfig, hasServerConfig, setClientConfig, setServerConfig, wallet])
|
||||||
|
|
||||||
@ -273,7 +281,7 @@ function useServerConfig (wallet) {
|
|||||||
priority,
|
priority,
|
||||||
enabled,
|
enabled,
|
||||||
...config
|
...config
|
||||||
}) => {
|
}, { priorityOnly }) => {
|
||||||
try {
|
try {
|
||||||
const mutation = generateMutation(wallet)
|
const mutation = generateMutation(wallet)
|
||||||
return await client.mutate({
|
return await client.mutate({
|
||||||
@ -286,7 +294,8 @@ function useServerConfig (wallet) {
|
|||||||
autoWithdrawMaxFeePercent: Number(autoWithdrawMaxFeePercent),
|
autoWithdrawMaxFeePercent: Number(autoWithdrawMaxFeePercent),
|
||||||
priority,
|
priority,
|
||||||
enabled
|
enabled
|
||||||
}
|
},
|
||||||
|
priorityOnly
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} finally {
|
} finally {
|
||||||
@ -326,13 +335,13 @@ function generateMutation (wallet) {
|
|||||||
}
|
}
|
||||||
return arg
|
return arg
|
||||||
}).join(', ')
|
}).join(', ')
|
||||||
headerArgs += ', $settings: AutowithdrawSettings!'
|
headerArgs += ', $settings: AutowithdrawSettings!, $priorityOnly: Boolean'
|
||||||
|
|
||||||
let inputArgs = 'id: $id, '
|
let inputArgs = 'id: $id, '
|
||||||
inputArgs += wallet.fields
|
inputArgs += wallet.fields
|
||||||
.filter(isServerField)
|
.filter(isServerField)
|
||||||
.map(f => `${f.name}: $${f.name}`).join(', ')
|
.map(f => `${f.name}: $${f.name}`).join(', ')
|
||||||
inputArgs += ', settings: $settings'
|
inputArgs += ', settings: $settings, priorityOnly: $priorityOnly'
|
||||||
|
|
||||||
return gql`mutation ${resolverName}(${headerArgs}) {
|
return gql`mutation ${resolverName}(${headerArgs}) {
|
||||||
${resolverName}(${inputArgs})
|
${resolverName}(${inputArgs})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user