@zeniai/client-epic-state 4.18.29 → 4.18.30

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/index.d.ts CHANGED
@@ -846,7 +846,7 @@ export { AiCfoSelectorView, getAllQuestionAnswersForChatSession, getQuestionAnsw
846
846
  export { AiCfoQuestionWithAnswer, AiCfoAnswerParagraph, AiCfoAnswerStateType, AiCfoChartType, AiCfoAnswerResponseType, TableVisualization, ChartVisualization, AiCfoVisualization, AiCfoVisualizationType, AiCfoState, ChatSession, ALL_AI_CFO_CHARTS_TYPES, ALL_AI_CFO_VISUALIZATION_TYPES, ALL_AI_CFO_ANSWER_STATE_TYPES, ALL_AI_CFO_ANSWER_RESPONSE_TYPES, toAiCfoVisualizationType, toAiCfoVisualizationTypeStrict, toAiCfoChartType, toAiCfoChartTypeStrict, toAiCfoAnswerStateType, toAiCfoAnswerStateTypeStrict, toAiCfoAnswerResponseType, toAiCfoAnswerResponseTypeStrict, ChatSessionWithMessages, ResponseBlockBase, AnswerContentBlockBase, QuestionContentBlockBase, ResponseBlockType, toMessageSender, toMessageType, MessageSender, MessageType, } from './entity/aiCfo/aiCfoState';
847
847
  export { fetchTreasuryOverviewDetail, updateTreasuryTransactionListUIState, } from './view/spendManagement/treasury/treasuryList/treasuryDetailReducer';
848
848
  export { TreasuryDetailSelectorView, getTreasuryDetail, } from './view/spendManagement/treasury/treasuryList/treasuryDetailSelector';
849
- export { TreasuryListUIState, TreasuryViewSortKey, TreasuryTransaction, } from './view/spendManagement/treasury/treasuryList/treasuryDetailState';
849
+ export { TreasuryListUIState, TreasuryViewSortKey, TreasuryTransaction, FundAllocation, } from './view/spendManagement/treasury/treasuryList/treasuryDetailState';
850
850
  export { executeTreasuryTransferMoney, updateTreasuryTransferMoneyLocalData, clearTreasuryTransferMoney, } from './view/spendManagement/treasury/treasuryTransferMoney/treasuryTransferMoneyReducer';
851
851
  export { TreasuryTransferMoneySelectorView, getTreasuryTransferMoney, } from './view/spendManagement/treasury/treasuryTransferMoney/treasuryTransferMoneySelector';
852
852
  export { TreasuryTransferMoneyLocalData, TreasuryTransferMoneyState, TreasuryAccount, } from './view/spendManagement/treasury/treasuryTransferMoney/treasuryTransferMoneyState';
@@ -1,27 +1,19 @@
1
1
  import { ZeniAPIResponse } from '../../../../responsePayload';
2
2
  import { AccountHistoryWithBalance } from './treasuryDetailState';
3
+ interface AmountPayload {
4
+ amount: number;
5
+ currency_code: string;
6
+ currency_symbol: string;
7
+ }
3
8
  interface TreasuryDetailPayload {
4
9
  treasury_account: {
5
- available_balance: {
6
- amount: number;
7
- currency_code: string;
8
- currency_symbol: string;
9
- };
10
- insured_funds: {
11
- amount: number;
12
- currency_code: string;
13
- currency_symbol: string;
14
- };
15
- processing_transactions_balance: {
16
- amount: number;
17
- currency_code: string;
18
- currency_symbol: string;
19
- };
20
- total_yield: {
21
- amount: number;
22
- currency_code: string;
23
- currency_symbol: string;
10
+ available_balance: AmountPayload;
11
+ fund_code_to_portfolio_value: {
12
+ [fundCode: string]: AmountPayload;
24
13
  };
14
+ insured_funds: AmountPayload;
15
+ processing_transactions_balance: AmountPayload;
16
+ total_yield: AmountPayload;
25
17
  };
26
18
  }
27
19
  export type FetchTreasuryDetailResponse = ZeniAPIResponse<TreasuryDetailPayload>;
@@ -115,6 +115,11 @@ const treasuryDetail = (0, toolkit_1.createSlice)({
115
115
  fetchTreasurySummarySuccess(draft, action) {
116
116
  const { data } = action.payload;
117
117
  if (data === null || data === void 0 ? void 0 : data.data) {
118
+ let fundAllocations = undefined;
119
+ fundAllocations = Object.entries(data.data.treasury_account.fund_code_to_portfolio_value).map(([fundCode, amountPayload]) => ({
120
+ fundCode,
121
+ amount: (0, amount_1.toAmount)(amountPayload.amount, amountPayload.currency_code, amountPayload.currency_symbol),
122
+ }));
118
123
  const summary = {
119
124
  insuredFunds: (0, amount_1.toAmount)(data.data.treasury_account.insured_funds.amount, data.data.treasury_account.insured_funds.currency_code, data.data.treasury_account.insured_funds.currency_symbol),
120
125
  totalYield: (0, amount_1.toAmount)(data.data.treasury_account.total_yield.amount, data.data.treasury_account.total_yield.currency_code, data.data.treasury_account.total_yield.currency_symbol),
@@ -124,6 +129,7 @@ const treasuryDetail = (0, toolkit_1.createSlice)({
124
129
  .currency_symbol),
125
130
  totalBalance: (0, amount_1.toAmount)(data.data.treasury_account.available_balance.amount +
126
131
  data.data.treasury_account.processing_transactions_balance.amount, data.data.treasury_account.available_balance.currency_code, data.data.treasury_account.available_balance.currency_symbol),
132
+ fundAllocations,
127
133
  };
128
134
  draft.accountSummary = summary;
129
135
  draft.fetchState = 'Completed';
@@ -20,8 +20,13 @@ export interface TreasuryTransaction {
20
20
  id: ID;
21
21
  status: TreasuryTransactionStatus;
22
22
  }
23
+ export interface FundAllocation {
24
+ amount: Amount;
25
+ fundCode: string;
26
+ }
23
27
  export interface TreasurySummaryWithBalance {
24
28
  availableBalance: Amount;
29
+ fundAllocations: FundAllocation[];
25
30
  insuredFunds: Amount;
26
31
  processingBalance: Amount;
27
32
  totalBalance: Amount;
@@ -26,6 +26,7 @@ const getTreasuryTransferMoney = (state) => {
26
26
  label: 'Treasury',
27
27
  id: 'treasury',
28
28
  balance: (_a = treasuryDetailState.accountSummary) === null || _a === void 0 ? void 0 : _a.availableBalance,
29
+ fundAllocations: getValidFundAllocations(treasuryDetailState.accountSummary, treasurySetupViewState.treasuryFundsDetails.fundsDetails),
29
30
  };
30
31
  const allRequiredDataFetchState = (0, reduceFetchState_1.reduceAllFetchState)([
31
32
  depositAccountsView,
@@ -53,3 +54,19 @@ const getTreasuryTransferMoney = (state) => {
53
54
  };
54
55
  };
55
56
  exports.getTreasuryTransferMoney = getTreasuryTransferMoney;
57
+ const getValidFundAllocations = (summary, fundsDetails) => {
58
+ var _a, _b;
59
+ // there could be entries in the allocations that are not in the fundsDetails. eg - 'CASH_USD'. These need to be ignored.
60
+ const FUND_ALLOCATION_TOLERANCE = 5;
61
+ const validFundCodes = new Set((fundsDetails !== null && fundsDetails !== void 0 ? fundsDetails : []).map((fund) => fund.fundCode));
62
+ const allocations = (_a = summary === null || summary === void 0 ? void 0 : summary.fundAllocations) === null || _a === void 0 ? void 0 : _a.filter((allocation) => validFundCodes.has(allocation.fundCode));
63
+ const availableAmount = (_b = summary === null || summary === void 0 ? void 0 : summary.availableBalance) === null || _b === void 0 ? void 0 : _b.amount;
64
+ const total = allocations === null || allocations === void 0 ? void 0 : allocations.reduce((sum, allocation) => { var _a, _b; return sum + ((_b = (_a = allocation.amount) === null || _a === void 0 ? void 0 : _a.amount) !== null && _b !== void 0 ? _b : 0); }, 0);
65
+ if (availableAmount == null || total == null) {
66
+ return undefined;
67
+ }
68
+ // only show the allocations if the difference between available balance and total is less than $5
69
+ return Math.abs(availableAmount - total) <= FUND_ALLOCATION_TOLERANCE
70
+ ? allocations
71
+ : undefined;
72
+ };
@@ -1,6 +1,7 @@
1
1
  import { Amount } from '../../../../commonStateTypes/amount';
2
2
  import { FetchStateAndError } from '../../../../commonStateTypes/common';
3
3
  import { FundingAccount } from '../../commonSetup/setupViewSelector';
4
+ import { FundAllocation } from '../treasuryList/treasuryDetailState';
4
5
  export interface TreasuryTransferMoneyState extends FetchStateAndError {
5
6
  localData: TreasuryTransferMoneyLocalData;
6
7
  }
@@ -14,4 +15,5 @@ export interface TreasuryAccount {
14
15
  id: 'treasury';
15
16
  label: 'Treasury';
16
17
  balance?: Amount;
18
+ fundAllocations?: FundAllocation[];
17
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeniai/client-epic-state",
3
- "version": "4.18.29",
3
+ "version": "4.18.30",
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",