@zeniai/client-epic-state 5.0.92 → 5.0.93-betaAK1
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/commonStateTypes/amount.d.ts +1 -0
- package/lib/commonStateTypes/amount.js +3 -1
- package/lib/commonStateTypes/workingDayHelper.d.ts +9 -0
- package/lib/commonStateTypes/workingDayHelper.js +28 -1
- package/lib/entity/tenant/clearAllEpic.d.ts +3 -1
- package/lib/entity/tenant/clearAllEpic.js +4 -0
- package/lib/epic.d.ts +7 -1
- package/lib/epic.js +7 -1
- package/lib/esm/commonStateTypes/amount.js +1 -0
- package/lib/esm/commonStateTypes/workingDayHelper.js +26 -0
- package/lib/esm/entity/tenant/clearAllEpic.js +4 -0
- package/lib/esm/epic.js +7 -1
- package/lib/esm/index.js +7 -2
- package/lib/esm/reducer.js +6 -0
- package/lib/esm/view/spendManagement/autotransferRules/autoTransferRulesSelector.js +22 -2
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.js +31 -0
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer.js +69 -0
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.js +29 -0
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState.js +47 -0
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/epics/fetchCashManagementSettingsEpic.js +34 -0
- package/lib/esm/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js +32 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewPayload.js +54 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer.js +92 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.js +225 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState.js +10 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementBannerEpic.js +39 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementOverviewPageEpic.js +36 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementRecommendationEpic.js +27 -0
- package/lib/esm/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchRecentTransferEpic.js +28 -0
- package/lib/index.d.ts +12 -3
- package/lib/index.js +34 -14
- package/lib/reducer.d.ts +6 -0
- package/lib/reducer.js +6 -0
- package/lib/view/spendManagement/autotransferRules/autoTransferRulesSelector.d.ts +8 -1
- package/lib/view/spendManagement/autotransferRules/autoTransferRulesSelector.js +21 -1
- package/lib/view/spendManagement/autotransferRules/autoTransferRulesState.d.ts +22 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.d.ts +48 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowPayload.js +36 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer.d.ts +21 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer.js +73 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.d.ts +40 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowSelector.js +33 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState.d.ts +37 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState.js +53 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/fetchCashManagementSettingsEpic.d.ts +14 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/fetchCashManagementSettingsEpic.js +38 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.d.ts +7 -0
- package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js +36 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewPayload.d.ts +56 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewPayload.js +60 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer.d.ts +22 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer.js +96 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.d.ts +59 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewSelector.js +230 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState.d.ts +122 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState.js +13 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementBannerEpic.d.ts +23 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementBannerEpic.js +43 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementOverviewPageEpic.d.ts +9 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementOverviewPageEpic.js +40 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementRecommendationEpic.d.ts +7 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchCashManagementRecommendationEpic.js +31 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchRecentTransferEpic.d.ts +15 -0
- package/lib/view/spendManagement/cashManagement/cashManagementOverview/epics/fetchRecentTransferEpic.js +32 -0
- package/lib/zeniAPI.d.ts +1 -0
- package/package.json +1 -1
package/lib/reducer.d.ts
CHANGED
|
@@ -156,6 +156,8 @@ import { InternationalWireVerificationState } from './view/spendManagement/billP
|
|
|
156
156
|
import { MagicLinkViewState } from './view/spendManagement/billPay/magicLinkView/magicLinkViewState';
|
|
157
157
|
import { PreviousBillsState } from './view/spendManagement/billPay/previousBills/previousBillsState';
|
|
158
158
|
import { WiseRedirectState } from './view/spendManagement/billPay/wiseRedirectView/wiseRedirectState';
|
|
159
|
+
import { AutoSweepFlowState } from './view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowState';
|
|
160
|
+
import { CashManagementOverviewState } from './view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewState';
|
|
159
161
|
import { CardUserOnboardingState } from './view/spendManagement/chargeCards/cardUserOnboarding/cardUserOnboardingState';
|
|
160
162
|
import { CashbackDetailState } from './view/spendManagement/chargeCards/cashbackDetail/cashbackDetailState';
|
|
161
163
|
import { ChargeCardConfigState } from './view/spendManagement/chargeCards/chargeCardConfig/chargeCardConfigState';
|
|
@@ -305,6 +307,7 @@ type ViewsState = {
|
|
|
305
307
|
arAgingState: ArAgingState;
|
|
306
308
|
auditReportViewState: AuditReportViewState;
|
|
307
309
|
authenticationViewState: AuthenticationViewState;
|
|
310
|
+
autoSweepFlowState: AutoSweepFlowState;
|
|
308
311
|
autotransferRulesState: AutoTransferRulesState;
|
|
309
312
|
balanceSheetState: BalanceSheetState;
|
|
310
313
|
bankAccountViewState: BankAccountViewState;
|
|
@@ -324,6 +327,7 @@ type ViewsState = {
|
|
|
324
327
|
cashBalanceState: CashBalanceState;
|
|
325
328
|
cashFlowState: CashFlowState;
|
|
326
329
|
cashInCashOutState: CashInCashOutState;
|
|
330
|
+
cashManagementOverviewState: CashManagementOverviewState;
|
|
327
331
|
cashPositionState: CashPositionState;
|
|
328
332
|
chargeCardConfigState: ChargeCardConfigState;
|
|
329
333
|
chargeCardDetailState: ChargeCardDetailState;
|
|
@@ -468,6 +472,7 @@ declare const reducers: import("redux").Reducer<import("redux").CombinedState<{
|
|
|
468
472
|
arAgingState: ArAgingState;
|
|
469
473
|
auditReportViewState: AuditReportViewState;
|
|
470
474
|
authenticationViewState: AuthenticationViewState;
|
|
475
|
+
autoSweepFlowState: AutoSweepFlowState;
|
|
471
476
|
autotransferRulesState: AutoTransferRulesState;
|
|
472
477
|
balanceSheetState: BalanceSheetState;
|
|
473
478
|
bankAccountViewState: BankAccountViewState;
|
|
@@ -485,6 +490,7 @@ declare const reducers: import("redux").Reducer<import("redux").CombinedState<{
|
|
|
485
490
|
cashBalanceState: CashBalanceState;
|
|
486
491
|
cashFlowState: CashFlowState;
|
|
487
492
|
cashInCashOutState: CashInCashOutState;
|
|
493
|
+
cashManagementOverviewState: CashManagementOverviewState;
|
|
488
494
|
cashPositionState: CashPositionState;
|
|
489
495
|
chargeCardConfigState: ChargeCardConfigState;
|
|
490
496
|
chargeCardDetailState: ChargeCardDetailState;
|
package/lib/reducer.js
CHANGED
|
@@ -197,6 +197,8 @@ const internationalWireVerificationReducer_1 = __importStar(require("./view/spen
|
|
|
197
197
|
const magicLinkViewReducer_1 = __importStar(require("./view/spendManagement/billPay/magicLinkView/magicLinkViewReducer"));
|
|
198
198
|
const previousBillsReducer_1 = __importStar(require("./view/spendManagement/billPay/previousBills/previousBillsReducer"));
|
|
199
199
|
const wiseRedirectReducer_1 = __importStar(require("./view/spendManagement/billPay/wiseRedirectView/wiseRedirectReducer"));
|
|
200
|
+
const autoSweepFlowReducer_1 = __importStar(require("./view/spendManagement/cashManagement/autoSweepFlow/autoSweepFlowReducer"));
|
|
201
|
+
const cashManagementOverviewReducer_1 = __importStar(require("./view/spendManagement/cashManagement/cashManagementOverview/cashManagementOverviewReducer"));
|
|
200
202
|
const cardUserOnboardingReducer_1 = __importStar(require("./view/spendManagement/chargeCards/cardUserOnboarding/cardUserOnboardingReducer"));
|
|
201
203
|
const cashbackDetailReducer_1 = __importStar(require("./view/spendManagement/chargeCards/cashbackDetail/cashbackDetailReducer"));
|
|
202
204
|
const chargeCardConfigReducer_1 = __importStar(require("./view/spendManagement/chargeCards/chargeCardConfig/chargeCardConfigReducer"));
|
|
@@ -348,6 +350,7 @@ const initialViewsState = {
|
|
|
348
350
|
arAgingState: arAgingReducer_1.initialState,
|
|
349
351
|
auditReportViewState: auditReportViewReducer_1.initialState,
|
|
350
352
|
authenticationViewState: authenticationViewReducer_1.initialState,
|
|
353
|
+
autoSweepFlowState: autoSweepFlowReducer_1.initialState,
|
|
351
354
|
autotransferRulesState: autoTransferRulesReducer_1.initialState,
|
|
352
355
|
balanceSheetState: balanceSheetReducer_1.initialState,
|
|
353
356
|
bankAccountViewState: bankAccountViewReducer_1.initialState,
|
|
@@ -366,6 +369,7 @@ const initialViewsState = {
|
|
|
366
369
|
cashBalanceState: cashBalanceReducer_1.initialState,
|
|
367
370
|
cashFlowState: cashFlowReducer_1.initialState,
|
|
368
371
|
cashInCashOutState: cashInCashOutReducer_1.initialState,
|
|
372
|
+
cashManagementOverviewState: cashManagementOverviewReducer_1.initialState,
|
|
369
373
|
cashPositionState: cashPositionReducer_1.initialState,
|
|
370
374
|
chargeCardConfigState: chargeCardConfigReducer_1.initialState,
|
|
371
375
|
chargeCardDetailState: chargeCardDetailReducer_1.initialState,
|
|
@@ -585,6 +589,7 @@ const viewReducers = {
|
|
|
585
589
|
arAgingState: arAgingReducer_1.default,
|
|
586
590
|
auditReportViewState: auditReportViewReducer_1.default,
|
|
587
591
|
authenticationViewState: authenticationViewReducer_1.default,
|
|
592
|
+
autoSweepFlowState: autoSweepFlowReducer_1.default,
|
|
588
593
|
autotransferRulesState: autoTransferRulesReducer_1.default,
|
|
589
594
|
balanceSheetState: balanceSheetReducer_1.default,
|
|
590
595
|
bankAccountViewState: bankAccountViewReducer_1.default,
|
|
@@ -602,6 +607,7 @@ const viewReducers = {
|
|
|
602
607
|
cashBalanceState: cashBalanceReducer_1.default,
|
|
603
608
|
cashFlowState: cashFlowReducer_1.default,
|
|
604
609
|
cashInCashOutState: cashInCashOutReducer_1.default,
|
|
610
|
+
cashManagementOverviewState: cashManagementOverviewReducer_1.default,
|
|
605
611
|
cashPositionState: cashPositionReducer_1.default,
|
|
606
612
|
chargeCardConfigState: chargeCardConfigReducer_1.default,
|
|
607
613
|
chargeCardDetailState: chargeCardDetailReducer_1.default,
|
|
@@ -6,7 +6,7 @@ import { FundingAccount } from '../commonSetup/setupViewSelector';
|
|
|
6
6
|
import { TreasuryAccount } from '../treasury/treasuryTransferMoney/treasuryTransferMoneyState';
|
|
7
7
|
import { ReviewTransferDetail } from '../zeniAccounts/transferDetail/transferDetailState';
|
|
8
8
|
import { AutoTransferRuleLocalData } from './autoTransferRulesPayload';
|
|
9
|
-
import { AutoTransferRule } from './autoTransferRulesState';
|
|
9
|
+
import { AutoTransferRule, CashManagementRule } from './autoTransferRulesState';
|
|
10
10
|
export interface AutoTransferRulesSelectorView extends SelectorView {
|
|
11
11
|
autoTransferReviewDetail: ReviewTransferDetail;
|
|
12
12
|
createRuleFetchState: FetchStateAndError;
|
|
@@ -17,6 +17,13 @@ export interface AutoTransferRulesSelectorView extends SelectorView {
|
|
|
17
17
|
transferMoneyParties: FundingAccount[];
|
|
18
18
|
transferMoneyPartiesFetchState: FetchState;
|
|
19
19
|
treasuryAccount: TreasuryAccount;
|
|
20
|
+
/**
|
|
21
|
+
* The user's saved auto-sweep cash-management config, surfaced here so the
|
|
22
|
+
* rules list page can render it alongside the auto-transfer rules.
|
|
23
|
+
* `undefined` when the user hasn't saved auto-sweep settings yet
|
|
24
|
+
* (i.e. `autoSweepFlowState.settingsId == null`).
|
|
25
|
+
*/
|
|
26
|
+
cashManagementRule?: CashManagementRule;
|
|
20
27
|
ruleHistory?: Record<string, CommonHistoryView>;
|
|
21
28
|
}
|
|
22
29
|
export declare const getAutoTransferRules: (state: RootState) => AutoTransferRulesSelectorView;
|
|
@@ -6,11 +6,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getAutoTransferRuleHistory = exports.getAutoTransferRuleById = exports.getAutoTransferRules = void 0;
|
|
7
7
|
const get_1 = __importDefault(require("lodash/get"));
|
|
8
8
|
const reduceFetchState_1 = require("../../../commonStateTypes/reduceFetchState");
|
|
9
|
+
const depositAccountSelector_1 = require("../../../entity/depositAccount/depositAccountSelector");
|
|
9
10
|
const setupViewSelector_1 = require("../commonSetup/setupViewSelector");
|
|
10
11
|
const depositAccountListSelector_1 = require("../zeniAccounts/depositAccountList/depositAccountListSelector");
|
|
11
12
|
const paymentAccountListSelector_1 = require("../zeniAccounts/paymentAccountList/paymentAccountListSelector");
|
|
13
|
+
const buildCashManagementRule = (autoSweepFlowState, depositAccountState, treasuryDetailState) => {
|
|
14
|
+
const { settingsId, bufferAmount, frequency, memo, primaryFundingAccountId, nextTransferDate } = autoSweepFlowState;
|
|
15
|
+
if (settingsId == null || primaryFundingAccountId == null) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const depositAccount = (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(depositAccountState, primaryFundingAccountId);
|
|
19
|
+
return {
|
|
20
|
+
bufferAmount,
|
|
21
|
+
frequency,
|
|
22
|
+
memo,
|
|
23
|
+
settingsId,
|
|
24
|
+
primaryFundingAccount: depositAccount != null
|
|
25
|
+
? (0, setupViewSelector_1.mapDepositAccToFundingAccount)(depositAccount)
|
|
26
|
+
: undefined,
|
|
27
|
+
treasurySummary: treasuryDetailState.accountSummary,
|
|
28
|
+
nextTransferDate,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
12
31
|
const getAutoTransferRules = (state) => {
|
|
13
|
-
const { autotransferRulesState, depositAccountState, paymentAccountState, depositAccountListState, paymentAccountListState, treasuryDetailState, } = state;
|
|
32
|
+
const { autotransferRulesState, autoSweepFlowState, depositAccountState, paymentAccountState, depositAccountListState, paymentAccountListState, treasuryDetailState, } = state;
|
|
14
33
|
const { rules, error, historyByRuleId, ruleUpdateLocalData, ruleUpdateStatusById, ruleDeleteStatusById, createRuleFetchState, autoTransferReviewDetail, } = autotransferRulesState;
|
|
15
34
|
const depositAccountsView = (0, depositAccountListSelector_1.getAllDepositAccounts)(depositAccountState, depositAccountListState);
|
|
16
35
|
const paymentAccountsView = (0, paymentAccountListSelector_1.getAllPaymentAccounts)(paymentAccountState, paymentAccountListState);
|
|
@@ -45,6 +64,7 @@ const getAutoTransferRules = (state) => {
|
|
|
45
64
|
transferMoneyParties,
|
|
46
65
|
transferMoneyPartiesFetchState,
|
|
47
66
|
createRuleFetchState,
|
|
67
|
+
cashManagementRule: buildCashManagementRule(autoSweepFlowState, depositAccountState, treasuryDetailState),
|
|
48
68
|
fetchState,
|
|
49
69
|
error,
|
|
50
70
|
version: 0,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { Amount } from '../../../commonStateTypes/amount';
|
|
1
2
|
import { FetchStateAndError, FetchedState, ID } from '../../../commonStateTypes/common';
|
|
2
3
|
import { ZeniDate } from '../../../zeniDayJS';
|
|
4
|
+
import { AutoSweepFrequency } from '../cashManagement/autoSweepFlow/autoSweepFlowState';
|
|
5
|
+
import { FundingAccount } from '../commonSetup/setupViewSelector';
|
|
3
6
|
import { CommonHistoryView } from '../commonHistoryView/commonHistory';
|
|
7
|
+
import { TreasurySummaryWithBalance } from '../treasury/treasuryList/treasuryDetailState';
|
|
4
8
|
import { ReviewTransferDetail } from '../zeniAccounts/transferDetail/transferDetailState';
|
|
5
9
|
import { AutoTransferRuleFrequency, AutoTransferRuleLocalData, AutoTransferRuleType } from './autoTransferRulesPayload';
|
|
6
10
|
export interface AutoTransferRule {
|
|
@@ -27,6 +31,24 @@ export interface DestinationBankAccountMetadata {
|
|
|
27
31
|
accountType: string;
|
|
28
32
|
percentage: number;
|
|
29
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Render-ready view of the user's auto-sweep cash-management config,
|
|
36
|
+
* surfaced alongside `AutoTransferRule[]` in `AutoTransferRulesSelectorView`.
|
|
37
|
+
* Kept as a distinct shape (not folded into `AutoTransferRule`) so the rules
|
|
38
|
+
* list can special-case its rendering without polluting the rule type union.
|
|
39
|
+
*
|
|
40
|
+
* Present only when `autoSweepFlowState.settingsId` is set — i.e. the user
|
|
41
|
+
* has saved their auto-sweep settings at least once.
|
|
42
|
+
*/
|
|
43
|
+
export interface CashManagementRule {
|
|
44
|
+
bufferAmount: Amount;
|
|
45
|
+
frequency: AutoSweepFrequency;
|
|
46
|
+
memo: string;
|
|
47
|
+
settingsId: ID;
|
|
48
|
+
nextTransferDate?: ZeniDate;
|
|
49
|
+
primaryFundingAccount?: FundingAccount;
|
|
50
|
+
treasurySummary?: TreasurySummaryWithBalance;
|
|
51
|
+
}
|
|
30
52
|
export interface AutoTransferRulesState extends FetchedState {
|
|
31
53
|
autoTransferReviewDetail: ReviewTransferDetail;
|
|
32
54
|
createRuleFetchState: FetchStateAndError;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Amount } from '../../../../commonStateTypes/amount';
|
|
2
|
+
import { ID } from '../../../../commonStateTypes/common';
|
|
3
|
+
import { DepositAccountPayload } from '../../../../entity/depositAccount/depositAccountPayload';
|
|
4
|
+
import { ZeniAPIResponse } from '../../../../responsePayload';
|
|
5
|
+
import { ZeniDate } from '../../../../zeniDayJS';
|
|
6
|
+
import { AutoSweepFlowState, AutoSweepFrequency } from './autoSweepFlowState';
|
|
7
|
+
/**
|
|
8
|
+
* Body sent to `PUT /cash-management/settings`. Field names match the
|
|
9
|
+
* cash-management-agent contract; `minimum_buffer_usd` is a plain number
|
|
10
|
+
* (the slice tracks the canonical `Amount` value).
|
|
11
|
+
*/
|
|
12
|
+
export type SaveAutoSweepSettingsBody = {
|
|
13
|
+
first_run_date: string;
|
|
14
|
+
frequency: string;
|
|
15
|
+
memo: string;
|
|
16
|
+
minimum_buffer_usd: number;
|
|
17
|
+
};
|
|
18
|
+
export type SaveAutoSweepSettingsResponse = ZeniAPIResponse<unknown>;
|
|
19
|
+
export declare const toSaveAutoSweepSettingsBody: (state: Pick<AutoSweepFlowState, "bufferAmount" | "frequency" | "memo">) => SaveAutoSweepSettingsBody;
|
|
20
|
+
/**
|
|
21
|
+
* `source_bank_account` on the cash-management settings response matches the
|
|
22
|
+
* shared `DepositAccountPayload` shape, so the fetch epic dispatches it into
|
|
23
|
+
* the deposit-account entity bucket and the auto-sweep slice only keeps the
|
|
24
|
+
* id. The selector hydrates the full `FundingAccount` on read.
|
|
25
|
+
*/
|
|
26
|
+
export interface CashManagementSettingsPayload {
|
|
27
|
+
cash_management_settings_id: string | null;
|
|
28
|
+
frequency: string;
|
|
29
|
+
minimum_buffer_usd: number;
|
|
30
|
+
next_transfer_date: string;
|
|
31
|
+
source_bank_account: DepositAccountPayload;
|
|
32
|
+
}
|
|
33
|
+
export type CashManagementSettingsResponse = ZeniAPIResponse<CashManagementSettingsPayload>;
|
|
34
|
+
/**
|
|
35
|
+
* Map a `GET /cash-management/settings` payload into the slice's writable
|
|
36
|
+
* fields. Defensive on the frequency (string-from-the-wire → union via
|
|
37
|
+
* `toAutoSweepFrequency`, falling back to `'weekly'` if the server returns
|
|
38
|
+
* something we don't model yet). Only the source account *id* is stored
|
|
39
|
+
* here — the full deposit-account payload is published to the entity bucket
|
|
40
|
+
* by the fetch epic.
|
|
41
|
+
*/
|
|
42
|
+
export declare const toAutoSweepFlowStatePatch: (payload: CashManagementSettingsPayload) => {
|
|
43
|
+
bufferAmount: Amount;
|
|
44
|
+
frequency: AutoSweepFrequency;
|
|
45
|
+
nextTransferDate?: ZeniDate;
|
|
46
|
+
primaryFundingAccountId?: ID;
|
|
47
|
+
settingsId?: ID;
|
|
48
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toAutoSweepFlowStatePatch = exports.toSaveAutoSweepSettingsBody = void 0;
|
|
4
|
+
const amount_1 = require("../../../../commonStateTypes/amount");
|
|
5
|
+
const workingDayHelper_1 = require("../../../../commonStateTypes/workingDayHelper");
|
|
6
|
+
const zeniDayJS_1 = require("../../../../zeniDayJS");
|
|
7
|
+
const autoSweepFlowState_1 = require("./autoSweepFlowState");
|
|
8
|
+
const toSaveAutoSweepSettingsBody = (state) => ({
|
|
9
|
+
first_run_date: (0, workingDayHelper_1.getNextTransferDate)(state.frequency).format('YYYY-MM-DD'),
|
|
10
|
+
frequency: state.frequency,
|
|
11
|
+
memo: state.memo,
|
|
12
|
+
minimum_buffer_usd: state.bufferAmount.amount,
|
|
13
|
+
});
|
|
14
|
+
exports.toSaveAutoSweepSettingsBody = toSaveAutoSweepSettingsBody;
|
|
15
|
+
/**
|
|
16
|
+
* Map a `GET /cash-management/settings` payload into the slice's writable
|
|
17
|
+
* fields. Defensive on the frequency (string-from-the-wire → union via
|
|
18
|
+
* `toAutoSweepFrequency`, falling back to `'weekly'` if the server returns
|
|
19
|
+
* something we don't model yet). Only the source account *id* is stored
|
|
20
|
+
* here — the full deposit-account payload is published to the entity bucket
|
|
21
|
+
* by the fetch epic.
|
|
22
|
+
*/
|
|
23
|
+
const toAutoSweepFlowStatePatch = (payload) => {
|
|
24
|
+
const currencyCode = payload.source_bank_account.balances?.currency_code;
|
|
25
|
+
const currencySymbol = payload.source_bank_account.balances?.currency_symbol;
|
|
26
|
+
return {
|
|
27
|
+
bufferAmount: (0, amount_1.toAmount)(payload.minimum_buffer_usd, currencyCode ?? 'USD', currencySymbol ?? '$'),
|
|
28
|
+
frequency: (0, autoSweepFlowState_1.toAutoSweepFrequency)(payload.frequency) ?? 'weekly',
|
|
29
|
+
nextTransferDate: payload.next_transfer_date != null && payload.next_transfer_date !== ''
|
|
30
|
+
? (0, zeniDayJS_1.date)(payload.next_transfer_date)
|
|
31
|
+
: undefined,
|
|
32
|
+
primaryFundingAccountId: payload.source_bank_account.deposit_account_id ?? undefined,
|
|
33
|
+
settingsId: payload.cash_management_settings_id ?? undefined,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.toAutoSweepFlowStatePatch = toAutoSweepFlowStatePatch;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Amount } from '../../../../commonStateTypes/amount';
|
|
2
|
+
import { FetchState } from '../../../../commonStateTypes/common';
|
|
3
|
+
import { ZeniAPIStatus } from '../../../../responsePayload';
|
|
4
|
+
import { CashManagementSettingsPayload } from './autoSweepFlowPayload';
|
|
5
|
+
import { AutoSweepFlowState, AutoSweepFrequency } from './autoSweepFlowState';
|
|
6
|
+
export declare const initialState: AutoSweepFlowState;
|
|
7
|
+
export declare const fetchCashManagementSettings: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"autoSweepFlow/fetchCashManagementSettings">, updateCashManagementSettings: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
8
|
+
data: CashManagementSettingsPayload;
|
|
9
|
+
}, "autoSweepFlow/updateCashManagementSettings">, updateCashManagementSettingsFetchStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
10
|
+
fetchState: FetchState;
|
|
11
|
+
error?: ZeniAPIStatus;
|
|
12
|
+
}, "autoSweepFlow/updateCashManagementSettingsFetchStatus">, updateAutoSweepDraft: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
13
|
+
bufferAmount: Amount;
|
|
14
|
+
frequency: AutoSweepFrequency;
|
|
15
|
+
memo: string;
|
|
16
|
+
}, "autoSweepFlow/updateAutoSweepDraft">, saveAutoSweepSettings: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"autoSweepFlow/saveAutoSweepSettings">, updateAutoSweepSettingsFetchStatus: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
17
|
+
fetchState: FetchState;
|
|
18
|
+
error?: ZeniAPIStatus;
|
|
19
|
+
}, "autoSweepFlow/updateAutoSweepSettingsFetchStatus">, clearAutoSweepFlow: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"autoSweepFlow/clearAutoSweepFlow">;
|
|
20
|
+
declare const _default: import("redux").Reducer<AutoSweepFlowState>;
|
|
21
|
+
export default _default;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.clearAutoSweepFlow = exports.updateAutoSweepSettingsFetchStatus = exports.saveAutoSweepSettings = exports.updateAutoSweepDraft = exports.updateCashManagementSettingsFetchStatus = exports.updateCashManagementSettings = exports.fetchCashManagementSettings = exports.initialState = void 0;
|
|
5
|
+
const toolkit_1 = require("@reduxjs/toolkit");
|
|
6
|
+
const autoSweepFlowPayload_1 = require("./autoSweepFlowPayload");
|
|
7
|
+
const autoSweepFlowState_1 = require("./autoSweepFlowState");
|
|
8
|
+
exports.initialState = autoSweepFlowState_1.initialAutoSweepFlowState;
|
|
9
|
+
const autoSweepFlow = (0, toolkit_1.createSlice)({
|
|
10
|
+
name: 'autoSweepFlow',
|
|
11
|
+
initialState: exports.initialState,
|
|
12
|
+
reducers: {
|
|
13
|
+
/**
|
|
14
|
+
* Kicks off `GET /cash-management/settings`. Flips the top-level
|
|
15
|
+
* fetchState to `In-Progress`; the fetch epic picks this up.
|
|
16
|
+
*/
|
|
17
|
+
fetchCashManagementSettings(draft) {
|
|
18
|
+
draft.fetchState = 'In-Progress';
|
|
19
|
+
draft.error = undefined;
|
|
20
|
+
},
|
|
21
|
+
/**
|
|
22
|
+
* Hydrates the form fields with the server-side settings (and stashes
|
|
23
|
+
* the settings id for subsequent saves). Marks the GET as `Completed`.
|
|
24
|
+
*/
|
|
25
|
+
updateCashManagementSettings(draft, action) {
|
|
26
|
+
const patch = (0, autoSweepFlowPayload_1.toAutoSweepFlowStatePatch)(action.payload.data);
|
|
27
|
+
draft.bufferAmount = patch.bufferAmount;
|
|
28
|
+
draft.frequency = patch.frequency;
|
|
29
|
+
draft.nextTransferDate = patch.nextTransferDate;
|
|
30
|
+
draft.primaryFundingAccountId = patch.primaryFundingAccountId;
|
|
31
|
+
draft.settingsId = patch.settingsId;
|
|
32
|
+
draft.fetchState = 'Completed';
|
|
33
|
+
draft.error = undefined;
|
|
34
|
+
},
|
|
35
|
+
updateCashManagementSettingsFetchStatus(draft, action) {
|
|
36
|
+
draft.fetchState = action.payload.fetchState;
|
|
37
|
+
draft.error = action.payload.error;
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Stage the in-flight form values without submitting them — fired from
|
|
41
|
+
* the setup→review transition so other selectors (and devtools) can see
|
|
42
|
+
* what the user is about to confirm. Leaves `saveStatus` untouched; the
|
|
43
|
+
* actual PUT only kicks off when the user clicks "Confirm Sweep" via
|
|
44
|
+
* `saveAutoSweepSettings`.
|
|
45
|
+
*/
|
|
46
|
+
updateAutoSweepDraft(draft, action) {
|
|
47
|
+
draft.bufferAmount = action.payload.bufferAmount;
|
|
48
|
+
draft.frequency = action.payload.frequency;
|
|
49
|
+
draft.memo = action.payload.memo;
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* Trigger the PUT for the auto-sweep settings already staged via
|
|
53
|
+
* `updateAutoSweepDraft`. Carries no payload — flips `saveStatus` to
|
|
54
|
+
* `In-Progress` and the save epic reads `bufferAmount` / `frequency` /
|
|
55
|
+
* `memo` straight from the slice. Callers must ensure those fields
|
|
56
|
+
* reflect the user's latest input before dispatching.
|
|
57
|
+
*/
|
|
58
|
+
saveAutoSweepSettings(draft) {
|
|
59
|
+
draft.saveStatus = { fetchState: 'In-Progress', error: undefined };
|
|
60
|
+
},
|
|
61
|
+
updateAutoSweepSettingsFetchStatus(draft, action) {
|
|
62
|
+
draft.saveStatus = {
|
|
63
|
+
fetchState: action.payload.fetchState,
|
|
64
|
+
error: action.payload.error,
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
clearAutoSweepFlow() {
|
|
68
|
+
return autoSweepFlowState_1.initialAutoSweepFlowState;
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
_a = autoSweepFlow.actions, exports.fetchCashManagementSettings = _a.fetchCashManagementSettings, exports.updateCashManagementSettings = _a.updateCashManagementSettings, exports.updateCashManagementSettingsFetchStatus = _a.updateCashManagementSettingsFetchStatus, exports.updateAutoSweepDraft = _a.updateAutoSweepDraft, exports.saveAutoSweepSettings = _a.saveAutoSweepSettings, exports.updateAutoSweepSettingsFetchStatus = _a.updateAutoSweepSettingsFetchStatus, exports.clearAutoSweepFlow = _a.clearAutoSweepFlow;
|
|
73
|
+
exports.default = autoSweepFlow.reducer;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Amount } from '../../../../commonStateTypes/amount';
|
|
2
|
+
import { FetchStateAndError, ID } from '../../../../commonStateTypes/common';
|
|
3
|
+
import { SelectorView } from '../../../../commonStateTypes/viewAndReport/viewAndReport';
|
|
4
|
+
import { RootState } from '../../../../reducer';
|
|
5
|
+
import { FundingAccount } from '../../commonSetup/setupViewSelector';
|
|
6
|
+
import { TreasurySummaryWithBalance } from '../../treasury/treasuryList/treasuryDetailState';
|
|
7
|
+
import { AutoSweepFrequency, RiskLevel } from './autoSweepFlowState';
|
|
8
|
+
/**
|
|
9
|
+
* The editable form state behind `<AutoSweepSetupPage>`. Kept as a nested
|
|
10
|
+
* object on the selector view so the screen can pass it through as a single
|
|
11
|
+
* unit and the rest of the view (server-derived data + statuses) stays
|
|
12
|
+
* separate from "what the user is currently editing".
|
|
13
|
+
*/
|
|
14
|
+
export interface AutoSweepFlowFormData {
|
|
15
|
+
bufferAmount: Amount;
|
|
16
|
+
frequency: AutoSweepFrequency;
|
|
17
|
+
memo: string;
|
|
18
|
+
/** Derived from `bufferAmount` — the matching preset risk level, falling
|
|
19
|
+
* back to `'moderate'` for custom server-side values. */
|
|
20
|
+
risk: RiskLevel;
|
|
21
|
+
}
|
|
22
|
+
export interface AutoSweepFlowSelectorView extends SelectorView {
|
|
23
|
+
formData: AutoSweepFlowFormData;
|
|
24
|
+
saveStatus: FetchStateAndError;
|
|
25
|
+
/**
|
|
26
|
+
* Recommended sweep amount. Sourced from the cash management banner
|
|
27
|
+
* (the first money_movements[0].movements[0].amount returned by the
|
|
28
|
+
* agent's `/recommend` endpoint). Defaults to zero when the agent
|
|
29
|
+
* hasn't returned a movement yet.
|
|
30
|
+
*/
|
|
31
|
+
sweepAmount: Amount;
|
|
32
|
+
/** Resolved from `primaryFundingAccountId` against the deposit-account
|
|
33
|
+
* entity bucket. `undefined` until the GET fetch publishes the account. */
|
|
34
|
+
primaryFundingAccount?: FundingAccount;
|
|
35
|
+
settingsId?: ID;
|
|
36
|
+
/** Treasury account summary used by the setup / review flow to render the
|
|
37
|
+
* destination column. Mirrors `getTreasuryDetail().accountSummary`. */
|
|
38
|
+
treasurySummary?: TreasurySummaryWithBalance;
|
|
39
|
+
}
|
|
40
|
+
export declare const getAutoSweepFlow: (state: RootState) => AutoSweepFlowSelectorView;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAutoSweepFlow = void 0;
|
|
4
|
+
const depositAccountSelector_1 = require("../../../../entity/depositAccount/depositAccountSelector");
|
|
5
|
+
const setupViewSelector_1 = require("../../commonSetup/setupViewSelector");
|
|
6
|
+
const treasuryDetailSelector_1 = require("../../treasury/treasuryList/treasuryDetailSelector");
|
|
7
|
+
const cashManagementOverviewSelector_1 = require("../cashManagementOverview/cashManagementOverviewSelector");
|
|
8
|
+
const autoSweepFlowState_1 = require("./autoSweepFlowState");
|
|
9
|
+
const getAutoSweepFlow = (state) => {
|
|
10
|
+
const { bufferAmount, frequency, memo, saveStatus, settingsId, primaryFundingAccountId, fetchState, error, } = state.autoSweepFlowState;
|
|
11
|
+
const depositAccount = primaryFundingAccountId != null
|
|
12
|
+
? (0, depositAccountSelector_1.getDepositAccountByDepositAccountId)(state.depositAccountState, primaryFundingAccountId)
|
|
13
|
+
: undefined;
|
|
14
|
+
return {
|
|
15
|
+
fetchState,
|
|
16
|
+
error,
|
|
17
|
+
formData: {
|
|
18
|
+
bufferAmount,
|
|
19
|
+
frequency,
|
|
20
|
+
memo,
|
|
21
|
+
risk: (0, autoSweepFlowState_1.bufferAmountToRisk)(bufferAmount.amount),
|
|
22
|
+
},
|
|
23
|
+
primaryFundingAccount: depositAccount != null
|
|
24
|
+
? (0, setupViewSelector_1.mapDepositAccToFundingAccount)(depositAccount)
|
|
25
|
+
: undefined,
|
|
26
|
+
saveStatus,
|
|
27
|
+
settingsId,
|
|
28
|
+
sweepAmount: (0, cashManagementOverviewSelector_1.getCashManagementOverviewBanner)(state).amount,
|
|
29
|
+
treasurySummary: (0, treasuryDetailSelector_1.getTreasuryDetail)(state).accountSummary,
|
|
30
|
+
version: 0,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.getAutoSweepFlow = getAutoSweepFlow;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Amount } from '../../../../commonStateTypes/amount';
|
|
2
|
+
import { FetchStateAndError, ID } from '../../../../commonStateTypes/common';
|
|
3
|
+
import { ZeniDate } from '../../../../zeniDayJS';
|
|
4
|
+
/**
|
|
5
|
+
* Cadence at which the auto-sweep transfer fires. Lowercase to match the
|
|
6
|
+
* cash-management settings API contract (and the `SweepFrequency` literal
|
|
7
|
+
* already used by `<AutoSweepSetupPage>` in web-components).
|
|
8
|
+
*/
|
|
9
|
+
export declare const ALL_AUTO_SWEEP_FREQUENCIES: readonly ["daily", "weekly", "biweekly", "monthly"];
|
|
10
|
+
export declare const toAutoSweepFrequency: (v?: string) => "weekly" | "biweekly" | "monthly" | "daily";
|
|
11
|
+
export type AutoSweepFrequency = NonNullable<ReturnType<typeof toAutoSweepFrequency>>;
|
|
12
|
+
/**
|
|
13
|
+
* Risk presets the auto-sweep setup form exposes. Each level maps to a
|
|
14
|
+
* canonical minimum-buffer amount (USD). Selecting a level in the UI is
|
|
15
|
+
* shorthand for choosing that buffer.
|
|
16
|
+
*/
|
|
17
|
+
export declare const ALL_AUTO_SWEEP_RISK_LEVELS: readonly ["low", "moderate", "high"];
|
|
18
|
+
export declare const toAutoSweepRiskLevel: (v?: string) => "high" | "low" | "moderate";
|
|
19
|
+
export type RiskLevel = NonNullable<ReturnType<typeof toAutoSweepRiskLevel>>;
|
|
20
|
+
export declare const RISK_BUFFER_AMOUNT: Record<RiskLevel, number>;
|
|
21
|
+
/**
|
|
22
|
+
* Maps a buffer amount back onto the closest preset risk level. Falls back
|
|
23
|
+
* to `'moderate'` when the amount doesn't match a known preset (e.g. the
|
|
24
|
+
* server returned a custom value). The dropdown in `<AutoSweepSetupPage>`
|
|
25
|
+
* uses this so it can pre-select the user's existing band on edit.
|
|
26
|
+
*/
|
|
27
|
+
export declare const bufferAmountToRisk: (amount: number) => RiskLevel;
|
|
28
|
+
export interface AutoSweepFlowState extends FetchStateAndError {
|
|
29
|
+
bufferAmount: Amount;
|
|
30
|
+
frequency: AutoSweepFrequency;
|
|
31
|
+
memo: string;
|
|
32
|
+
saveStatus: FetchStateAndError;
|
|
33
|
+
nextTransferDate?: ZeniDate;
|
|
34
|
+
primaryFundingAccountId?: ID;
|
|
35
|
+
settingsId?: ID;
|
|
36
|
+
}
|
|
37
|
+
export declare const initialAutoSweepFlowState: AutoSweepFlowState;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initialAutoSweepFlowState = exports.bufferAmountToRisk = exports.RISK_BUFFER_AMOUNT = exports.toAutoSweepRiskLevel = exports.ALL_AUTO_SWEEP_RISK_LEVELS = exports.toAutoSweepFrequency = exports.ALL_AUTO_SWEEP_FREQUENCIES = void 0;
|
|
4
|
+
const amount_1 = require("../../../../commonStateTypes/amount");
|
|
5
|
+
const stringToUnion_1 = require("../../../../commonStateTypes/stringToUnion");
|
|
6
|
+
/**
|
|
7
|
+
* Cadence at which the auto-sweep transfer fires. Lowercase to match the
|
|
8
|
+
* cash-management settings API contract (and the `SweepFrequency` literal
|
|
9
|
+
* already used by `<AutoSweepSetupPage>` in web-components).
|
|
10
|
+
*/
|
|
11
|
+
exports.ALL_AUTO_SWEEP_FREQUENCIES = [
|
|
12
|
+
'daily',
|
|
13
|
+
'weekly',
|
|
14
|
+
'biweekly',
|
|
15
|
+
'monthly',
|
|
16
|
+
];
|
|
17
|
+
const toAutoSweepFrequency = (v) => (0, stringToUnion_1.stringToUnion)(v ?? '', exports.ALL_AUTO_SWEEP_FREQUENCIES);
|
|
18
|
+
exports.toAutoSweepFrequency = toAutoSweepFrequency;
|
|
19
|
+
/**
|
|
20
|
+
* Risk presets the auto-sweep setup form exposes. Each level maps to a
|
|
21
|
+
* canonical minimum-buffer amount (USD). Selecting a level in the UI is
|
|
22
|
+
* shorthand for choosing that buffer.
|
|
23
|
+
*/
|
|
24
|
+
exports.ALL_AUTO_SWEEP_RISK_LEVELS = ['low', 'moderate', 'high'];
|
|
25
|
+
const toAutoSweepRiskLevel = (v) => (0, stringToUnion_1.stringToUnion)(v ?? '', exports.ALL_AUTO_SWEEP_RISK_LEVELS);
|
|
26
|
+
exports.toAutoSweepRiskLevel = toAutoSweepRiskLevel;
|
|
27
|
+
exports.RISK_BUFFER_AMOUNT = {
|
|
28
|
+
low: 15000,
|
|
29
|
+
moderate: 10000,
|
|
30
|
+
high: 5000,
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Maps a buffer amount back onto the closest preset risk level. Falls back
|
|
34
|
+
* to `'moderate'` when the amount doesn't match a known preset (e.g. the
|
|
35
|
+
* server returned a custom value). The dropdown in `<AutoSweepSetupPage>`
|
|
36
|
+
* uses this so it can pre-select the user's existing band on edit.
|
|
37
|
+
*/
|
|
38
|
+
const bufferAmountToRisk = (amount) => {
|
|
39
|
+
const match = Object.entries(exports.RISK_BUFFER_AMOUNT).find(([, presetAmount]) => presetAmount === amount);
|
|
40
|
+
return match != null ? match[0] : 'moderate';
|
|
41
|
+
};
|
|
42
|
+
exports.bufferAmountToRisk = bufferAmountToRisk;
|
|
43
|
+
exports.initialAutoSweepFlowState = {
|
|
44
|
+
bufferAmount: (0, amount_1.toAmount)(10000, 'USD', '$'),
|
|
45
|
+
frequency: 'weekly',
|
|
46
|
+
memo: '',
|
|
47
|
+
saveStatus: { fetchState: 'Not-Started', error: undefined },
|
|
48
|
+
nextTransferDate: undefined,
|
|
49
|
+
primaryFundingAccountId: undefined,
|
|
50
|
+
settingsId: undefined,
|
|
51
|
+
fetchState: 'Not-Started',
|
|
52
|
+
error: undefined,
|
|
53
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { updateDepositAccounts } from '../../../../../entity/depositAccount/depositAccountReducer';
|
|
4
|
+
import { RootState } from '../../../../../reducer';
|
|
5
|
+
import { ZeniAPI } from '../../../../../zeniAPI';
|
|
6
|
+
import { fetchCashManagementSettings, updateCashManagementSettings, updateCashManagementSettingsFetchStatus } from '../autoSweepFlowReducer';
|
|
7
|
+
export type ActionType = ReturnType<typeof fetchCashManagementSettings> | ReturnType<typeof updateCashManagementSettings> | ReturnType<typeof updateCashManagementSettingsFetchStatus> | ReturnType<typeof updateDepositAccounts>;
|
|
8
|
+
/**
|
|
9
|
+
* Hits `GET /cash-management/settings` and hydrates the auto-sweep slice
|
|
10
|
+
* with the server's existing settings (frequency, minimum buffer, settings
|
|
11
|
+
* id). Called from the cash management overview page-fetch epic alongside
|
|
12
|
+
* the other top-level fetches.
|
|
13
|
+
*/
|
|
14
|
+
export declare const fetchCashManagementSettingsEpic: (actions$: ActionsObservable<ActionType>, _state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchCashManagementSettingsEpic = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const depositAccountReducer_1 = require("../../../../../entity/depositAccount/depositAccountReducer");
|
|
7
|
+
const responsePayload_1 = require("../../../../../responsePayload");
|
|
8
|
+
const autoSweepFlowReducer_1 = require("../autoSweepFlowReducer");
|
|
9
|
+
/**
|
|
10
|
+
* Hits `GET /cash-management/settings` and hydrates the auto-sweep slice
|
|
11
|
+
* with the server's existing settings (frequency, minimum buffer, settings
|
|
12
|
+
* id). Called from the cash management overview page-fetch epic alongside
|
|
13
|
+
* the other top-level fetches.
|
|
14
|
+
*/
|
|
15
|
+
const fetchCashManagementSettingsEpic = (actions$, _state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(autoSweepFlowReducer_1.fetchCashManagementSettings.match), (0, operators_1.switchMap)(() => {
|
|
16
|
+
const endpoint = `${zeniAPI.apiEndPoints.cashManagementAgentBaseUrl}/1.0/cash-management/settings`;
|
|
17
|
+
return zeniAPI
|
|
18
|
+
.getJSON(endpoint)
|
|
19
|
+
.pipe((0, operators_1.mergeMap)((response) => {
|
|
20
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
21
|
+
return (0, rxjs_1.of)(
|
|
22
|
+
// Publish the source deposit account into the shared entity
|
|
23
|
+
// bucket so the selector can hydrate the full `FundingAccount`
|
|
24
|
+
// from `getDepositAccountByDepositAccountId` rather than the
|
|
25
|
+
// auto-sweep slice holding a duplicate copy.
|
|
26
|
+
(0, depositAccountReducer_1.updateDepositAccounts)([response.data.source_bank_account]), (0, autoSweepFlowReducer_1.updateCashManagementSettings)({ data: response.data }));
|
|
27
|
+
}
|
|
28
|
+
return (0, rxjs_1.of)((0, autoSweepFlowReducer_1.updateCashManagementSettingsFetchStatus)({
|
|
29
|
+
fetchState: 'Error',
|
|
30
|
+
error: response.status,
|
|
31
|
+
}));
|
|
32
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, autoSweepFlowReducer_1.updateCashManagementSettingsFetchStatus)({
|
|
33
|
+
fetchState: 'Error',
|
|
34
|
+
error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Fetch cash management settings REST API call errored out: ' +
|
|
35
|
+
(error?.message ?? String(error))),
|
|
36
|
+
}))));
|
|
37
|
+
}));
|
|
38
|
+
exports.fetchCashManagementSettingsEpic = fetchCashManagementSettingsEpic;
|
package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ActionsObservable, StateObservable } from 'redux-observable';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { RootState } from '../../../../../reducer';
|
|
4
|
+
import { ZeniAPI } from '../../../../../zeniAPI';
|
|
5
|
+
import { saveAutoSweepSettings, updateAutoSweepSettingsFetchStatus } from '../autoSweepFlowReducer';
|
|
6
|
+
export type ActionType = ReturnType<typeof saveAutoSweepSettings> | ReturnType<typeof updateAutoSweepSettingsFetchStatus>;
|
|
7
|
+
export declare const saveAutoSweepSettingsEpic: (actions$: ActionsObservable<ActionType>, state$: StateObservable<RootState>, zeniAPI: ZeniAPI) => Observable<ActionType>;
|
package/lib/view/spendManagement/cashManagement/autoSweepFlow/epics/saveAutoSweepSettingsEpic.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveAutoSweepSettingsEpic = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const responsePayload_1 = require("../../../../../responsePayload");
|
|
7
|
+
const autoSweepFlowPayload_1 = require("../autoSweepFlowPayload");
|
|
8
|
+
const autoSweepFlowReducer_1 = require("../autoSweepFlowReducer");
|
|
9
|
+
const saveAutoSweepSettingsEpic = (actions$, state$, zeniAPI) => actions$.pipe((0, operators_1.filter)(autoSweepFlowReducer_1.saveAutoSweepSettings.match), (0, operators_1.switchMap)(() => {
|
|
10
|
+
const endpoint = `${zeniAPI.apiEndPoints.cashManagementAgentBaseUrl}/1.0/cash-management/settings`;
|
|
11
|
+
const { bufferAmount, frequency, memo, settingsId } = state$.value.autoSweepFlowState;
|
|
12
|
+
const payload = (0, autoSweepFlowPayload_1.toSaveAutoSweepSettingsBody)({
|
|
13
|
+
bufferAmount,
|
|
14
|
+
frequency,
|
|
15
|
+
memo,
|
|
16
|
+
});
|
|
17
|
+
// First-time setup (no settings id from the GET yet) → POST a new
|
|
18
|
+
// record. Subsequent edits update the existing one via PUT.
|
|
19
|
+
const request$ = settingsId == null
|
|
20
|
+
? zeniAPI.postAndGetJSON(endpoint, payload)
|
|
21
|
+
: zeniAPI.putAndGetJSON(endpoint, payload);
|
|
22
|
+
return request$.pipe((0, operators_1.mergeMap)((response) => {
|
|
23
|
+
if ((0, responsePayload_1.isSuccessResponse)(response) && response.data != null) {
|
|
24
|
+
return (0, rxjs_1.of)((0, autoSweepFlowReducer_1.updateAutoSweepSettingsFetchStatus)({ fetchState: 'Completed' }));
|
|
25
|
+
}
|
|
26
|
+
return (0, rxjs_1.of)((0, autoSweepFlowReducer_1.updateAutoSweepSettingsFetchStatus)({
|
|
27
|
+
fetchState: 'Error',
|
|
28
|
+
error: response?.status,
|
|
29
|
+
}));
|
|
30
|
+
}), (0, operators_1.catchError)((error) => (0, rxjs_1.of)((0, autoSweepFlowReducer_1.updateAutoSweepSettingsFetchStatus)({
|
|
31
|
+
fetchState: 'Error',
|
|
32
|
+
error: (0, responsePayload_1.createZeniAPIStatus)('Unexpected Error', 'Save auto-sweep settings REST API call errored out: ' +
|
|
33
|
+
(error?.message ?? String(error))),
|
|
34
|
+
}))));
|
|
35
|
+
}));
|
|
36
|
+
exports.saveAutoSweepSettingsEpic = saveAutoSweepSettingsEpic;
|