Skip to content

Commit

Permalink
Merge pull request #571 from logion-network/feature/manage-secrets
Browse files Browse the repository at this point in the history
Manage secrets
  • Loading branch information
benoitdevos authored May 16, 2024
2 parents 2e988f9 + bb89303 commit e8f02c9
Show file tree
Hide file tree
Showing 26 changed files with 422 additions and 19 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-2",
"@logion/client": "^0.45.0-7",
"@logion/client-browser": "^0.3.5",
"@logion/crossmint": "^0.1.32",
"@logion/extension": "^0.8.1-1",
Expand Down
2 changes: 2 additions & 0 deletions src/__mocks__/@logion/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
LocsState,
HashOrContent,
ClosedLoc,
ClosedIdentityLoc,
ReadOnlyLocState,
PendingRequest,
} from '../LogionClientMock';
Expand All @@ -39,6 +40,7 @@ export {
LocsState,
HashOrContent,
ClosedLoc,
ClosedIdentityLoc,
ReadOnlyLocState,
isTokenCompatibleWith,
LegalOfficerClass,
Expand Down
9 changes: 9 additions & 0 deletions src/__mocks__/LogionClientMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ export class ClosedLoc extends LocRequestState {
};
}

export class ClosedIdentityLoc extends LocRequestState {

legalOfficer: {
requestVote: any,
} = {
requestVote: jest.fn(),
};
}

export class EditableRequest extends LocRequestState {
addMetadata: jest.Mock<Promise<EditableRequest>> | undefined;
deleteMetadata: jest.Mock<Promise<EditableRequest>> | undefined;
Expand Down
3 changes: 2 additions & 1 deletion src/components/toggle/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import './Checkbox.css';
import './Toggle.css';
import './Eye.css';
import { customClassName } from "../../common/types/Helpers";

export type Skin = "Checkbox" | "Toggle white" | "Toggle black";
export type Skin = "Checkbox" | "Toggle white" | "Toggle black" | "Eye";

export interface Props {
checked: boolean;
Expand Down
34 changes: 34 additions & 0 deletions src/components/toggle/Eye.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.Eye {
content: " ";
position: relative;
height: 37px;
width: 50px;
}

.Eye.clickable {
cursor: pointer;
}

.Eye.checked:after {
background-image: url("../../img/eye.svg");
}
.Eye:not(.checked):after {
background-image: url("../../img/eye-closed.svg");
}

.Eye:after {
content: " ";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-repeat: no-repeat;
background-position: center;
}

.Eye.disabled,
.Eye.clickable.disabled {
cursor: default;
opacity: 0.5;
}
3 changes: 3 additions & 0 deletions src/img/eye-closed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/img/eye.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/loc/CertificateAndDetailsButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import ViewQrCodeButton from './ViewQrCodeButton';
import ViewCertificateButton from './ViewCertificateButton';
import InvitedContributorsButton from "./invited-contributor/InvitedContributorsButton";
import { CollectionLimits, DEFAULT_LIMITS } from "./CollectionLimitsForm";
import SecretsButton from "./secrets/SecretsButton";

export interface Props {
loc: LocData;
Expand Down Expand Up @@ -87,7 +88,7 @@ export default function CertificateAndDetailsButtons(props: Props) {
{ loc.locType === 'Identity' && props.viewer === 'LegalOfficer' && !isLogionIdentityLoc({ ...loc, requesterAddress: loc.requesterAccountId?.address }) && loc.requesterAccountId?.type === "Polkadot" && loc.status ==='CLOSED' && !props.isReadOnly && <Nominate/> }

{ loc.locType === 'Identity' && !isLogionIdentityLoc({ ...loc, requesterAddress: loc.requesterAccountId?.address }) && props.viewer === 'LegalOfficer' && loc.status === "CLOSED" && hasVoteFeature && !loc.voteId && !props.isReadOnly && <RequestVoteButton/> }

{ loc.locType === 'Identity' && props.viewer === 'User' && loc.status === "CLOSED" && <SecretsButton /> }
{ loc.locType === 'Collection' && props.viewer === 'LegalOfficer' && <ArchiveButton/> }
{ loc.locType !== 'Collection' && props.viewer === 'LegalOfficer' && !props.isReadOnly && <ArchiveButton/> }

Expand Down
8 changes: 4 additions & 4 deletions src/loc/RequestVoteButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, waitFor } from "@testing-library/react";
import { clickByName } from "src/tests";
import RequestVoteButton from "./RequestVoteButton";
import { ClosedLoc } from "src/__mocks__/@logion/client";
import { ClosedIdentityLoc } from "src/__mocks__/@logion/client";
import { setLocState } from "./__mocks__/LocContextMock";
import { FAILED_SUBMISSION, NO_SUBMISSION, SUCCESSFUL_SUBMISSION, setExtrinsicSubmissionState } from "src/logion-chain/__mocks__/LogionChainMock";
import { expectSubmitting } from "src/test/Util";
Expand All @@ -12,7 +12,7 @@ jest.mock("../logion-chain");
describe("RequestVoteButton", () => {

it("submits vote", async () => {
const locState = new ClosedLoc();
const locState = new ClosedIdentityLoc();
setLocState(locState);
locState.legalOfficer.requestVote = async (params: any) => {
return VOTE_ID;
Expand All @@ -25,7 +25,7 @@ describe("RequestVoteButton", () => {
});

it("successfully creates a vote", async () => {
const locState = new ClosedLoc();
const locState = new ClosedIdentityLoc();
setLocState(locState);
locState.legalOfficer.requestVote = async (params: any) => {
return VOTE_ID;
Expand All @@ -39,7 +39,7 @@ describe("RequestVoteButton", () => {
});

it("shows error on failure", async () => {
const locState = new ClosedLoc();
const locState = new ClosedIdentityLoc();
setLocState(locState);
locState.legalOfficer.requestVote = async () => {};
setExtrinsicSubmissionState(FAILED_SUBMISSION);
Expand Down
4 changes: 2 additions & 2 deletions src/loc/RequestVoteButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClosedLoc } from "@logion/client";
import { ClosedIdentityLoc } from "@logion/client";
import { useCallback, useState } from "react";
import ClientExtrinsicSubmitter, { Call, CallCallback } from "src/ClientExtrinsicSubmitter";
import Button from "src/common/Button";
Expand All @@ -18,7 +18,7 @@ export default function RequestVoteButton() {
const [ submissionFailed, setSubmissionFailed ] = useState<boolean>(false);

const requestVoteCallback = useCallback(async (callback: CallCallback) => {
if(signer && (locState instanceof ClosedLoc)) {
if(signer && (locState instanceof ClosedIdentityLoc)) {
const requestedVoteId = await locState.legalOfficer.requestVote({
callback,
signer,
Expand Down
3 changes: 2 additions & 1 deletion src/loc/TestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function buildLocRequest(locId: UUID, loc: LegalOfficerCase): LocData {
legalFee: loc.legalFee,
collectionItemFee: loc.collectionItemFee,
tokensRecordFee: loc.tokensRecordFee,
}
},
secrets: [],
};
}
7 changes: 7 additions & 0 deletions src/loc/__snapshots__/ContextualizedLocDetails.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ exports[`ContextualizedLocDetails renders 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -124,6 +125,7 @@ exports[`ContextualizedLocDetails renders 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -199,6 +201,7 @@ exports[`ContextualizedLocDetails renders 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -271,6 +274,7 @@ exports[`ContextualizedLocDetails renders 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -336,6 +340,7 @@ exports[`ContextualizedLocDetails renders 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -401,6 +406,7 @@ exports[`ContextualizedLocDetails renders 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -473,6 +479,7 @@ exports[`ContextualizedLocDetails renders 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down
12 changes: 12 additions & 0 deletions src/loc/__snapshots__/UserContextualizedLocDetails.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -160,6 +161,7 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -229,6 +231,7 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -295,6 +298,7 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -361,6 +365,7 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -426,6 +431,7 @@ exports[`UserContextualizedLocDetails renders for requester 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -501,6 +507,7 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -601,6 +608,7 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -670,6 +678,7 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -736,6 +745,7 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -802,6 +812,7 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down Expand Up @@ -867,6 +878,7 @@ exports[`UserContextualizedLocDetails renders for verified issuer 1`] = `
},
},
"requesterLocId": undefined,
"secrets": Array [],
"status": "OPEN",
"verifiedIssuer": false,
}
Expand Down
6 changes: 3 additions & 3 deletions src/loc/issuer/Nominate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Icon from "../../common/Icon";
import Dialog from "../../common/Dialog";
import { useLocContext } from "../LocContext";
import { CallCallback, useLogionChain } from "../../logion-chain";
import { ClosedLoc } from "@logion/client";
import { ClosedIdentityLoc } from "@logion/client";
import './Nominate.css';
import ExtrinsicSubmissionStateView from "src/ExtrinsicSubmissionStateView";

Expand All @@ -26,7 +26,7 @@ export default function Nominate() {
const changeIssuer = useCallback(async () => {
setStatus('Confirming');
const call = async (callback: CallCallback) => mutateLocState(async current => {
if(signer && current instanceof ClosedLoc) {
if(signer && current instanceof ClosedIdentityLoc) {
if(isIssuer) {
return current.legalOfficer.dismissIssuer({
signer,
Expand All @@ -36,7 +36,7 @@ export default function Nominate() {
return current.legalOfficer.nominateIssuer({
signer,
callback,
});
});
}
} else {
return current;
Expand Down
Loading

0 comments on commit e8f02c9

Please sign in to comment.