From 3ac863098f5f54eee2e9895e8f2b8578ebc6f9ef Mon Sep 17 00:00:00 2001 From: Baptiste Grob <60621355+baptiste-grob@users.noreply.github.com> Date: Wed, 26 Aug 2020 18:34:15 +0200 Subject: [PATCH] fix: update encryption status after a passcode operation completes --- .../directives/views/accountMenu.ts | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/directives/views/accountMenu.ts b/app/assets/javascripts/directives/views/accountMenu.ts index 27c3f6026..1cc34851f 100644 --- a/app/assets/javascripts/directives/views/accountMenu.ts +++ b/app/assets/javascripts/directives/views/accountMenu.ts @@ -109,7 +109,7 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> { this.setState(this.refreshedCredentialState()); this.loadHost(); this.reloadAutoLockInterval(); - this.loadBackupsAvailability(); + this.refreshEncryptionStatus(); } refreshedCredentialState() { @@ -148,27 +148,21 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> { this.application!.setHost(url); } - async loadBackupsAvailability() { - const hasUser = !isNullOrUndefined(this.application!.getUser()); + refreshEncryptionStatus() { + const hasUser = this.application!.hasAccount(); const hasPasscode = this.application!.hasPasscode(); - const encryptedAvailable = hasUser || hasPasscode; - - function encryptionStatusString() { - if (hasUser) { - return STRING_E2E_ENABLED; - } else if (hasPasscode) { - return STRING_LOCAL_ENC_ENABLED; - } else { - return STRING_ENC_NOT_ENABLED; - } - } + const encryptionEnabled = hasUser || hasPasscode; this.setState({ - encryptionStatusString: encryptionStatusString(), - encryptionEnabled: encryptedAvailable, + encryptionStatusString: hasUser + ? STRING_E2E_ENABLED + : hasPasscode + ? STRING_LOCAL_ENC_ENABLED + : STRING_ENC_NOT_ENABLED, + encryptionEnabled, mutable: { ...this.getState().mutable, - backupEncrypted: encryptedAvailable + backupEncrypted: encryptionEnabled } }); } @@ -515,18 +509,19 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> { return; } - preventRefreshing(STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE, async () => { + await preventRefreshing(STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE, async () => { if (this.application!.hasPasscode()) { await this.application!.changePasscode(passcode); } else { await this.application!.setPasscode(passcode); } - this.setFormDataState({ - passcode: undefined, - confirmPasscode: undefined, - showPasscodeForm: false - }); }); + this.setFormDataState({ + passcode: undefined, + confirmPasscode: undefined, + showPasscodeForm: false + }); + this.refreshEncryptionStatus(); } async changePasscodePressed() { @@ -558,9 +553,10 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> { text: message, confirmButtonStyle: 'danger' })) { - preventRefreshing(STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_REMOVAL, async () => { + await preventRefreshing(STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_REMOVAL, async () => { await this.application!.removePasscode(); }); + this.refreshEncryptionStatus(); } }; const needsPrivilege = await this.application!.privilegesService!.actionRequiresPrivilege(