From 50fb2ff67cecccd9c38546628cb728b5c3c1ce4d Mon Sep 17 00:00:00 2001 From: Amitabh Aggarwal Date: Tue, 14 Jan 2025 17:33:16 -0600 Subject: [PATCH] fix: Enable Earn CTA navigation on unsupported networks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This PR fixes Earn CTA navigation behavior when clicked on unsupported networks. Previously, the button was unresponsive when clicked on networks that don't support staking. Now, it properly switches to mainnet and navigates to the staking UI. ## **Related issues** - Jira ticket: [STAKE-916](https://consensyssoftware.atlassian.net/browse/STAKE-916) ## **Manual testing steps** N/A ## **Screenshots/Recordings** ### **Before** N/A ### **After** N/A ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. ## **Description** ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- .../UI/Stake/components/StakeButton/index.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/components/UI/Stake/components/StakeButton/index.tsx b/app/components/UI/Stake/components/StakeButton/index.tsx index 9b13d2fe4bf..dda6b83917b 100644 --- a/app/components/UI/Stake/components/StakeButton/index.tsx +++ b/app/components/UI/Stake/components/StakeButton/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useCallback } from 'react'; import { TokenI, BrowserTab } from '../../../Tokens/types'; import { useNavigation } from '@react-navigation/native'; import Routes from '../../../../../constants/navigation/Routes'; @@ -25,6 +25,8 @@ import { RootState } from '../../../../../reducers'; import useStakingEligibility from '../../hooks/useStakingEligibility'; import { StakeSDKProvider } from '../../sdk/stakeSdkProvider'; import { EVENT_LOCATIONS } from '../../constants/events'; +import useStakingChain from '../../hooks/useStakingChain'; +import Engine from '../../../../../core/Engine'; interface StakeButtonProps { asset: TokenI; @@ -37,10 +39,22 @@ const StakeButtonContent = ({ asset }: StakeButtonProps) => { const browserTabs = useSelector((state: RootState) => state.browser.tabs); const chainId = useSelector(selectChainId); + const { isStakingSupportedChain } = useStakingChain(); const { refreshPooledStakingEligibility } = useStakingEligibility(); + const switchToMainnet = useCallback(() => { + const { NetworkController } = Engine.context; + NetworkController.setActiveNetwork('mainnet'); + }, []); + const onStakeButtonPress = async () => { + // Check if current chain is supported for stakings + + if (!isStakingSupportedChain) { + switchToMainnet(); + } + const { isEligible } = await refreshPooledStakingEligibility(); if (isEligible) { navigation.navigate('StakeScreens', { screen: Routes.STAKING.STAKE });