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

chore: Remove notifications logic from wallet view #12276

Merged
merged 9 commits into from
Nov 14, 2024
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);
});
});
53 changes: 4 additions & 49 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 @@ -162,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 @@ -415,35 +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();
};
}, [listNotifications, dispatchAccountSyncing]);

useEffect(() => {
navigation.setOptions(
getWalletNavbarOptions(
Expand Down Expand Up @@ -533,12 +491,9 @@ const Wallet = ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let stakedBalance: any = 0;

const assets = [
...(tokens || []),
];
const assets = [...(tokens || [])];

if (accountBalanceByChainId) {

balance = renderFromWei(accountBalanceByChainId.balance);
const nativeAsset = {
// TODO: Add name property to Token interface in controllers.
Expand Down Expand Up @@ -575,8 +530,8 @@ const Wallet = ({
conversionRate,
currentCurrency,
),
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
assets.push(stakedAsset);
}
Expand Down
4 changes: 2 additions & 2 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ stages:
- run_ios_api_specs: {}
- run_tag_smoke_accounts_ios: {}
- run_tag_smoke_accounts_android: {}
- run_tag_smoke_notifications_ios: {}
- run_tag_smoke_notifications_android: {}
# - run_tag_smoke_notifications_ios: {}
# - run_tag_smoke_notifications_android: {}
# - run_tag_smoke_assets_ios: {}
- run_tag_smoke_assets_android: {}
- run_tag_smoke_confirmations_ios: {}
Expand Down
Loading