1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/pages/confirmation/templates/switch-ethereum-chain.js

102 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-02-22 17:20:42 +01:00
import { ethErrors } from 'eth-rpc-errors';
import {
JustifyContent,
2021-02-22 17:20:42 +01:00
SEVERITIES,
TextColor,
TypographyVariant,
2021-02-22 17:20:42 +01:00
} 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(_pendingApproval, state) {
const alerts = [];
if (state.unapprovedTxsCount > 0) {
alerts.push(PENDING_TX_DROP_NOTICE);
}
return alerts;
2021-02-22 17:20:42 +01:00
}
function getValues(pendingApproval, t, actions) {
return {
content: [
{
element: 'Typography',
key: 'title',
children: t('switchEthereumChainConfirmationTitle'),
props: {
variant: TypographyVariant.H3,
2021-02-22 17:20:42 +01:00
align: 'center',
fontWeight: 'normal',
2021-02-22 17:20:42 +01:00
boxProps: {
margin: [0, 0, 2],
padding: [0, 4, 0, 4],
2021-02-22 17:20:42 +01:00
},
},
},
{
element: 'Typography',
key: 'description',
children: t('switchEthereumChainConfirmationDescription'),
props: {
variant: TypographyVariant.H7,
color: TextColor.textAlternative,
2021-02-22 17:20:42 +01:00
align: 'center',
boxProps: {
padding: [0, 4, 0, 4],
2021-02-22 17:20:42 +01:00
},
},
},
{
element: 'Box',
key: 'status-box',
props: {
justifyContent: JustifyContent.center,
2021-02-22 17:20:42 +01:00
},
children: {
element: 'ConfirmationNetworkSwitch',
2021-02-22 17:20:42 +01:00
key: 'network-being-switched',
props: {
newNetwork: {
chainId: pendingApproval.requestData.chainId,
nickname: pendingApproval.requestData.nickname,
2021-02-22 17:20:42 +01:00
},
},
},
},
],
cancelText: t('cancel'),
submitText: t('switchNetwork'),
onSubmit: () =>
2021-02-22 17:20:42 +01:00
actions.resolvePendingApproval(
pendingApproval.id,
pendingApproval.requestData,
),
onCancel: () =>
actions.rejectPendingApproval(
pendingApproval.id,
ethErrors.provider.userRejectedRequest().serialize(),
2021-02-22 17:20:42 +01:00
),
networkDisplay: true,
2021-02-22 17:20:42 +01:00
};
}
const switchEthereumChain = {
getAlerts,
getValues,
};
export default switchEthereumChain;