From 226e2857baaf38b8d0287f70ed870f915933769d Mon Sep 17 00:00:00 2001 From: Keefer Taylor Date: Thu, 10 Sep 2020 10:39:25 -0700 Subject: [PATCH] refactor method --- src/XRP/serializer.ts | 15 +++++++-------- test/XRP/serializer.test.ts | 4 ---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/XRP/serializer.ts b/src/XRP/serializer.ts index 7bf6826f..369f7656 100644 --- a/src/XRP/serializer.ts +++ b/src/XRP/serializer.ts @@ -436,7 +436,10 @@ const serializer = { object.TxnSignature = signature } - Object.assign(object, this.memosToJSON(transaction.getMemosList())) + const memoList = transaction.getMemosList() + if (memoList.length > 0) { + object.Memos = this.memoListToJSON(memoList) + } const additionalTransactionData = getAdditionalTransactionData(transaction) if (additionalTransactionData === undefined) { @@ -805,13 +808,9 @@ const serializer = { * * @returns An array of the Memos in JSON format, or undefined. */ - memosToJSON(memos: Memo[]): { Memos: MemoJSON[] } | undefined { - if (!memos.length) { - return undefined - } - - const convertedMemos = memos.map((memo) => this.memoToJSON(memo)) - return { Memos: convertedMemos } + memoListToJSON(memos: Memo[]): MemoJSON[] { + // eslint-disable-next-line @typescript-eslint/unbound-method -- Manually assigning `this`. + return memos.map(this.memoToJSON, this) }, /** diff --git a/test/XRP/serializer.test.ts b/test/XRP/serializer.test.ts index 9ccc33dd..0d510549 100644 --- a/test/XRP/serializer.test.ts +++ b/test/XRP/serializer.test.ts @@ -341,10 +341,6 @@ describe('serializer', function (): void { assert.deepEqual(serialized, expectedJSON) }) - it('serializes empty or blank memo arrays or objects to undefined', function (): void { - assert.isUndefined(Serializer.memosToJSON([])) - }) - it('serializes both memos with empty fields and complete fields correctly', function (): void { const memo = new Memo() const memoData = new MemoData()