Skip to content

Commit

Permalink
Merge branch 'test/remove-list-notifications' of github.com:MetaMask/…
Browse files Browse the repository at this point in the history
…metamask-mobile into test/remove-list-notifications
  • Loading branch information
Cal-L committed Nov 13, 2024
2 parents 1637a56 + 235fcb9 commit 465d3d1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 92 deletions.
40 changes: 1 addition & 39 deletions app/components/Views/Wallet/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React from 'react';
import Wallet from './';
import { renderScreen } from '../../../util/test/renderWithProvider';
import { act, screen } from '@testing-library/react-native';
import { screen } from '@testing-library/react-native';
import ScrollableTabView from 'react-native-scrollable-tab-view';
import Routes from '../../../constants/navigation/Routes';
import { backgroundState } from '../../../util/test/initial-root-state';
import { MOCK_ACCOUNTS_CONTROLLER_STATE } from '../../../util/test/accountsControllerTestUtils';
import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors';
import { useAccountSyncing } from '../../../util/notifications/hooks/useAccountSyncing';
import { AppState } from 'react-native';

const MOCK_ADDRESS = '0xc4955c0d639d99699bfd7ec54d9fafee40e4d272';

Expand Down Expand Up @@ -186,40 +184,4 @@ describe('Wallet', () => {
);
expect(accountPicker).toBeDefined();
});
it('dispatches account syncing on mount', () => {
jest.clearAllMocks();
//@ts-expect-error we are ignoring the navigation params on purpose because we do not want to mock setOptions to test the navbar
render(Wallet);
expect(useAccountSyncing().dispatchAccountSyncing).toHaveBeenCalledTimes(1);
});
it('dispatches account syncing when appState switches from inactive|background to active', () => {
jest.clearAllMocks();

const addEventListener = jest.spyOn(AppState, 'addEventListener');

//@ts-expect-error we are ignoring the navigation params on purpose because we do not want to mock setOptions to test the navbar
render(Wallet);

expect(addEventListener).toHaveBeenCalledWith(
'change',
expect.any(Function),
);
const handleAppStateChange = (
addEventListener as jest.Mock
).mock.calls.find(([event]) => event === 'change')[1];

act(() => {
handleAppStateChange('background');
handleAppStateChange('active');
});

expect(useAccountSyncing().dispatchAccountSyncing).toHaveBeenCalledTimes(2);

act(() => {
handleAppStateChange('inactive');
handleAppStateChange('active');
});

expect(useAccountSyncing().dispatchAccountSyncing).toHaveBeenCalledTimes(3);
});
});
55 changes: 2 additions & 53 deletions app/components/Views/Wallet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import React, {
useEffect,
useRef,
useCallback,
useContext,
useLayoutEffect,
} from 'react';
import React, { useEffect, useRef, useCallback, useContext } from 'react';
import {
ActivityIndicator,
StyleSheet,
View,
TextStyle,
InteractionManager,
Linking,
AppState,
AppStateStatus,
} from 'react-native';
import type { Theme } from '@metamask/design-tokens';
import { connect, useSelector } from 'react-redux';
Expand Down Expand Up @@ -93,9 +85,7 @@ import {
selectIsProfileSyncingEnabled,
} from '../../../selectors/notifications';
import { ButtonVariants } from '../../../component-library/components/Buttons/Button';
//import { useListNotifications } from '../../../util/notifications/hooks/useNotifications';
import { useAccountName } from '../../hooks/useAccountName';
//import { useAccountSyncing } from '../../../util/notifications/hooks/useAccountSyncing';

import { PortfolioBalance } from '../../UI/Tokens/TokenList/PortfolioBalance';
import useCheckNftAutoDetectionModal from '../../hooks/useCheckNftAutoDetectionModal';
Expand Down Expand Up @@ -151,10 +141,6 @@ interface WalletProps {
hideNftFetchingLoadingIndicator: () => void;
}

const Wallet2 = () => {
return <View style={{ flex: 1, backgroundColor: 'red' }}></View>;
};

/**
* Main view for the wallet
*/
Expand All @@ -166,10 +152,7 @@ const Wallet = ({
showNftFetchingLoadingIndicator,
hideNftFetchingLoadingIndicator,
}: WalletProps) => {
const appState = useRef(AppState.currentState);
const { navigate } = useNavigation();
// const { listNotifications } = useListNotifications();
//const { dispatchAccountSyncing } = useAccountSyncing();
const walletRef = useRef(null);
const theme = useTheme();
const { toastRef } = useContext(ToastContext);
Expand Down Expand Up @@ -419,40 +402,6 @@ const Wallet = ({
[navigation, providerConfig.chainId],
);

// Layout effect when component/view is visible
// - fetches notifications
// - dispatches account syncing
useLayoutEffect(
() => {
const handleAppStateChange = (nextAppState: AppStateStatus) => {
if (
appState.current?.match(/inactive|background/) &&
nextAppState === 'active'
) {
// listNotifications();
// dispatchAccountSyncing();
}

appState.current = nextAppState;
};

const subscription = AppState.addEventListener(
'change',
handleAppStateChange,
);

// listNotifications();
// dispatchAccountSyncing();

return () => {
subscription.remove();
};
},
[
/* dispatchAccountSyncing */
],
);

useEffect(() => {
navigation.setOptions(
getWalletNavbarOptions(
Expand Down Expand Up @@ -702,5 +651,5 @@ const mapDispatchToProps = (dispatch: any) => ({
hideNftFetchingLoadingIndicator: () =>
dispatch(hideNftFetchingLoadingIndicatorAction()),
});
//export default Wallet2;

export default connect(mapStateToProps, mapDispatchToProps)(Wallet);
36 changes: 36 additions & 0 deletions app/core/RPCMethods/wallet_addEthereumChain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,42 @@ describe('RPC Method - wallet_addEthereumChain', () => {
}
});

it('should report native currency symbol length being too long', async () => {
const symbol = 'aaaaaaaaaaaaaaa';
await expect(
wallet_addEthereumChain({
req: {
params: [{
...correctParams,
nativeCurrency: { symbol, decimals: 18 },
}],
},
...otherOptions,
}),
).rejects.toThrow(
`Expected 1-6 character string 'nativeCurrency.symbol'. Received:\n${symbol}`,
);
});

it('should allow 1 letter native currency symbols', async () => {
jest.mock('./networkChecker.util');
jest
.spyOn(Engine.context.NetworkController, 'addNetwork')
.mockResolvedValue({ rpcEndpoints: [] });

await wallet_addEthereumChain({
req: {
params: [
{
...correctParams,
nativeCurrency: { symbol: 'a', decimals: 18 },
},
],
},
...otherOptions,
});
});

describe('Approval Flow', () => {
it('should start and end a new approval flow if chain does not already exist', async () => {
jest
Expand Down

0 comments on commit 465d3d1

Please sign in to comment.