@@ -25,116 +25,116 @@ export const useCommonTransactionsChartDataSet =
2525 orderedCommonTransactions : TransactionData [ ] ,
2626 commonCreatedAt ?: Time ,
2727 ) => {
28- const uniqueTransactionsMonths = new Set ( ) ;
29-
30- const groupedByMonthPayInsSummaries : { [ key : string ] : number } = { } ;
31- const groupedByMonthPayOutsSummaries : { [ key : string ] : number } = { } ;
32-
33- orderedCommonTransactions
34- . filter (
35- ( transaction ) =>
36- getMonthsDifference (
37- new Date ( transaction . createdAt . seconds * 1000 ) ,
38- new Date ( ) ,
39- ) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT ,
40- )
41- . map ( ( transaction ) => ( {
42- ...transaction ,
43- amount : transaction . amount / 100 ,
44- } ) )
45- . reverse ( )
46- . map ( ( transaction ) => {
47- const transactionMonthNotation =
48- BRIEF_MONTH_NAMES [
49- new Date ( transaction . createdAt . seconds * 1000 ) . getMonth ( )
50- ] ;
51-
52- uniqueTransactionsMonths . add ( transactionMonthNotation ) ;
53-
54- if (
55- groupedByMonthPayInsSummaries [ transactionMonthNotation ] ===
56- undefined
57- )
58- groupedByMonthPayInsSummaries [ transactionMonthNotation ] = 0 ;
59-
60- if (
61- groupedByMonthPayOutsSummaries [ transactionMonthNotation ] ===
62- undefined
63- )
64- groupedByMonthPayOutsSummaries [ transactionMonthNotation ] = 0 ;
65-
66- if ( transaction . type === TransactionType . PayIn ) {
67- groupedByMonthPayInsSummaries [ transactionMonthNotation ] +=
68- transaction . amount ;
69- } else if ( transaction . type === TransactionType . PayOut ) {
70- groupedByMonthPayOutsSummaries [ transactionMonthNotation ] +=
71- transaction . amount ;
72- }
73-
74- return transaction ;
75- } ) ;
76-
77- const chartMonthLabelsList = Array . from (
78- uniqueTransactionsMonths ,
79- ) as string [ ] ;
80-
81- /*
82- FIXME: tempo decision to prevent common's crashing (some common-records have createdAt set in null),
83- should be reverted after full merging of the Governance & clearing the DB from legacy stuff
84- */
85- if ( commonCreatedAt ) {
86- const commonCreatedAtMonthNotation =
87- BRIEF_MONTH_NAMES [
88- new Date ( commonCreatedAt . seconds * 1000 ) . getMonth ( )
89- ] ;
90-
91- if (
92- ! chartMonthLabelsList . includes ( commonCreatedAtMonthNotation ) &&
93- getMonthsDifference (
94- new Date ( commonCreatedAt . seconds * 1000 ) ,
95- new Date ( ) ,
96- ) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT
97- ) {
98- chartMonthLabelsList . unshift ( commonCreatedAtMonthNotation ) ;
99-
100- groupedByMonthPayInsSummaries [ commonCreatedAtMonthNotation ] = 0 ;
101- groupedByMonthPayOutsSummaries [ commonCreatedAtMonthNotation ] = 0 ;
102- }
103- }
104-
105- const payInsChartData = chartMonthLabelsList . map (
106- ( monthLabel ) => groupedByMonthPayInsSummaries [ monthLabel ] ,
107- ) ;
108- const payOutsChartData = chartMonthLabelsList . map (
109- ( monthLabel ) => groupedByMonthPayOutsSummaries [ monthLabel ] ,
110- ) ;
111- const balanceChartData = payInsChartData . reduce (
112- (
113- accum : { currentBalance : number ; balances : number [ ] } ,
114- payInsMonthSum ,
115- index ,
116- ) => {
117- let newBalance = accum . currentBalance ;
118-
119- newBalance += payInsMonthSum ;
120- newBalance -= payOutsChartData [ index ] ;
121-
122- return {
123- currentBalance : newBalance ,
124- balances : [ ...accum . balances , newBalance ] ,
125- } ;
126- } ,
127- {
128- currentBalance : 0 ,
129- balances : [ ] ,
130- } ,
131- ) . balances ;
28+ // const uniqueTransactionsMonths = new Set();
29+
30+ // const groupedByMonthPayInsSummaries: { [key: string]: number } = {};
31+ // const groupedByMonthPayOutsSummaries: { [key: string]: number } = {};
32+
33+ // orderedCommonTransactions
34+ // .filter(
35+ // (transaction) =>
36+ // getMonthsDifference(
37+ // new Date(transaction.createdAt.seconds * 1000),
38+ // new Date(),
39+ // ) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT,
40+ // )
41+ // .map((transaction) => ({
42+ // ...transaction,
43+ // amount: transaction.amount / 100,
44+ // }))
45+ // .reverse()
46+ // .map((transaction) => {
47+ // const transactionMonthNotation =
48+ // BRIEF_MONTH_NAMES[
49+ // new Date(transaction.createdAt.seconds * 1000).getMonth()
50+ // ];
51+
52+ // uniqueTransactionsMonths.add(transactionMonthNotation);
53+
54+ // if (
55+ // groupedByMonthPayInsSummaries[transactionMonthNotation] ===
56+ // undefined
57+ // )
58+ // groupedByMonthPayInsSummaries[transactionMonthNotation] = 0;
59+
60+ // if (
61+ // groupedByMonthPayOutsSummaries[transactionMonthNotation] ===
62+ // undefined
63+ // )
64+ // groupedByMonthPayOutsSummaries[transactionMonthNotation] = 0;
65+
66+ // if (transaction.type === TransactionType.PayIn) {
67+ // groupedByMonthPayInsSummaries[transactionMonthNotation] +=
68+ // transaction.amount;
69+ // } else if (transaction.type === TransactionType.PayOut) {
70+ // groupedByMonthPayOutsSummaries[transactionMonthNotation] +=
71+ // transaction.amount;
72+ // }
73+
74+ // return transaction;
75+ // });
76+
77+ // const chartMonthLabelsList = Array.from(
78+ // uniqueTransactionsMonths,
79+ // ) as string[];
80+
81+ // /*
82+ // FIXME: tempo decision to prevent common's crashing (some common-records have createdAt set in null),
83+ // should be reverted after full merging of the Governance & clearing the DB from legacy stuff
84+ // */
85+ // if (commonCreatedAt) {
86+ // const commonCreatedAtMonthNotation =
87+ // BRIEF_MONTH_NAMES[
88+ // new Date(commonCreatedAt.seconds * 1000).getMonth()
89+ // ];
90+
91+ // if (
92+ // !chartMonthLabelsList.includes(commonCreatedAtMonthNotation) &&
93+ // getMonthsDifference(
94+ // new Date(commonCreatedAt.seconds * 1000),
95+ // new Date(),
96+ // ) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT
97+ // ) {
98+ // chartMonthLabelsList.unshift(commonCreatedAtMonthNotation);
99+
100+ // groupedByMonthPayInsSummaries[commonCreatedAtMonthNotation] = 0;
101+ // groupedByMonthPayOutsSummaries[commonCreatedAtMonthNotation] = 0;
102+ // }
103+ // }
104+
105+ // const payInsChartData = chartMonthLabelsList.map(
106+ // (monthLabel) => groupedByMonthPayInsSummaries[monthLabel],
107+ // );
108+ // const payOutsChartData = chartMonthLabelsList.map(
109+ // (monthLabel) => groupedByMonthPayOutsSummaries[monthLabel],
110+ // );
111+ // const balanceChartData = payInsChartData.reduce(
112+ // (
113+ // accum: { currentBalance: number; balances: number[] },
114+ // payInsMonthSum,
115+ // index,
116+ // ) => {
117+ // let newBalance = accum.currentBalance;
118+
119+ // newBalance += payInsMonthSum;
120+ // newBalance -= payOutsChartData[index];
121+
122+ // return {
123+ // currentBalance: newBalance,
124+ // balances: [...accum.balances, newBalance],
125+ // };
126+ // },
127+ // {
128+ // currentBalance: 0,
129+ // balances: [],
130+ // },
131+ // ).balances;
132132
133133 return {
134- chartMonthLabelsList,
135- payInsChartData,
136- payOutsChartData,
137- balanceChartData,
134+ chartMonthLabelsList : [ ] ,
135+ payInsChartData : [ ] ,
136+ payOutsChartData : [ ] ,
137+ balanceChartData : [ ] ,
138138 } ;
139139 } ,
140140 [ ] ,
0 commit comments