From d915bd8c86b32bb0bfc13cf389a76965b4d1d85a Mon Sep 17 00:00:00 2001 From: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com> Date: Tue, 30 Jul 2024 14:41:10 -0400 Subject: [PATCH] Auth/PM-10069 - Unauthenticated UI Extension Refresh Swap Utility (#10327) * PM-3515 - Lock component - remove isUnlocked check on lock comp load b/c lock guard should cover all cases with its existing logic for all clients. * PM-9685 - Add new feature flag * PM-10069 - ExtensionRefreshRouteUtils - Add unauthExtensionRefreshSwap helper * Restore lock component --- .../popup/extension-refresh-route-utils.ts | 24 +++++++++++++++++++ libs/common/src/enums/feature-flag.enum.ts | 2 ++ 2 files changed, 26 insertions(+) diff --git a/apps/browser/src/popup/extension-refresh-route-utils.ts b/apps/browser/src/popup/extension-refresh-route-utils.ts index 3c2ca33f86e..6960b650fa7 100644 --- a/apps/browser/src/popup/extension-refresh-route-utils.ts +++ b/apps/browser/src/popup/extension-refresh-route-utils.ts @@ -27,6 +27,30 @@ export function extensionRefreshSwap( ); } +/** + * Helper function to swap between two components based on the UnauthenticatedExtensionUIRefresh feature flag. + * We need this because the auth teams's authenticated UI will be refreshed as part of the MVP but the + * unauthenticated UIs will not necessarily make the cut. + * @param defaultComponent - The current non-refreshed component to render. + * @param refreshedComponent - The new refreshed component to render. + * @param options - The shared route options to apply to both components. + */ +export function unauthExtensionRefreshSwap( + defaultComponent: Type, + refreshedComponent: Type, + options: Route, +): Routes { + return componentRouteSwap( + defaultComponent, + refreshedComponent, + async () => { + const configService = inject(ConfigService); + return configService.getFeatureFlag(FeatureFlag.UnauthenticatedExtensionUIRefresh); + }, + options, + ); +} + /** * Helper function to redirect to a new URL based on the ExtensionRefresh feature flag. * @param redirectUrl - The URL to redirect to if the ExtensionRefresh flag is enabled. diff --git a/libs/common/src/enums/feature-flag.enum.ts b/libs/common/src/enums/feature-flag.enum.ts index 08c8c35df3c..f077e5a554f 100644 --- a/libs/common/src/enums/feature-flag.enum.ts +++ b/libs/common/src/enums/feature-flag.enum.ts @@ -27,6 +27,7 @@ export enum FeatureFlag { AC2828_ProviderPortalMembersPage = "AC-2828_provider-portal-members-page", DeviceTrustLogging = "pm-8285-device-trust-logging", AuthenticatorTwoFactorToken = "authenticator-2fa-token", + UnauthenticatedExtensionUIRefresh = "unauth-ui-refresh", EnableUpgradePasswordManagerSub = "AC-2708-upgrade-password-manager-sub", } @@ -65,6 +66,7 @@ export const DefaultFeatureFlagValue = { [FeatureFlag.AC2828_ProviderPortalMembersPage]: FALSE, [FeatureFlag.DeviceTrustLogging]: FALSE, [FeatureFlag.AuthenticatorTwoFactorToken]: FALSE, + [FeatureFlag.UnauthenticatedExtensionUIRefresh]: FALSE, [FeatureFlag.EnableUpgradePasswordManagerSub]: FALSE, } satisfies Record;