Skip to content

Commit

Permalink
feat: disable request diagnostics on install
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Hendrickson authored and pete-watters committed Apr 25, 2024
1 parent 12e229d commit e6cd821
Show file tree
Hide file tree
Showing 17 changed files with 13 additions and 185 deletions.
7 changes: 2 additions & 5 deletions src/app/common/hooks/analytics/use-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { analytics, initAnalytics } from '@shared/utils/analytics';
import { flow, origin } from '@app/common/initial-search-params';
import { useWalletType } from '@app/common/use-wallet-type';
import { useCurrentNetworkState } from '@app/store/networks/networks.hooks';
import { useHasUserExplicitlyDeclinedAnalytics } from '@app/store/settings/settings.selectors';

const IGNORED_PATH_REGEXPS = [/^\/$/];

Expand All @@ -27,12 +26,10 @@ function isHiroApiUrl(url: string) {
}

export function useInitalizeAnalytics() {
const hasUserDeclinedAnalytics = useHasUserExplicitlyDeclinedAnalytics();

useEffect(() => {
if (hasUserDeclinedAnalytics || !SEGMENT_WRITE_KEY || IS_TEST_ENV) return;
if (!SEGMENT_WRITE_KEY || IS_TEST_ENV) return;
initAnalytics();
}, [hasUserDeclinedAnalytics]);
}, []);
}

export function useAnalytics() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/container/utils/route-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function isHomePage(pathname: RouteUrls) {
}

export function isLandingPage(pathname: RouteUrls) {
return pathname === RouteUrls.RequestDiagnostics || pathname.match(RouteUrls.Onboarding); // need to match get-started/ledger
return pathname.match(RouteUrls.Onboarding); // need to match get-started/ledger
}

function isOnboardingPage(pathname: RouteUrls) {
Expand Down

This file was deleted.

45 changes: 0 additions & 45 deletions src/app/pages/onboarding/allow-diagnostics/allow-diagnostics.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/app/pages/onboarding/welcome/welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import { useOnboardingState } from '@app/common/hooks/auth/use-onboarding-state'
import { useKeyActions } from '@app/common/hooks/use-key-actions';
import { doesBrowserSupportWebUsbApi, isPopupMode, whenPageMode } from '@app/common/utils';
import { openIndexPageInNewTab } from '@app/common/utils/open-in-new-tab';
import { useHasUserRespondedToAnalyticsConsent } from '@app/store/settings/settings.selectors';
import { WelcomeLayout } from '@app/ui/pages/welcome.layout';

export function WelcomePage() {
const hasResponded = useHasUserRespondedToAnalyticsConsent();
const navigate = useNavigate();
const { decodedAuthRequest } = useOnboardingState();
const analytics = useAnalytics();
Expand All @@ -39,7 +37,6 @@ export function WelcomePage() {
}, [keyActions, analytics, decodedAuthRequest, navigate]);

useEffect(() => {
if (!hasResponded) navigate(RouteUrls.RequestDiagnostics);
return () => setIsGeneratingWallet(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
2 changes: 0 additions & 2 deletions src/app/routes/app-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { ChooseAccount } from '@app/pages/choose-account/choose-account';
import { ChooseCryptoAssetToFund } from '@app/pages/fund/choose-asset-to-fund/choose-asset-to-fund';
import { FundPage } from '@app/pages/fund/fund';
import { Home } from '@app/pages/home/home';
import { AllowDiagnosticsModal } from '@app/pages/onboarding/allow-diagnostics/allow-diagnostics';
import { BackUpSecretKeyPage } from '@app/pages/onboarding/back-up-secret-key/back-up-secret-key';
import { SignIn } from '@app/pages/onboarding/sign-in/sign-in';
import { WelcomePage } from '@app/pages/onboarding/welcome/welcome';
Expand Down Expand Up @@ -129,7 +128,6 @@ function useAppRoutes() {
</OnboardingGate>
}
>
<Route path={RouteUrls.RequestDiagnostics} element={<AllowDiagnosticsModal />} />
<Route path={RouteUrls.ConnectLedgerStart} element={<ConnectLedgerStart />} />
<Route path={RouteUrls.LedgerUnsupportedBrowser} element={<UnsupportedBrowserLayout />} />

Expand Down
18 changes: 0 additions & 18 deletions src/app/store/settings/settings.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@ export function useUserSelectedTheme() {
return useSelector(selectUserSelectedTheme);
}

const selectHasUserExplicitlyDeclinedAnalytics = createSelector(
selectSettings,
state => state.hasAllowedAnalytics === false
);

export function useHasUserExplicitlyDeclinedAnalytics() {
return useSelector(selectHasUserExplicitlyDeclinedAnalytics);
}

const selectHasUserRespondedToAnalyticsConsent = createSelector(
selectSettings,
state => state.hasAllowedAnalytics !== null
);

export function useHasUserRespondedToAnalyticsConsent() {
return useSelector(selectHasUserRespondedToAnalyticsConsent);
}

const selectDismissedMessageIds = createSelector(
selectSettings,
state => state.dismissedMessages ?? []
Expand Down
6 changes: 0 additions & 6 deletions src/app/store/settings/settings.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import { PayloadAction, createSlice } from '@reduxjs/toolkit';

import { UserSelectedTheme } from '@app/common/theme-provider';

type HasAcceptedAnalytics = null | boolean;
interface InitialState {
userSelectedTheme: UserSelectedTheme;
hasAllowedAnalytics: HasAcceptedAnalytics;
dismissedMessages: string[];
}

const initialState: InitialState = {
userSelectedTheme: 'system',
hasAllowedAnalytics: null,
dismissedMessages: [],
};

Expand All @@ -22,9 +19,6 @@ export const settingsSlice = createSlice({
setUserSelectedTheme(state, action: PayloadAction<UserSelectedTheme>) {
state.userSelectedTheme = action.payload;
},
setHasAllowedAnalytics(state, action: PayloadAction<boolean>) {
state.hasAllowedAnalytics = action.payload;
},
messageDismissed(state, action: PayloadAction<string>) {
if (!Array.isArray(state.dismissedMessages)) state.dismissedMessages = [];
state.dismissedMessages = [...state.dismissedMessages, action.payload];
Expand Down
6 changes: 5 additions & 1 deletion src/app/ui/components/containers/dialog/dialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export function Dialog() {
return (
<>
<Button onClick={() => setIsShowing(!isShowing)}>Open</Button>
<Component isShowing={isShowing} onClose={() => setIsShowing(false)}>
<Component
header={<h1>Some Header</h1>}
isShowing={isShowing}
onClose={() => setIsShowing(false)}
>
<h1>Some Dialog</h1>
</Component>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/components/containers/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface DialogProps {
interface RadixDialogProps extends DialogProps {
children: ReactNode;
footer?: ReactNode;
header?: ReactElement<any, string | JSXElementConstructor<any>>;
header: ReactElement<any, string | JSXElementConstructor<any>>;
onGoBack?(): void;
wrapChildren?: boolean;
}
Expand Down
3 changes: 1 addition & 2 deletions src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// https://developer.chrome.com/docs/extensions/mv3/architecture-overview/#background_script
import { logger } from '@shared/logger';
import { CONTENT_SCRIPT_PORT, type LegacyMessageFromContentScript } from '@shared/message-types';
import { RouteUrls } from '@shared/route-urls';
import { WalletRequests } from '@shared/rpc/rpc-methods';
import { warnUsersAboutDevToolsDangers } from '@shared/utils/dev-tools-warning-log';

Expand All @@ -21,7 +20,7 @@ warnUsersAboutDevToolsDangers();
chrome.runtime.onInstalled.addListener(async details => {
if (details.reason === 'install' && process.env.WALLET_ENVIRONMENT !== 'testing') {
await chrome.tabs.create({
url: chrome.runtime.getURL(`index.html#${RouteUrls.RequestDiagnostics}`),
url: chrome.runtime.getURL(`index.html`),
});
}
});
Expand Down
1 change: 0 additions & 1 deletion src/shared/route-urls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export enum RouteUrls {
// Onboarding routes
RequestDiagnostics = '/get-started/request-diagnostics',
Onboarding = '/get-started',
BackUpSecretKey = '/back-up-secret-key',
SetPassword = '/set-password',
Expand Down
9 changes: 0 additions & 9 deletions src/shared/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ import { base58 } from '@scure/base';
import { AnalyticsBrowser } from '@segment/analytics-next';
import * as Sentry from '@sentry/react';
import { token } from 'leather-styles/tokens';
import { getStoredState } from 'redux-persist';

import {
IS_TEST_ENV,
SEGMENT_WRITE_KEY,
SENTRY_DSN,
WALLET_ENVIRONMENT,
} from '@shared/environment';
import { persistConfig } from '@shared/storage/redux-pesist';

import type { RootState } from '@app/store';

export const analytics = new AnalyticsBrowser();

Expand Down Expand Up @@ -110,11 +106,6 @@ export function initSentry() {
environment: WALLET_ENVIRONMENT,
autoSessionTracking: false,
async beforeSend(event) {
const state = (await getStoredState(persistConfig)) as RootState;
const hasAllowedAnalytics = state.settings.hasAllowedAnalytics;

if (!hasAllowedAnalytics) return null;

delete event.user?.ip_address;
delete event.extra?.ip_address;

Expand Down
10 changes: 1 addition & 9 deletions tests/page-object-models/onboarding.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const testSoftwareAccountDefaultWalletState = {
},
settings: {
userSelectedTheme: 'system',
hasAllowedAnalytics: false,
dismissedMessages: [],
},
_persist: { version: 2, rehydrated: true },
Expand Down Expand Up @@ -225,18 +224,13 @@ export function makeLedgerTestAccountWalletState(keysToInclude: SupportedBlockch
'Explore apps': 0,
},
},
settings: { dismissedMessages: [], hasAllowedAnalytics: false, userSelectedTheme: 'system' },
settings: { dismissedMessages: [], userSelectedTheme: 'system' },
};
}

export class OnboardingPage {
constructor(readonly page: Page) {}

async denyAnalytics() {
await this.page.getByTestId(OnboardingSelectors.DenyAnalyticsBtn).click();
await this.page.waitForURL('**' + RouteUrls.Onboarding);
}

async setPassword() {
await this.page.waitForURL('**' + RouteUrls.SetPassword);
await this.page.getByTestId(OnboardingSelectors.NewPasswordInput).fill(TEST_PASSWORD);
Expand All @@ -245,14 +239,12 @@ export class OnboardingPage {
}

async signUpNewUser() {
await this.denyAnalytics();
await this.page.getByTestId(OnboardingSelectors.SignUpBtn).click();
await this.page.waitForURL('**' + RouteUrls.BackUpSecretKey);
await this.page.getByTestId(OnboardingSelectors.BackUpSecretKeyBtn).click();
await this.setPassword();
}
async initiateSignIn() {
await this.denyAnalytics();
await this.page.getByTestId(OnboardingSelectors.SignInLink).click();
}

Expand Down
2 changes: 0 additions & 2 deletions tests/selectors/onboarding.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export enum OnboardingSelectors {
AllowAnalyticsBtn = 'allow-analytics-btn',
BackUpSecretKeyBtn = 'back-up-secret-key-btn',
DenyAnalyticsBtn = 'deny-analytics-btn',
LogoRouteToHome = 'logo-route-to-home',
NewPasswordInput = 'set-or-enter-password-input',
NoAssetsFundAccountLink = 'no-assets-fund-account-link',
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/settings/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test.describe('Settings menu', () => {

test('that menu item can perform sign out', async ({ homePage, onboardingPage }) => {
await homePage.signOut();
const button = onboardingPage.page.getByTestId(OnboardingSelectors.DenyAnalyticsBtn);
const button = onboardingPage.page.getByTestId(OnboardingSelectors.SignUpBtn);
test.expect(button).toBeTruthy();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/specs/store-migrations/store-migrations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test.describe('Store migrations', () => {

test.describe('Migration 0 --> 2', () => {
const previousSerializedState =
'{"analytics":"{\\"hasStxDeposits\\":{\\"1\\":true,\\"2147483648\\":true}}","chains":"{\\"stx\\":{\\"default\\":{\\"highestAccountIndex\\":16,\\"currentAccountIndex\\":0}}}","keys":"{\\"ids\\":[\\"default\\"],\\"entities\\":{\\"default\\":{\\"type\\":\\"software\\",\\"id\\":\\"default\\",\\"salt\\":\\"c4cccf33166051f7704cd877a2f03f93\\",\\"encryptedSecretKey\\":\\"b7f516798e7160eca15c50b62e588698937f8ecf3930efc42baa690ddc0c7a51b74e3e4b129859274ed272652bc47651c6b6effbddf4d72a3eb9d2ea657b64a833c9bdccb562e45d94f0cc1366154072f12d35290566a99a6f952cd234ca9259\\"}}}","networks":"{\\"ids\\":[],\\"entities\\":{},\\"currentNetworkId\\":\\"mainnet\\"}","onboarding":"{\\"hideSteps\\":true,\\"stepsStatus\\":{\\"Back up secret key\\":1,\\"Add some funds\\":0,\\"Explore apps\\":0,\\"Buy an NFT\\":0}}","settings":"{\\"userSelectedTheme\\":\\"system\\",\\"hasAllowedAnalytics\\":false,\\"dismissedMessages\\":[]}","_persist":"{\\"version\\":1,\\"rehydrated\\":true}"}';
'{"analytics":"{\\"hasStxDeposits\\":{\\"1\\":true,\\"2147483648\\":true}}","chains":"{\\"stx\\":{\\"default\\":{\\"highestAccountIndex\\":16,\\"currentAccountIndex\\":0}}}","keys":"{\\"ids\\":[\\"default\\"],\\"entities\\":{\\"default\\":{\\"type\\":\\"software\\",\\"id\\":\\"default\\",\\"salt\\":\\"c4cccf33166051f7704cd877a2f03f93\\",\\"encryptedSecretKey\\":\\"b7f516798e7160eca15c50b62e588698937f8ecf3930efc42baa690ddc0c7a51b74e3e4b129859274ed272652bc47651c6b6effbddf4d72a3eb9d2ea657b64a833c9bdccb562e45d94f0cc1366154072f12d35290566a99a6f952cd234ca9259\\"}}}","networks":"{\\"ids\\":[],\\"entities\\":{},\\"currentNetworkId\\":\\"mainnet\\"}","onboarding":"{\\"hideSteps\\":true,\\"stepsStatus\\":{\\"Back up secret key\\":1,\\"Add some funds\\":0,\\"Explore apps\\":0,\\"Buy an NFT\\":0}}","settings":"{\\"userSelectedTheme\\":\\"system\\",\\"dismissedMessages\\":[]}","_persist":"{\\"version\\":1,\\"rehydrated\\":true}"}';

test('that the app detects old store format', async ({ extensionId, globalPage }) => {
const { page } = globalPage;
Expand Down

0 comments on commit e6cd821

Please sign in to comment.