Skip to content

Commit

Permalink
Rename CreateCrossSigningDialog to InitialCryptoSetupDialog (#28658)
Browse files Browse the repository at this point in the history
* Rename CreateCrossSigningDialog to InitialCryptoSetup

because it will soon encompass things other than just creating cross
signing.

* Fix name & tests

* Fix import

* Remove code creating key backup

Because this was split out from my key backup by default PR

* Fix comment

* Convert to named export
  • Loading branch information
dbkr authored Dec 6, 2024
1 parent 9cc5564 commit c659afa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/components/structures/auth/E2eSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MatrixClient } from "matrix-js-sdk/src/matrix";

import AuthPage from "../../views/auth/AuthPage";
import CompleteSecurityBody from "../../views/auth/CompleteSecurityBody";
import CreateCrossSigningDialog from "../../views/dialogs/security/CreateCrossSigningDialog";
import { InitialCryptoSetupDialog } from "../../views/dialogs/security/InitialCryptoSetupDialog";

interface IProps {
matrixClient: MatrixClient;
Expand All @@ -25,7 +25,7 @@ export default class E2eSetup extends React.Component<IProps> {
return (
<AuthPage>
<CompleteSecurityBody>
<CreateCrossSigningDialog
<InitialCryptoSetupDialog
matrixClient={this.props.matrixClient}
onFinished={this.props.onFinished}
accountPassword={this.props.accountPassword}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,27 @@ interface Props {
}

/*
* Walks the user through the process of creating a cross-signing keys. In most
* cases, only a spinner is shown, but for more complex auth like SSO, the user
* may need to complete some steps to proceed.
* Walks the user through the process of creating a cross-signing keys.
* In most cases, only a spinner is shown, but for more
* complex auth like SSO, the user may need to complete some steps to proceed.
*/
const CreateCrossSigningDialog: React.FC<Props> = ({ matrixClient, accountPassword, tokenLogin, onFinished }) => {
export const InitialCryptoSetupDialog: React.FC<Props> = ({
matrixClient,
accountPassword,
tokenLogin,
onFinished,
}) => {
const [error, setError] = useState(false);

const bootstrapCrossSigning = useCallback(async () => {
const doSetup = useCallback(async () => {
const cryptoApi = matrixClient.getCrypto();
if (!cryptoApi) return;

setError(false);

try {
await createCrossSigning(matrixClient, tokenLogin, accountPassword);

onFinished(true);
} catch (e) {
if (tokenLogin) {
Expand All @@ -58,8 +64,8 @@ const CreateCrossSigningDialog: React.FC<Props> = ({ matrixClient, accountPasswo
}, [onFinished]);

useEffect(() => {
bootstrapCrossSigning();
}, [bootstrapCrossSigning]);
doSetup();
}, [doSetup]);

let content;
if (error) {
Expand All @@ -69,7 +75,7 @@ const CreateCrossSigningDialog: React.FC<Props> = ({ matrixClient, accountPasswo
<div className="mx_Dialog_buttons">
<DialogButtons
primaryButton={_t("action|retry")}
onPrimaryButtonClick={bootstrapCrossSigning}
onPrimaryButtonClick={doSetup}
onCancel={onCancel}
/>
</div>
Expand All @@ -95,5 +101,3 @@ const CreateCrossSigningDialog: React.FC<Props> = ({ matrixClient, accountPasswo
</BaseDialog>
);
};

export default CreateCrossSigningDialog;
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { mocked } from "jest-mock";
import { MatrixClient } from "matrix-js-sdk/src/matrix";

import { createCrossSigning } from "../../../../../src/CreateCrossSigning";
import CreateCrossSigningDialog from "../../../../../src/components/views/dialogs/security/CreateCrossSigningDialog";
import { InitialCryptoSetupDialog } from "../../../../../src/components/views/dialogs/security/InitialCryptoSetupDialog";
import { createTestClient } from "../../../../test-utils";

jest.mock("../../../../../src/CreateCrossSigning", () => ({
createCrossSigning: jest.fn(),
}));

describe("CreateCrossSigningDialog", () => {
describe("InitialCryptoSetupDialog", () => {
let client: MatrixClient;
let createCrossSigningResolve: () => void;
let createCrossSigningReject: (e: Error) => void;
Expand All @@ -43,7 +43,7 @@ describe("CreateCrossSigningDialog", () => {
const onFinished = jest.fn();

render(
<CreateCrossSigningDialog
<InitialCryptoSetupDialog
matrixClient={client}
accountPassword="hunter2"
tokenLogin={false}
Expand All @@ -61,7 +61,7 @@ describe("CreateCrossSigningDialog", () => {

it("should display an error if createCrossSigning fails", async () => {
render(
<CreateCrossSigningDialog
<InitialCryptoSetupDialog
matrixClient={client}
accountPassword="hunter2"
tokenLogin={false}
Expand All @@ -78,7 +78,7 @@ describe("CreateCrossSigningDialog", () => {
const onFinished = jest.fn();

render(
<CreateCrossSigningDialog
<InitialCryptoSetupDialog
matrixClient={client}
accountPassword="hunter2"
tokenLogin={true}
Expand All @@ -95,7 +95,7 @@ describe("CreateCrossSigningDialog", () => {
const onFinished = jest.fn();

render(
<CreateCrossSigningDialog
<InitialCryptoSetupDialog
matrixClient={client}
accountPassword="hunter2"
tokenLogin={false}
Expand All @@ -113,7 +113,7 @@ describe("CreateCrossSigningDialog", () => {

it("should retry when the retry button is clicked", async () => {
render(
<CreateCrossSigningDialog
<InitialCryptoSetupDialog
matrixClient={client}
accountPassword="hunter2"
tokenLogin={false}
Expand Down

0 comments on commit c659afa

Please sign in to comment.