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: network Controller Migration + UI #11622

Closed
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
32 changes: 30 additions & 2 deletions app/components/Views/Wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
isMainNet,
} from '../../../util/networks';
import {
selectNetworkConfigurations,
selectProviderConfig,
selectTicker,
} from '../../../selectors/networkController';
Expand Down Expand Up @@ -80,8 +81,14 @@ import { RootState } from '../../../reducers';
import usePrevious from '../../hooks/usePrevious';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';
import { selectAccountBalanceByChainId } from '../../../selectors/accountTrackerController';
import { selectUseNftDetection } from '../../../selectors/preferencesController';
import { setNftAutoDetectionModalOpen } from '../../../actions/security';
import {
selectShowMultiRpcModal,
selectUseNftDetection,
} from '../../../selectors/preferencesController';
import {
setNftAutoDetectionModalOpen,
setMultiRpcMigrationModalOpen,
} from '../../../actions/security';
import {
hideNftFetchingLoadingIndicator as hideNftFetchingLoadingIndicatorAction,
showNftFetchingLoadingIndicator as showNftFetchingLoadingIndicatorAction,
Expand All @@ -96,6 +103,7 @@ import {
} from '../../../selectors/notifications';
import { ButtonVariants } from '../../../component-library/components/Buttons/Button';
import { useListNotifications } from '../../../util/notifications/hooks/useNotifications';
import { isObject } from 'lodash';
const createStyles = ({ colors, typography }: Theme) =>
StyleSheet.create({
base: {
Expand Down Expand Up @@ -167,6 +175,8 @@ const Wallet = ({
const styles = createStyles(theme);
const { colors } = theme;
const dispatch = useDispatch();
const networkConfigurations = useSelector(selectNetworkConfigurations);

/**
* Object containing the balance of the current selected account
*/
Expand Down Expand Up @@ -300,6 +310,7 @@ const Wallet = ({

const networkImageSource = useSelector(selectNetworkImageSource);
const useNftDetection = useSelector(selectUseNftDetection);
const showMultiRpcModal = useSelector(selectShowMultiRpcModal);
const isNFTAutoDetectionModalViewed = useSelector(
(state: RootState) => state.security.isNFTAutoDetectionModalViewed,
);
Expand All @@ -316,6 +327,13 @@ const Wallet = ({
});
}, [navigate, providerConfig.chainId, trackEvent]);

const isNetworkDuplicated = Object.values(networkConfigurations).some(
(networkConfiguration) =>
isObject(networkConfiguration) &&
Array.isArray(networkConfiguration.rpcEndpoints) &&
networkConfiguration.rpcEndpoints.length > 1,
);

const checkNftAutoDetectionModal = useCallback(() => {
const isOnMainnet = isMainNet(providerConfig.chainId);
if (!useNftDetection && isOnMainnet && !isNFTAutoDetectionModalViewed) {
Expand All @@ -332,12 +350,22 @@ const Wallet = ({
useNftDetection,
]);

const checkMultiRpcModal = useCallback(() => {
if (showMultiRpcModal && isNetworkDuplicated) {
navigation.navigate(Routes.MODAL.ROOT_MODAL_FLOW, {
screen: Routes.MODAL.MULTI_RPC_MIGRATION_MODAL,
});
dispatch(setMultiRpcMigrationModalOpen(true));
}
}, [dispatch, showMultiRpcModal, navigation, isNetworkDuplicated]);

useEffect(() => {
if (
currentRouteName === 'Wallet' ||
currentRouteName === 'SecuritySettings'
) {
checkNftAutoDetectionModal();
checkMultiRpcModal();
}

async function checkIfNotificationsAreEnabled() {
Expand Down
Loading
Loading