@zeniai/client-epic-state 5.0.87-betaAK1 → 5.0.87-betaAK2
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/cashManagementOverview/cashManagementOverviewSelector.js +31 -1
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.d.ts +16 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.js +31 -1
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { zeroAmount } from '../../../../commonStateTypes/amount';
|
|
2
2
|
import { reduceAllFetchState } from '../../../../commonStateTypes/reduceFetchState';
|
|
3
|
+
import { getDepositAccountByDepositAccountId } from '../../../../entity/depositAccount/depositAccountSelector';
|
|
4
|
+
import { mapDepositAccToFundingAccount, } from '../../commonSetup/setupViewSelector';
|
|
3
5
|
/**
|
|
4
6
|
* Default account type used when the recommend payload has no movement to
|
|
5
7
|
* expose yet (e.g. before the first fetch resolves). Callers that care about
|
|
@@ -18,6 +20,26 @@ export const getCashManagementOverviewBanner = (state) => {
|
|
|
18
20
|
{ fetchState: banner.fetchState, error: banner.error },
|
|
19
21
|
{ fetchState: autoSweep.fetchState, error: autoSweep.error },
|
|
20
22
|
]);
|
|
23
|
+
const subMovementType = movement?.subMovementType ?? DEFAULT_SUB_MOVEMENT_TYPE;
|
|
24
|
+
// The "primary" account is the deposit-account side of the movement —
|
|
25
|
+
// source for a push (money leaving primary → treasury) and destination
|
|
26
|
+
// for a pull (money returning to primary).
|
|
27
|
+
const primaryAccountId = subMovementType === 'pull'
|
|
28
|
+
? movement?.destinationBankAccountId
|
|
29
|
+
: movement?.sourceBankAccountId;
|
|
30
|
+
const primaryDepositAccount = primaryAccountId != null && primaryAccountId !== ''
|
|
31
|
+
? getDepositAccountByDepositAccountId(state.depositAccountState, primaryAccountId)
|
|
32
|
+
: undefined;
|
|
33
|
+
const primaryFundingAccount = primaryDepositAccount != null
|
|
34
|
+
? mapDepositAccToFundingAccount(primaryDepositAccount)
|
|
35
|
+
: undefined;
|
|
36
|
+
// For pull, surface the largest outflow in the horizon as the
|
|
37
|
+
// "triggering" event. This is a heuristic — the agent doesn't tag a
|
|
38
|
+
// specific outflow today, but the largest one is the most likely cause
|
|
39
|
+
// of the buffer breach and matches what the design wants to highlight.
|
|
40
|
+
const triggeringOutflow = subMovementType === 'pull'
|
|
41
|
+
? pickLargestOutflow(banner.data?.outflows)
|
|
42
|
+
: undefined;
|
|
21
43
|
return {
|
|
22
44
|
fetchState: aggregate.fetchState,
|
|
23
45
|
error: aggregate.error,
|
|
@@ -28,10 +50,18 @@ export const getCashManagementOverviewBanner = (state) => {
|
|
|
28
50
|
reasoning: movement?.reasoning ?? '',
|
|
29
51
|
sourceBankAccountId: movement?.sourceBankAccountId ?? '',
|
|
30
52
|
sourceBankAccountType: movement?.sourceBankAccountType ?? DEFAULT_BANK_ACCOUNT_TYPE,
|
|
31
|
-
subMovementType
|
|
53
|
+
subMovementType,
|
|
54
|
+
primaryFundingAccount,
|
|
55
|
+
triggeringOutflow,
|
|
32
56
|
version: 0,
|
|
33
57
|
};
|
|
34
58
|
};
|
|
59
|
+
const pickLargestOutflow = (outflows) => {
|
|
60
|
+
if (outflows == null || outflows.length === 0) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
return outflows.reduce((largest, event) => event.amount.amount > largest.amount.amount ? event : largest);
|
|
64
|
+
};
|
|
35
65
|
export const getCashManagementOverview = (state) => {
|
|
36
66
|
const { cashManagementOverviewState, depositAccountListState, depositAccountState, paymentAccountListState, paymentAccountState, treasuryDetailState, } = state;
|
|
37
67
|
const aggregate = reduceAllFetchState([
|
|
@@ -2,9 +2,25 @@ import { Amount } from '../../../../commonStateTypes/amount';
|
|
|
2
2
|
import { ID } from '../../../../commonStateTypes/common';
|
|
3
3
|
import { SelectorView } from '../../../../commonStateTypes/viewAndReport/viewAndReport';
|
|
4
4
|
import { RootState } from '../../../../reducer';
|
|
5
|
+
import { FundingAccount } from '../../commonSetup/setupViewSelector';
|
|
5
6
|
import { CashManagementMovement, UpcomingPaymentEvent } from './cashManagementOverviewState';
|
|
6
7
|
export interface CashManagementOverviewBannerSelectorView extends SelectorView, CashManagementMovement {
|
|
7
8
|
cashManagementSettingsId?: ID;
|
|
9
|
+
/**
|
|
10
|
+
* Resolved funding account whose buffer the agent is managing. For a push
|
|
11
|
+
* movement this is the `sourceBankAccountId`; for a pull it is the
|
|
12
|
+
* `destinationBankAccountId`. `undefined` when the agent hasn't returned a
|
|
13
|
+
* movement yet or the deposit account hasn't been hydrated into the entity
|
|
14
|
+
* bucket.
|
|
15
|
+
*/
|
|
16
|
+
primaryFundingAccount?: FundingAccount;
|
|
17
|
+
/**
|
|
18
|
+
* Pull-variant only. The largest upcoming outflow in the horizon — the
|
|
19
|
+
* event most likely to have pushed the primary account below its buffer
|
|
20
|
+
* and triggered the recommended pull. `undefined` for push movements or
|
|
21
|
+
* when the agent returned no outflow events.
|
|
22
|
+
*/
|
|
23
|
+
triggeringOutflow?: UpcomingPaymentEvent;
|
|
8
24
|
}
|
|
9
25
|
export interface CashProjectionPoint {
|
|
10
26
|
balance: Amount;
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getCashManagementOverview = exports.getCashManagementOverviewBanner = void 0;
|
|
4
4
|
const amount_1 = require("../../../../commonStateTypes/amount");
|
|
5
5
|
const reduceFetchState_1 = require("../../../../commonStateTypes/reduceFetchState");
|
|
6
|
+
const depositAccountSelector_1 = require("../../../../entity/depositAccount/depositAccountSelector");
|
|
7
|
+
const setupViewSelector_1 = require("../../commonSetup/setupViewSelector");
|
|
6
8
|
/**
|
|
7
9
|
* Default account type used when the recommend payload has no movement to
|
|
8
10
|
* expose yet (e.g. before the first fetch resolves). Callers that care about
|
|
@@ -21,6 +23,26 @@ const getCashManagementOverviewBanner = (state) => {
|
|
|
21
23
|
{ fetchState: banner.fetchState, error: banner.error },
|
|
22
24
|
{ fetchState: autoSweep.fetchState, error: autoSweep.error },
|
|
23
25
|
]);
|
|
26
|
+
const subMovementType = movement?.subMovementType ?? DEFAULT_SUB_MOVEMENT_TYPE;
|
|
27
|
+
// The "primary" account is the deposit-account side of the movement —
|
|
28
|
+
// source for a push (money leaving primary → treasury) and destination
|
|
29
|
+
// for a pull (money returning to primary).
|
|
30
|
+
const primaryAccountId = subMovementType === 'pull'
|
|
31
|
+
? movement?.destinationBankAccountId
|
|
32
|
+
: movement?.sourceBankAccountId;
|
|
33
|
+
const primaryDepositAccount = primaryAccountId != null && primaryAccountId !== ''
|
|
34
|
+
? (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(state.depositAccountState, primaryAccountId)
|
|
35
|
+
: undefined;
|
|
36
|
+
const primaryFundingAccount = primaryDepositAccount != null
|
|
37
|
+
? (0, setupViewSelector_1.mapDepositAccToFundingAccount)(primaryDepositAccount)
|
|
38
|
+
: undefined;
|
|
39
|
+
// For pull, surface the largest outflow in the horizon as the
|
|
40
|
+
// "triggering" event. This is a heuristic — the agent doesn't tag a
|
|
41
|
+
// specific outflow today, but the largest one is the most likely cause
|
|
42
|
+
// of the buffer breach and matches what the design wants to highlight.
|
|
43
|
+
const triggeringOutflow = subMovementType === 'pull'
|
|
44
|
+
? pickLargestOutflow(banner.data?.outflows)
|
|
45
|
+
: undefined;
|
|
24
46
|
return {
|
|
25
47
|
fetchState: aggregate.fetchState,
|
|
26
48
|
error: aggregate.error,
|
|
@@ -31,11 +53,19 @@ const getCashManagementOverviewBanner = (state) => {
|
|
|
31
53
|
reasoning: movement?.reasoning ?? '',
|
|
32
54
|
sourceBankAccountId: movement?.sourceBankAccountId ?? '',
|
|
33
55
|
sourceBankAccountType: movement?.sourceBankAccountType ?? DEFAULT_BANK_ACCOUNT_TYPE,
|
|
34
|
-
subMovementType
|
|
56
|
+
subMovementType,
|
|
57
|
+
primaryFundingAccount,
|
|
58
|
+
triggeringOutflow,
|
|
35
59
|
version: 0,
|
|
36
60
|
};
|
|
37
61
|
};
|
|
38
62
|
exports.getCashManagementOverviewBanner = getCashManagementOverviewBanner;
|
|
63
|
+
const pickLargestOutflow = (outflows) => {
|
|
64
|
+
if (outflows == null || outflows.length === 0) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
return outflows.reduce((largest, event) => event.amount.amount > largest.amount.amount ? event : largest);
|
|
68
|
+
};
|
|
39
69
|
const getCashManagementOverview = (state) => {
|
|
40
70
|
const { cashManagementOverviewState, depositAccountListState, depositAccountState, paymentAccountListState, paymentAccountState, treasuryDetailState, } = state;
|
|
41
71
|
const aggregate = (0, reduceFetchState_1.reduceAllFetchState)([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeniai/client-epic-state",
|
|
3
|
-
"version": "5.0.87-
|
|
3
|
+
"version": "5.0.87-betaAK2",
|
|
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",
|