From db2fb3c502b076afc748393f13a6b80ecae24ff8 Mon Sep 17 00:00:00 2001 From: Amitabh Aggarwal Date: Tue, 14 Jan 2025 18:44:53 -0600 Subject: [PATCH 1/2] feat: enhance staking button functionality with chain support check This update introduces a check for staking support based on the current chain before proceeding with staking actions. It integrates the `useStakingChain` hook to determine if the active chain supports staking, and sets the active network to 'mainnet' if it does not. --- .../UI/Stake/components/StakeButton/index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/components/UI/Stake/components/StakeButton/index.tsx b/app/components/UI/Stake/components/StakeButton/index.tsx index 9b13d2fe4bf..9e18af410f0 100644 --- a/app/components/UI/Stake/components/StakeButton/index.tsx +++ b/app/components/UI/Stake/components/StakeButton/index.tsx @@ -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,11 +39,14 @@ const StakeButtonContent = ({ asset }: StakeButtonProps) => { const browserTabs = useSelector((state: RootState) => state.browser.tabs); const chainId = useSelector(selectChainId); - - const { refreshPooledStakingEligibility } = useStakingEligibility(); + const { isEligible } = useStakingEligibility(); + const { isStakingSupportedChain } = useStakingChain(); const onStakeButtonPress = async () => { - const { isEligible } = await refreshPooledStakingEligibility(); + if (!isStakingSupportedChain) { + const { NetworkController } = Engine.context; + await NetworkController.setActiveNetwork('mainnet'); + } if (isEligible) { navigation.navigate('StakeScreens', { screen: Routes.STAKING.STAKE }); } else { From 1971ee3fa240711d4cb8ddf757b01f729db3d2ed Mon Sep 17 00:00:00 2001 From: Amitabh Aggarwal Date: Wed, 15 Jan 2025 09:17:21 -0600 Subject: [PATCH 2/2] feat: update token tests to include useStakingChain mock --- app/components/UI/Tokens/index.test.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/components/UI/Tokens/index.test.tsx b/app/components/UI/Tokens/index.test.tsx index e8a0df5103e..838143c7b21 100644 --- a/app/components/UI/Tokens/index.test.tsx +++ b/app/components/UI/Tokens/index.test.tsx @@ -248,10 +248,14 @@ jest.mock('../../UI/Stake/hooks/useStakingEligibility', () => ({ })), })); -jest.mock('../Stake/hooks/useStakingChain', () => ({ - useStakingChainByChainId: () => ({ +jest.mock('../../UI/Stake/hooks/useStakingChain', () => ({ + __esModule: true, + default: jest.fn(() => ({ isStakingSupportedChain: true, - }), + })), + useStakingChainByChainId: jest.fn(() => ({ + isStakingSupportedChain: true, + })), })); const Stack = createStackNavigator();