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: STAKE-914 Remove MM_POOLED_STAKING_UI_ENABLED feature flag #12852

Open
wants to merge 1 commit 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
5 changes: 1 addition & 4 deletions app/components/UI/AssetOverview/Balance/Balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -167,9 +166,7 @@ const Balance = ({ asset, mainBalance, secondaryBalance }: BalanceProps) => {
{asset.name || asset.symbol}
</Text>
</AssetElement>
{isPooledStakingFeatureEnabled() && asset?.isETH && (
<StakingBalance asset={asset} />
)}
{asset?.isETH && <StakingBalance asset={asset} />}
</View>
);
};
Expand Down
74 changes: 66 additions & 8 deletions app/components/UI/AssetOverview/Balance/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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);
Expand Down Expand Up @@ -131,13 +183,19 @@ describe('Balance', () => {
});

it('should not fire navigation event for native tokens', () => {
const { queryByTestId } = render(
const { queryAllByTestId } = render(
<Provider store={store}>
<Balance asset={mockETH} mainBalance="100" secondaryBalance="200" />
<Balance asset={mockETH} mainBalance="100" secondaryBalance="200" />,
</Provider>,
);
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);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -147,7 +146,7 @@ const TokenDetails: React.FC<TokenDetailsProps> = ({ asset }) => {

return (
<View style={styles.tokenDetailsContainer}>
{asset.isETH && isPooledStakingFeatureEnabled() && <StakingEarnings />}
{asset.isETH && <StakingEarnings />}
{(asset.isETH || tokenMetadata) && (
<TokenDetailsList tokenDetails={tokenDetails} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof useMetrics>).mockReturnValue({
Expand Down
7 changes: 2 additions & 5 deletions app/components/UI/Stake/components/StakeButton/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -42,7 +41,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) =>
Expand Down Expand Up @@ -87,9 +86,7 @@ const StakeButtonContent = ({ asset }: StakeButtonProps) => {
<Text variant={TextVariant.BodyLGMedium}>
{' • '}
<Text color={TextColor.Primary} variant={TextVariant.BodyLGMedium}>
{isPooledStakingFeatureEnabled()
? `${strings('stake.earn')} `
: `${strings('stake.stake')} `}
{`${strings('stake.earn')} `}
</Text>
</Text>
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const StakingBalanceContent = ({ asset }: StakingBalanceProps) => {

return (
<View>
{hasEthToUnstake && (
{hasEthToUnstake && !isLoadingPooledStakesData && (
Matt561 marked this conversation as resolved.
Show resolved Hide resolved
<AssetElement
asset={asset}
mainBalance={stakedBalanceETH}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import renderWithProvider from '../../../../../util/test/renderWithProvider';
import { strings } from '../../../../../../locales/i18n';
import { mockNetworkState } from '../../../../../util/test/network';

jest.mock('../../constants', () => ({
isPooledStakingFeatureEnabled: jest.fn().mockReturnValue(true),
}));

const mockNavigate = jest.fn();

const STATE_MOCK = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -47,12 +46,7 @@ const StakingEarningsContent = () => {

const { isStakingSupportedChain } = useStakingChain();

if (
!isPooledStakingFeatureEnabled() ||
!isStakingSupportedChain ||
!hasStakedPositions
)
return <></>;
if (!isStakingSupportedChain || !hasStakedPositions) return <></>;

return (
<View style={styles.stakingEarningsContainer}>
Expand Down
4 changes: 0 additions & 4 deletions app/components/UI/Stake/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
/* eslint-disable import/prefer-default-export */
export const isPooledStakingFeatureEnabled = () =>
process.env.MM_POOLED_STAKING_UI_ENABLED === 'true';

export const POOLED_STAKING_FAQ_URL =
'https://support.metamask.io/metamask-portfolio/move-crypto/stake/staking-pool/';
4 changes: 0 additions & 4 deletions app/components/UI/Stake/sdk/stakeSdkProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 0 additions & 4 deletions app/components/UI/Tokens/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => ({
Expand Down
27 changes: 15 additions & 12 deletions app/core/Engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@
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,
Expand Down Expand Up @@ -735,7 +734,7 @@
assetsContractController.getStakedBalanceForChain.bind(
assetsContractController,
),
includeStakedAssets: isPooledStakingFeatureEnabled(),
includeStakedAssets: true,
});
const permissionController = new PermissionController({
messenger: this.controllerMessenger.getRestricted({
Expand Down Expand Up @@ -971,8 +970,8 @@
disableSnaps: !isBasicFunctionalityToggleEnabled(),
}),
clientCryptography: {
pbkdf2Sha512: pbkdf2
}
pbkdf2Sha512: pbkdf2,
},
});

const authenticationController = new AuthenticationController.Controller({
Expand Down Expand Up @@ -1173,7 +1172,7 @@

return Boolean(
hasProperty(showIncomingTransactions, currentChainId) &&
showIncomingTransactions?.[currentHexChainId],
showIncomingTransactions?.[currentHexChainId],
);
},
updateTransactions: true,
Expand Down Expand Up @@ -1302,7 +1301,9 @@
.addProperties({
token_standard: 'ERC20',
asset_type: 'token',
chain_id: getDecimalChainId(getGlobalChainId(networkController)),
chain_id: getDecimalChainId(
getGlobalChainId(networkController),
),
})
.build(),
),
Expand Down Expand Up @@ -1518,7 +1519,7 @@
if (
state.networksMetadata[state.selectedNetworkClientId].status ===
NetworkStatus.Available &&
getGlobalChainId(networkController) !== currentChainId
getGlobalChainId(networkController) !== currentChainId
) {
// We should add a state or event emitter saying the provider changed
setTimeout(() => {
Expand All @@ -1538,7 +1539,9 @@
} catch (error) {
console.error(
error,
`Network ID not changed, current chainId: ${getGlobalChainId(networkController)}`,
`Network ID not changed, current chainId: ${getGlobalChainId(
networkController,
)}`,
);
}
},
Expand Down Expand Up @@ -1780,7 +1783,7 @@

const tokenBalances =
allTokenBalances?.[selectedInternalAccount.address as Hex]?.[
chainId
chainId
] ?? {};
tokens.forEach(
(item: { address: string; balance?: string; decimals: number }) => {
Expand All @@ -1791,9 +1794,9 @@
item.balance ||
(item.address in tokenBalances
? renderFromTokenMinimalUnit(
tokenBalances[item.address as Hex],
item.decimals,
)
tokenBalances[item.address as Hex],
item.decimals,
)
: undefined);
const tokenBalanceFiat = balanceToFiatNumber(
// TODO: Fix this by handling or eliminating the undefined case
Expand Down Expand Up @@ -1868,12 +1871,12 @@
try {
const {
engine: { backgroundState },
} = store.getState();

Check warning on line 1874 in app/core/Engine/Engine.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Unexpected labeled statement
// TODO: Check `allNfts[currentChainId]` property instead
// @ts-expect-error This property does not exist
const nfts = backgroundState.NftController.nfts;

const { tokenBalances } = backgroundState.TokenBalancesController;

Check warning on line 1879 in app/core/Engine/Engine.ts

View workflow job for this annotation

GitHub Actions / scripts (lint)

Unexpected label in break statement

let tokenFound = false;
tokenLoop: for (const chains of Object.values(tokenBalances)) {
Expand Down
Loading
Loading