@@ -13,6 +13,7 @@ import { phraseRecoveryPage } from "../recovery/recoverWith/phrase";
13
13
import { mainWindow } from "../../components/mainWindow" ;
14
14
import {
15
15
isRecoveryDevice ,
16
+ RecoveryDevice ,
16
17
recoveryDeviceToLabel ,
17
18
} from "../../utils/recoveryDevice" ;
18
19
@@ -28,7 +29,7 @@ const deviceSettingsTemplate = ({
28
29
isOnlyDevice,
29
30
back,
30
31
} : {
31
- protectDevice : ( ) => void ;
32
+ protectDevice : ( device : DeviceData & RecoveryDevice ) => void ;
32
33
deleteDevice : ( ) => void ;
33
34
device : DeviceData ;
34
35
isOnlyDevice : boolean ;
@@ -48,7 +49,7 @@ const deviceSettingsTemplate = ({
48
49
your recovery phrase to delete it.
49
50
</ p >
50
51
< button
51
- @click ="${ ( ) => protectDevice ( ) } "
52
+ @click ="${ ( ) => protectDevice ( device ) } "
52
53
data-action ="protect "
53
54
class ="c-button "
54
55
>
@@ -96,7 +97,9 @@ const deviceSettingsTemplate = ({
96
97
97
98
// We offer to protect unprotected recovery phrases only, although in the
98
99
// 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 =>
100
103
"recovery" in device . purpose &&
101
104
"seed_phrase" in device . key_type &&
102
105
! isProtected ( device ) ;
@@ -125,8 +128,14 @@ export const deviceSettings = async (
125
128
device,
126
129
isOnlyDevice,
127
130
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
+ ) ,
130
139
deleteDevice : ( ) =>
131
140
deleteDevice ( userNumber , connection , device , isOnlyDevice , resolve ) ,
132
141
} ) ;
@@ -138,7 +147,7 @@ export const deviceSettings = async (
138
147
const deviceConnection = async (
139
148
connection : Connection ,
140
149
userNumber : bigint ,
141
- device : DeviceData ,
150
+ device : DeviceData & RecoveryDevice ,
142
151
recoveryPhraseMessage : string
143
152
) : Promise < AuthenticatedConnection | null > => {
144
153
try {
@@ -200,14 +209,15 @@ const deleteDevice = async (
200
209
201
210
// If the device is protected then we need to be authenticated with the device to remove it
202
211
// 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 ;
211
221
212
222
await withLoader ( async ( ) => {
213
223
// if null then user canceled so we just redraw the manage page
@@ -233,7 +243,7 @@ const deleteDevice = async (
233
243
const protectDevice = async (
234
244
userNumber : bigint ,
235
245
connection : AuthenticatedConnection ,
236
- device : DeviceData ,
246
+ device : DeviceData & RecoveryDevice ,
237
247
isOnlyDevice : boolean ,
238
248
back : ( ) => void
239
249
) => {
0 commit comments