From 261975f50c64ba6aca6c84f2580e0335f9187799 Mon Sep 17 00:00:00 2001 From: Matthew Grainger <46547583+Matt561@users.noreply.github.com> Date: Tue, 14 Jan 2025 10:31:01 -0500 Subject: [PATCH] feat: STAKE-914 Remove MM_POOLED_STAKING_UI_ENABLED feature flag (#12852) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This PR removes the `MM_POOLED_STAKING_UI_ENABLED` feature flag, removed related usages in the codebase, and updates breaking tests. We no longer need this feature flag as pooled-staking is live. ## **Related issues** - Jira ticket: [STAKE-914 Remove MM_POOLED_STAKING_UI_ENABLED feature flag](https://consensyssoftware.atlassian.net/browse/STAKE-914) ## **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. --- .../UI/AssetOverview/Balance/Balance.tsx | 5 +- .../UI/AssetOverview/Balance/index.test.tsx | 74 +++++++++++++++++-- .../TokenDetails/TokenDetails.tsx | 3 +- .../StakeButton/StakeButton.test.tsx | 4 - .../UI/Stake/components/StakeButton/index.tsx | 7 +- .../StakingBalance/StakingBalance.tsx | 2 +- .../StakingEarnings/StakingEarnings.test.tsx | 4 - .../components/StakingEarnings/index.tsx | 8 +- app/components/UI/Stake/constants/index.ts | 4 - .../UI/Stake/sdk/stakeSdkProvider.test.tsx | 4 - app/components/UI/Tokens/index.test.tsx | 4 - app/core/Engine/Engine.ts | 3 +- bitrise.yml | 3 - 13 files changed, 73 insertions(+), 52 deletions(-) diff --git a/app/components/UI/AssetOverview/Balance/Balance.tsx b/app/components/UI/AssetOverview/Balance/Balance.tsx index 82662417e44..8dc96b67932 100644 --- a/app/components/UI/AssetOverview/Balance/Balance.tsx +++ b/app/components/UI/AssetOverview/Balance/Balance.tsx @@ -29,7 +29,6 @@ import Text, { } from '../../../../component-library/components/Texts/Text'; import { TokenI } from '../../Tokens/types'; import { useNavigation } from '@react-navigation/native'; -import { isPooledStakingFeatureEnabled } from '../../Stake/constants'; import StakingBalance from '../../Stake/components/StakingBalance/StakingBalance'; import { PopularList, @@ -167,9 +166,7 @@ const Balance = ({ asset, mainBalance, secondaryBalance }: BalanceProps) => { {asset.name || asset.symbol} - {isPooledStakingFeatureEnabled() && asset?.isETH && ( - - )} + {asset?.isETH && } ); }; diff --git a/app/components/UI/AssetOverview/Balance/index.test.tsx b/app/components/UI/AssetOverview/Balance/index.test.tsx index ba5dd5f2fc3..724b02bc1a4 100644 --- a/app/components/UI/AssetOverview/Balance/index.test.tsx +++ b/app/components/UI/AssetOverview/Balance/index.test.tsx @@ -58,11 +58,21 @@ const mockETH = { isNative: true, }; -const mockInitialState = { - engine: { - backgroundState, +jest.mock('../../../../core/Engine', () => ({ + context: { + NetworkController: { + getNetworkClientById: () => ({ + configuration: { + chainId: '0x1', + rpcUrl: 'https://mainnet.infura.io/v3', + ticker: 'ETH', + type: 'custom', + }, + }), + findNetworkClientIdByChainId: () => 'mainnet', + }, }, -}; +})); jest.mock('../../../../util/networks', () => ({ ...jest.requireActual('../../../../util/networks'), @@ -74,6 +84,48 @@ jest.mock('../../../../util/networks', () => ({ isPortfolioViewEnabled: jest.fn(), })); +jest.mock('../../Stake/hooks/usePooledStakes', () => ({ + __esModule: true, + default: () => ({ + pooledStakesData: { + account: '0xabc', + assets: '10000000000000000', + exitRequests: [], + lifetimeRewards: '100000000000000', + }, + exchangeRate: 1.018, + hasStakedPositions: true, + hasEthToUnstake: true, + isLoadingPooledStakesData: false, + }), +})); + +jest.mock('../../Stake/hooks/useVaultData', () => ({ + __esModule: true, + default: () => ({ + vaultData: { + apy: '2.437033146840025387168141592920355', + capacity: '1000000000000000000000000000000000000000000000000000000000000', + feePercent: 1500, + totalAssets: '10000000000000000000000', + vaultAddress: '0xdef', + }, + }), +})); + +jest.mock('../../Stake/hooks/useStakingEligibility', () => ({ + __esModule: true, + default: () => ({ + isEligible: true, + }), +})); + +const mockInitialState = { + engine: { + backgroundState, + }, +}; + describe('Balance', () => { const mockStore = configureMockStore(); const store = mockStore(mockInitialState); @@ -131,13 +183,19 @@ describe('Balance', () => { }); it('should not fire navigation event for native tokens', () => { - const { queryByTestId } = render( + const { queryAllByTestId } = render( - + , , ); - const assetElement = queryByTestId('asset-ETH'); - fireEvent.press(assetElement); + + // Includes native ETH and staked ETH + const ethElements = queryAllByTestId('asset-ETH'); + + ethElements.forEach((ethElement) => { + fireEvent.press(ethElement); + }); + expect(mockNavigate).toHaveBeenCalledTimes(0); }); diff --git a/app/components/UI/AssetOverview/TokenDetails/TokenDetails.tsx b/app/components/UI/AssetOverview/TokenDetails/TokenDetails.tsx index 54df1781873..8b7203262f1 100644 --- a/app/components/UI/AssetOverview/TokenDetails/TokenDetails.tsx +++ b/app/components/UI/AssetOverview/TokenDetails/TokenDetails.tsx @@ -28,7 +28,6 @@ import Logger from '../../../../util/Logger'; import TokenDetailsList from './TokenDetailsList'; import MarketDetailsList from './MarketDetailsList'; import { TokenI } from '../../Tokens/types'; -import { isPooledStakingFeatureEnabled } from '../../Stake/constants'; import StakingEarnings from '../../Stake/components/StakingEarnings'; import { isPortfolioViewEnabled } from '../../../../util/networks'; @@ -147,7 +146,7 @@ const TokenDetails: React.FC = ({ asset }) => { return ( - {asset.isETH && isPooledStakingFeatureEnabled() && } + {asset.isETH && } {(asset.isETH || tokenMetadata) && ( )} diff --git a/app/components/UI/Stake/components/StakeButton/StakeButton.test.tsx b/app/components/UI/Stake/components/StakeButton/StakeButton.test.tsx index 637ae857c92..2d4374e5c4b 100644 --- a/app/components/UI/Stake/components/StakeButton/StakeButton.test.tsx +++ b/app/components/UI/Stake/components/StakeButton/StakeButton.test.tsx @@ -21,10 +21,6 @@ jest.mock('@react-navigation/native', () => { }; }); -jest.mock('../../constants', () => ({ - isPooledStakingFeatureEnabled: jest.fn().mockReturnValue(true), -})); - jest.mock('../../../../hooks/useMetrics'); (useMetrics as jest.MockedFn).mockReturnValue({ diff --git a/app/components/UI/Stake/components/StakeButton/index.tsx b/app/components/UI/Stake/components/StakeButton/index.tsx index f197ed15dfc..9b13d2fe4bf 100644 --- a/app/components/UI/Stake/components/StakeButton/index.tsx +++ b/app/components/UI/Stake/components/StakeButton/index.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { TokenI, BrowserTab } from '../../../Tokens/types'; import { useNavigation } from '@react-navigation/native'; -import { isPooledStakingFeatureEnabled } from '../../constants'; import Routes from '../../../../../constants/navigation/Routes'; import { useSelector } from 'react-redux'; import AppConstants from '../../../../../core/AppConstants'; @@ -43,7 +42,7 @@ const StakeButtonContent = ({ asset }: StakeButtonProps) => { const onStakeButtonPress = async () => { const { isEligible } = await refreshPooledStakingEligibility(); - if (isPooledStakingFeatureEnabled() && isEligible) { + if (isEligible) { navigation.navigate('StakeScreens', { screen: Routes.STAKING.STAKE }); } else { const existingStakeTab = browserTabs.find((tab: BrowserTab) => @@ -88,9 +87,7 @@ const StakeButtonContent = ({ asset }: StakeButtonProps) => { {' • '} - {isPooledStakingFeatureEnabled() - ? `${strings('stake.earn')} ` - : `${strings('stake.stake')} `} + {`${strings('stake.earn')} `} { return ( - {hasEthToUnstake && ( + {hasEthToUnstake && !isLoadingPooledStakesData && ( ({ - isPooledStakingFeatureEnabled: jest.fn().mockReturnValue(true), -})); - const mockNavigate = jest.fn(); const STATE_MOCK = { diff --git a/app/components/UI/Stake/components/StakingEarnings/index.tsx b/app/components/UI/Stake/components/StakingEarnings/index.tsx index b5a7d035c02..c16fe9bfee4 100644 --- a/app/components/UI/Stake/components/StakingEarnings/index.tsx +++ b/app/components/UI/Stake/components/StakingEarnings/index.tsx @@ -15,7 +15,6 @@ import ButtonIcon, { } from '../../../../../component-library/components/Buttons/ButtonIcon'; import useTooltipModal from '../../../../../components/hooks/useTooltipModal'; import { strings } from '../../../../../../locales/i18n'; -import { isPooledStakingFeatureEnabled } from '../../../Stake/constants'; import useStakingChain from '../../hooks/useStakingChain'; import { StakeSDKProvider } from '../../sdk/stakeSdkProvider'; import useStakingEarnings from '../../hooks/useStakingEarnings'; @@ -47,12 +46,7 @@ const StakingEarningsContent = () => { const { isStakingSupportedChain } = useStakingChain(); - if ( - !isPooledStakingFeatureEnabled() || - !isStakingSupportedChain || - !hasStakedPositions - ) - return <>; + if (!isStakingSupportedChain || !hasStakedPositions) return <>; return ( diff --git a/app/components/UI/Stake/constants/index.ts b/app/components/UI/Stake/constants/index.ts index 6083f05f903..c3d8b9b6d5a 100644 --- a/app/components/UI/Stake/constants/index.ts +++ b/app/components/UI/Stake/constants/index.ts @@ -1,7 +1,3 @@ -/* eslint-disable import/prefer-default-export */ -export const isPooledStakingFeatureEnabled = () => - process.env.MM_POOLED_STAKING_UI_ENABLED === 'true'; - export const isStablecoinLendingFeatureEnabled = () => process.env.MM_STABLECOIN_LENDING_UI_ENABLED === 'true'; diff --git a/app/components/UI/Stake/sdk/stakeSdkProvider.test.tsx b/app/components/UI/Stake/sdk/stakeSdkProvider.test.tsx index 142dc2d1ad6..3ba6230913e 100644 --- a/app/components/UI/Stake/sdk/stakeSdkProvider.test.tsx +++ b/app/components/UI/Stake/sdk/stakeSdkProvider.test.tsx @@ -8,10 +8,6 @@ import { View } from 'react-native'; import Text from '../../../../component-library/components/Texts/Text'; import { MOCK_POOL_STAKING_SDK } from '../__mocks__/mockData'; -jest.mock('../../Stake/constants', () => ({ - isPooledStakingFeatureEnabled: jest.fn().mockReturnValue(true), -})); - jest.mock('../../../../core/Engine', () => ({ context: { NetworkController: { diff --git a/app/components/UI/Tokens/index.test.tsx b/app/components/UI/Tokens/index.test.tsx index 4928d4368e1..e8a0df5103e 100644 --- a/app/components/UI/Tokens/index.test.tsx +++ b/app/components/UI/Tokens/index.test.tsx @@ -236,10 +236,6 @@ jest.mock('@react-navigation/native', () => { }; }); -jest.mock('../../UI/Stake/constants', () => ({ - isPooledStakingFeatureEnabled: jest.fn().mockReturnValue(true), -})); - jest.mock('../../UI/Stake/hooks/useStakingEligibility', () => ({ __esModule: true, default: jest.fn(() => ({ diff --git a/app/core/Engine/Engine.ts b/app/core/Engine/Engine.ts index 9759da68339..a0fe49693c3 100644 --- a/app/core/Engine/Engine.ts +++ b/app/core/Engine/Engine.ts @@ -199,7 +199,6 @@ import { getSmartTransactionMetricsProperties } from '../../util/smart-transacti import { trace } from '../../util/trace'; import { MetricsEventBuilder } from '../Analytics/MetricsEventBuilder'; import { JsonMap } from '../Analytics/MetaMetrics.types'; -import { isPooledStakingFeatureEnabled } from '../../components/UI/Stake/constants'; import { ControllerMessenger, EngineState, @@ -740,7 +739,7 @@ export class Engine { assetsContractController.getStakedBalanceForChain.bind( assetsContractController, ), - includeStakedAssets: isPooledStakingFeatureEnabled(), + includeStakedAssets: true, }); const permissionController = new PermissionController({ messenger: this.controllerMessenger.getRestricted({ diff --git a/bitrise.yml b/bitrise.yml index 827ee5e8202..80960c25e40 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -1755,9 +1755,6 @@ app: - opts: is_expand: false MM_PERMISSIONS_SETTINGS_V1_ENABLED: false - - opts: - is_expand: false - MM_POOLED_STAKING_UI_ENABLED: true - opts: is_expand: false MM_SECURITY_ALERTS_API_ENABLED: true