Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-14219] Add service for new device verification notice #11988

Merged
merged 6 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libs/common/src/platform/state/state-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,7 @@ export const PREMIUM_BANNER_DISK_LOCAL = new StateDefinition("premiumBannerRepro
});
export const BANNERS_DISMISSED_DISK = new StateDefinition("bannersDismissed", "disk");
export const VAULT_BROWSER_UI_ONBOARDING = new StateDefinition("vaultBrowserUiOnboarding", "disk");
export const NEW_DEVICE_VERIFICATION_NOTICE = new StateDefinition(
"newDeviceVerificationNotice",
"disk",
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";

import {
ActiveUserState,
StateProvider,
UserKeyDefinition,
NEW_DEVICE_VERIFICATION_NOTICE,
} from "@bitwarden/common/platform/state";

export type NewDeviceVerificationNotice = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐ŸŽจ We should add some documentation on what these values represent / how they're expected to be used.

last_dismissal: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โ“ What type of values will last_dismissal hold? Is it a date?

permanent_dismissal: boolean;
};

const NEW_DEVICE_VERIFICATION_NOTICE_KEY = new UserKeyDefinition<NewDeviceVerificationNotice>(
NEW_DEVICE_VERIFICATION_NOTICE,
"noticeState",
{
deserializer: (jsonData) => jsonData,
clearOn: [],
},
);

@Injectable()
export class NewDeviceVerificationNoticeService {
private noticeState: ActiveUserState<NewDeviceVerificationNotice>;
noticeState$: Observable<NewDeviceVerificationNotice>;

constructor(private stateProvider: StateProvider) {
this.noticeState = this.stateProvider.getActive(NEW_DEVICE_VERIFICATION_NOTICE_KEY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โš ๏ธ We're moving away from ActiveUserState and should require a userId for service methods/state. Something like

noticeState$(userId: userId) {
  return this.stateProvider.getUser(userId, NEW_DEVICE_VERIFICATION_NOTICE_KEY).state$;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can reference this

this.noticeState$ = this.noticeState.state$;
}

async updateNewDeviceVerificationNoticeState(
newState: NewDeviceVerificationNotice,
): Promise<void> {
await this.noticeState.update(() => {
return { ...newState };
});
}
}
Loading