From ded3bd680fc451c19eaee9d7a3c51f93e560c559 Mon Sep 17 00:00:00 2001 From: ekzyis <27162016+ekzyis@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:12:36 +0200 Subject: [PATCH] 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 --- lib/validate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/validate.js b/lib/validate.js index 88ca62a5..59e554b8 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -83,12 +83,12 @@ export function advPostSchemaMembers (client) { .compact((v) => !v.nym && !v.pct) .test({ 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%' }) .test({ 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' }) }