mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
Removed the Infura v3 key from rpcUrl display (#15193)
* Removed infura v3 key from rpcUrl display * Code refactor * Fixed error * Prevent submission of form when editing an featured rpc and there is a chainId error * Add optional chaining to rpcurls to prevent type errors Co-authored-by: Dan J Miller <danjm.com@gmail.com>
This commit is contained in:
parent
aeb0147846
commit
6b4fa46908
@ -56,7 +56,7 @@ export const FANTOM_DISPLAY_NAME = 'Fantom Opera';
|
||||
export const HARMONY_DISPLAY_NAME = 'Harmony Mainnet Shard 0';
|
||||
export const PALM_DISPLAY_NAME = 'Palm';
|
||||
|
||||
const infuraProjectId = process.env.INFURA_PROJECT_ID;
|
||||
export const infuraProjectId = process.env.INFURA_PROJECT_ID;
|
||||
export const getRpcUrl = ({ network, excludeProjectId = false }) =>
|
||||
`https://${network}.infura.io/v3/${excludeProjectId ? '' : infuraProjectId}`;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { ethErrors } from 'eth-rpc-errors';
|
||||
import React from 'react';
|
||||
import { infuraProjectId } from '../../../../shared/constants/network';
|
||||
import {
|
||||
SEVERITIES,
|
||||
TYPOGRAPHY,
|
||||
@ -267,7 +268,14 @@ function getValues(pendingApproval, t, actions) {
|
||||
},
|
||||
dictionary: {
|
||||
[t('networkName')]: pendingApproval.requestData.chainName,
|
||||
[t('networkURL')]: pendingApproval.requestData.rpcUrl,
|
||||
[t('networkURL')]: pendingApproval.requestData.rpcUrl?.includes(
|
||||
`/v3/${infuraProjectId}`,
|
||||
)
|
||||
? pendingApproval.requestData.rpcUrl.replace(
|
||||
`/v3/${infuraProjectId}`,
|
||||
'',
|
||||
)
|
||||
: pendingApproval.requestData.rpcUrl,
|
||||
[t('chainId')]: parseInt(pendingApproval.requestData.chainId, 16),
|
||||
[t('currencySymbol')]: pendingApproval.requestData.ticker,
|
||||
[t('blockExplorerUrl')]: pendingApproval.requestData
|
||||
|
@ -36,6 +36,10 @@ import fetchWithCache from '../../../../helpers/utils/fetch-with-cache';
|
||||
import { usePrevious } from '../../../../hooks/usePrevious';
|
||||
import { MetaMetricsContext } from '../../../../contexts/metametrics';
|
||||
import { EVENT } from '../../../../../shared/constants/metametrics';
|
||||
import {
|
||||
infuraProjectId,
|
||||
FEATURED_RPCS,
|
||||
} from '../../../../../shared/constants/network';
|
||||
|
||||
/**
|
||||
* Attempts to convert the given chainId to a decimal string, for display
|
||||
@ -96,6 +100,9 @@ const NetworksForm = ({
|
||||
const [errors, setErrors] = useState({});
|
||||
const [warnings, setWarnings] = useState({});
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const chainIdMatchesFeaturedRPC = FEATURED_RPCS.some(
|
||||
(featuredRpc) => Number(featuredRpc.chainId) === Number(chainId),
|
||||
);
|
||||
|
||||
const resetForm = useCallback(() => {
|
||||
setNetworkName(selectedNetworkName || '');
|
||||
@ -555,10 +562,13 @@ const NetworksForm = ({
|
||||
};
|
||||
const deletable = !isCurrentRpcTarget && !viewOnly && !addNewNetwork;
|
||||
const stateUnchanged = stateIsUnchanged();
|
||||
const chainIdErrorOnFeaturedRpcDuringEdit =
|
||||
selectedNetwork?.rpcUrl && warnings.chainId && chainIdMatchesFeaturedRPC;
|
||||
const isSubmitDisabled =
|
||||
hasErrors() ||
|
||||
isSubmitting ||
|
||||
stateUnchanged ||
|
||||
chainIdErrorOnFeaturedRpcDuringEdit ||
|
||||
!rpcUrl ||
|
||||
!chainId ||
|
||||
!ticker;
|
||||
@ -599,7 +609,11 @@ const NetworksForm = ({
|
||||
error={errors.rpcUrl?.msg || ''}
|
||||
onChange={setRpcUrl}
|
||||
titleText={t('rpcUrl')}
|
||||
value={rpcUrl}
|
||||
value={
|
||||
rpcUrl?.includes(`/v3/${infuraProjectId}`)
|
||||
? rpcUrl.replace(`/v3/${infuraProjectId}`, '')
|
||||
: rpcUrl
|
||||
}
|
||||
disabled={viewOnly}
|
||||
/>
|
||||
<FormField
|
||||
|
Loading…
Reference in New Issue
Block a user