@zeniai/client-epic-state 5.1.1 → 5.1.2
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.
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.js +7 -5
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.js +7 -19
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.js +7 -5
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.js +7 -19
- package/package.json +1 -1
|
@@ -17,14 +17,16 @@ export const getAutoSweepFlow = (state) => {
|
|
|
17
17
|
: undefined;
|
|
18
18
|
const risk = bufferAmountToRisk(bufferAmount.amount);
|
|
19
19
|
// The banner's recommended sweep assumes the default buffer band; shift it
|
|
20
|
-
// by the delta between the user's selected band
|
|
21
|
-
// tighter buffer sweeps more and a looser
|
|
20
|
+
// by the delta between the default buffer and the user's selected band so a
|
|
21
|
+
// tighter buffer (higher risk → smaller buffer) sweeps more and a looser
|
|
22
|
+
// buffer (lower risk → larger buffer) sweeps less. Clamp at zero so a buffer
|
|
23
|
+
// larger than the available surplus never yields a negative sweep.
|
|
22
24
|
const baseSweepAmount = getCashManagementOverviewBanner(state).amount;
|
|
23
25
|
const sweepAmount = {
|
|
24
26
|
...baseSweepAmount,
|
|
25
|
-
amount: baseSweepAmount.amount +
|
|
26
|
-
RISK_BUFFER_AMOUNT[
|
|
27
|
-
RISK_BUFFER_AMOUNT[
|
|
27
|
+
amount: Math.max(0, baseSweepAmount.amount +
|
|
28
|
+
RISK_BUFFER_AMOUNT[DEFAULT_RISK_LEVEL] -
|
|
29
|
+
RISK_BUFFER_AMOUNT[risk]),
|
|
28
30
|
};
|
|
29
31
|
return {
|
|
30
32
|
fetchState,
|
|
@@ -65,7 +65,7 @@ const pickLargestOutflow = (outflows) => {
|
|
|
65
65
|
return outflows.reduce((largest, event) => event.amount.amount > largest.amount.amount ? event : largest);
|
|
66
66
|
};
|
|
67
67
|
export const getCashManagementOverview = (state) => {
|
|
68
|
-
const { cashManagementOverviewState, depositAccountListState,
|
|
68
|
+
const { cashManagementOverviewState, depositAccountListState, paymentAccountListState, treasuryDetailState, } = state;
|
|
69
69
|
const aggregate = reduceAllFetchState([
|
|
70
70
|
{
|
|
71
71
|
fetchState: paymentAccountListState.fetchState,
|
|
@@ -89,7 +89,11 @@ export const getCashManagementOverview = (state) => {
|
|
|
89
89
|
},
|
|
90
90
|
]);
|
|
91
91
|
const treasuryBalance = treasuryDetailState.accountSummary?.totalBalance ?? zeroAmount();
|
|
92
|
-
const
|
|
92
|
+
const bannerView = getCashManagementOverviewBanner(state);
|
|
93
|
+
// cashBalance is the primary (agent-managed) deposit account's available
|
|
94
|
+
// balance — the account the banner resolves as primaryFundingAccount — not
|
|
95
|
+
// the sum of all cash accounts. Zero until that account resolves.
|
|
96
|
+
const cashBalance = bannerView.primaryFundingAccount?.accountBalance?.available ?? zeroAmount();
|
|
93
97
|
const totalCash = addAmounts(treasuryBalance, cashBalance);
|
|
94
98
|
const bannerData = cashManagementOverviewState.banner.data;
|
|
95
99
|
const inflowEvents = bannerData?.inflows ?? [];
|
|
@@ -99,7 +103,7 @@ export const getCashManagementOverview = (state) => {
|
|
|
99
103
|
const cashflow = subtractAmounts(totalInFlow, totalOutFlow);
|
|
100
104
|
const projectionData = buildProjectionData(cashBalance, inflowEvents, outflowEvents);
|
|
101
105
|
return {
|
|
102
|
-
banner:
|
|
106
|
+
banner: bannerView,
|
|
103
107
|
cashBalance,
|
|
104
108
|
cashflow,
|
|
105
109
|
inflowEvents,
|
|
@@ -206,19 +210,3 @@ const addAmounts = (a, b) => {
|
|
|
206
210
|
currencySymbol: a.currencySymbol,
|
|
207
211
|
};
|
|
208
212
|
};
|
|
209
|
-
const sumCashBalances = (paymentAccountIds, paymentAccountState, depositAccountIds, depositAccountState) => {
|
|
210
|
-
let total = zeroAmount();
|
|
211
|
-
paymentAccountIds.forEach((id) => {
|
|
212
|
-
const balance = paymentAccountState.paymentAccountByID[id]?.balances?.available;
|
|
213
|
-
if (balance != null) {
|
|
214
|
-
total = addAmounts(total, balance);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
depositAccountIds.forEach((id) => {
|
|
218
|
-
const balance = depositAccountState.depositAccountByID[id]?.accountBalance?.available;
|
|
219
|
-
if (balance != null) {
|
|
220
|
-
total = addAmounts(total, balance);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
return total;
|
|
224
|
-
};
|
|
@@ -20,14 +20,16 @@ const getAutoSweepFlow = (state) => {
|
|
|
20
20
|
: undefined;
|
|
21
21
|
const risk = (0, autoSweepFlowState_1.bufferAmountToRisk)(bufferAmount.amount);
|
|
22
22
|
// The banner's recommended sweep assumes the default buffer band; shift it
|
|
23
|
-
// by the delta between the user's selected band
|
|
24
|
-
// tighter buffer sweeps more and a looser
|
|
23
|
+
// by the delta between the default buffer and the user's selected band so a
|
|
24
|
+
// tighter buffer (higher risk → smaller buffer) sweeps more and a looser
|
|
25
|
+
// buffer (lower risk → larger buffer) sweeps less. Clamp at zero so a buffer
|
|
26
|
+
// larger than the available surplus never yields a negative sweep.
|
|
25
27
|
const baseSweepAmount = (0, cashManagementOverviewSelector_1.getCashManagementOverviewBanner)(state).amount;
|
|
26
28
|
const sweepAmount = {
|
|
27
29
|
...baseSweepAmount,
|
|
28
|
-
amount: baseSweepAmount.amount +
|
|
29
|
-
autoSweepFlowState_1.RISK_BUFFER_AMOUNT[
|
|
30
|
-
autoSweepFlowState_1.RISK_BUFFER_AMOUNT[
|
|
30
|
+
amount: Math.max(0, baseSweepAmount.amount +
|
|
31
|
+
autoSweepFlowState_1.RISK_BUFFER_AMOUNT[DEFAULT_RISK_LEVEL] -
|
|
32
|
+
autoSweepFlowState_1.RISK_BUFFER_AMOUNT[risk]),
|
|
31
33
|
};
|
|
32
34
|
return {
|
|
33
35
|
fetchState,
|
|
@@ -69,7 +69,7 @@ const pickLargestOutflow = (outflows) => {
|
|
|
69
69
|
return outflows.reduce((largest, event) => event.amount.amount > largest.amount.amount ? event : largest);
|
|
70
70
|
};
|
|
71
71
|
const getCashManagementOverview = (state) => {
|
|
72
|
-
const { cashManagementOverviewState, depositAccountListState,
|
|
72
|
+
const { cashManagementOverviewState, depositAccountListState, paymentAccountListState, treasuryDetailState, } = state;
|
|
73
73
|
const aggregate = (0, reduceFetchState_1.reduceAllFetchState)([
|
|
74
74
|
{
|
|
75
75
|
fetchState: paymentAccountListState.fetchState,
|
|
@@ -93,7 +93,11 @@ const getCashManagementOverview = (state) => {
|
|
|
93
93
|
},
|
|
94
94
|
]);
|
|
95
95
|
const treasuryBalance = treasuryDetailState.accountSummary?.totalBalance ?? (0, amount_1.zeroAmount)();
|
|
96
|
-
const
|
|
96
|
+
const bannerView = (0, exports.getCashManagementOverviewBanner)(state);
|
|
97
|
+
// cashBalance is the primary (agent-managed) deposit account's available
|
|
98
|
+
// balance — the account the banner resolves as primaryFundingAccount — not
|
|
99
|
+
// the sum of all cash accounts. Zero until that account resolves.
|
|
100
|
+
const cashBalance = bannerView.primaryFundingAccount?.accountBalance?.available ?? (0, amount_1.zeroAmount)();
|
|
97
101
|
const totalCash = addAmounts(treasuryBalance, cashBalance);
|
|
98
102
|
const bannerData = cashManagementOverviewState.banner.data;
|
|
99
103
|
const inflowEvents = bannerData?.inflows ?? [];
|
|
@@ -103,7 +107,7 @@ const getCashManagementOverview = (state) => {
|
|
|
103
107
|
const cashflow = subtractAmounts(totalInFlow, totalOutFlow);
|
|
104
108
|
const projectionData = buildProjectionData(cashBalance, inflowEvents, outflowEvents);
|
|
105
109
|
return {
|
|
106
|
-
banner:
|
|
110
|
+
banner: bannerView,
|
|
107
111
|
cashBalance,
|
|
108
112
|
cashflow,
|
|
109
113
|
inflowEvents,
|
|
@@ -211,19 +215,3 @@ const addAmounts = (a, b) => {
|
|
|
211
215
|
currencySymbol: a.currencySymbol,
|
|
212
216
|
};
|
|
213
217
|
};
|
|
214
|
-
const sumCashBalances = (paymentAccountIds, paymentAccountState, depositAccountIds, depositAccountState) => {
|
|
215
|
-
let total = (0, amount_1.zeroAmount)();
|
|
216
|
-
paymentAccountIds.forEach((id) => {
|
|
217
|
-
const balance = paymentAccountState.paymentAccountByID[id]?.balances?.available;
|
|
218
|
-
if (balance != null) {
|
|
219
|
-
total = addAmounts(total, balance);
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
depositAccountIds.forEach((id) => {
|
|
223
|
-
const balance = depositAccountState.depositAccountByID[id]?.accountBalance?.available;
|
|
224
|
-
if (balance != null) {
|
|
225
|
-
total = addAmounts(total, balance);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
return total;
|
|
229
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.2",
|
|
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
|
"module": "lib/esm/index.js",
|