@@ -30,13 +30,12 @@ const TOAST_KEY = "setupencryption";
30
30
31
31
const getTitle = ( kind : Kind ) : string => {
32
32
switch ( kind ) {
33
- case Kind . SET_UP_ENCRYPTION :
34
- return _t ( "encryption|set_up_toast_title" ) ;
35
33
case Kind . SET_UP_RECOVERY :
36
34
return _t ( "encryption|set_up_recovery" ) ;
37
35
case Kind . VERIFY_THIS_SESSION :
38
36
return _t ( "encryption|verify_toast_title" ) ;
39
37
case Kind . KEY_STORAGE_OUT_OF_SYNC :
38
+ case Kind . KEY_STORAGE_OUT_OF_SYNC_STORE :
40
39
return _t ( "encryption|key_storage_out_of_sync" ) ;
41
40
case Kind . TURN_ON_KEY_STORAGE :
42
41
return _t ( "encryption|turn_on_key_storage" ) ;
@@ -45,12 +44,11 @@ const getTitle = (kind: Kind): string => {
45
44
46
45
const getIcon = ( kind : Kind ) : string | undefined => {
47
46
switch ( kind ) {
48
- case Kind . SET_UP_ENCRYPTION :
49
- return "secure_backup" ;
50
47
case Kind . SET_UP_RECOVERY :
51
48
return undefined ;
52
49
case Kind . VERIFY_THIS_SESSION :
53
50
case Kind . KEY_STORAGE_OUT_OF_SYNC :
51
+ case Kind . KEY_STORAGE_OUT_OF_SYNC_STORE :
54
52
return "verification_warning" ;
55
53
case Kind . TURN_ON_KEY_STORAGE :
56
54
return "key_storage" ;
@@ -59,13 +57,12 @@ const getIcon = (kind: Kind): string | undefined => {
59
57
60
58
const getSetupCaption = ( kind : Kind ) : string => {
61
59
switch ( kind ) {
62
- case Kind . SET_UP_ENCRYPTION :
63
- return _t ( "action|continue" ) ;
64
60
case Kind . SET_UP_RECOVERY :
65
61
return _t ( "action|continue" ) ;
66
62
case Kind . VERIFY_THIS_SESSION :
67
63
return _t ( "action|verify" ) ;
68
64
case Kind . KEY_STORAGE_OUT_OF_SYNC :
65
+ case Kind . KEY_STORAGE_OUT_OF_SYNC_STORE :
69
66
return _t ( "encryption|enter_recovery_key" ) ;
70
67
case Kind . TURN_ON_KEY_STORAGE :
71
68
return _t ( "action|continue" ) ;
@@ -79,6 +76,7 @@ const getSetupCaption = (kind: Kind): string => {
79
76
const getPrimaryButtonIcon = ( kind : Kind ) : ComponentType < React . SVGAttributes < SVGElement > > | undefined => {
80
77
switch ( kind ) {
81
78
case Kind . KEY_STORAGE_OUT_OF_SYNC :
79
+ case Kind . KEY_STORAGE_OUT_OF_SYNC_STORE :
82
80
return KeyIcon ;
83
81
default :
84
82
return ;
@@ -89,10 +87,10 @@ const getSecondaryButtonLabel = (kind: Kind): string => {
89
87
switch ( kind ) {
90
88
case Kind . SET_UP_RECOVERY :
91
89
return _t ( "action|dismiss" ) ;
92
- case Kind . SET_UP_ENCRYPTION :
93
90
case Kind . VERIFY_THIS_SESSION :
94
91
return _t ( "encryption|verification|unverified_sessions_toast_reject" ) ;
95
92
case Kind . KEY_STORAGE_OUT_OF_SYNC :
93
+ case Kind . KEY_STORAGE_OUT_OF_SYNC_STORE :
96
94
return _t ( "encryption|forgot_recovery_key" ) ;
97
95
case Kind . TURN_ON_KEY_STORAGE :
98
96
return _t ( "action|dismiss" ) ;
@@ -101,13 +99,12 @@ const getSecondaryButtonLabel = (kind: Kind): string => {
101
99
102
100
const getDescription = ( kind : Kind ) : string => {
103
101
switch ( kind ) {
104
- case Kind . SET_UP_ENCRYPTION :
105
- return _t ( "encryption|set_up_toast_description" ) ;
106
102
case Kind . SET_UP_RECOVERY :
107
103
return _t ( "encryption|set_up_recovery_toast_description" ) ;
108
104
case Kind . VERIFY_THIS_SESSION :
109
105
return _t ( "encryption|verify_toast_description" ) ;
110
106
case Kind . KEY_STORAGE_OUT_OF_SYNC :
107
+ case Kind . KEY_STORAGE_OUT_OF_SYNC_STORE :
111
108
return _t ( "encryption|key_storage_out_of_sync_description" ) ;
112
109
case Kind . TURN_ON_KEY_STORAGE :
113
110
return _t ( "encryption|turn_on_key_storage_description" ) ;
@@ -118,10 +115,6 @@ const getDescription = (kind: Kind): string => {
118
115
* The kind of toast to show.
119
116
*/
120
117
export enum Kind {
121
- /**
122
- * Prompt the user to set up encryption
123
- */
124
- SET_UP_ENCRYPTION = "set_up_encryption" ,
125
118
/**
126
119
* Prompt the user to set up a recovery key
127
120
*/
@@ -131,9 +124,13 @@ export enum Kind {
131
124
*/
132
125
VERIFY_THIS_SESSION = "verify_this_session" ,
133
126
/**
134
- * Prompt the user to enter their recovery key
127
+ * Prompt the user to enter their recovery key, to retrieve secrets
135
128
*/
136
129
KEY_STORAGE_OUT_OF_SYNC = "key_storage_out_of_sync" ,
130
+ /**
131
+ * Prompt the user to enter their recovery key, to store secrets
132
+ */
133
+ KEY_STORAGE_OUT_OF_SYNC_STORE = "key_storage_out_of_sync_store" ,
137
134
/**
138
135
* Prompt the user to turn on key storage
139
136
*/
@@ -156,77 +153,115 @@ export const showToast = (kind: Kind): void => {
156
153
}
157
154
158
155
const onPrimaryClick = async ( ) : Promise < void > => {
159
- if ( kind === Kind . VERIFY_THIS_SESSION ) {
160
- Modal . createDialog ( SetupEncryptionDialog , { } , undefined , /* priority = */ false , /* static = */ true ) ;
161
- } else if ( kind == Kind . TURN_ON_KEY_STORAGE ) {
162
- // Open the user settings dialog to the encryption tab
163
- const payload : OpenToTabPayload = {
164
- action : Action . ViewUserSettings ,
165
- initialTabId : UserTab . Encryption ,
166
- } ;
167
- defaultDispatcher . dispatch ( payload ) ;
168
- } else {
169
- const modal = Modal . createDialog (
170
- Spinner ,
171
- undefined ,
172
- "mx_Dialog_spinner" ,
173
- /* priority */ false ,
174
- /* static */ true ,
175
- ) ;
176
- try {
177
- await accessSecretStorage ( ) ;
178
- } catch ( error ) {
179
- onAccessSecretStorageFailed ( error as Error ) ;
180
- } finally {
181
- modal . close ( ) ;
156
+ switch ( kind ) {
157
+ case Kind . TURN_ON_KEY_STORAGE : {
158
+ // Open the user settings dialog to the encryption tab
159
+ const payload : OpenToTabPayload = {
160
+ action : Action . ViewUserSettings ,
161
+ initialTabId : UserTab . Encryption ,
162
+ } ;
163
+ defaultDispatcher . dispatch ( payload ) ;
164
+ break ;
165
+ }
166
+ case Kind . VERIFY_THIS_SESSION :
167
+ Modal . createDialog ( SetupEncryptionDialog , { } , undefined , /* priority = */ false , /* static = */ true ) ;
168
+ break ;
169
+ case Kind . SET_UP_RECOVERY :
170
+ case Kind . KEY_STORAGE_OUT_OF_SYNC :
171
+ case Kind . KEY_STORAGE_OUT_OF_SYNC_STORE : {
172
+ const modal = Modal . createDialog (
173
+ Spinner ,
174
+ undefined ,
175
+ "mx_Dialog_spinner" ,
176
+ /* priority */ false ,
177
+ /* static */ true ,
178
+ ) ;
179
+ try {
180
+ await accessSecretStorage ( ) ;
181
+ } catch ( error ) {
182
+ onAccessSecretStorageFailed ( kind , error as Error ) ;
183
+ } finally {
184
+ modal . close ( ) ;
185
+ }
186
+ break ;
182
187
}
183
188
}
184
189
} ;
185
190
186
191
const onSecondaryClick = async ( ) : Promise < void > => {
187
- if ( kind === Kind . KEY_STORAGE_OUT_OF_SYNC ) {
188
- // Open the user settings dialog to the encryption tab and start the flow to reset encryption
189
- const payload : OpenToTabPayload = {
190
- action : Action . ViewUserSettings ,
191
- initialTabId : UserTab . Encryption ,
192
- props : { initialEncryptionState : "reset_identity_forgot" } ,
193
- } ;
194
- defaultDispatcher . dispatch ( payload ) ;
195
- } else if ( kind === Kind . TURN_ON_KEY_STORAGE ) {
196
- // The user clicked "Dismiss": offer them "Are you sure?"
197
- const modal = Modal . createDialog ( ConfirmKeyStorageOffDialog , undefined , "mx_ConfirmKeyStorageOffDialog" ) ;
198
- const [ dismissed ] = await modal . finished ;
199
- if ( dismissed ) {
192
+ switch ( kind ) {
193
+ case Kind . SET_UP_RECOVERY : {
194
+ // Record that the user doesn't want to set up recovery
200
195
const deviceListener = DeviceListener . sharedInstance ( ) ;
201
- await deviceListener . recordKeyBackupDisabled ( ) ;
196
+ await deviceListener . recordRecoveryDisabled ( ) ;
202
197
deviceListener . dismissEncryptionSetup ( ) ;
198
+ break ;
203
199
}
204
- } else if ( kind === Kind . SET_UP_RECOVERY ) {
205
- // Record that the user doesn't want to set up recovery
206
- const deviceListener = DeviceListener . sharedInstance ( ) ;
207
- await deviceListener . recordRecoveryDisabled ( ) ;
208
- deviceListener . dismissEncryptionSetup ( ) ;
209
- } else {
210
- DeviceListener . sharedInstance ( ) . dismissEncryptionSetup ( ) ;
200
+ case Kind . KEY_STORAGE_OUT_OF_SYNC : {
201
+ // Open the user settings dialog to the encryption tab and start the flow to reset encryption
202
+ const payload : OpenToTabPayload = {
203
+ action : Action . ViewUserSettings ,
204
+ initialTabId : UserTab . Encryption ,
205
+ props : { initialEncryptionState : "reset_identity_forgot" } ,
206
+ } ;
207
+ defaultDispatcher . dispatch ( payload ) ;
208
+ break ;
209
+ }
210
+ case Kind . KEY_STORAGE_OUT_OF_SYNC_STORE : {
211
+ // Open the user settings dialog to the encryption tab and start the flow to reset 4S
212
+ const payload : OpenToTabPayload = {
213
+ action : Action . ViewUserSettings ,
214
+ initialTabId : UserTab . Encryption ,
215
+ props : { initialEncryptionState : "change_recovery_key" } ,
216
+ } ;
217
+ defaultDispatcher . dispatch ( payload ) ;
218
+ break ;
219
+ }
220
+ case Kind . TURN_ON_KEY_STORAGE : {
221
+ // The user clicked "Dismiss": offer them "Are you sure?"
222
+ const modal = Modal . createDialog (
223
+ ConfirmKeyStorageOffDialog ,
224
+ undefined ,
225
+ "mx_ConfirmKeyStorageOffDialog" ,
226
+ ) ;
227
+ const [ dismissed ] = await modal . finished ;
228
+ if ( dismissed ) {
229
+ const deviceListener = DeviceListener . sharedInstance ( ) ;
230
+ await deviceListener . recordKeyBackupDisabled ( ) ;
231
+ deviceListener . dismissEncryptionSetup ( ) ;
232
+ }
233
+ break ;
234
+ }
235
+ default :
236
+ DeviceListener . sharedInstance ( ) . dismissEncryptionSetup ( ) ;
211
237
}
212
238
} ;
213
239
214
240
/**
215
241
* We tried to accessSecretStorage, which triggered us to ask for the
216
242
* recovery key, but this failed. If the user just gave up, that is fine,
217
243
* but if not, that means downloading encryption info from 4S did not fix
218
- * the problem we identified. Presumably, something is wrong with what
219
- * they have in 4S: we tell them to reset their identity.
244
+ * the problem we identified. Presumably, something is wrong with what they
245
+ * have in 4S. If we were trying to fetch secrets from 4S, we tell them to
246
+ * reset their identity, to reset everything. If we were trying to store
247
+ * secrets in 4S, or set up recovery, we tell them to change their recovery
248
+ * key, to create a new 4S that we can store the secrets in.
220
249
*/
221
- const onAccessSecretStorageFailed = ( error : Error ) : void => {
250
+ const onAccessSecretStorageFailed = (
251
+ kind : Kind . SET_UP_RECOVERY | Kind . KEY_STORAGE_OUT_OF_SYNC | Kind . KEY_STORAGE_OUT_OF_SYNC_STORE ,
252
+ error : Error ,
253
+ ) : void => {
222
254
if ( error instanceof AccessCancelledError ) {
223
255
// The user cancelled the dialog - just allow it to close
224
256
} else {
225
257
// A real error happened - jump to the reset identity tab
226
258
const payload : OpenToTabPayload = {
227
259
action : Action . ViewUserSettings ,
228
260
initialTabId : UserTab . Encryption ,
229
- props : { initialEncryptionState : "reset_identity_sync_failed" } ,
261
+ props : {
262
+ initialEncryptionState :
263
+ kind === Kind . KEY_STORAGE_OUT_OF_SYNC ? "reset_identity_sync_failed" : "change_recovery_key" ,
264
+ } ,
230
265
} ;
231
266
defaultDispatcher . dispatch ( payload ) ;
232
267
}
0 commit comments