/* eslint-disable no-mixed-spaces-and-tabs */ import React, { useMemo } from 'react'; import { View, Text, StyleSheet } from 'react-native'; import StyledButton from '../StyledButton'; import { strings } from '../../../../locales/i18n'; import NetworkMainAssetLogo from '../NetworkMainAssetLogo'; import { MAINNET, RPC } from '../../../constants/network'; import { connect } from 'react-redux'; import Description from './InfoDescription'; import { useAppThemeFromContext, mockTheme } from '../../../util/theme'; import { NETWORK_EDUCATION_MODAL_CONTAINER_ID, NETWORK_EDUCATION_MODAL_CLOSE_BUTTON_ID, NETWORK_EDUCATION_MODAL_NETWORK_NAME_ID, } from '../../../constants/test-ids'; import { fontStyles } from '../../../styles/common'; import { util as controllerUtils } from '@metamask/controllers'; const createStyles = (colors: { background: { default: string }; text: { default: string }; border: { muted: string }; }) => StyleSheet.create({ wrapper: { backgroundColor: colors.background.default, borderRadius: 10, }, modalContentView: { padding: 20, }, title: { fontSize: 16, ...fontStyles.bold, marginVertical: 10, textAlign: 'center', color: colors.text.default, }, tokenView: { marginBottom: 30, alignItems: 'center', }, tokenType: { padding: 10, borderRadius: 40, alignItems: 'center', justifyContent: 'center', flexDirection: 'row', backgroundColor: colors.border.muted, }, ethLogo: { width: 30, height: 30, overflow: 'hidden', marginHorizontal: 5, }, tokenText: { fontSize: 15, color: colors.text.default, textAlign: 'center', paddingRight: 10, }, capitalizeText: { textTransform: 'capitalize', }, messageTitle: { fontSize: 14, ...fontStyles.bold, marginBottom: 15, textAlign: 'center', color: colors.text.default, }, descriptionViews: { marginBottom: 15, }, closeButton: { marginVertical: 20, borderColor: colors.border.muted, }, rpcUrl: { ...fontStyles.normal, fontSize: 10, color: colors.border.muted, textAlign: 'center', paddingVertical: 5, }, unknownWrapper: { backgroundColor: colors.background.default, marginRight: 6, height: 20, width: 20, borderRadius: 10, alignItems: 'center', justifyContent: 'center', }, unknownText: { ...fontStyles.normal, color: colors.text.default, fontSize: 13, }, }); interface NetworkInfoProps { onClose: () => void; type: string; ticker: string; networkProvider: { nickname: string; type: string; ticker: { networkTicker: string; }; rpcTarget: string; chainId: string; }; isTokenDetectionEnabled: boolean; } const NetworkInfo = (props: NetworkInfoProps) => { const { onClose, ticker, isTokenDetectionEnabled, networkProvider: { nickname, type, ticker: networkTicker, rpcTarget, chainId, }, } = props; const { colors } = useAppThemeFromContext() || mockTheme; const styles = createStyles(colors); const isTokenDetectionSupported = controllerUtils.isTokenDetectionSupportedForNetwork(chainId); const isTokenDetectionEnabledForNetwork = useMemo(() => { if (isTokenDetectionSupported && isTokenDetectionEnabled) { return true; } return false; }, [isTokenDetectionEnabled, isTokenDetectionSupported]); return ( {strings('network_information.switched_network')} {ticker === undefined ? ( <> ? {`${nickname}` || strings('network_information.unknown_network')} ) : ( <> {type === RPC ? `${nickname}` : type === MAINNET ? `${type}` : `${strings('network_information.testnet_network', { type, })}`} )} {ticker === undefined && ( {rpcTarget} )} {strings('network_information.things_to_keep_in_mind')}: {strings('network_information.got_it')} ); }; const mapStateToProps = (state: any) => ({ isTokenDetectionEnabled: state.engine.backgroundState.PreferencesController.useTokenDetection, networkProvider: state.engine.backgroundState.NetworkController.provider, }); export default connect(mapStateToProps)(NetworkInfo);