From 9342407822d9ac57ee2ba6ba54ef955aa1986700 Mon Sep 17 00:00:00 2001 From: siibars <9662464+siibars@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:52:02 +0200 Subject: [PATCH 1/4] feat: add stake input text entered, stake input clicked analytics event and increase test coverage --- .../UI/Stake/hooks/useStakingInput.ts | 12 ++++++-- app/components/UI/Tokens/index.test.tsx | 28 +++++++++++++++++++ app/core/Analytics/MetaMetrics.events.ts | 11 ++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/app/components/UI/Stake/hooks/useStakingInput.ts b/app/components/UI/Stake/hooks/useStakingInput.ts index d9d233d19af..ac0244072b1 100644 --- a/app/components/UI/Stake/hooks/useStakingInput.ts +++ b/app/components/UI/Stake/hooks/useStakingInput.ts @@ -15,8 +15,10 @@ import { renderFiat, } from '../../../../util/number'; import { strings } from '../../../../../locales/i18n'; +import { MetaMetricsEvents, useMetrics } from '../../../hooks/useMetrics'; const useStakingInputHandlers = (balance: BN) => { + const { trackEvent } = useMetrics(); const [amountEth, setAmountEth] = useState('0'); const [amountWei, setAmountWei] = useState(new BN(0)); const [estimatedAnnualRewards, setEstimatedAnnualRewards] = useState('-'); @@ -71,13 +73,19 @@ const useStakingInputHandlers = (balance: BN) => { const handleKeypadChange = useCallback( ({ value }) => { isEth ? handleEthInput(value) : handleFiatInput(value); + trackEvent(MetaMetricsEvents.STAKE_INPUT_CLICKED, { + selected_provider: 'consensys', + }) }, - [handleEthInput, handleFiatInput, isEth], + [handleEthInput, handleFiatInput, isEth, trackEvent], ); const handleCurrencySwitch = useCallback(() => { setIsEth(!isEth); - }, [isEth]); + trackEvent(MetaMetricsEvents.STAKE_INPUT_TEXT_ENTERED, { + selected_provider: 'consensys', + }); + }, [isEth, trackEvent]); const percentageOptions = [ { value: 0.25, label: '25%' }, diff --git a/app/components/UI/Tokens/index.test.tsx b/app/components/UI/Tokens/index.test.tsx index b01f5f25866..62be3e72f9f 100644 --- a/app/components/UI/Tokens/index.test.tsx +++ b/app/components/UI/Tokens/index.test.tsx @@ -11,6 +11,10 @@ import { strings } from '../../../../locales/i18n'; import AppConstants from '../../../../app/core/AppConstants'; import Routes from '../../../../app/constants/navigation/Routes'; import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors'; +import { + MetaMetricsEvents, + useMetrics, +} from '../../../../app/components/hooks/useMetrics'; jest.mock('../../../core/Engine', () => ({ getTotalFiatAccountBalance: jest.fn(), @@ -104,6 +108,10 @@ jest.mock('@react-navigation/native', () => { }; }); +jest.mock('../../../components/hooks/useMetrics', () => ({ + useMetrics: jest.fn(), +})); + const Stack = createStackNavigator(); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -123,6 +131,11 @@ const renderComponent = (state: any = {}) => ); describe('Tokens', () => { + beforeEach(() => { + (useMetrics as jest.Mock).mockReturnValue({ + trackEvent: jest.fn(), + }); + }); afterEach(() => { mockNavigate.mockClear(); mockPush.mockClear(); @@ -256,6 +269,10 @@ describe('Tokens', () => { expect(getByTestId(WalletViewSelectorsIDs.STAKE_BUTTON)).toBeDefined(); }); it('navigates to Portfolio Stake url when stake button is pressed', () => { + const trackEvent = jest.fn(); + (useMetrics as jest.Mock).mockReturnValue({ + trackEvent, + }); const { getByTestId } = renderComponent(initialState); fireEvent.press(getByTestId(WalletViewSelectorsIDs.STAKE_BUTTON)); @@ -266,5 +283,16 @@ describe('Tokens', () => { }, screen: Routes.BROWSER.VIEW, }); + expect(trackEvent).toHaveBeenNthCalledWith( + 1, + MetaMetricsEvents.STAKE_BUTTON_CLICKED, + { + chain_id: expect.any(String), + location: 'Home Screen', + text: 'Stake', + token_symbol: expect.any(String), + url: AppConstants.STAKE.URL, + }, + ); }); }); diff --git a/app/core/Analytics/MetaMetrics.events.ts b/app/core/Analytics/MetaMetrics.events.ts index d15622a6aac..e5a3133eea2 100644 --- a/app/core/Analytics/MetaMetrics.events.ts +++ b/app/core/Analytics/MetaMetrics.events.ts @@ -275,6 +275,8 @@ enum EVENT_NAME { // Stake STAKE_BUTTON_CLICKED = 'Stake Button Clicked', + STAKE_INPUT_TEXT_ENTERED = 'Stake Input Text Entered', + STAKE_INPUT_CLICKED = 'Stake Input Clicked', // Force Upgrade | Automatic Security Checks FORCE_UPGRADE_UPDATE_NEEDED_PROMPT_VIEWED = 'Force Upgrade Update Needed Prompt Viewed', @@ -1222,11 +1224,20 @@ const legacyMetaMetricsEvents = { ACTIONS.BRIDGE, DESCRIPTION.BRIDGE, ), + // Stake STAKE_BUTTON_CLICKED: generateOpt( EVENT_NAME.STAKE_BUTTON_CLICKED, ACTIONS.STAKE, DESCRIPTION.STAKE, ), + STAKE_INPUT_TEXT_ENTERED: generateOpt( + EVENT_NAME.STAKE_INPUT_TEXT_ENTERED, + ACTIONS.STAKE, + DESCRIPTION.STAKE, + ), + STAKE_INPUT_CLICKED: generateOpt( + EVENT_NAME.STAKE_INPUT_CLICKED, + ), }; const MetaMetricsEvents = { ...events, ...legacyMetaMetricsEvents }; From fd926482d716f89ca5a0c67fbb1a244edbbb0fc0 Mon Sep 17 00:00:00 2001 From: siibars <9662464+siibars@users.noreply.github.com> Date: Mon, 14 Oct 2024 11:17:47 +0200 Subject: [PATCH 2/4] chore: enable pooled staking in bitrise --- bitrise.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitrise.yml b/bitrise.yml index 4df0c76e2c4..2fba382044a 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -1464,7 +1464,7 @@ app: MM_MULTICHAIN_V1_ENABLED: false - opts: is_expand: false - MM_POOLED_STAKING_UI_ENABLED: false + MM_POOLED_STAKING_UI_ENABLED: true - opts: is_expand: false PROJECT_LOCATION: android From 810c85b805d4a5d3f9221a85a8e319ec12d9137c Mon Sep 17 00:00:00 2001 From: siibars <9662464+siibars@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:48:23 +0200 Subject: [PATCH 3/4] chore: simple events with no schema for now --- app/components/UI/Stake/hooks/useStakingInput.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/components/UI/Stake/hooks/useStakingInput.ts b/app/components/UI/Stake/hooks/useStakingInput.ts index ac0244072b1..17b0f9b9779 100644 --- a/app/components/UI/Stake/hooks/useStakingInput.ts +++ b/app/components/UI/Stake/hooks/useStakingInput.ts @@ -73,18 +73,14 @@ const useStakingInputHandlers = (balance: BN) => { const handleKeypadChange = useCallback( ({ value }) => { isEth ? handleEthInput(value) : handleFiatInput(value); - trackEvent(MetaMetricsEvents.STAKE_INPUT_CLICKED, { - selected_provider: 'consensys', - }) + trackEvent(MetaMetricsEvents.STAKE_INPUT_CLICKED) }, [handleEthInput, handleFiatInput, isEth, trackEvent], ); const handleCurrencySwitch = useCallback(() => { setIsEth(!isEth); - trackEvent(MetaMetricsEvents.STAKE_INPUT_TEXT_ENTERED, { - selected_provider: 'consensys', - }); + trackEvent(MetaMetricsEvents.STAKE_INPUT_TEXT_ENTERED); }, [isEth, trackEvent]); const percentageOptions = [ From 419d57d4215c796e414d4c1eb48da5895ee57bf5 Mon Sep 17 00:00:00 2001 From: siibars <9662464+siibars@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:54:34 +0200 Subject: [PATCH 4/4] chore: yarn lint fix --- app/components/UI/Stake/hooks/useStakingInput.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/UI/Stake/hooks/useStakingInput.ts b/app/components/UI/Stake/hooks/useStakingInput.ts index 17b0f9b9779..1a9536828a3 100644 --- a/app/components/UI/Stake/hooks/useStakingInput.ts +++ b/app/components/UI/Stake/hooks/useStakingInput.ts @@ -73,7 +73,7 @@ const useStakingInputHandlers = (balance: BN) => { const handleKeypadChange = useCallback( ({ value }) => { isEth ? handleEthInput(value) : handleFiatInput(value); - trackEvent(MetaMetricsEvents.STAKE_INPUT_CLICKED) + trackEvent(MetaMetricsEvents.STAKE_INPUT_CLICKED); }, [handleEthInput, handleFiatInput, isEth, trackEvent], );