import { getRecipientsAmount , Transaction , TransactionType } from '@signumjs/core' ; import { Amount } from '@signumjs/util' ; import { BalanceHistoryItem } from './typings' ; import { flow , map , filter } from 'lodash/fp' ; const isOwnTransaction = ( accountId , transaction ) : boolean => transaction . sender === accountId ; function getRelativeTransactionAmount ( accountId , transaction ) { if ( isOwnTransaction ( accountId , transaction ) ) { const amount = Amount . fromPlanck ( transaction . amountNQT ) . add ( Amount . fromPlanck ( transaction . feeNQT ) ) . getSigna ( ) ; return - parseFloat ( amount ) ; } return getRecipientsAmount ( accountId , transaction ) ; } param accountId param currentBalance param transactions return export function getBalanceHistoryFromTransactions ( accountId , currentBalance , transactions ) { let balance = currentBalance ; return flow ( filter ( ( t ) => t . type === TransactionType . Payment ) , map ( ( t ) => { const relativeAmount = getRelativeTransactionAmount ( accountId , t ) ; const deducedBalances = { timestamp : t . blockTimestamp , transactionId : t . transaction , balance , transaction : t } ; balance = balance - relativeAmount ; return deducedBalances ; } ) ) ( transactions ) ; }