1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 06:07:06 +01:00
metamask-extension/ui/pages/confirmation/templates/switch-ethereum-chain.js
ryanml a75092762f
Fix built-in networks switch-ethereum-chain, Including RPC url in switchEthereumChain requestData (#11268)
* Moving RPC Urls to network constants

* Including RPC url in switchEthereumChain requestData

* Setting project id to var

* Fix built-in networks switch-ethereum-chain

`switch-ethereum-chain` did not work correctly with built-in networks.
It was treating them as custom networks, rather than as built-in
networks. This affected how they were displayed in the network
dropdown, and resulted in slight differences to the network stack used
as well.

The problem was that `updateRpcTarget` was used, which was meant for
custom networks only. Now that `setProviderType` is used in the case of
a built-in network, the behaviour should match the network switcher
exactly.

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2021-06-09 15:18:38 -07:00

97 lines
2.2 KiB
JavaScript

import { ethErrors } from 'eth-rpc-errors';
import { NETWORK_TYPE_RPC } from '../../../../shared/constants/network';
import {
JUSTIFY_CONTENT,
SEVERITIES,
TYPOGRAPHY,
} from '../../../helpers/constants/design-system';
const PENDING_TX_DROP_NOTICE = {
id: 'PENDING_TX_DROP_NOTICE',
severity: SEVERITIES.WARNING,
content: {
element: 'span',
children: {
element: 'MetaMaskTranslation',
props: {
translationKey: 'switchingNetworksCancelsPendingConfirmations',
},
},
},
};
async function getAlerts() {
return [PENDING_TX_DROP_NOTICE];
}
function getValues(pendingApproval, t, actions) {
return {
content: [
{
element: 'Typography',
key: 'title',
children: t('switchEthereumChainConfirmationTitle'),
props: {
variant: TYPOGRAPHY.H3,
align: 'center',
fontWeight: 'bold',
boxProps: {
margin: [0, 0, 4],
},
},
},
{
element: 'Typography',
key: 'description',
children: t('switchEthereumChainConfirmationDescription'),
props: {
variant: TYPOGRAPHY.H7,
align: 'center',
boxProps: {
margin: [0, 0, 4],
},
},
},
{
element: 'Box',
key: 'status-box',
props: {
justifyContent: JUSTIFY_CONTENT.CENTER,
},
children: {
element: 'NetworkDisplay',
key: 'network-being-switched',
props: {
colored: false,
outline: true,
targetNetwork: {
type: pendingApproval.requestData.type || NETWORK_TYPE_RPC,
nickname: pendingApproval.requestData.nickname,
},
},
},
},
],
approvalText: t('switchNetwork'),
cancelText: t('cancel'),
onApprove: () =>
actions.resolvePendingApproval(
pendingApproval.id,
pendingApproval.requestData,
),
onCancel: () =>
actions.rejectPendingApproval(
pendingApproval.id,
ethErrors.provider.userRejectedRequest(),
),
};
}
const switchEthereumChain = {
getAlerts,
getValues,
};
export default switchEthereumChain;