Skip to content

Commit

Permalink
add metametricsid to redux
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoloureirop committed Jan 15, 2025
1 parent 9f285b5 commit e93b201
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 27 deletions.
13 changes: 13 additions & 0 deletions app/actions/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
type CheckedAuthAction,
type PersistedDataLoadedAction,
UserActionType,
SetMetaMetricsIdAction,
} from './types';

export * from './types';
Expand Down Expand Up @@ -151,6 +152,18 @@ export function checkedAuth(initialScreen: string): CheckedAuthAction {
};
}

/**
* Temporary action to initialize metametricsId before Engine Init
*
* @param metaMetricsId - MetaMetrics ID
*/
export function setMetaMetricsId(metaMetricsId: string): SetMetaMetricsIdAction {
return {
type: UserActionType.SET_METAMETRICS_ID,
payload: { metaMetricsId },
}
}

/**
* Action to signal that persisted data has been loaded
*/
Expand Down
9 changes: 8 additions & 1 deletion app/actions/user/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setMetaMetricsId } from '.';
import { type AppThemeKey } from '../../util/theme/models';
import { type Action } from 'redux';

Expand All @@ -23,6 +24,7 @@ export enum UserActionType {
SET_GAS_EDUCATION_CAROUSEL_SEEN = 'SET_GAS_EDUCATION_CAROUSEL_SEEN',
SET_APP_THEME = 'SET_APP_THEME',
CHECKED_AUTH = 'CHECKED_AUTH',
SET_METAMETRICS_ID = 'SET_METAMETRICS_ID',
}

// User actions
Expand Down Expand Up @@ -85,6 +87,10 @@ export type CheckedAuthAction = Action<UserActionType.CHECKED_AUTH> & {
payload: { initialScreen: string };
};

export type SetMetaMetricsIdAction = Action<UserActionType.SET_METAMETRICS_ID> & {
payload: { metaMetricsId: string };
};

/**
* User actions union type
*/
Expand All @@ -108,4 +114,5 @@ export type UserAction =
| LoadingUnsetAction
| SetGasEducationCarouselSeenAction
| SetAppThemeAction
| CheckedAuthAction;
| CheckedAuthAction
| SetMetaMetricsIdAction;
6 changes: 5 additions & 1 deletion app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
setCurrentRoute,
onNavigationReady,
} from '../../../actions/navigation';
import { setMetaMetricsId } from '../../../actions/user';
import { findRouteNameFromNavigatorState } from '../../../util/general';
import { Authentication } from '../../../core/';
import { useTheme } from '../../../util/theme';
Expand Down Expand Up @@ -748,9 +749,12 @@ const App = (props) => {
...generateUserSettingsAnalyticsMetaData(),
};
await metrics.addTraitsToUser(consolidatedTraits);
return await metrics.getMetaMetricsId();
};

initMetrics().catch((err) => {
initMetrics().then((metaMetricsId) => {
dispatch(setMetaMetricsId(metaMetricsId));
}).catch((err) => {
Logger.error(err, 'Error initializing MetaMetrics');
});
}, []);
Expand Down
8 changes: 1 addition & 7 deletions app/core/Engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,6 @@ export class Engine {
'https://gas.api.cx.metamask.io/networks/<chain_id>/suggestedGasFees',
});

const getMetaMetricsId = () => {
// MetaMetrics.getInstance().getMetaMetricsId()
return 'uid';

};

const remoteFeatureFlagController = createRemoteFeatureFlagController({
state: initialState.RemoteFeatureFlagController,
messenger: this.controllerMessenger.getRestricted({
Expand All @@ -516,7 +510,7 @@ export class Engine {
allowedEvents: [],
}),
disabled: !isBasicFunctionalityToggleEnabled(),
getMetaMetricsId,
getMetaMetricsId: () => store.getState().user.metaMetricsId,
});

const phishingController = new PhishingController({
Expand Down
6 changes: 6 additions & 0 deletions app/reducers/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const userInitialState: UserState = {
initialScreen: '',
appTheme: AppThemeKey.os,
ambiguousAddressEntries: {},
metaMetricsId: '',
};

/**
Expand Down Expand Up @@ -109,6 +110,11 @@ const userReducer = (
...state,
appTheme: action.payload.theme,
};
case UserActionType.SET_METAMETRICS_ID:
return {
...state,
metaMetricsId: action.payload.metaMetricsId,
}
default:
return state;
}
Expand Down
1 change: 1 addition & 0 deletions app/reducers/user/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export interface UserState {
initialScreen: string;
appTheme: AppThemeKey;
ambiguousAddressEntries: Record<string, unknown>;
metaMetricsId: string;
}
3 changes: 3 additions & 0 deletions app/store/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ export function* startAppServices() {
yield all([
take(UserActionType.ON_PERSISTED_DATA_LOADED),
take(NavigationActionType.ON_NAVIGATION_READY),
//temp set metametrics id before engine init
take(UserActionType.SET_METAMETRICS_ID),
]);
// Start services
// init metametrics
EngineService.start();
AppStateEventProcessor.start();
// TODO: Track a property in redux to gate keep the app until services are initialized
Expand Down
18 changes: 0 additions & 18 deletions metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,17 @@
const { getDefaultConfig } = require('expo/metro-config');
const { mergeConfig } = require('@react-native/metro-config');

const path = require("path");

const featureFlagModuleDir = path.resolve(__dirname, "../../core/feature-flags/packages/remote-feature-flag-controller");

const extraNodeModules = {
"@metamask/remote-feature-flag-controller": featureFlagModuleDir,
};

const watchFolders = [
featureFlagModuleDir,
];

module.exports = function (baseConfig) {
const defaultConfig = mergeConfig(baseConfig, getDefaultConfig(__dirname));
const {
resolver: { assetExts, sourceExts },
} = defaultConfig;

return mergeConfig(defaultConfig, {
watchFolders,
resolver: {
assetExts: assetExts.filter((ext) => ext !== 'svg'),
sourceExts: [...sourceExts, 'svg', 'cjs', 'mjs'],
resolverMainFields: ['sbmodern', 'react-native', 'browser', 'main'],
extraNodeModules: new Proxy (extraNodeModules, {
get: (target, name) =>
name in target ? target[name] : path.join(process.cwd(), `node_modules/${name}`),
}),
unstable_enableSymlinks: true,
},
transformer: {
babelTransformerPath: require.resolve('./metro.transform.js'),
Expand Down

0 comments on commit e93b201

Please sign in to comment.