Skip to content

Commit

Permalink
harmonize
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Jan 17, 2024
1 parent a85c06e commit 66e0055
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
10 changes: 8 additions & 2 deletions src/script/E2EIdentity/DelayTimer/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import {EnrollmentConfig} from '../E2EIdentityEnrollment';
import {MLSStatuses, WireIdentity} from '../E2EIdentityVerification';
import {MLSStatuses, WireIdentity, isFreshMLSSelfClient} from '../E2EIdentityVerification';

/* eslint-disable no-magic-numbers */

Expand Down Expand Up @@ -54,7 +54,13 @@ export function getDelayTime(gracePeriodInMs: number): number {
return 0;
}

export function shouldEnableSoftLock(enrollmentConfig: EnrollmentConfig, identity?: WireIdentity): boolean {
export async function shouldEnableSoftLock(
enrollmentConfig: EnrollmentConfig,
identity?: WireIdentity,
): Promise<boolean> {
if (await isFreshMLSSelfClient()) {
return true;
}
if (!enrollmentConfig.timer.isSnoozeTimeAvailable()) {
// The user has used up the entire grace period or has a fresh new client, he now needs to enroll
return true;
Expand Down
15 changes: 6 additions & 9 deletions src/script/E2EIdentity/E2EIdentityEnrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
getActiveWireIdentity,
MLSStatuses,
WireIdentity,
isFreshMLSSelfClient,
} from './E2EIdentityVerification';
import {getModalOptions, ModalType} from './Modals';
import {OIDCService} from './OIDCService';
Expand Down Expand Up @@ -307,7 +306,8 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
// clear the oidc service progress/data and successful enrolment
await this.cleanUp(false);

return this.showSuccessMessage(isCertificateRenewal);
await this.showSuccessMessage(isCertificateRenewal);
this.emit('identityUpdated', {enrollmentConfig: this.config!});
} catch (error) {
this.currentStep = E2EIHandlerStep.ERROR;

Expand Down Expand Up @@ -365,7 +365,7 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
// Clear the e2e identity progress
this.coreE2EIService.clearAllProgress();

const isSoftLockEnabled = shouldEnableSoftLock(this.config!);
const isSoftLockEnabled = await shouldEnableSoftLock(this.config!);

return new Promise<void>(resolve => {
const {modalOptions, modalType} = getModalOptions({
Expand Down Expand Up @@ -411,11 +411,9 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
}
}

private async showEnrollmentModal(
modalType: ModalType.ENROLL | ModalType.CERTIFICATE_RENEWAL,
disableSnooze: boolean,
): Promise<void> {
private async showEnrollmentModal(modalType: ModalType.ENROLL | ModalType.CERTIFICATE_RENEWAL): Promise<void> {
// Show the modal with the provided modal type
const disableSnooze = await shouldEnableSoftLock(this.config!);
return new Promise<void>(resolve => {
const {modalOptions, modalType: determinedModalType} = getModalOptions({
hideSecondary: disableSnooze,
Expand Down Expand Up @@ -467,8 +465,7 @@ export class E2EIHandler extends TypedEventEmitter<Events> {

// If the timer is not active, show the notification modal
if (this.config && !this.config.timer.isDelayTimerActive()) {
const isFreshDevice = await isFreshMLSSelfClient();
return this.showEnrollmentModal(modalType, isFreshDevice);
return this.showEnrollmentModal(modalType);
}
}
}
4 changes: 2 additions & 2 deletions src/script/hooks/useAppSoftLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export function useAppSoftLock(callingRepository: CallingRepository, notificatio
const [softLockEnabled, setSoftLockEnabled] = useState(false);

const handleSoftLockActivation = useCallback(
({enrollmentConfig, identity}: {enrollmentConfig: EnrollmentConfig; identity?: WireIdentity}) => {
const isSoftLockEnabled = shouldEnableSoftLock(enrollmentConfig, identity);
async ({enrollmentConfig, identity}: {enrollmentConfig: EnrollmentConfig; identity?: WireIdentity}) => {
const isSoftLockEnabled = await shouldEnableSoftLock(enrollmentConfig, identity);

setSoftLockEnabled(isSoftLockEnabled);
callingRepository.setSoftLock(isSoftLockEnabled);
Expand Down

0 comments on commit 66e0055

Please sign in to comment.