From b0e1eb5641b8b71d4521369a106863b1622d4b5e Mon Sep 17 00:00:00 2001 From: Michael Jay Date: Thu, 12 Sep 2024 09:37:23 -0400 Subject: [PATCH] handle bad usage of getTransactions, & formatting --- lib/xrp/XrpClientAdapter.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/xrp/XrpClientAdapter.js b/lib/xrp/XrpClientAdapter.js index b16f8e3..16b85a8 100644 --- a/lib/xrp/XrpClientAdapter.js +++ b/lib/xrp/XrpClientAdapter.js @@ -53,25 +53,30 @@ class XrpClientAdapter extends xrpl.Client { excludeFailures }) { /** - * Behavior defaults to 'true', but this error is to document that 'includeRawTransactions: false' is NOT supported - * Truthiness is not sufficient for this check - it must explicitly be an equality check, & strict equality is prefered - */ + * Behavior defaults to 'true', but this error is to document that 'includeRawTransactions: false' is NOT supported + * Truthiness is not sufficient for this check - it must explicitly be an equality check, & strict equality is prefered + */ if (includeRawTransactions === false) { throw new Error('"includeRawTransactions: false" not supported'); } /** - * Filtering constants with defaults - */ - const TYPES = Array.isArray(types) && types.length > 0 ? - types.reduce(( acc, cur ) => { + * Filtering constants with defaults + */ + let TYPES = SUPPORTED_TRANSACTION_TYPES; + if (Array.isArray(types)) { + if (types.length === 0) { + throw new Error('If types is included, it should include at least one supported type'); + } + TYPES = types.reduce(( acc, cur ) => { const type = cur.toLowerCase(); if (SUPPORTED_TRANSACTION_TYPES.has(type)) { acc.add(type); } return acc; - }, new Set()) - : SUPPORTED_TRANSACTION_TYPES; + }, new Set()); + } + // Boolean option checks must be checked against type for existence instead of using fallback assignment const INITIATED = typeof initiated === 'boolean' ? initiated : false; const EXCLUDE_FAILURES = typeof excludeFailures === 'boolean' ? excludeFailures : true;