Skip to content

Commit

Permalink
cherry-pick 9ac1488
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioAslau authored and sethkfman committed Oct 16, 2024
1 parent e7ae695 commit edb5b29
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 27 deletions.
11 changes: 10 additions & 1 deletion app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ import { SnapsExecutionWebView } from '../../../lib/snaps';
import OptionsSheet from '../../UI/SelectOptionSheet/OptionsSheet';
import FoxLoader from '../../../components/UI/FoxLoader';
import { AppStateEventProcessor } from '../../../core/AppStateEventListener';
import { trace, TraceName, TraceOperation } from '../../../util/trace';

const clearStackNavigatorOptions = {
headerShown: false,
Expand Down Expand Up @@ -335,7 +336,15 @@ const App = (props) => {
setOnboarded(!!existingUser);
try {
if (existingUser) {
await Authentication.appTriggeredAuth();
await trace(
{
name: TraceName.BiometricAuthentication,
op: TraceOperation.BiometricAuthentication,
},
async () => {
await Authentication.appTriggeredAuth();
},
);
// we need to reset the navigator here so that the user cannot go back to the login screen
navigator.reset({ routes: [{ name: Routes.ONBOARDING.HOME_NAV }] });
} else {
Expand Down
18 changes: 14 additions & 4 deletions app/components/Views/LockScreen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import Routes from '../../../constants/navigation/Routes';
import { CommonActions } from '@react-navigation/native';
import trackErrorAsAnalytics from '../../../util/metrics/TrackError/trackErrorAsAnalytics';
import { trace, TraceName, TraceOperation } from '../../../util/trace';

const LOGO_SIZE = 175;
const createStyles = (colors) =>
Expand Down Expand Up @@ -134,10 +135,19 @@ class LockScreen extends PureComponent {
// Retrieve the credentials
Logger.log('Lockscreen::unlockKeychain - getting credentials');

await Authentication.appTriggeredAuth({
bioStateMachineId,
disableAutoLogout: true,
});
await trace(
{
name: TraceName.BiometricAuthentication,
op: TraceOperation.BiometricAuthentication,
},
async () => {
await Authentication.appTriggeredAuth({
bioStateMachineId,
disableAutoLogout: true,
});
},
);

this.setState({ ready: true });
Logger.log('Lockscreen::unlockKeychain - state: ready');
} catch (error) {
Expand Down
31 changes: 29 additions & 2 deletions app/components/Views/Login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ import { LoginViewSelectors } from '../../../../e2e/selectors/LoginView.selector
import { withMetricsAwareness } from '../../../components/hooks/useMetrics';
import trackErrorAsAnalytics from '../../../util/metrics/TrackError/trackErrorAsAnalytics';
import { downloadStateLogs } from '../../../util/logs';
import {
trace,
endTrace,
TraceName,
TraceOperation,
} from '../../../util/trace';

const deviceHeight = Device.getDeviceHeight();
const breakPoint = deviceHeight < 700;
Expand Down Expand Up @@ -245,6 +251,10 @@ class Login extends PureComponent {
fieldRef = React.createRef();

async componentDidMount() {
trace({
name: TraceName.LoginToPasswordEntry,
op: TraceOperation.LoginToPasswordEntry,
});
this.props.metrics.trackEvent(MetaMetricsEvents.LOGIN_SCREEN_VIEWED);
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);

Expand Down Expand Up @@ -368,7 +378,15 @@ class Login extends PureComponent {
);

try {
await Authentication.userEntryAuth(password, authType);
await trace(
{
name: TraceName.AuthenticateUser,
op: TraceOperation.AuthenticateUser,
},
async () => {
await Authentication.userEntryAuth(password, authType);
},
);

Keyboard.dismiss();

Expand Down Expand Up @@ -436,7 +454,15 @@ class Login extends PureComponent {
const { current: field } = this.fieldRef;
field?.blur();
try {
await Authentication.appTriggeredAuth();
await trace(
{
name: TraceName.BiometricAuthentication,
op: TraceOperation.BiometricAuthentication,
},
async () => {
await Authentication.appTriggeredAuth();
},
);
const onboardingWizard = await StorageWrapper.getItem(ONBOARDING_WIZARD);
if (!onboardingWizard) this.props.setOnboardingWizardStep(1);
this.props.navigation.replace(Routes.ONBOARDING.HOME_NAV);
Expand All @@ -455,6 +481,7 @@ class Login extends PureComponent {
};

triggerLogIn = () => {
endTrace({ name: TraceName.LoginToPasswordEntry });
this.onLogin();
};

Expand Down
38 changes: 24 additions & 14 deletions app/components/Views/Onboarding/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { OnboardingSelectorIDs } from '../../../../e2e/selectors/Onboarding/Onbo
import Routes from '../../../constants/navigation/Routes';
import { selectAccounts } from '../../../selectors/accountTrackerController';
import trackOnboarding from '../../../util/metrics/TrackOnboarding/trackOnboarding';
import { trace, TraceName, TraceOperation } from '../../../util/trace';

const createStyles = (colors) =>
StyleSheet.create({
Expand Down Expand Up @@ -275,24 +276,33 @@ class Onboarding extends PureComponent {
};

onPressCreate = () => {
const action = async () => {
const { metrics } = this.props;
if (metrics.isEnabled()) {
this.props.navigation.navigate('ChoosePassword', {
[PREVIOUS_SCREEN]: ONBOARDING,
});
this.track(MetaMetricsEvents.WALLET_SETUP_STARTED);
} else {
this.props.navigation.navigate('OptinMetrics', {
onContinue: () => {
this.props.navigation.replace('ChoosePassword', {
const action = () => {
trace(
{
name: TraceName.CreateNewWalletToChoosePassword,
op: TraceOperation.CreateNewWalletToChoosePassword,
},
() => {
const { metrics } = this.props;
if (metrics.isEnabled()) {
this.props.navigation.navigate('ChoosePassword', {
[PREVIOUS_SCREEN]: ONBOARDING,
});
this.track(MetaMetricsEvents.WALLET_SETUP_STARTED);
},
});
}
} else {
this.props.navigation.navigate('OptinMetrics', {
onContinue: () => {
this.props.navigation.replace('ChoosePassword', {
[PREVIOUS_SCREEN]: ONBOARDING,
});
this.track(MetaMetricsEvents.WALLET_SETUP_STARTED);
},
});
}
},
);
};

this.handleExistingUser(action);
};

Expand Down
1 change: 1 addition & 0 deletions app/components/Views/Wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import {
} from '../../../selectors/notifications';
import { ButtonVariants } from '../../../component-library/components/Buttons/Button';
import { useListNotifications } from '../../../util/notifications/hooks/useNotifications';

const createStyles = ({ colors, typography }: Theme) =>
StyleSheet.create({
base: {
Expand Down
58 changes: 54 additions & 4 deletions app/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { Authentication } from '../core';
import LockManagerService from '../core/LockManagerService';
import ReadOnlyNetworkStore from '../util/test/network-store';
import { isE2E } from '../util/test/utils';
import { trace, endTrace, TraceName, TraceOperation } from '../util/trace';
import StorageWrapper from './storage-wrapper';

import thunk from 'redux-thunk';

import persistConfig from './persistConfig';
Expand All @@ -24,7 +27,7 @@ const pReducer = persistReducer<RootState, any>(persistConfig, rootReducer);
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any, import/no-mutable-exports
let store: Store<RootState, any>, persistor;
const createStoreAndPersistor = async () => {
const createStoreAndPersistor = async (appStartTime: number) => {
// Obtain the initial state from ReadOnlyNetworkStore for E2E tests.
const initialState = isE2E
? await ReadOnlyNetworkStore.getState()
Expand All @@ -46,6 +49,24 @@ const createStoreAndPersistor = async () => {
middlewares.push(createReduxFlipperDebugger());
}

const jsStartTime = performance.now();

trace({
name: TraceName.LoadScripts,
op: TraceOperation.LoadScripts,
startTime: appStartTime,
});

endTrace({
name: TraceName.LoadScripts,
timestamp: appStartTime + jsStartTime,
});

trace({
name: TraceName.CreateStore,
op: TraceOperation.CreateStore,
});

store = configureStore({
reducer: pReducer,
middleware: middlewares,
Expand All @@ -54,10 +75,19 @@ const createStoreAndPersistor = async () => {

sagaMiddleware.run(rootSaga);

endTrace({ name: TraceName.CreateStore });

trace({
name: TraceName.StorageRehydration,
op: TraceOperation.StorageRehydration,
});

/**
* Initialize services after persist is completed
*/
const onPersistComplete = () => {
const onPersistComplete = async () => {
endTrace({ name: TraceName.StorageRehydration });

/**
* EngineService.initalizeEngine(store) with SES/lockdown:
* Requires ethjs nested patches (lib->src)
Expand All @@ -73,6 +103,7 @@ const createStoreAndPersistor = async () => {
* - TypeError: undefined is not an object (evaluating 'TokenListController.tokenList')
* - V8: SES_UNHANDLED_REJECTION
*/

store.dispatch({
type: 'TOGGLE_BASIC_FUNCTIONALITY',
basicFunctionalityEnabled:
Expand All @@ -83,7 +114,17 @@ const createStoreAndPersistor = async () => {
store.dispatch({
type: 'FETCH_FEATURE_FLAGS',
});
EngineService.initalizeEngine(store);

await trace(
{
name: TraceName.EngineInitialization,
op: TraceOperation.EngineInitialization,
},
() => {
EngineService.initalizeEngine(store);
},
);

Authentication.init(store);
AppStateEventProcessor.init(store);
LockManagerService.init(store);
Expand All @@ -93,7 +134,16 @@ const createStoreAndPersistor = async () => {
};

(async () => {
await createStoreAndPersistor();
const appStartTime = await StorageWrapper.getItem('appStartTime');

await trace(
{
name: TraceName.UIStartup,
op: TraceOperation.UIStartup,
startTime: appStartTime,
},
async () => await createStoreAndPersistor(appStartTime),
);
})();

export { store, persistor };
38 changes: 36 additions & 2 deletions app/util/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,32 @@ export enum TraceName {
Middleware = 'Middleware',
NestedTest1 = 'Nested Test 1',
NestedTest2 = 'Nested Test 2',
NotificationDisplay = 'Notification Display',
PPOMValidation = 'PPOM Validation',
Signature = 'Signature',
LoadScripts = 'Load Scripts',
SetupStore = 'Setup Store',
LoginToPasswordEntry = 'Login to Password Entry',
AuthenticateUser = 'Authenticate User',
BiometricAuthentication = 'Biometrics Authentication',
EngineInitialization = 'Engine Initialization',
CreateStore = 'Create Store',
CreateNewWalletToChoosePassword = 'Create New Wallet to Choose Password',
StorageRehydration = 'Storage Rehydration',
UIStartup = 'Custom UIStartup',
}

export enum TraceOperation {
LoadScripts = 'custom.load.scripts',
SetupStore = 'custom.setup.store',
LoginToPasswordEntry = 'custom.login.to.password.entry',
BiometricAuthentication = 'biometrics.authentication',
AuthenticateUser = 'custom.authenticate.user',
EngineInitialization = 'custom.engine.initialization',
CreateStore = 'custom.create.store',
CreateNewWalletToChoosePassword = 'custom.create.new.wallet',
StorageRehydration = 'custom.storage.rehydration',
UIStartup = 'custom.ui.startup',
}

const ID_DEFAULT = 'default';
Expand All @@ -42,6 +68,7 @@ export interface TraceRequest {
parentContext?: TraceContext;
startTime?: number;
tags?: Record<string, number | string | boolean>;
op?: string;
}

export interface EndTraceRequest {
Expand Down Expand Up @@ -151,13 +178,20 @@ function startSpan<T>(
request: TraceRequest,
callback: (spanOptions: StartSpanOptions) => T,
) {
const { data: attributes, name, parentContext, startTime, tags } = request;
const {
data: attributes,
name,
parentContext,
startTime,
tags,
op,
} = request;
const parentSpan = (parentContext ?? null) as Span | null;

const spanOptions: StartSpanOptions = {
attributes,
name,
op: OP_DEFAULT,
op: op || OP_DEFAULT,
// This needs to be parentSpan once we have the withIsolatedScope implementation in place in the Sentry SDK for React Native
// Reference PR that updates @sentry/react-native: https://github.com/getsentry/sentry-react-native/pull/3895
parentSpanId: parentSpan?.spanId,
Expand Down

0 comments on commit edb5b29

Please sign in to comment.