Skip to content

Commit

Permalink
fix: use single event name property to identify
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistevam committed Mar 1, 2023
1 parent 464608b commit 380f8b2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const DESKTOP_ERROR_EXTENSION_OUTDATED_ROUTE = `${DESKTOP_ERROR_ROUTE}/${EXTENSI
const DESKTOP_ERROR_NOT_FOUND_ROUTE = `${DESKTOP_ERROR_ROUTE}/${EXTENSION_ERROR_PAGE_TYPES.NOT_FOUND}`;
const DESKTOP_ERROR_PAIRING_KEY_NOT_MATCH_ROUTE = `${DESKTOP_ERROR_ROUTE}/${EXTENSION_ERROR_PAGE_TYPES.PAIRING_KEY_NOT_MATCH}`;
const SKIP_PAIRING_RESTART_DELAY = 2 * SECOND;
const DESKTOP_UPDATE_SETTINGS_EVENT = 'Settings Updated';

export default function DesktopEnableButton() {
const t = useContext(I18nContext);
Expand All @@ -45,7 +46,10 @@ export default function DesktopEnableButton() {
setDesktopEnabled(false);
trackEvent({
category: EVENT.CATEGORIES.DESKTOP,
event: `Disable Desktop Button Clicked`,
event: DESKTOP_UPDATE_SETTINGS_EVENT,
properties: {
desktop_enabled: false,
},
});
return;
}
Expand Down Expand Up @@ -85,10 +89,6 @@ export default function DesktopEnableButton() {
return;
}

trackEvent({
category: EVENT.CATEGORIES.DESKTOP,
event: `Enable Desktop Button Clicked`,
});
history.push(DESKTOP_PAIRING_ROUTE);
};

Expand Down
85 changes: 33 additions & 52 deletions ui/pages/desktop-error/render-desktop-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ export function renderDesktopError({
}) {
let content;

const DESKTOP_ERROR_BUTTON_DOWNLOAD_ID = 'desktop-error-button-download-mmd';
const DESKTOP_ERROR_BUTTON_OPEN_OR_DOWNLOAD_ID =
'desktop-error-button-open-or-download-mmd';
const DESKTOP_ERROR_BUTTON_DISABLE_ID = 'desktop-error-button-disable-mmd';
const DESKTOP_ERROR_BUTTON_UPDATE_ID = 'desktop-error-button-update-mmd';
const DESKTOP_ERROR_BUTTON_NAVIGATE_SETTINGS_ID =
'desktop-error-button-navigate-settings';
const DESKTOP_ERROR_BUTTON_UPDATE_EXTENSION_ID =
'desktop-error-button-update-extension';
const DESKTOP_ERROR_BUTTON_RESTART_ID = 'desktop-error-button-restart-mm';
const DESKTOP_BUTTON_ACTIONS = {
DOWNLOAD_METAMASK_DESKTOP: 'Download MetaMask Desktop',
OPEN_METAMASK_DESKTOP: 'Open MetaMask Desktop',
DISABLE_METAMASK_DESKTOP: 'Disable MetaMask Desktop',
UPDATE_METAMASK_DESKTOP: 'Update MetaMask Desktop',
RETURN_SETTINGS_PAGE: 'Return to Settings Page',
UPDATE_METAMASK_EXTENSION: 'Update MetaMask Extension',
RESTART_METAMASK: 'Restart MetaMask',
RETURN_METAMASK_HOME: 'Return MetaMask Home',
};

const noop = () => {
// do nothing
Expand Down Expand Up @@ -74,38 +74,7 @@ export function renderDesktopError({
);
};

const getEventNameById = (id) => {
let eventName;
switch (id) {
case DESKTOP_ERROR_BUTTON_DOWNLOAD_ID:
eventName = 'Download MetaMask Desktop';
break;
case DESKTOP_ERROR_BUTTON_OPEN_OR_DOWNLOAD_ID:
eventName = 'Open MetaMask Desktop';
break;
case DESKTOP_ERROR_BUTTON_DISABLE_ID:
eventName = 'Disable MetaMask Desktop';
break;
case DESKTOP_ERROR_BUTTON_UPDATE_ID:
eventName = 'Update MetaMask Desktop';
break;
case DESKTOP_ERROR_BUTTON_NAVIGATE_SETTINGS_ID:
eventName = 'Return to Settings Page';
break;
case DESKTOP_ERROR_BUTTON_UPDATE_EXTENSION_ID:
eventName = 'Update MetaMask Extension';
break;
case DESKTOP_ERROR_BUTTON_RESTART_ID:
eventName = 'Restart MetaMask';
break;
default:
eventName = 'Return MetaMask Home';
break;
}
return eventName;
};

const renderCTA = (id, text, onClick) => {
const renderCTA = (id, text, onClick, action) => {
return (
<Box marginTop={6}>
<Button
Expand All @@ -116,7 +85,10 @@ export function renderDesktopError({
if (typeof trackEvent === 'function') {
trackEvent({
category: EVENT.CATEGORIES.DESKTOP,
event: `${getEventNameById(id)} Button Clicked`,
event: 'Desktop Button Clicked',
properties: {
button_action: action,
},
});
}
} else {
Expand Down Expand Up @@ -145,9 +117,10 @@ export function renderDesktopError({
{renderDescription(t('desktopNotFoundErrorDescription1'))}
{renderDescription(t('desktopNotFoundErrorDescription2'))}
{renderCTA(
DESKTOP_ERROR_BUTTON_DOWNLOAD_ID,
'desktop-error-button-download-mmd',
t('desktopNotFoundErrorCTA'),
downloadDesktopApp,
DESKTOP_BUTTON_ACTIONS.DOWNLOAD_METAMASK_DESKTOP,
)}
</>
);
Expand All @@ -159,14 +132,15 @@ export function renderDesktopError({
{renderHeader(t('desktopConnectionLostErrorTitle'))}
{renderDescription(t('desktopConnectionLostErrorDescription'))}
{renderCTA(
DESKTOP_ERROR_BUTTON_OPEN_OR_DOWNLOAD_ID,
'desktop-error-button-open-or-download-mmd',
t('desktopOpenOrDownloadCTA'),
openOrDownloadDesktopApp,
)}
{renderCTA(
DESKTOP_ERROR_BUTTON_DISABLE_ID,
'desktop-error-button-disable-mmd',
t('desktopDisableErrorCTA'),
disableDesktop,
DESKTOP_BUTTON_ACTIONS.DISABLE_METAMASK_DESKTOP,
)}
</>
);
Expand All @@ -178,9 +152,10 @@ export function renderDesktopError({
{renderHeader(t('desktopOutdatedErrorTitle'))}
{renderDescription(t('desktopOutdatedErrorDescription'))}
{renderCTA(
DESKTOP_ERROR_BUTTON_UPDATE_ID,
'desktop-error-button-update-mmd',
t('desktopOutdatedErrorCTA'),
downloadDesktopApp,
DESKTOP_BUTTON_ACTIONS.UPDATE_METAMASK_DESKTOP,
)}
</>
);
Expand All @@ -192,9 +167,10 @@ export function renderDesktopError({
{renderHeader(t('desktopOutdatedExtensionErrorTitle'))}
{renderDescription(t('desktopOutdatedExtensionErrorDescription'))}
{renderCTA(
DESKTOP_ERROR_BUTTON_UPDATE_EXTENSION_ID,
'desktop-error-button-update-extension',
t('desktopOutdatedExtensionErrorCTA'),
downloadExtension,
DESKTOP_BUTTON_ACTIONS.UPDATE_METAMASK_EXTENSION,
)}
</>
);
Expand All @@ -206,14 +182,16 @@ export function renderDesktopError({
{renderHeader(t('desktopConnectionCriticalErrorTitle'))}
{renderDescription(t('desktopConnectionCriticalErrorDescription'))}
{renderCTA(
DESKTOP_ERROR_BUTTON_RESTART_ID,
'desktop-error-button-restart-mm',
t('desktopErrorRestartMMCTA'),
restartExtension,
DESKTOP_BUTTON_ACTIONS.RESTART_METAMASK,
)}
{renderCTA(
DESKTOP_ERROR_BUTTON_DISABLE_ID,
'desktop-error-button-disable-mmd',
t('desktopDisableErrorCTA'),
disableDesktop,
DESKTOP_BUTTON_ACTIONS.DISABLE_METAMASK_DESKTOP,
)}
</>
);
Expand All @@ -227,9 +205,10 @@ export function renderDesktopError({
{renderHeader(t('desktopRouteNotFoundErrorTitle'))}
{renderDescription(t('desktopRouteNotFoundErrorDescription'))}
{renderCTA(
DESKTOP_ERROR_BUTTON_NAVIGATE_SETTINGS_ID,
'desktop-error-button-navigate-settings',
t('desktopErrorNavigateSettingsCTA'),
navigateSettings,
DESKTOP_BUTTON_ACTIONS.RETURN_SETTINGS_PAGE,
)}
</>
);
Expand All @@ -251,9 +230,10 @@ export function renderDesktopError({
{t('desktopPairedWarningDeepLink')}
</Button>
{renderCTA(
DESKTOP_ERROR_BUTTON_NAVIGATE_SETTINGS_ID,
'desktop-error-button-navigate-settings',
t('desktopErrorNavigateSettingsCTA'),
navigateSettings,
DESKTOP_BUTTON_ACTIONS.RETURN_SETTINGS_PAGE,
)}
</>
);
Expand All @@ -268,6 +248,7 @@ export function renderDesktopError({
'desktop-error-button-return-mm-home',
t('desktopUnexpectedErrorCTA'),
returnExtensionHome,
DESKTOP_BUTTON_ACTIONS.RETURN_METAMASK_HOME,
)}
</>
);
Expand Down

0 comments on commit 380f8b2

Please sign in to comment.