addEthereumChain bug fixes (#10520)

feature/default_network_editable
Brad Decker 4 years ago committed by GitHub
parent 20b2c5f004
commit 1a2dc850a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/_locales/en/messages.json
  2. 4
      app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js
  3. 18
      ui/app/pages/confirmation/confirmation.js
  4. 2
      ui/app/store/actionConstants.js
  5. 14
      ui/app/store/actions.js

@ -1945,7 +1945,7 @@
"message": "View in activity" "message": "View in activity"
}, },
"switchEthereumChainConfirmationDescription": { "switchEthereumChainConfirmationDescription": {
"message": "This will will switch the selected network within MetaMask to a previously added network:" "message": "This will switch the selected network within MetaMask to a previously added network:"
}, },
"switchEthereumChainConfirmationTitle": { "switchEthereumChainConfirmationTitle": {
"message": "Allow this site to switch the network?" "message": "Allow this site to switch the network?"

@ -32,7 +32,9 @@ async function addEthereumChainHandler(
if (!req.params?.[0] || typeof req.params[0] !== 'object') { if (!req.params?.[0] || typeof req.params[0] !== 'object') {
return end( return end(
ethErrors.rpc.invalidParams({ ethErrors.rpc.invalidParams({
message: `Expected single, object parameter. Received:\n${req.params}`, message: `Expected single, object parameter. Received:\n${JSON.stringify(
req.params,
)}`,
}), }),
); );
} }

@ -9,11 +9,6 @@ import { useDispatch, useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
import { produce } from 'immer'; import { produce } from 'immer';
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
import {
ENVIRONMENT_TYPE_FULLSCREEN,
ENVIRONMENT_TYPE_POPUP,
} from '../../../../shared/constants/app';
import Box from '../../components/ui/box'; import Box from '../../components/ui/box';
import Chip from '../../components/ui/chip'; import Chip from '../../components/ui/chip';
import MetaMaskTemplateRenderer from '../../components/app/metamask-template-renderer'; import MetaMaskTemplateRenderer from '../../components/app/metamask-template-renderer';
@ -138,16 +133,11 @@ export default function ConfirmationPage() {
}, [pendingConfirmation, t, dispatch]); }, [pendingConfirmation, t, dispatch]);
useEffect(() => { useEffect(() => {
const environmentType = getEnvironmentType();
// If the number of pending confirmations reduces to zero when the user // If the number of pending confirmations reduces to zero when the user
// is in the fullscreen or popup UI, return them to the default route. // return them to the default route. Otherwise, if the number of pending
// Otherwise, if the number of pending confirmations reduces to a number // confirmations reduces to a number that is less than the currently
// that is less than the currently viewed index, reset the index. // viewed index, reset the index.
if ( if (pendingConfirmations.length === 0) {
pendingConfirmations.length === 0 &&
(environmentType === ENVIRONMENT_TYPE_FULLSCREEN ||
environmentType === ENVIRONMENT_TYPE_POPUP)
) {
history.push(DEFAULT_ROUTE); history.push(DEFAULT_ROUTE);
} else if (pendingConfirmations.length <= currentPendingConfirmation) { } else if (pendingConfirmations.length <= currentPendingConfirmation) {
setCurrentPendingConfirmation(pendingConfirmations.length - 1); setCurrentPendingConfirmation(pendingConfirmations.length - 1);

@ -2,8 +2,6 @@ export const GO_HOME = 'GO_HOME';
// modal state // modal state
export const MODAL_OPEN = 'UI_MODAL_OPEN'; export const MODAL_OPEN = 'UI_MODAL_OPEN';
export const MODAL_CLOSE = 'UI_MODAL_CLOSE'; export const MODAL_CLOSE = 'UI_MODAL_CLOSE';
// notification state
export const CLOSE_NOTIFICATION_WINDOW = 'CLOSE_NOTIFICATION_WINDOW';
// sidebar state // sidebar state
export const SIDEBAR_OPEN = 'UI_SIDEBAR_OPEN'; export const SIDEBAR_OPEN = 'UI_SIDEBAR_OPEN';
export const SIDEBAR_CLOSE = 'UI_SIDEBAR_CLOSE'; export const SIDEBAR_CLOSE = 'UI_SIDEBAR_CLOSE';

@ -1772,21 +1772,13 @@ export function hideModal(payload) {
} }
export function closeCurrentNotificationWindow() { export function closeCurrentNotificationWindow() {
return (dispatch, getState) => { return (_, getState) => {
if ( if (
getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION && getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION &&
!hasUnconfirmedTransactions(getState()) !hasUnconfirmedTransactions(getState())
) { ) {
global.platform.closeCurrentWindow(); global.platform.closeCurrentWindow();
dispatch(closeNotificationWindow());
}
};
} }
export function closeNotificationWindow() {
return {
type: actionConstants.CLOSE_NOTIFICATION_WINDOW,
}; };
} }
@ -2476,7 +2468,7 @@ export function resolvePendingApproval(id, value) {
await promisifiedBackground.resolvePendingApproval(id, value); await promisifiedBackground.resolvePendingApproval(id, value);
// Before closing the current window, check if any additional confirmations // Before closing the current window, check if any additional confirmations
// are added as a result of this confirmation being accepted // are added as a result of this confirmation being accepted
const { pendingApprovals } = await promisifiedBackground.getState(); const { pendingApprovals } = await forceUpdateMetamaskState(dispatch);
if (Object.values(pendingApprovals).length === 0) { if (Object.values(pendingApprovals).length === 0) {
dispatch(closeCurrentNotificationWindow()); dispatch(closeCurrentNotificationWindow());
} }
@ -2494,7 +2486,7 @@ export function rejectPendingApproval(id, error) {
await promisifiedBackground.rejectPendingApproval(id, error); await promisifiedBackground.rejectPendingApproval(id, error);
// Before closing the current window, check if any additional confirmations // Before closing the current window, check if any additional confirmations
// are added as a result of this confirmation being rejected // are added as a result of this confirmation being rejected
const { pendingApprovals } = await promisifiedBackground.getState(); const { pendingApprovals } = await forceUpdateMetamaskState(dispatch);
if (Object.values(pendingApprovals).length === 0) { if (Object.values(pendingApprovals).length === 0) {
dispatch(closeCurrentNotificationWindow()); dispatch(closeCurrentNotificationWindow());
} }

Loading…
Cancel
Save