Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/XRP/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Copy link
Contributor

@tedkalaw tedkalaw Sep 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use an arrow function instead here?

return memos.map((memo) => this.memoToJSON(memo))

this is preserved in arrow functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally. I was trying to make the linter happy here (we do this other places too).

Do we have any thoughts on whether we should disable this linter rule?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it gets mad with arrow functions? the dox for the rule implies that arrow funcs are cool: https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unbound-method.md

if we're doing this other places already, i say just go for it as is

},

/**
Expand Down
4 changes: 0 additions & 4 deletions test/XRP/serializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down