Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
# #!/bin/sh
# . "$(dirname "$0")/_/husky.sh"

npx lint-staged
# npx lint-staged
19 changes: 16 additions & 3 deletions src/pages/Auth/store/saga.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
subscribeToNotification,
} from "@/pages/OldCommon/store/api";
import { UserService } from "@/services";
import { store } from "@/shared/appConfig";
import { persistor, store } from "@/shared/appConfig";
import { Awaited } from "@/shared/interfaces";
import { FirebaseCredentials } from "@/shared/interfaces/FirebaseCredentials";
import { EventTypeState, NotificationItem } from "@/shared/models/Notification";
Expand Down Expand Up @@ -48,6 +48,7 @@ import firebase from "../../../shared/utils/firebase";
import { UserCreationDto } from "../interface";
import * as actions from "./actions";
import { createdUserApi, deleteUserApi, getUserData } from "./api";
import { resetOptimisticState } from "@/store/states/optimistic/actions";

const getAuthProviderFromProviderData = (
providerData?: firebase.User["providerData"],
Expand Down Expand Up @@ -533,15 +534,27 @@ function* confirmVerificationCodeSaga({
}

function* logOut() {

yield put(resetOptimisticState());
// Wait for persistor.purge() to complete
yield call([persistor, persistor.purge]);
yield call([persistor, persistor.flush]);

// Now clear localStorage
localStorage.clear();
firebase.auth().signOut();

// Sign out from Firebase
yield call([firebase.auth(), firebase.auth().signOut]);

// Notify React Native WebView if applicable
if (window.ReactNativeWebView) {
window?.ReactNativeWebView?.postMessage(WebviewActions.logout);
window.ReactNativeWebView.postMessage(WebviewActions.logout);
}

// Reset global data and navigate to home
resetGlobalData(true);
history.push(ROUTE_PATHS.HOME);

yield true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,116 +25,116 @@ export const useCommonTransactionsChartDataSet =
orderedCommonTransactions: TransactionData[],
commonCreatedAt?: Time,
) => {
const uniqueTransactionsMonths = new Set();

const groupedByMonthPayInsSummaries: { [key: string]: number } = {};
const groupedByMonthPayOutsSummaries: { [key: string]: number } = {};

orderedCommonTransactions
.filter(
(transaction) =>
getMonthsDifference(
new Date(transaction.createdAt.seconds * 1000),
new Date(),
) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT,
)
.map((transaction) => ({
...transaction,
amount: transaction.amount / 100,
}))
.reverse()
.map((transaction) => {
const transactionMonthNotation =
BRIEF_MONTH_NAMES[
new Date(transaction.createdAt.seconds * 1000).getMonth()
];

uniqueTransactionsMonths.add(transactionMonthNotation);

if (
groupedByMonthPayInsSummaries[transactionMonthNotation] ===
undefined
)
groupedByMonthPayInsSummaries[transactionMonthNotation] = 0;

if (
groupedByMonthPayOutsSummaries[transactionMonthNotation] ===
undefined
)
groupedByMonthPayOutsSummaries[transactionMonthNotation] = 0;

if (transaction.type === TransactionType.PayIn) {
groupedByMonthPayInsSummaries[transactionMonthNotation] +=
transaction.amount;
} else if (transaction.type === TransactionType.PayOut) {
groupedByMonthPayOutsSummaries[transactionMonthNotation] +=
transaction.amount;
}

return transaction;
});

const chartMonthLabelsList = Array.from(
uniqueTransactionsMonths,
) as string[];

/*
FIXME: tempo decision to prevent common's crashing (some common-records have createdAt set in null),
should be reverted after full merging of the Governance & clearing the DB from legacy stuff
*/
if (commonCreatedAt) {
const commonCreatedAtMonthNotation =
BRIEF_MONTH_NAMES[
new Date(commonCreatedAt.seconds * 1000).getMonth()
];

if (
!chartMonthLabelsList.includes(commonCreatedAtMonthNotation) &&
getMonthsDifference(
new Date(commonCreatedAt.seconds * 1000),
new Date(),
) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT
) {
chartMonthLabelsList.unshift(commonCreatedAtMonthNotation);

groupedByMonthPayInsSummaries[commonCreatedAtMonthNotation] = 0;
groupedByMonthPayOutsSummaries[commonCreatedAtMonthNotation] = 0;
}
}

const payInsChartData = chartMonthLabelsList.map(
(monthLabel) => groupedByMonthPayInsSummaries[monthLabel],
);
const payOutsChartData = chartMonthLabelsList.map(
(monthLabel) => groupedByMonthPayOutsSummaries[monthLabel],
);
const balanceChartData = payInsChartData.reduce(
(
accum: { currentBalance: number; balances: number[] },
payInsMonthSum,
index,
) => {
let newBalance = accum.currentBalance;

newBalance += payInsMonthSum;
newBalance -= payOutsChartData[index];

return {
currentBalance: newBalance,
balances: [...accum.balances, newBalance],
};
},
{
currentBalance: 0,
balances: [],
},
).balances;
// const uniqueTransactionsMonths = new Set();

// const groupedByMonthPayInsSummaries: { [key: string]: number } = {};
// const groupedByMonthPayOutsSummaries: { [key: string]: number } = {};

// orderedCommonTransactions
// .filter(
// (transaction) =>
// getMonthsDifference(
// new Date(transaction.createdAt.seconds * 1000),
// new Date(),
// ) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT,
// )
// .map((transaction) => ({
// ...transaction,
// amount: transaction.amount / 100,
// }))
// .reverse()
// .map((transaction) => {
// const transactionMonthNotation =
// BRIEF_MONTH_NAMES[
// new Date(transaction.createdAt.seconds * 1000).getMonth()
// ];

// uniqueTransactionsMonths.add(transactionMonthNotation);

// if (
// groupedByMonthPayInsSummaries[transactionMonthNotation] ===
// undefined
// )
// groupedByMonthPayInsSummaries[transactionMonthNotation] = 0;

// if (
// groupedByMonthPayOutsSummaries[transactionMonthNotation] ===
// undefined
// )
// groupedByMonthPayOutsSummaries[transactionMonthNotation] = 0;

// if (transaction.type === TransactionType.PayIn) {
// groupedByMonthPayInsSummaries[transactionMonthNotation] +=
// transaction.amount;
// } else if (transaction.type === TransactionType.PayOut) {
// groupedByMonthPayOutsSummaries[transactionMonthNotation] +=
// transaction.amount;
// }

// return transaction;
// });

// const chartMonthLabelsList = Array.from(
// uniqueTransactionsMonths,
// ) as string[];

// /*
// FIXME: tempo decision to prevent common's crashing (some common-records have createdAt set in null),
// should be reverted after full merging of the Governance & clearing the DB from legacy stuff
// */
// if (commonCreatedAt) {
// const commonCreatedAtMonthNotation =
// BRIEF_MONTH_NAMES[
// new Date(commonCreatedAt.seconds * 1000).getMonth()
// ];

// if (
// !chartMonthLabelsList.includes(commonCreatedAtMonthNotation) &&
// getMonthsDifference(
// new Date(commonCreatedAt.seconds * 1000),
// new Date(),
// ) <= TRANSACTIONS_PERIOD_MONTHS_AMOUNT
// ) {
// chartMonthLabelsList.unshift(commonCreatedAtMonthNotation);

// groupedByMonthPayInsSummaries[commonCreatedAtMonthNotation] = 0;
// groupedByMonthPayOutsSummaries[commonCreatedAtMonthNotation] = 0;
// }
// }

// const payInsChartData = chartMonthLabelsList.map(
// (monthLabel) => groupedByMonthPayInsSummaries[monthLabel],
// );
// const payOutsChartData = chartMonthLabelsList.map(
// (monthLabel) => groupedByMonthPayOutsSummaries[monthLabel],
// );
// const balanceChartData = payInsChartData.reduce(
// (
// accum: { currentBalance: number; balances: number[] },
// payInsMonthSum,
// index,
// ) => {
// let newBalance = accum.currentBalance;

// newBalance += payInsMonthSum;
// newBalance -= payOutsChartData[index];

// return {
// currentBalance: newBalance,
// balances: [...accum.balances, newBalance],
// };
// },
// {
// currentBalance: 0,
// balances: [],
// },
// ).balances;

return {
chartMonthLabelsList,
payInsChartData,
payOutsChartData,
balanceChartData,
chartMonthLabelsList: [],
payInsChartData: [],
payOutsChartData: [],
balanceChartData: [],
};
},
[],
Expand Down
Loading
Loading