@zeniai/client-epic-state 4.15.59 → 4.15.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,18 +58,47 @@ const updateReconcileTabLocalDataEpic = (actions$, state$) => actions$.pipe((0,
58
58
  }));
59
59
  exports.updateReconcileTabLocalDataEpic = updateReconcileTabLocalDataEpic;
60
60
  function calculateUpdatedClearedBalance(transactions, initialClearedBalance) {
61
- // Reduce the transactions to calculate the updated cleared balance
62
- const updatedClearedBalance = transactions.reduce((updatedBalance, transaction) => {
61
+ // Convert initial balance to string with 2 decimal places
62
+ let updatedClearedBalance = initialClearedBalance.amount.toFixed(2);
63
+ // Process each transaction
64
+ for (const transaction of transactions) {
65
+ // Convert both numbers to strings with 2 decimal places
66
+ const transactionAmount = transaction.amount.amount.toFixed(2);
67
+ // Split into integer and decimal parts while preserving sign
68
+ const [int1, dec1] = updatedClearedBalance.split('.');
69
+ const [int2, dec2] = transactionAmount.split('.');
70
+ // Convert to numbers while preserving negative sign for integer part
71
+ const num1 = Number(int1);
72
+ const num2 = Number(int2);
73
+ const decimal1 = Number(dec1);
74
+ const decimal2 = Number(dec2);
63
75
  if (transaction.transactionDirection === 'payment') {
64
- return updatedBalance - transaction.amount.amount; // Deduct for debit
76
+ // Calculate decimal part first
77
+ let newDec = decimal1 - decimal2;
78
+ let newInt = num1 - num2;
79
+ // Handle negative decimal by borrowing
80
+ if (newDec < 0) {
81
+ newDec += 100;
82
+ newInt -= 1;
83
+ }
84
+ // Combine and format
85
+ updatedClearedBalance = `${newInt}.${newDec.toString().padStart(2, '0')}`;
65
86
  }
66
87
  else if (transaction.transactionDirection === 'deposit') {
67
- return updatedBalance + transaction.amount.amount; // Add for credit
88
+ // Calculate decimal part first
89
+ let newDec = decimal1 + decimal2;
90
+ let newInt = num1 + num2;
91
+ // Handle decimal >= 100 by carrying over
92
+ if (newDec >= 100) {
93
+ newDec -= 100;
94
+ newInt += 1;
95
+ }
96
+ // Combine and format
97
+ updatedClearedBalance = `${newInt}.${newDec.toString().padStart(2, '0')}`;
68
98
  }
69
- return updatedBalance; // Return unchanged balance for other cases
70
- }, initialClearedBalance.amount);
99
+ }
71
100
  return {
72
- amount: updatedClearedBalance,
101
+ amount: Number(updatedClearedBalance),
73
102
  currencyCode: initialClearedBalance.currencyCode,
74
103
  currencySymbol: initialClearedBalance.currencySymbol,
75
104
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "4.15.59",
3
+ "version": "4.15.60",
4
4
  "description": "Shared module between Web & Mobile containing required abstractions for state management, async network communication. ",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",