Skip to content

Commit

Permalink
feat: use SDK for recovery review.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdevos committed May 27, 2024
1 parent d611b94 commit e0c26f4
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 243 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"dependencies": {
"@creativecommons/cc-assets": "^0.1.0",
"@logion/client": "^0.45.0-8",
"@logion/client": "^0.45.0-10",
"@logion/client-browser": "^0.3.5",
"@logion/crossmint": "^0.1.32",
"@logion/extension": "^0.8.1-1",
Expand Down
31 changes: 14 additions & 17 deletions src/legal-officer/LegalOfficerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
LegalOfficer,
LocsState,
Votes,
PendingRecoveryRequest,
ReviewedRecoveryRequest,
} from '@logion/client';
import { LocType, LegalOfficerData, ValidAccountId } from "@logion/node-api";

Expand All @@ -15,7 +17,6 @@ import { VaultApi } from '../vault/VaultApi';
import { DateTime } from "luxon";
import { fetchAllLocsParams } from 'src/loc/LegalOfficerLocContext';
import { Locs, getLocsMap } from 'src/loc/Locs';
import { RecoveryRequest, fetchRecoveryRequests } from './Model';

export const SETTINGS_KEYS = [ 'oath' ];

Expand All @@ -37,8 +38,8 @@ export interface MissingSettings {
export interface LegalOfficerContext {
refreshRequests: ((clearBeforeRefresh: boolean) => void);
locsState: LocsState | null;
pendingRecoveryRequests: RecoveryRequest[] | null;
recoveryRequestsHistory: RecoveryRequest[] | null;
pendingRecoveryRequests: PendingRecoveryRequest[] | null;
recoveryRequestsHistory: ReviewedRecoveryRequest[] | null;
axios?: AxiosInstance;
pendingVaultTransferRequests?: VaultTransferRequest[];
vaultTransferRequestsHistory?: VaultTransferRequest[];
Expand Down Expand Up @@ -127,8 +128,8 @@ interface Action {
type: ActionType;
dataAddress?: ValidAccountId;
locsState?: LocsState;
pendingRecoveryRequests?: RecoveryRequest[],
recoveryRequestsHistory?: RecoveryRequest[],
pendingRecoveryRequests?: PendingRecoveryRequest[],
recoveryRequestsHistory?: ReviewedRecoveryRequest[],
refreshRequests?: (clearBeforeRefresh: boolean) => void;
clearBeforeRefresh?: boolean;
axios?: AxiosInstance;
Expand Down Expand Up @@ -484,24 +485,20 @@ export function LegalOfficerContextProvider(props: Props) {
// ------------------ Protection, recovery and vault -------------------------------

const refreshRequests = useCallback(() => {
if(accounts && accounts.current && axiosFactory && isReadyLegalOfficer) {
if(accounts && accounts.current && axiosFactory && isReadyLegalOfficer && client !== null) {
dispatch({
type: "REFRESH_REQUESTS_CALLED"
});
const currentAddress = accounts.current.accountId;

(async function() {
const axios = axiosFactory(currentAddress);

const allAccountRecoveryRequests = await fetchRecoveryRequests(axios);
const pendingRecoveryRequests: RecoveryRequest[] = allAccountRecoveryRequests
.filter(request => ["PENDING"].includes(request.status))
.sort((a, b) => a.createdOn.localeCompare(b.createdOn));
const recoveryRequestsHistory: RecoveryRequest[] = allAccountRecoveryRequests
.filter(request =>
["ACCEPTED", "REJECTED", "ACTIVATED", "CANCELLED", "REJECTED_CANCELLED", "ACCEPTED_CANCELLED"].includes(request.status)
)
.sort((a, b) => b.createdOn.localeCompare(a.createdOn));
const recoveryReview = client.withCurrentAccount(currentAddress).recoveryReview;
const allAccountRecoveryRequests = await recoveryReview.fetchRecoveryRequests();
const pendingRecoveryRequests = allAccountRecoveryRequests.pendingRequests
.sort((a, b) => a.data.createdOn.localeCompare(b.data.createdOn));
const recoveryRequestsHistory = allAccountRecoveryRequests.reviewedRequests
.sort((a, b) => b.data.createdOn.localeCompare(a.data.createdOn));

const allVaultTransferRequestsResult = (await new VaultApi(axios, currentAddress).getVaultTransferRequests({
legalOfficerAddress: currentAddress.address,
Expand All @@ -522,7 +519,7 @@ export function LegalOfficerContextProvider(props: Props) {
});
})();
}
}, [ accounts, axiosFactory, isReadyLegalOfficer ]);
}, [ accounts, axiosFactory, isReadyLegalOfficer, client ]);

useEffect(() => {
if(contextValue.refreshRequests !== refreshRequests) {
Expand Down
2 changes: 1 addition & 1 deletion src/legal-officer/LegalOfficerPaths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
LOC_REQUESTS_RELATIVE_PATH,
LOC_DETAILS_RELATIVE_PATH,
} from '../RootPaths';
import { RecoveryRequestType } from './Model';
import { RecoveryRequestType } from "@logion/client";

export const HOME_PATH = LEGAL_OFFICER_PATH;

Expand Down
115 changes: 0 additions & 115 deletions src/legal-officer/Model.tsx

This file was deleted.

15 changes: 0 additions & 15 deletions src/legal-officer/__mocks__/Model.tsx

This file was deleted.

17 changes: 0 additions & 17 deletions src/legal-officer/__mocks__/ModelMock.tsx

This file was deleted.

16 changes: 8 additions & 8 deletions src/legal-officer/recovery/PendingRecoveryRequests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useLegalOfficerContext } from '../LegalOfficerContext';
import RecoveryRequestStatus from './RecoveryRequestStatus';
import { recoveryDetailsPath } from "../LegalOfficerPaths";
import { useLogionChain } from '../../logion-chain';
import { RecoveryRequest } from '../Model';
import { PendingRecoveryRequest } from "@logion/client";

export default function PendingRecoveryRequests() {
const { api } = useLogionChain();
Expand All @@ -19,32 +19,32 @@ export default function PendingRecoveryRequests() {
return null;
}

let columns: Column<RecoveryRequest>[];
let columns: Column<PendingRecoveryRequest>[];

columns = [
{
header: "First name",
render: request => <Cell content={ request.userIdentity.firstName } />,
render: request => <Cell content={ request.data.userIdentity.firstName } />,
align: 'left',
},
{
header: "Last name",
render: request => <Cell content={ request.userIdentity.lastName } />,
render: request => <Cell content={ request.data.userIdentity.lastName } />,
align: 'left',
},
{
header: "Status",
render: request => <RecoveryRequestStatus status={ request.status } type={ request.type } />,
render: request => <RecoveryRequestStatus status={ request.data.status } type={ request.data.type } />,
width: "140px",
},
{
header: "Submission date",
render: request => <DateTimeCell dateTime={ request.createdOn } />,
render: request => <DateTimeCell dateTime={ request.data.createdOn } />,
width: "120px",
},
{
header: "Type",
render: request => <Cell content={ request.type } />,
render: request => <Cell content={ request.data.type } />,
width: "200px",
},
{
Expand All @@ -53,7 +53,7 @@ export default function PendingRecoveryRequests() {
<ButtonGroup aria-label="actions">
<Button
variant="primary"
onClick={ () => navigate(recoveryDetailsPath(request.id, request.type)) }
onClick={ () => navigate(recoveryDetailsPath(request.data.id, request.data.type)) }
>
Review and proceed
</Button>
Expand Down
Loading

0 comments on commit e0c26f4

Please sign in to comment.