From 7a39e73ca5a8b117770b5b11de77ae6c3a3e0454 Mon Sep 17 00:00:00 2001 From: Matthew Grainger Date: Wed, 11 Dec 2024 15:36:14 -0500 Subject: [PATCH 01/10] feat: added metricsOptions to getStakingNavbar --- app/components/UI/Navbar/index.js | 34 +++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/app/components/UI/Navbar/index.js b/app/components/UI/Navbar/index.js index b7763524b3e..8a59e6e2296 100644 --- a/app/components/UI/Navbar/index.js +++ b/app/components/UI/Navbar/index.js @@ -63,6 +63,7 @@ import { toChecksumHexAddress } from '@metamask/controller-utils'; ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) import { isBtcAccount } from '../../../core/Multichain/utils'; ///: END:ONLY_INCLUDE_IF +import { withMetaMetrics } from '../Stake/utils/metaMetrics/withMetaMetrics'; const trackEvent = (event, params = {}) => { MetaMetrics.getInstance().trackEvent(event); @@ -1935,16 +1936,23 @@ export const getSettingsNavigationOptions = (title, themeColors) => { * @param {String} title - Navbar Title. * @param {NavigationProp} navigation Navigation object returned from useNavigation hook. * @param {ThemeColors} themeColors theme.colors returned from useStyles hook. - * @param {{ backgroundColor?: string, hasCancelButton?: boolean, hasBackButton?: boolean }} [options] - Optional options for navbar. + * @param {{ backgroundColor?: string, hasCancelButton?: boolean, hasBackButton?: boolean }} [navBarOptions] - Optional navbar options. + * @param {{ cancelButtonEvent?: { event: IMetaMetricsEvent, properties: Record }, backButtonEvent?: { event: IMetaMetricsEvent, properties: Record} }} [metricsOptions] - Optional metrics options. * @returns Staking Navbar Component. */ -export function getStakingNavbar(title, navigation, themeColors, options) { - const { hasBackButton = true, hasCancelButton = true } = options ?? {}; +export function getStakingNavbar( + title, + navigation, + themeColors, + navBarOptions, + metricsOptions, +) { + const { hasBackButton = true, hasCancelButton = true } = navBarOptions ?? {}; const innerStyles = StyleSheet.create({ headerStyle: { backgroundColor: - options?.backgroundColor ?? themeColors.background.default, + navBarOptions?.backgroundColor ?? themeColors.background.default, shadowOffset: null, }, headerLeft: { @@ -1976,7 +1984,14 @@ export function getStakingNavbar(title, navigation, themeColors, options) { ) : ( @@ -1985,7 +2000,14 @@ export function getStakingNavbar(title, navigation, themeColors, options) { headerRight: () => hasCancelButton ? ( navigation.dangerouslyGetParent()?.pop()} + onPress={ + metricsOptions?.cancelButtonEvent + ? withMetaMetrics(navigationPop, { + event: metricsOptions.cancelButtonEvent.event, + properties: metricsOptions.cancelButtonEvent.properties, + }) + : navigationPop + } style={styles.closeButton} > From 6684053a28dbac2b2f6b5a7ac3c303ff147ad68d Mon Sep 17 00:00:00 2001 From: Matthew Grainger Date: Wed, 11 Dec 2024 15:37:21 -0500 Subject: [PATCH 02/10] feat: added stake-input-cancel-clicked and unstake-input-cancel-clicked events --- .../Views/StakeInputView/StakeInputView.tsx | 20 ++++++++++++++++--- .../UnstakeInputView/UnstakeInputView.tsx | 20 ++++++++++++++++--- app/core/Analytics/MetaMetrics.events.ts | 4 ++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/components/UI/Stake/Views/StakeInputView/StakeInputView.tsx b/app/components/UI/Stake/Views/StakeInputView/StakeInputView.tsx index ead9d7016c8..044a9b1ae1f 100644 --- a/app/components/UI/Stake/Views/StakeInputView/StakeInputView.tsx +++ b/app/components/UI/Stake/Views/StakeInputView/StakeInputView.tsx @@ -124,9 +124,23 @@ const StakeInputView = () => { useEffect(() => { navigation.setOptions( - getStakingNavbar(title, navigation, theme.colors, { - hasBackButton: false, - }), + getStakingNavbar( + title, + navigation, + theme.colors, + { + hasBackButton: false, + }, + { + cancelButtonEvent: { + event: MetaMetricsEvents.STAKE_CANCEL_CLICKED, + properties: { + selected_provider: 'consensys', + location: 'StakeInputView', + }, + }, + }, + ), ); }, [navigation, theme.colors, title]); diff --git a/app/components/UI/Stake/Views/UnstakeInputView/UnstakeInputView.tsx b/app/components/UI/Stake/Views/UnstakeInputView/UnstakeInputView.tsx index b27bbbe07e0..25bfb52380a 100644 --- a/app/components/UI/Stake/Views/UnstakeInputView/UnstakeInputView.tsx +++ b/app/components/UI/Stake/Views/UnstakeInputView/UnstakeInputView.tsx @@ -54,9 +54,23 @@ const UnstakeInputView = () => { useEffect(() => { navigation.setOptions( - getStakingNavbar(title, navigation, theme.colors, { - hasBackButton: false, - }), + getStakingNavbar( + title, + navigation, + theme.colors, + { + hasBackButton: false, + }, + { + cancelButtonEvent: { + event: MetaMetricsEvents.UNSTAKE_CANCEL_CLICKED, + properties: { + selected_provider: 'consensys', + location: 'UnstakeInputView', + }, + }, + }, + ), ); }, [navigation, theme.colors, title]); diff --git a/app/core/Analytics/MetaMetrics.events.ts b/app/core/Analytics/MetaMetrics.events.ts index ed8898687ef..47b225237d0 100644 --- a/app/core/Analytics/MetaMetrics.events.ts +++ b/app/core/Analytics/MetaMetrics.events.ts @@ -283,7 +283,9 @@ enum EVENT_NAME { STAKE_CLAIM_BUTTON_CLICKED = 'Stake Claim Button Clicked', STAKE_LEARN_MORE_CLICKED = 'Stake Learn More Clicked', STAKE_INPUT_CURRENCY_SWITCH_CLICKED = 'Stake Input Currency Switch Clicked', + STAKE_CANCEL_CLICKED = 'Stake Cancel Clicked', UNSTAKE_INPUT_CURRENCY_SWITCH_CLICKED = 'Unstake Input Currency Switch Clicked', + UNSTAKE_CANCEL_CLICKED = 'Unstake Cancel Clicked', // Force Upgrade | Automatic Security Checks FORCE_UPGRADE_UPDATE_NEEDED_PROMPT_VIEWED = 'Force Upgrade Update Needed Prompt Viewed', @@ -913,9 +915,11 @@ const events = { STAKE_INPUT_CURRENCY_SWITCH_CLICKED: generateOpt( EVENT_NAME.STAKE_INPUT_CURRENCY_SWITCH_CLICKED, ), + STAKE_CANCEL_CLICKED: generateOpt(EVENT_NAME.STAKE_CANCEL_CLICKED), UNSTAKE_INPUT_CURRENCY_SWITCH_CLICKED: generateOpt( EVENT_NAME.UNSTAKE_INPUT_CURRENCY_SWITCH_CLICKED, ), + UNSTAKE_CANCEL_CLICKED: generateOpt(EVENT_NAME.UNSTAKE_CANCEL_CLICKED), }; /** From f4b6088599346e8d526bee382ff6fdd12e92d434 Mon Sep 17 00:00:00 2001 From: Matthew Grainger Date: Wed, 11 Dec 2024 15:50:54 -0500 Subject: [PATCH 03/10] feat: added stake-cancel-clicked and unstake-cancel-clicked events to stake and unstake confirmation views --- .../FooterButtonGroup/FooterButtonGroup.tsx | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/app/components/UI/Stake/components/StakingConfirmation/ConfirmationFooter/FooterButtonGroup/FooterButtonGroup.tsx b/app/components/UI/Stake/components/StakingConfirmation/ConfirmationFooter/FooterButtonGroup/FooterButtonGroup.tsx index c60c393fb18..594652775ff 100644 --- a/app/components/UI/Stake/components/StakingConfirmation/ConfirmationFooter/FooterButtonGroup/FooterButtonGroup.tsx +++ b/app/components/UI/Stake/components/StakingConfirmation/ConfirmationFooter/FooterButtonGroup/FooterButtonGroup.tsx @@ -24,6 +24,10 @@ import { import Routes from '../../../../../../../constants/navigation/Routes'; import usePoolStakedUnstake from '../../../../hooks/usePoolStakedUnstake'; import usePooledStakes from '../../../../hooks/usePooledStakes'; +import { + MetaMetricsEvents, + useMetrics, +} from '../../../../../../hooks/useMetrics'; const FooterButtonGroup = ({ valueWei, action }: FooterButtonGroupProps) => { const { styles } = useStyles(styleSheet, {}); @@ -31,6 +35,8 @@ const FooterButtonGroup = ({ valueWei, action }: FooterButtonGroupProps) => { const navigation = useNavigation(); const { navigate } = navigation; + const { trackEvent, createEventBuilder } = useMetrics(); + const activeAccount = useSelector(selectSelectedInternalAccount); const { attemptDepositTransaction } = usePoolStakedDeposit(); @@ -110,6 +116,27 @@ const FooterButtonGroup = ({ valueWei, action }: FooterButtonGroupProps) => { } }; + const handleCancelPress = () => { + const isStaking = action === FooterButtonGroupActions.STAKE; + + const event = { + name: isStaking + ? MetaMetricsEvents.STAKE_CANCEL_CLICKED + : MetaMetricsEvents.UNSTAKE_CANCEL_CLICKED, + location: isStaking ? 'StakeConfirmationView' : 'UnstakeConfirmationView', + }; + + trackEvent( + createEventBuilder(event.name) + .addProperties({ + location: event.location, + }) + .build(), + ); + + navigation.goBack(); + }; + return (