Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 2 staking analytics events #11732

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/components/UI/Stake/hooks/useStakingInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BN>(new BN(0));
const [estimatedAnnualRewards, setEstimatedAnnualRewards] = useState('-');
Expand Down Expand Up @@ -71,13 +73,15 @@ const useStakingInputHandlers = (balance: BN) => {
const handleKeypadChange = useCallback(
({ value }) => {
isEth ? handleEthInput(value) : handleFiatInput(value);
trackEvent(MetaMetricsEvents.STAKE_INPUT_CLICKED);
},
[handleEthInput, handleFiatInput, isEth],
[handleEthInput, handleFiatInput, isEth, trackEvent],
);

const handleCurrencySwitch = useCallback(() => {
setIsEth(!isEth);
}, [isEth]);
trackEvent(MetaMetricsEvents.STAKE_INPUT_TEXT_ENTERED);
}, [isEth, trackEvent]);

const percentageOptions = [
{ value: 0.25, label: '25%' },
Expand Down
28 changes: 28 additions & 0 deletions app/components/UI/Tokens/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand All @@ -123,6 +131,11 @@ const renderComponent = (state: any = {}) =>
);

describe('Tokens', () => {
beforeEach(() => {
(useMetrics as jest.Mock).mockReturnValue({
trackEvent: jest.fn(),
});
});
afterEach(() => {
mockNavigate.mockClear();
mockPush.mockClear();
Expand Down Expand Up @@ -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));
Expand All @@ -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,
},
);
});
});
11 changes: 11 additions & 0 deletions app/core/Analytics/MetaMetrics.events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,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
Expand Down
Loading