Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | 540x 540x 540x 540x 1x 1x 3x 3x 3x 1x 2x 1x 1x 1x 540x 540x 33x 540x 21x 540x 540x 6x | import { RootState } from "@redux/types/store";
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import moment from "moment";
import { TransactionRiskProfile, TTimeFilter, TTypeFilter } from "./types";
const last24Hours = moment(new Date()).subtract(24, "hours").unix();
const last30days = moment(new Date())
.subtract(30, "days")
.startOf("day")
.unix();
const initialState: TransactionRiskProfile = {
filters: {
type: "all",
time: "all", // default
},
queries: {
type: "",
time: "",
},
};
const transactionRiskProfile = createSlice({
name: "transaction-risk-profile",
initialState,
reducers: {
setTypeFilter: (
state: TransactionRiskProfile,
action: PayloadAction<TTypeFilter>,
) => {
const type = action.payload;
state.filters.type = type;
},
setTimeFilter: (
state: TransactionRiskProfile,
action: PayloadAction<TTimeFilter>,
) => {
const time = action.payload;
state.filters.time = time;
if (time === "day") {
state.queries.time = `createdAt:>d${last24Hours}`;
} else if (time === "month") {
state.queries.time = `createdAt:>d${last30days}`;
} else Eif (time === "all") {
state.queries.time = ""; // no filter for all time
}
},
reset: () => initialState,
},
});
export const { setTypeFilter, setTimeFilter, reset } =
transactionRiskProfile.actions;
export const selectTypeFilter = (state: RootState) =>
state.transactionRiskProfile.filters.type;
export const selectTimeFilter = (state: RootState) =>
state.transactionRiskProfile.filters.time;
export const selectTypeFilterQuery = (state: RootState) =>
state.transactionRiskProfile.queries.type;
export const selectTimeFilterQuery = (state: RootState) =>
state.transactionRiskProfile.queries.time;
export default transactionRiskProfile.reducer;
|