diff --git a/src/api/ledger/parse/utils.js b/src/api/ledger/parse/utils.js index 33241b7c..97d4c071 100644 --- a/src/api/ledger/parse/utils.js +++ b/src/api/ledger/parse/utils.js @@ -13,6 +13,26 @@ function removeUndefined(obj: ?Object): ?Object { return obj ? _.omit(obj, _.isUndefined) : obj; } +function removeEmptyCounterparty(amount) { + if (amount.counterparty === '') { + delete amount.counterparty; + } +} + +function removeEmptyCounterpartyInBalanceChanges(balanceChanges) { + _.forEach(balanceChanges, (changes) => { + _.forEach(changes, removeEmptyCounterparty); + }); +} + +function removeEmptyCounterpartyInOrderbookChanges(orderbookChanges) { + _.forEach(orderbookChanges, (changes) => { + _.forEach(changes, (change) => { + _.forEach(change, removeEmptyCounterparty); + }); + }); +} + function parseOutcome(tx: Object): ?Object { if (!tx.validated) { return undefined; @@ -20,6 +40,8 @@ function parseOutcome(tx: Object): ?Object { const balanceChanges = transactionParser.parseBalanceChanges(tx.meta); const orderbookChanges = transactionParser.parseOrderBookChanges(tx.meta); + removeEmptyCounterpartyInBalanceChanges(balanceChanges); + removeEmptyCounterpartyInOrderbookChanges(orderbookChanges); return { result: tx.meta.TransactionResult, diff --git a/test/fixtures/account-transactions-response.json b/test/fixtures/account-transactions-response.json index 184cad0e..e55ce92d 100644 --- a/test/fixtures/account-transactions-response.json +++ b/test/fixtures/account-transactions-response.json @@ -47,14 +47,12 @@ ], "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59": [ { - "counterparty": "", "currency": "XRP", "value": "-1.101208" } ], "r9tGqzZgKxVFvzKFdUqXAqTzazWBUia8Qr": [ { - "counterparty": "", "currency": "XRP", "value": "1.101198" }, @@ -70,7 +68,6 @@ { "taker_pays": { "currency": "XRP", - "counterparty": "", "value": "-1.101198" }, "taker_gets": { @@ -136,14 +133,12 @@ ], "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59": [ { - "counterparty": "", "currency": "XRP", "value": "-1.101208" } ], "r9tGqzZgKxVFvzKFdUqXAqTzazWBUia8Qr": [ { - "counterparty": "", "currency": "XRP", "value": "1.101198" }, @@ -159,7 +154,6 @@ { "taker_pays": { "currency": "XRP", - "counterparty": "", "value": "-1.101198" }, "taker_gets": { diff --git a/test/fixtures/transaction-response.json b/test/fixtures/transaction-response.json index 339e01ee..cd266c4c 100644 --- a/test/fixtures/transaction-response.json +++ b/test/fixtures/transaction-response.json @@ -47,14 +47,12 @@ ], "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59": [ { - "counterparty": "", "currency": "XRP", "value": "-1.101208" } ], "r9tGqzZgKxVFvzKFdUqXAqTzazWBUia8Qr": [ { - "counterparty": "", "currency": "XRP", "value": "1.101198" }, @@ -70,7 +68,6 @@ { "taker_pays": { "currency": "XRP", - "counterparty": "", "value": "-1.101198" }, "taker_gets": {