diff --git a/ui/components/app/dropdowns/network-dropdown.js b/ui/components/app/dropdowns/network-dropdown.js index 3c1ceb8e2..1fa626fc6 100644 --- a/ui/components/app/dropdowns/network-dropdown.js +++ b/ui/components/app/dropdowns/network-dropdown.js @@ -230,27 +230,6 @@ class NetworkDropdown extends Component { ); } - getNetworkName() { - const { providerConfig } = this.props; - const providerName = providerConfig.type; - const { t } = this.context; - - switch (providerName) { - case NETWORK_TYPES.MAINNET: - return t('mainnet'); - case NETWORK_TYPES.GOERLI: - return t('goerli'); - case NETWORK_TYPES.SEPOLIA: - return t('sepolia'); - case NETWORK_TYPES.LINEA_TESTNET: - return t('lineatestnet'); - case NETWORK_TYPES.LOCALHOST: - return t('localhost'); - default: - return providerConfig.nickname || t('unknownNetwork'); - } - } - renderNetworkEntry(network) { const { providerConfig: { type: providerType }, diff --git a/ui/components/app/signature-request-original/signature-request-original.component.js b/ui/components/app/signature-request-original/signature-request-original.component.js index 0cc27dd42..c60ed16a8 100644 --- a/ui/components/app/signature-request-original/signature-request-original.component.js +++ b/ui/components/app/signature-request-original/signature-request-original.component.js @@ -5,6 +5,7 @@ import { ObjectInspector } from 'react-inspector'; import LedgerInstructionField from '../ledger-instruction-field'; import { MESSAGE_TYPE } from '../../../../shared/constants/app'; import { + getNetworkNameFromProviderType, getURLHostName, sanitizeString, ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) @@ -30,7 +31,6 @@ import { BackgroundColor, ///: END:ONLY_INCLUDE_IN } from '../../../helpers/constants/design-system'; -import { NETWORK_TYPES } from '../../../../shared/constants/network'; import { Numeric } from '../../../../shared/modules/Numeric'; import { EtherDenomination } from '../../../../shared/constants/common'; import ConfirmPageContainerNavigation from '../confirm-page-container/confirm-page-container-navigation'; @@ -81,27 +81,6 @@ export default class SignatureRequestOriginal extends Component { showSignatureRequestWarning: false, }; - getNetworkName() { - const { providerConfig } = this.props; - const providerName = providerConfig.type; - const { t } = this.context; - - switch (providerName) { - case NETWORK_TYPES.MAINNET: - return t('mainnet'); - case NETWORK_TYPES.GOERLI: - return t('goerli'); - case NETWORK_TYPES.SEPOLIA: - return t('sepolia'); - case NETWORK_TYPES.LINEA_TESTNET: - return t('lineatestnet'); - case NETWORK_TYPES.LOCALHOST: - return t('localhost'); - default: - return providerConfig.nickname || t('unknownNetwork'); - } - } - msgHexToText = (hex) => { try { const stripped = stripHexPrefix(hex); @@ -348,6 +327,7 @@ export default class SignatureRequestOriginal extends Component { render = () => { const { + providerConfig, messagesCount, nativeCurrency, currentCurrency, @@ -358,7 +338,11 @@ export default class SignatureRequestOriginal extends Component { const { t } = this.context; const rejectNText = t('rejectRequestsN', [messagesCount]); - const currentNetwork = this.getNetworkName(); + const networkName = getNetworkNameFromProviderType(providerConfig.type); + const currentNetwork = + networkName === '' + ? providerConfig.nickname || t('unknownNetwork') + : t(networkName); const balanceInBaseAsset = conversionRate ? formatCurrency( diff --git a/ui/components/app/signature-request/signature-request.component.js b/ui/components/app/signature-request/signature-request.component.js index 75d5708d6..cc426ab0f 100644 --- a/ui/components/app/signature-request/signature-request.component.js +++ b/ui/components/app/signature-request/signature-request.component.js @@ -5,6 +5,7 @@ import LedgerInstructionField from '../ledger-instruction-field'; import { sanitizeMessage, getURLHostName, + getNetworkNameFromProviderType, ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) shortenAddress, ///: END:ONLY_INCLUDE_IN @@ -28,7 +29,6 @@ import { ///: END:ONLY_INCLUDE_IN } from '../../../helpers/constants/design-system'; import NetworkAccountBalanceHeader from '../network-account-balance-header'; -import { NETWORK_TYPES } from '../../../../shared/constants/network'; import { Numeric } from '../../../../shared/modules/Numeric'; import { EtherDenomination } from '../../../../shared/constants/common'; import ConfirmPageContainerNavigation from '../confirm-page-container/confirm-page-container-navigation'; @@ -121,27 +121,6 @@ export default class SignatureRequest extends PureComponent { )}`; } - getNetworkName() { - const { providerConfig } = this.props; - const providerName = providerConfig.type; - const { t } = this.context; - - switch (providerName) { - case NETWORK_TYPES.MAINNET: - return t('mainnet'); - case NETWORK_TYPES.GOERLI: - return t('goerli'); - case NETWORK_TYPES.SEPOLIA: - return t('sepolia'); - case NETWORK_TYPES.LINEA_TESTNET: - return t('lineatestnet'); - case NETWORK_TYPES.LOCALHOST: - return t('localhost'); - default: - return providerConfig.nickname || t('unknownNetwork'); - } - } - memoizedParseMessage = memoize((data) => { const { message, domain = {}, primaryType, types } = JSON.parse(data); const sanitizedMessage = sanitizeMessage(message, primaryType, types); @@ -170,6 +149,7 @@ export default class SignatureRequest extends PureComponent { render() { const { + providerConfig, txData: { msgParams: { data, origin, version }, type, @@ -196,7 +176,11 @@ export default class SignatureRequest extends PureComponent { primaryType, } = this.memoizedParseMessage(data); const rejectNText = t('rejectRequestsN', [unapprovedMessagesCount]); - const currentNetwork = this.getNetworkName(); + const networkName = getNetworkNameFromProviderType(providerConfig.type); + const currentNetwork = + networkName === '' + ? providerConfig.nickname || t('unknownNetwork') + : t(networkName); const balanceInBaseAsset = conversionRate ? formatCurrency( diff --git a/ui/helpers/utils/util.js b/ui/helpers/utils/util.js index 5dda8a871..00bb738b5 100644 --- a/ui/helpers/utils/util.js +++ b/ui/helpers/utils/util.js @@ -10,7 +10,7 @@ import bowser from 'bowser'; ///: BEGIN:ONLY_INCLUDE_IN(snaps) import { getSnapPrefix } from '@metamask/snaps-utils'; ///: END:ONLY_INCLUDE_IN -import { CHAIN_IDS } from '../../../shared/constants/network'; +import { CHAIN_IDS, NETWORK_TYPES } from '../../../shared/constants/network'; import { toChecksumHexAddress, stripHexPrefix, @@ -584,3 +584,18 @@ export const sanitizeString = (value) => { const regex = /\u202E/giu; return value.replace(regex, '\\u202E'); }; + +/** + * This method checks current provider type and returns its string representation + * + * @param {*} provider + * @param {*} t + * @returns + */ + +export const getNetworkNameFromProviderType = (providerName) => { + if (providerName === NETWORK_TYPES.RPC) { + return ''; + } + return providerName; +}; diff --git a/ui/helpers/utils/util.test.js b/ui/helpers/utils/util.test.js index 8b23a1ea1..77ac796c2 100644 --- a/ui/helpers/utils/util.test.js +++ b/ui/helpers/utils/util.test.js @@ -918,4 +918,15 @@ describe('util', () => { expect(util.isDefaultMetaMaskChain(CHAIN_IDS.CELO)).toBeFalsy(); }); }); + + describe('getNetworkNameFromProviderType()', () => { + it('should return providerConfig.type if the type is not rpc', () => { + expect(util.getNetworkNameFromProviderType('mainnet')).toStrictEqual( + 'mainnet', + ); + }); + it('should return empty string if teh providerConfig.type is rpc', () => { + expect(util.getNetworkNameFromProviderType('rpc')).toStrictEqual(''); + }); + }); });