mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +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 HARMONY_DISPLAY_NAME = 'Harmony Mainnet Shard 0';
|
||||||
export const PALM_DISPLAY_NAME = 'Palm';
|
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 }) =>
|
export const getRpcUrl = ({ network, excludeProjectId = false }) =>
|
||||||
`https://${network}.infura.io/v3/${excludeProjectId ? '' : infuraProjectId}`;
|
`https://${network}.infura.io/v3/${excludeProjectId ? '' : infuraProjectId}`;
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { ethErrors } from 'eth-rpc-errors';
|
import { ethErrors } from 'eth-rpc-errors';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { infuraProjectId } from '../../../../shared/constants/network';
|
||||||
import {
|
import {
|
||||||
SEVERITIES,
|
SEVERITIES,
|
||||||
TYPOGRAPHY,
|
TYPOGRAPHY,
|
||||||
@ -267,7 +268,14 @@ function getValues(pendingApproval, t, actions) {
|
|||||||
},
|
},
|
||||||
dictionary: {
|
dictionary: {
|
||||||
[t('networkName')]: pendingApproval.requestData.chainName,
|
[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('chainId')]: parseInt(pendingApproval.requestData.chainId, 16),
|
||||||
[t('currencySymbol')]: pendingApproval.requestData.ticker,
|
[t('currencySymbol')]: pendingApproval.requestData.ticker,
|
||||||
[t('blockExplorerUrl')]: pendingApproval.requestData
|
[t('blockExplorerUrl')]: pendingApproval.requestData
|
||||||
|
@ -36,6 +36,10 @@ import fetchWithCache from '../../../../helpers/utils/fetch-with-cache';
|
|||||||
import { usePrevious } from '../../../../hooks/usePrevious';
|
import { usePrevious } from '../../../../hooks/usePrevious';
|
||||||
import { MetaMetricsContext } from '../../../../contexts/metametrics';
|
import { MetaMetricsContext } from '../../../../contexts/metametrics';
|
||||||
import { EVENT } from '../../../../../shared/constants/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
|
* Attempts to convert the given chainId to a decimal string, for display
|
||||||
@ -96,6 +100,9 @@ const NetworksForm = ({
|
|||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
const [warnings, setWarnings] = useState({});
|
const [warnings, setWarnings] = useState({});
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
const chainIdMatchesFeaturedRPC = FEATURED_RPCS.some(
|
||||||
|
(featuredRpc) => Number(featuredRpc.chainId) === Number(chainId),
|
||||||
|
);
|
||||||
|
|
||||||
const resetForm = useCallback(() => {
|
const resetForm = useCallback(() => {
|
||||||
setNetworkName(selectedNetworkName || '');
|
setNetworkName(selectedNetworkName || '');
|
||||||
@ -555,10 +562,13 @@ const NetworksForm = ({
|
|||||||
};
|
};
|
||||||
const deletable = !isCurrentRpcTarget && !viewOnly && !addNewNetwork;
|
const deletable = !isCurrentRpcTarget && !viewOnly && !addNewNetwork;
|
||||||
const stateUnchanged = stateIsUnchanged();
|
const stateUnchanged = stateIsUnchanged();
|
||||||
|
const chainIdErrorOnFeaturedRpcDuringEdit =
|
||||||
|
selectedNetwork?.rpcUrl && warnings.chainId && chainIdMatchesFeaturedRPC;
|
||||||
const isSubmitDisabled =
|
const isSubmitDisabled =
|
||||||
hasErrors() ||
|
hasErrors() ||
|
||||||
isSubmitting ||
|
isSubmitting ||
|
||||||
stateUnchanged ||
|
stateUnchanged ||
|
||||||
|
chainIdErrorOnFeaturedRpcDuringEdit ||
|
||||||
!rpcUrl ||
|
!rpcUrl ||
|
||||||
!chainId ||
|
!chainId ||
|
||||||
!ticker;
|
!ticker;
|
||||||
@ -599,7 +609,11 @@ const NetworksForm = ({
|
|||||||
error={errors.rpcUrl?.msg || ''}
|
error={errors.rpcUrl?.msg || ''}
|
||||||
onChange={setRpcUrl}
|
onChange={setRpcUrl}
|
||||||
titleText={t('rpcUrl')}
|
titleText={t('rpcUrl')}
|
||||||
value={rpcUrl}
|
value={
|
||||||
|
rpcUrl?.includes(`/v3/${infuraProjectId}`)
|
||||||
|
? rpcUrl.replace(`/v3/${infuraProjectId}`, '')
|
||||||
|
: rpcUrl
|
||||||
|
}
|
||||||
disabled={viewOnly}
|
disabled={viewOnly}
|
||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
|
Loading…
x
Reference in New Issue
Block a user