Skip to content

Commit

Permalink
Fix pushing large array into array for trx tax report
Browse files Browse the repository at this point in the history
  • Loading branch information
ZIMkaRU committed May 6, 2024
1 parent 579707b commit 43e2756
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 4 additions & 2 deletions workers/loc.api/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const {
pickLowerObjectsNumbers,
sumAllObjectsNumbers,
pickAllLowerObjectsNumbers,
sumArrayVolumes
sumArrayVolumes,
pushLargeArr
} = require('./utils')
const {
isSubAccountApiKeys,
Expand All @@ -33,5 +34,6 @@ module.exports = {
pickLowerObjectsNumbers,
sumAllObjectsNumbers,
pickAllLowerObjectsNumbers,
sumArrayVolumes
sumArrayVolumes,
pushLargeArr
}
9 changes: 8 additions & 1 deletion workers/loc.api/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ const sumArrayVolumes = (propName, objects = []) => {
}, [])
}

const pushLargeArr = (dest, src) => {
for (const item of src) {
dest.push(item)
}
}

module.exports = {
checkParamsAuth,
tryParseJSON,
Expand All @@ -276,5 +282,6 @@ module.exports = {
pickLowerObjectsNumbers,
sumAllObjectsNumbers,
pickAllLowerObjectsNumbers,
sumArrayVolumes
sumArrayVolumes,
pushLargeArr
}
13 changes: 9 additions & 4 deletions workers/loc.api/sync/transaction.tax.report/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const { pushLargeArr } = require('../../helpers/utils')

const {
lookUpTrades,
getTrxMapByCcy,
Expand Down Expand Up @@ -120,9 +122,12 @@ class TransactionTaxReport {
}
)

trxsForCurrPeriod.push(...buyTradesWithUnrealizedProfit)
trxsForConvToUsd.push(...buyTradesWithUnrealizedProfit
.filter((trx) => trx?.isMovements || trx?.lastSymb !== 'USD'))
pushLargeArr(trxsForCurrPeriod, buyTradesWithUnrealizedProfit)
pushLargeArr(
trxsForConvToUsd,
buyTradesWithUnrealizedProfit
.filter((trx) => trx?.isMovements || trx?.lastSymb !== 'USD')
)
await this.#convertCurrencies(trxsForConvToUsd)

const { saleTradesWithRealizedProfit } = await lookUpTrades(
Expand Down Expand Up @@ -207,7 +212,7 @@ class TransactionTaxReport {
(...args) => this.#getPublicTrades(...args)
)

pubTrades.push(...chunk)
pushLargeArr(pubTrades, chunk)
}

convertCurrencyBySymbol(trxData, pubTrades)
Expand Down

0 comments on commit 43e2756

Please sign in to comment.