Skip to content

Commit

Permalink
feat(extension): shared wallets feature flags are now controlled via …
Browse files Browse the repository at this point in the history
…posthog
  • Loading branch information
AngelCastilloB committed Sep 27, 2024
1 parent 368acc1 commit 8dc2acd
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 98 deletions.
6 changes: 1 addition & 5 deletions apps/browser-extension-wallet/.env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ USE_FOOR_TOPUP=true
USE_ADVANCED_RECEIVE=true
USE_POSTHOG_ANALYTICS_FOR_OPTED_OUT=false
USE_MULTI_WALLET=true
USE_SHARED_WALLET=false
USE_MESSAGE_SIGNING=true
USE_GLACIER_DROP=false

Expand Down Expand Up @@ -60,10 +59,7 @@ POSTHOG_EXCLUDED_EVENTS=
PRODUCTION_MODE_TRACKING=false

# Post Hog
POSTHOG_DEV_TOKEN_MAINNET=phc_gH96Lx5lEVXTTWEyytSdTFPDk3Xsxwi4BqG88mKObd1
POSTHOG_DEV_TOKEN_PREPROD=phc_Xlmldm6EYSfQVgB9Uxm3b2xC1noDlgFFXpF9AJ6SMfJ
POSTHOG_DEV_TOKEN_PREVIEW=phc_e8SaOOWpXpNE59TnpLumeUjWm4iv024AWjhQqU406jr
POSTHOG_DEV_TOKEN_SANCHONET=phc_OUu6sPucDu5S6skRmYbWN5Jn8TpggWTQu1Y1ETkm3xt
POSTHOG_DEV_TOKEN=phc_gH96Lx5lEVXTTWEyytSdTFPDk3Xsxwi4BqG88mKObd1

# Cardano Services
CARDANO_SERVICES_URL_MAINNET=https://dev-mainnet.lw.iog.io
Expand Down
6 changes: 1 addition & 5 deletions apps/browser-extension-wallet/.env.developerpreview
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ USE_FOOR_TOPUP=false

USE_POSTHOG_ANALYTICS_FOR_OPTED_OUT=false
USE_MULTI_WALLET=true
USE_SHARED_WALLET=false
USE_MESSAGE_SIGNING=true
USE_GLACIER_DROP=false

Expand Down Expand Up @@ -60,10 +59,7 @@ POSTHOG_EXCLUDED_EVENTS=
PRODUCTION_MODE_TRACKING=false

# Post Hog
POSTHOG_DEV_TOKEN_MAINNET=phc_gH96Lx5lEVXTTWEyytSdTFPDk3Xsxwi4BqG88mKObd1
POSTHOG_DEV_TOKEN_PREPROD=phc_Xlmldm6EYSfQVgB9Uxm3b2xC1noDlgFFXpF9AJ6SMfJ
POSTHOG_DEV_TOKEN_PREVIEW=phc_e8SaOOWpXpNE59TnpLumeUjWm4iv024AWjhQqU406jr
POSTHOG_DEV_TOKEN_SANCHONET=phc_OUu6sPucDu5S6skRmYbWN5Jn8TpggWTQu1Y1ETkm3xt
POSTHOG_DEV_TOKEN=phc_gH96Lx5lEVXTTWEyytSdTFPDk3Xsxwi4BqG88mKObd1

# Cardano Services
CARDANO_SERVICES_URL_MAINNET=https://dev-mainnet.lw.iog.io
Expand Down
5 changes: 1 addition & 4 deletions apps/browser-extension-wallet/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ POSTHOG_EXCLUDED_EVENTS=
POSTHOG_PRODUCTION_TOKEN_MAINNET=production-mainnet-token
POSTHOG_PRODUCTION_TOKEN_PREPROD=production-preprod-token
POSTHOG_PRODUCTION_TOKEN_PREVIEW=production-preview-token
POSTHOG_DEV_TOKEN_MAINNET=dev-mainnet-token
POSTHOG_DEV_TOKEN_PREPROD=dev-preprod-token
POSTHOG_DEV_TOKEN_PREVIEW=dev-preview-token
POSTHOG_DEV_TOKEN_SANCHONET=dev-sanchonet-token
POSTHOG_DEV_TOKEN=phc_gH96Lx5lEVXTTWEyytSdTFPDk3Xsxwi4BqG88mKObd1

# Cardano Services
CARDANO_SERVICES_URL_MAINNET=https://backend.live-mainnet.eks.lw.iog.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import classNames from 'classnames';
import type { AnyBip32Wallet } from '@cardano-sdk/web-extension';
import { WalletType } from '@cardano-sdk/web-extension';
import { Wallet } from '@lace/cardano';
import { usePostHogClientContext } from '@providers/PostHogClientProvider';

interface Props extends MenuProps {
isPopup?: boolean;
Expand All @@ -39,6 +40,8 @@ export const DropdownMenuOverlay: VFC<Props> = ({
sendAnalyticsEvent,
...props
}): React.ReactElement => {
const posthog = usePostHogClientContext();
const sharedWalletsEnabled = posthog?.isFeatureFlagEnabled('shared-wallets');
const [currentSection, setCurrentSection] = useState<Sections>(Sections.Main);
const { environmentName, setManageAccountsWallet, walletType, isSharedWallet } = useWalletStore();

Expand Down Expand Up @@ -85,7 +88,7 @@ export const DropdownMenuOverlay: VFC<Props> = ({
{process.env.USE_MULTI_WALLET === 'true' && (
<AddNewWalletLink isPopup={isPopup} sendAnalyticsEvent={sendAnalyticsEvent} />
)}
{process.env.USE_SHARED_WALLET === 'true' && !isSharedWallet && <AddSharedWalletLink isPopup={isPopup} />}
{sharedWalletsEnabled && !isSharedWallet && <AddSharedWalletLink isPopup={isPopup} />}
<AddressBookLink />
<SettingsLink />
<Separator />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ export const useWalletManager = (): UseWalletManager => {
deleteFromLocalStorage('userInfo');
deleteFromLocalStorage('keyAgentData');
await backgroundService.clearBackgroundStorage({
except: ['fiatPrices', 'userId', 'usePersistentUserId', 'experimentsConfiguration', 'customSubmitTxUrl']
except: ['fiatPrices', 'userId', 'usePersistentUserId', 'featureFlags', 'customSubmitTxUrl']
});
resetWalletLock();
setCardanoWallet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface BackgroundStorage {
fiatPrices?: { prices: ADAPrices; timestamp: number };
userId?: string;
usePersistentUserId?: boolean;
experimentsConfiguration?: Record<ExperimentName, string | boolean>;
featureFlags?: Record<number, Record<ExperimentName, string | boolean>>;
customSubmitTxUrl?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type PostHogMetadata = {
view: ExtensionViews;
sent_at_local: string;
posthog_project_id: number;
network: string;
} & PostHogPersonProperties;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { ExperimentName, ExperimentsConfig, FallbackConfiguration } from './types';

export const fallbackConfiguration: FallbackConfiguration = {
[ExperimentName.COMBINED_NAME_PASSWORD_ONBOARDING_SCREEN]: 'control',
export const getDefaultFeatureFlags = (): FallbackConfiguration => ({
[ExperimentName.CREATE_PAPER_WALLET]: false,
[ExperimentName.RESTORE_PAPER_WALLET]: false
};
[ExperimentName.RESTORE_PAPER_WALLET]: false,
[ExperimentName.SHARED_WALLETS]: false
});

export const experiments: ExperimentsConfig = {
[ExperimentName.COMBINED_NAME_PASSWORD_ONBOARDING_SCREEN]: {
variants: ['control', 'test'],
default: 'control'
},
[ExperimentName.CREATE_PAPER_WALLET]: {
value: false,
default: false
},
[ExperimentName.RESTORE_PAPER_WALLET]: {
value: false,
default: false
},
[ExperimentName.SHARED_WALLETS]: {
value: false,
default: false
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@ export enum ExperimentsConfigStatus {
}

export enum ExperimentName {
COMBINED_NAME_PASSWORD_ONBOARDING_SCREEN = 'combined-setup-name-password',
CREATE_PAPER_WALLET = 'create-paper-wallet',
RESTORE_PAPER_WALLET = 'restore-paper-wallet'
RESTORE_PAPER_WALLET = 'restore-paper-wallet',
SHARED_WALLETS = 'shared-wallets'
}

interface FeatureFlag {
value: boolean;
default: boolean;
}

type Variant = ReadonlyArray<string>;

interface ExperiementVariant {
variants: Variant;
default: string;
}

export type CombinedSetupNamePasswordVariants = readonly ['control', 'test'];

export type ExperimentsConfig = {
[key in ExperimentName]: FeatureFlag | ExperiementVariant;
[key in ExperimentName]: FeatureFlag;
};
export type FallbackConfiguration = Record<ExperimentName, 'control' | boolean>;
export type FallbackConfiguration = Record<ExperimentName, boolean>;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Wallet } from '@lace/cardano';
import dayjs from 'dayjs';
import { UserId } from '@lib/scripts/types';
import { ExtensionViews, PostHogAction, UserTrackingType } from '@providers/AnalyticsProvider/analyticsTracker';
import { DEV_NETWORK_ID_TO_POSTHOG_TOKEN_MAP } from '@providers/PostHogClientProvider/client/config';
import { DEV_POSTHOG_TOKEN } from '@providers/PostHogClientProvider/client/config';
import { PostHogClient } from './PostHogClient';
import { userIdServiceMock } from '@src/utils/mocks/test-helpers';
import posthog from 'posthog-js';
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('PostHogClient', () => {

await waitFor(() => expect(client).toBeDefined());
expect(posthog.init).toHaveBeenCalledWith(
expect.stringContaining(DEV_NETWORK_ID_TO_POSTHOG_TOKEN_MAP[chain.networkMagic]),
expect.stringContaining(DEV_POSTHOG_TOKEN),
expect.objectContaining({
// eslint-disable-next-line camelcase
api_host: posthogHost
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('PostHogClient', () => {
client.setChain(previewChain);
expect(posthog.set_config).toHaveBeenCalledWith(
expect.objectContaining({
token: DEV_NETWORK_ID_TO_POSTHOG_TOKEN_MAP[previewChain.networkMagic]
token: DEV_POSTHOG_TOKEN
})
);
});
Expand Down
Loading

0 comments on commit 8dc2acd

Please sign in to comment.