Skip to content

Commit 24b23df

Browse files
author
Frederik Rothenberger
committed
Implement review feedback
1 parent 1eb5f51 commit 24b23df

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed

src/frontend/src/flows/manage/deviceSettings.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { phraseRecoveryPage } from "../recovery/recoverWith/phrase";
1313
import { mainWindow } from "../../components/mainWindow";
1414
import {
1515
isRecoveryDevice,
16+
RecoveryDevice,
1617
recoveryDeviceToLabel,
1718
} from "../../utils/recoveryDevice";
1819

@@ -28,7 +29,7 @@ const deviceSettingsTemplate = ({
2829
isOnlyDevice,
2930
back,
3031
}: {
31-
protectDevice: () => void;
32+
protectDevice: (device: DeviceData & RecoveryDevice) => void;
3233
deleteDevice: () => void;
3334
device: DeviceData;
3435
isOnlyDevice: boolean;
@@ -48,7 +49,7 @@ const deviceSettingsTemplate = ({
4849
your recovery phrase to delete it.
4950
</p>
5051
<button
51-
@click="${() => protectDevice()}"
52+
@click="${() => protectDevice(device)}"
5253
data-action="protect"
5354
class="c-button"
5455
>
@@ -96,7 +97,9 @@ const deviceSettingsTemplate = ({
9697

9798
// We offer to protect unprotected recovery phrases only, although in the
9899
// future we may offer to protect all devices
99-
const shouldOfferToProtect = (device: DeviceData): boolean =>
100+
const shouldOfferToProtect = (
101+
device: DeviceData
102+
): device is RecoveryDevice & DeviceData =>
100103
"recovery" in device.purpose &&
101104
"seed_phrase" in device.key_type &&
102105
!isProtected(device);
@@ -125,8 +128,14 @@ export const deviceSettings = async (
125128
device,
126129
isOnlyDevice,
127130
back: resolve,
128-
protectDevice: () =>
129-
protectDevice(userNumber, connection, device, isOnlyDevice, resolve),
131+
protectDevice: (recoveryDevice: DeviceData & RecoveryDevice) =>
132+
protectDevice(
133+
userNumber,
134+
connection,
135+
recoveryDevice,
136+
isOnlyDevice,
137+
resolve
138+
),
130139
deleteDevice: () =>
131140
deleteDevice(userNumber, connection, device, isOnlyDevice, resolve),
132141
});
@@ -138,7 +147,7 @@ export const deviceSettings = async (
138147
const deviceConnection = async (
139148
connection: Connection,
140149
userNumber: bigint,
141-
device: DeviceData,
150+
device: DeviceData & RecoveryDevice,
142151
recoveryPhraseMessage: string
143152
): Promise<AuthenticatedConnection | null> => {
144153
try {
@@ -200,14 +209,15 @@ const deleteDevice = async (
200209

201210
// If the device is protected then we need to be authenticated with the device to remove it
202211
// NOTE: the user may be authenticated with the device already, but for consistency we still ask them to input their recovery phrase
203-
const removalConnection = isProtected(device)
204-
? await deviceConnection(
205-
connection,
206-
userNumber,
207-
device,
208-
"Please input your recovery phrase to remove it."
209-
)
210-
: connection;
212+
const removalConnection =
213+
isRecoveryDevice(device) && isProtected(device)
214+
? await deviceConnection(
215+
connection,
216+
userNumber,
217+
device,
218+
"Please input your recovery phrase to remove it."
219+
)
220+
: connection;
211221

212222
await withLoader(async () => {
213223
// if null then user canceled so we just redraw the manage page
@@ -233,7 +243,7 @@ const deleteDevice = async (
233243
const protectDevice = async (
234244
userNumber: bigint,
235245
connection: AuthenticatedConnection,
236-
device: DeviceData,
246+
device: DeviceData & RecoveryDevice,
237247
isOnlyDevice: boolean,
238248
back: () => void
239249
) => {

src/frontend/src/flows/recovery/recoverWith/device.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
LoginFlowSuccess,
88
LoginFlowCanceled,
99
} from "../../../utils/flowResult";
10-
import { DeviceData } from "../../../../generated/internet_identity_types";
1110
import { Connection } from "../../../utils/iiConnection";
1211
import { mainWindow } from "../../../components/mainWindow";
12+
import { RecoveryDevice } from "../../../utils/recoveryDevice";
1313

1414
const pageContent = () => {
1515
const pageContentSlot = html`
@@ -49,7 +49,7 @@ const pageContent = () => {
4949
export const deviceRecoveryPage = async (
5050
userNumber: bigint,
5151
connection: Connection,
52-
device: Omit<DeviceData, "alias">
52+
device: RecoveryDevice
5353
): Promise<LoginFlowSuccess | LoginFlowCanceled> => {
5454
const container = document.getElementById("pageContent") as HTMLElement;
5555
render(pageContent(), container);
@@ -59,7 +59,7 @@ export const deviceRecoveryPage = async (
5959
const init = (
6060
userNumber: bigint,
6161
connection: Connection,
62-
device: Omit<DeviceData, "alias">
62+
device: RecoveryDevice
6363
): Promise<LoginFlowSuccess | LoginFlowCanceled> =>
6464
new Promise((resolve) => {
6565
const buttonContinue = document.getElementById(

src/frontend/src/flows/recovery/recoverWith/phrase.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { html, nothing, render, TemplateResult } from "lit-html";
2-
import { DeviceData } from "../../../../generated/internet_identity_types";
32
import {
43
apiResultToLoginFlowResult,
54
LoginFlowCanceled,
@@ -17,6 +16,7 @@ import {
1716
} from "../../../crypto/mnemonic";
1817
import { warningIcon } from "../../../components/icons";
1918
import { mainWindow } from "../../../components/mainWindow";
19+
import { RecoveryDevice } from "../../../utils/recoveryDevice";
2020

2121
const pageContent = (userNumber: bigint, message?: string) => {
2222
const pageContentSlot = html`
@@ -80,7 +80,7 @@ const pageContent = (userNumber: bigint, message?: string) => {
8080
export const phraseRecoveryPage = async (
8181
userNumber: bigint,
8282
connection: Connection,
83-
device: Omit<DeviceData, "alias">,
83+
device: RecoveryDevice,
8484
prefilledPhrase?: string,
8585
message?: string
8686
): Promise<LoginFlowSuccess | LoginFlowCanceled> => {
@@ -92,7 +92,7 @@ export const phraseRecoveryPage = async (
9292
const init = (
9393
userNumber: bigint,
9494
connection: Connection,
95-
device: Omit<DeviceData, "alias">,
95+
device: RecoveryDevice,
9696
prefilledPhrase?: string /* if set, prefilled as input */,
9797
message?: string
9898
): Promise<LoginFlowSuccess | LoginFlowCanceled> =>

src/frontend/src/utils/recoveryDevice.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { DeviceData, Purpose } from "../../generated/internet_identity_types";
1+
import { DeviceData } from "../../generated/internet_identity_types";
22

33
export type RecoveryDevice = Omit<DeviceData, "alias"> & {
4-
purpose: Extract<Purpose, { recovery: null }>;
4+
purpose: { recovery: null };
55
};
66

7-
export const recoveryDeviceToLabel = (
8-
device: Omit<DeviceData, "alias"> & RecoveryDevice
9-
): string => {
7+
export const recoveryDeviceToLabel = (device: RecoveryDevice): string => {
108
if ("seed_phrase" in device.key_type) {
119
return "Recovery Phrase";
1210
}

0 commit comments

Comments
 (0)