-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support generated fields on serverside wallets #1769
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,14 +47,19 @@ function injectResolvers (resolvers) { | |
}) | ||
} | ||
|
||
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] }) | ||
const validate = async ({ data, settings, skipGenerated = false }) => { | ||
const validData = await validateWallet(walletDef, | ||
{ ...data, ...settings, vaultEntries: vaultEntries ?? existingVaultEntries }, | ||
{ serverSide: true, skipGenerated }) | ||
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] }) | ||
} | ||
} | ||
|
||
const needsTest = walletDef.testCreateInvoice && validateLightning && canReceive({ def: walletDef, config: data }) | ||
await validate({ data, settings, skipGenerated: needsTest }) | ||
|
||
// wallet in shape of db row | ||
const wallet = { | ||
field: walletDef.walletField, | ||
|
@@ -67,7 +72,7 @@ function injectResolvers (resolvers) { | |
wallet, | ||
walletDef, | ||
testCreateInvoice: | ||
walletDef.testCreateInvoice && validateLightning && canReceive({ def: walletDef, config: data }) | ||
needsTest | ||
? (data) => withTimeout( | ||
walletDef.testCreateInvoice(data, { | ||
logger, | ||
|
@@ -79,7 +84,7 @@ function injectResolvers (resolvers) { | |
settings, | ||
data, | ||
vaultEntries | ||
}, { logger, me, models }) | ||
}, { logger, me, models, validate }) | ||
} | ||
} | ||
console.groupEnd() | ||
|
@@ -770,7 +775,7 @@ export const walletLogger = ({ wallet, models }) => { | |
} | ||
|
||
async function upsertWallet ( | ||
{ wallet, walletDef, testCreateInvoice }, { settings, data, vaultEntries }, { logger, me, models }) { | ||
{ wallet, walletDef, testCreateInvoice }, { settings, data, vaultEntries }, { logger, me, models, validate }) { | ||
if (!me) { | ||
throw new GqlAuthenticationError() | ||
} | ||
|
@@ -779,6 +784,7 @@ async function upsertWallet ( | |
if (testCreateInvoice) { | ||
try { | ||
await testCreateInvoice(data) | ||
await validate({ data, settings, skipGenerated: false }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. validate again, since now we'll have the generated fields |
||
} catch (err) { | ||
const message = 'failed to create test invoice: ' + (err.message || err.toString?.()) | ||
logger.error(message) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ export function useWalletConfigurator (wallet) { | |
throw err | ||
} | ||
} else if (canReceive({ def: wallet.def, config: serverConfig })) { | ||
const transformedConfig = await validateWallet(wallet.def, serverConfig) | ||
const transformedConfig = await validateWallet(wallet.def, serverConfig, { skipGenerated: true }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the client needs to skip generated fields for receivers , because they are generated by the testCreateInvoice that runs serverside |
||
if (transformedConfig) { | ||
serverConfig = Object.assign(serverConfig, transformedConfig) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ function composeWalletSchema (walletDef, serverSide, skipGenerated) { | |
|
||
if (clientOnly && serverSide) { | ||
// For server-side validation, accumulate clientOnly fields as vaultEntries | ||
vaultEntrySchemas[optional ? 'optional' : 'required'].push(vaultEntrySchema(name)) | ||
vaultEntrySchemas[(optional || generated) ? 'optional' : 'required'].push(vaultEntrySchema(name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. every client-side generated field must be optional for server-side validation, otherwise if the user configures only the receiver part of a send&receiver wallet, the validation will fail because the non optional generated client-side fields are not compiled. |
||
} else { | ||
acc[name] = createFieldSchema(name, validate) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this becomes a function since we need to run it twice: