please refractor this code import { ResultType, StepResponse } from '@txp-core/runtime';…
- User
please refractor this code import { ResultType, StepResponse } from '@txp-core/runtime'; import { Effect, put } from 'redux-saga/effects'; import { paymentTableSelectors } from '@txp-core/payment-transactions-table'; import { TransactionSelectors, genericTxnUpdate } from '@txp-core/transactions-core'; import { getAmount, select } from '@txp-core/basic-utils';
export function* outstandingTransactionsHandler(): Generator<Effect, StepResponse, string> { const isNewTransaction = yield* select(TransactionSelectors.getIsNewTransaction); const outstandingTableLines = yield* select(paymentTableSelectors.getCharges);
if (outstandingTableLines) { let totalLinkedPaymentAmount; if (isNewTransaction) { totalLinkedPaymentAmount = outstandingTableLines.reduce((total, obj) => { if (obj.isLinkedPaymentAmount) { return getAmount(total).add(getAmount(obj.linkedPaymentAmount)); } return total; }, 0); } else { totalLinkedPaymentAmount = outstandingTableLines.reduce((total, obj) => { return getAmount(total).add(getAmount(obj.linkedPaymentAmount)); }, 0); } yield put(genericTxnUpdate({ amount: totalLinkedPaymentAmount.toString() })); } return { result: ResultType.SUCCESS };}
- Assistant
import { ResultType, StepResponse } from '@txp-core/runtime'; import { Effect, put } from 'redux-saga/effects'; import { paymentTableSelectors } from '@txp-core/payment-transactions-table'; import { TransactionSelectors, genericTxnUpdate } from '@txp-core/transactions-core'; import { getAmount, select } from '@txp-core/basic-utils';
export function* handleOutstandingTransactions(): Generator<Effect, StepResponse, string> { const isNewTransaction = yield* select(TransactionSelectors.getIsNewTransaction); const outstandingTableLines = yield* select(paymentTableSelectors.getCharges);
if (outstandingTableLines) { const getTotalLinkedPaymentAmount = (total, obj) => { if (isNewTransaction && !obj.isLinkedPaymentAmount) return total; return getAmount(total).add(getAmount(obj.linkedPaymentAmount)); }; const totalLinkedPaymentAmount = outstandingTableLines.reduce(getTotalLinkedPaymentAmount, 0); yield put(genericTxnUpdate({ amount: totalLinkedPaymentAmount.toString() })); } return { result: ResultType.SUCCESS };}