Skip to content

Commit b337923

Browse files
committed
remove "ConfirmReset" phase from SetupEncryption
1 parent 3260466 commit b337923

File tree

6 files changed

+21
-112
lines changed

6 files changed

+21
-112
lines changed

src/components/structures/auth/CompleteSecurity.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ export default class CompleteSecurity extends React.Component<IProps, IState> {
7878
} else if (phase === Phase.Busy) {
7979
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning" />;
8080
title = _t("encryption|verification|after_new_login|verify_this_device");
81-
} else if (phase === Phase.ConfirmReset) {
82-
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning" />;
83-
title = _t("encryption|verification|after_new_login|reset_confirmation");
8481
} else if (phase === Phase.Finished) {
8582
// SetupEncryptionBody will take care of calling onFinished, we don't need to do anything
8683
} else {
@@ -90,7 +87,7 @@ export default class CompleteSecurity extends React.Component<IProps, IState> {
9087
const forceVerification = SdkConfig.get("force_verification");
9188

9289
let skipButton;
93-
if (!forceVerification && (phase === Phase.Intro || phase === Phase.ConfirmReset)) {
90+
if (!forceVerification && phase === Phase.Intro) {
9491
skipButton = (
9592
<AccessibleButton
9693
onClick={this.onSkipClick}

src/components/structures/auth/SetupEncryptionBody.tsx

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -113,38 +113,15 @@ export default class SetupEncryptionBody extends React.Component<IProps, IState>
113113

114114
private onResetClick = (ev: ButtonEvent): void => {
115115
ev.preventDefault();
116-
const store = SetupEncryptionStore.sharedInstance();
117-
store.reset();
118-
Modal.createDialog(
119-
ResetIdentityDialog,
120-
/* props= */ {
121-
onReset: () => {
122-
// The user completed the reset process - close this dialog
123-
this.props.onFinished();
124-
store.done();
125-
},
126-
onCancelled: () => {
127-
// The user cancelled the reset dialog - go back a step
128-
store.returnAfterReset();
129-
},
130-
variant: "confirm",
131-
},
132-
/* className= */ undefined,
133-
/* isPriorityModal= */ false,
134-
/* isStaticModal= */ false,
135-
/* options= */ {
136-
onBeforeClose: async (reason): Promise<boolean> => {
137-
// This is the only time that we can detect that the dialog
138-
// is being closed due to the user clicking on the
139-
// background.
140-
if (reason === "backgroundClick") {
141-
// The user clicked away - go back a step
142-
store.returnAfterReset();
143-
}
144-
return true;
145-
},
116+
Modal.createDialog(ResetIdentityDialog, {
117+
onReset: () => {
118+
// The user completed the reset process - close this dialog
119+
this.props.onFinished();
120+
const store = SetupEncryptionStore.sharedInstance();
121+
store.done();
146122
},
147-
);
123+
variant: "confirm",
124+
});
148125
};
149126

150127
private onDoneClick = (): void => {
@@ -266,7 +243,7 @@ export default class SetupEncryptionBody extends React.Component<IProps, IState>
266243
</div>
267244
</div>
268245
);
269-
} else if (phase === Phase.Busy || phase === Phase.Loading || phase == Phase.ConfirmReset) {
246+
} else if (phase === Phase.Busy || phase === Phase.Loading) {
270247
return <Spinner />;
271248
} else {
272249
logger.log(`SetupEncryptionBody: Unknown phase ${phase}`);

src/components/views/dialogs/ResetIdentityDialog.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ interface ResetIdentityDialogProps {
1515
/**
1616
* Called when the dialog closes.
1717
*/
18-
onFinished: () => void;
18+
onFinished?: () => void;
1919

2020
/**
2121
* Called when the identity is reset (before onFinished is called).
2222
*/
23-
onReset: () => void;
23+
onReset?: () => void;
2424

2525
/**
2626
* Called when the reset is cancelled (before onFinished is called).
27+
*
28+
* Note: this is only called when the "Cancel" button is clicked, and not if
29+
* the user clicks outside out the dialog, as that is handled by `Modal`
30+
* rather than this component.
2731
*/
28-
onCancelled: () => void;
32+
onCancelled?: () => void;
2933

3034
/**
3135
* Which variant of this dialog to show.
@@ -48,12 +52,12 @@ export function ResetIdentityDialog({
4852
// whenever the reset is done, whether by completing successfully, or by
4953
// being cancelled
5054
const onResetWrapper: MouseEventHandler<HTMLButtonElement> = (...args) => {
51-
onReset();
52-
onFinished();
55+
onReset?.();
56+
onFinished?.();
5357
};
5458
const onCancelledWrapper: () => void = () => {
55-
onCancelled();
56-
onFinished();
59+
onCancelled?.();
60+
onFinished?.();
5761
};
5862
return (
5963
<MatrixClientContext.Provider value={matrixClient}>

src/i18n/strings/en_EN.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@
992992
"accepting": "Accepting…",
993993
"after_new_login": {
994994
"device_verified": "Device verified",
995-
"reset_confirmation": "Really reset verification keys?",
996995
"skip_verification": "Skip verification for now",
997996
"unable_to_verify": "Unable to verify this device",
998997
"verify_this_device": "Verify this device"

src/stores/SetupEncryptionStore.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export enum Phase {
2929
Done = 3, // final done stage, but still showing UX
3030
ConfirmSkip = 4,
3131
Finished = 5, // UX can be closed
32-
ConfirmReset = 6,
3332
}
3433

3534
/**
@@ -220,11 +219,6 @@ export class SetupEncryptionStore extends EventEmitter {
220219
this.emit("update");
221220
}
222221

223-
public reset(): void {
224-
this.phase = Phase.ConfirmReset;
225-
this.emit("update");
226-
}
227-
228222
public async resetConfirm(): Promise<void> {
229223
try {
230224
// If we've gotten here, the user presumably lost their

test/components/views/dialogs/security/SetupEncryptionDialog-test.tsx

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -51,68 +51,6 @@ describe("SetupEncryptionDialog", () => {
5151
// Then the phase has been set to Finished
5252
expect(store.phase).toBe(Phase.Finished);
5353
});
54-
55-
it("should launch a dialog when I say Proceed, then be ready when I cancel", async () => {
56-
mockClient();
57-
const store = new SetupEncryptionStore();
58-
jest.spyOn(SetupEncryptionStore, "sharedInstance").mockReturnValue(store);
59-
60-
// Given when you open the reset dialog we immediately cancel
61-
jest.spyOn(Modal, "createDialog").mockImplementation((_, props) => {
62-
// Simulate cancelling in the dialog
63-
props?.onCancelled();
64-
65-
return {
66-
close: jest.fn(),
67-
finished: Promise.resolve([]),
68-
};
69-
});
70-
71-
// When we launch the dialog and set it ready to start
72-
const onFinished = jest.fn();
73-
render(<SetupEncryptionDialog onFinished={onFinished} />);
74-
await act(async () => await store.fetchKeyInfo());
75-
expect(store.phase).toBe(Phase.Intro);
76-
77-
// And we hit the Proceed with reset button.
78-
// (The createDialog mock above simulates the user hitting cancel)
79-
await act(async () => screen.getByRole("button", { name: "Proceed with reset" }).click());
80-
81-
// Then the phase has been set to Intro
82-
expect(store.phase).toBe(Phase.Intro);
83-
});
84-
85-
it("should launch a dialog when I say Proceed, then be ready when I click outside the dialog", async () => {
86-
mockClient();
87-
const store = new SetupEncryptionStore();
88-
jest.spyOn(SetupEncryptionStore, "sharedInstance").mockReturnValue(store);
89-
90-
// Given when you open the reset dialog we immediately cancel
91-
jest.spyOn(Modal, "createDialog").mockImplementation(
92-
(_component, _props, _className, _isPriorityModal, _isStaticModal, options) => {
93-
// Simulate clicking outside the dialog
94-
options?.onBeforeClose?.("backgroundClick");
95-
96-
return {
97-
close: jest.fn(),
98-
finished: Promise.resolve([]),
99-
};
100-
},
101-
);
102-
103-
// When we launch the dialog and set it ready to start
104-
const onFinished = jest.fn();
105-
render(<SetupEncryptionDialog onFinished={onFinished} />);
106-
await act(async () => await store.fetchKeyInfo());
107-
expect(store.phase).toBe(Phase.Intro);
108-
109-
// And we hit the Proceed with reset button.
110-
// (The createDialog mock above simulates the user clicking outside the dialog)
111-
await act(async () => screen.getByRole("button", { name: "Proceed with reset" }).click());
112-
113-
// Then the phase has been set to Intro
114-
expect(store.phase).toBe(Phase.Intro);
115-
});
11654
});
11755

11856
function mockClient() {

0 commit comments

Comments
 (0)