Skip to content

Commit

Permalink
fix: update encryption status after a passcode operation completes
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Aug 26, 2020
1 parent 6483ad3 commit 3ac8630
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions app/assets/javascripts/directives/views/accountMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class AccountMenuCtrl extends PureViewCtrl<{}, AccountMenuState> {
this.setState(this.refreshedCredentialState());
this.loadHost();
this.reloadAutoLockInterval();
this.loadBackupsAvailability();
this.refreshEncryptionStatus();
}

refreshedCredentialState() {
Expand Down Expand Up @@ -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
}
});
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 3ac8630

Please sign in to comment.