1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00
metamask-extension/ui/ducks/institutional/institutional.js
Albert Olivé 319696b4ef
[MMI] Added compliance details modal and compliance details component (#18118)
* Added compliance details modal and compliance details component

* Finished component

* Fixed test name
2023-05-05 14:07:51 +02:00

107 lines
3.0 KiB
JavaScript

import { createSelector } from 'reselect';
import { createSlice } from '@reduxjs/toolkit';
import { captureException } from '@sentry/browser';
import { mmiActionsFactory } from '../../store/institutional/institution-background';
const name = 'institutionalFeatures';
const initialState = {
historicalReports: {},
complianceProjectId: '',
complianceClientId: '',
reportsInProgress: {},
};
const slice = createSlice({
name,
initialState,
reducers: {
setHistoricalReports(state, action) {
state.historicalReports[action.payload.address] = [
...action.payload.reports,
];
},
},
});
const { actions, reducer } = slice;
export default reducer;
export const getComplianceProjectId = (state) =>
state.metamask[name]?.complianceProjectId;
export const getComplianceClientId = (state) =>
state.metamask[name]?.complianceClientId;
export const getComplianceTenantSubdomain = (state) =>
state.metamask[name]?.complianceTenantSubdomain;
export const getComplianceHistoricalReports = (state) =>
state.metamask[name]?.historicalReports;
export const getComplianceReportsInProgress = (state) =>
state.metamask[name]?.reportsInProgress;
export const getInstitutionalConnectRequests = (state) =>
state.metamask[name]?.connectRequests;
export const complianceActivated = (state) =>
Boolean(state.metamask[name]?.complianceProjectId);
export const getComplianceHistoricalReportsByAddress = (address) =>
createSelector(getComplianceHistoricalReports, (reports) =>
reports ? reports[address] : [],
);
export const getComplianceReportsInProgressByAddress = (address) =>
createSelector(getComplianceReportsInProgress, (reports) =>
reports ? reports[address.toLowerCase()] : undefined,
);
export const fetchHistoricalReports = (address, testProjectId = undefined) => {
return async (dispatch, getState) => {
const state = getState();
const mmiActions = mmiActionsFactory();
let projectId;
// testProjectId is provided to make a test request, which checks if projectId is correct
if (!testProjectId) {
projectId = getComplianceProjectId(state);
if (!projectId) {
return;
}
}
try {
const result = await dispatch(
mmiActions.getComplianceHistoricalReportsByAddress(address, projectId),
);
dispatch(
mmiActions.syncReportsInProgress({
address,
historicalReports: result.items ? result.items : [],
}),
);
dispatch(
actions.setHistoricalReports({
address,
reports: result.items
? result.items.filter((report) => report.status !== 'inProgress')
: [],
}),
);
} catch (error) {
console.error(error);
captureException(error);
}
};
};
export function generateComplianceReport(address) {
return (dispatch, _getState) => {
const mmiActions = mmiActionsFactory();
dispatch(mmiActions.generateComplianceReport(address));
};
}
const { setHistoricalReports } = actions;
export { setHistoricalReports };