Fix forward required in GraphQL mutations (#446)

If no forward variable is set, the API responds with

> Cannot read properties of undefined (reading 'map')

Co-authored-by: ekzyis <ek@stacker.news>
This commit is contained in:
ekzyis 2023-08-28 14:12:36 +02:00 committed by GitHub
parent 107a7f9e77
commit ded3bd680f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -83,12 +83,12 @@ export function advPostSchemaMembers (client) {
.compact((v) => !v.nym && !v.pct) .compact((v) => !v.nym && !v.pct)
.test({ .test({
name: 'sum', name: 'sum',
test: forwards => forwards.map(fwd => Number(fwd.pct)).reduce((sum, cur) => sum + cur, 0) <= 100, test: forwards => forwards ? forwards.map(fwd => Number(fwd.pct)).reduce((sum, cur) => sum + cur, 0) <= 100 : true,
message: 'the total forward percentage exceeds 100%' message: 'the total forward percentage exceeds 100%'
}) })
.test({ .test({
name: 'uniqueStackers', name: 'uniqueStackers',
test: forwards => new Set(forwards.map(fwd => fwd.nym)).size === forwards.length, test: forwards => forwards ? new Set(forwards.map(fwd => fwd.nym)).size === forwards.length : true,
message: 'duplicate stackers cannot be specified to receive forwarded sats' message: 'duplicate stackers cannot be specified to receive forwarded sats'
}) })
} }