mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
d6f58bceb0
* allow SnapController to call `ApprovalController:updateRequestState` action * combine popups * show only autorship pill on result * lint * update `snaps-monorepo@0.31.0` and regen policies * dedupe deps and fix fencing * fix update button text * fix fencing * Update a bunch of e2es * address requested changes * update policy * bump key-tree * fix lint * Update RPC E2E * fix locales * Remove wrong instance of window handle polling * design changes and address pr comments * remove unused imports * fix lint * fix fencing * remove unused locales * fence things * re-add redirection * bump test-snaps version * Fix update e2e * fix redirecting logic and address requested changes * force update metamask state on approved * move force update --------- Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
194 lines
5.6 KiB
JavaScript
194 lines
5.6 KiB
JavaScript
import { SubjectType } from '@metamask/subject-metadata-controller';
|
|
import { connect } from 'react-redux';
|
|
import PropTypes from 'prop-types';
|
|
import {
|
|
getAccountsWithLabels,
|
|
getLastConnectedInfo,
|
|
getPermissionsRequests,
|
|
getSelectedAddress,
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
getSnapInstallOrUpdateRequests,
|
|
getRequestState,
|
|
getRequestType,
|
|
///: END:ONLY_INCLUDE_IN
|
|
getTargetSubjectMetadata,
|
|
} from '../../selectors';
|
|
import { getNativeCurrency } from '../../ducks/metamask/metamask';
|
|
|
|
import { formatDate, getURLHostName } from '../../helpers/utils/util';
|
|
import {
|
|
approvePermissionsRequest,
|
|
rejectPermissionsRequest,
|
|
showModal,
|
|
getRequestAccountTabIds,
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
resolvePendingApproval,
|
|
rejectPendingApproval,
|
|
///: END:ONLY_INCLUDE_IN
|
|
} from '../../store/actions';
|
|
import {
|
|
CONNECT_ROUTE,
|
|
CONNECT_CONFIRM_PERMISSIONS_ROUTE,
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
CONNECT_SNAP_INSTALL_ROUTE,
|
|
CONNECT_SNAP_UPDATE_ROUTE,
|
|
CONNECT_SNAP_RESULT_ROUTE,
|
|
///: END:ONLY_INCLUDE_IN
|
|
} from '../../helpers/constants/routes';
|
|
import PermissionApproval from './permissions-connect.component';
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
const {
|
|
match: {
|
|
params: { id: permissionsRequestId },
|
|
},
|
|
location: { pathname },
|
|
} = ownProps;
|
|
let permissionsRequests = getPermissionsRequests(state);
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
permissionsRequests = [
|
|
...permissionsRequests,
|
|
...getSnapInstallOrUpdateRequests(state),
|
|
];
|
|
///: END:ONLY_INCLUDE_IN
|
|
const currentAddress = getSelectedAddress(state);
|
|
|
|
const permissionsRequest = permissionsRequests.find(
|
|
(req) => req.metadata.id === permissionsRequestId,
|
|
);
|
|
|
|
const isRequestingAccounts = Boolean(
|
|
permissionsRequest?.permissions?.eth_accounts,
|
|
);
|
|
|
|
const { metadata = {} } = permissionsRequest || {};
|
|
const { origin } = metadata;
|
|
const nativeCurrency = getNativeCurrency(state);
|
|
|
|
const targetSubjectMetadata = getTargetSubjectMetadata(state, origin) ?? {
|
|
name: getURLHostName(origin) || origin,
|
|
origin,
|
|
iconUrl: null,
|
|
extensionId: null,
|
|
subjectType: SubjectType.Unknown,
|
|
};
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
const isSnap = targetSubjectMetadata.subjectType === SubjectType.Snap;
|
|
|
|
const requestType = getRequestType(state, permissionsRequestId);
|
|
|
|
const requestState = getRequestState(state, permissionsRequestId);
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
const accountsWithLabels = getAccountsWithLabels(state);
|
|
|
|
const lastConnectedInfo = getLastConnectedInfo(state) || {};
|
|
const addressLastConnectedMap = lastConnectedInfo[origin]?.accounts || {};
|
|
|
|
Object.keys(addressLastConnectedMap).forEach((key) => {
|
|
addressLastConnectedMap[key] = formatDate(
|
|
addressLastConnectedMap[key],
|
|
'yyyy-MM-dd',
|
|
);
|
|
});
|
|
|
|
const connectPath = `${CONNECT_ROUTE}/${permissionsRequestId}`;
|
|
const confirmPermissionPath = `${CONNECT_ROUTE}/${permissionsRequestId}${CONNECT_CONFIRM_PERMISSIONS_ROUTE}`;
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
const snapInstallPath = `${CONNECT_ROUTE}/${permissionsRequestId}${CONNECT_SNAP_INSTALL_ROUTE}`;
|
|
const snapUpdatePath = `${CONNECT_ROUTE}/${permissionsRequestId}${CONNECT_SNAP_UPDATE_ROUTE}`;
|
|
const snapResultPath = `${CONNECT_ROUTE}/${permissionsRequestId}${CONNECT_SNAP_RESULT_ROUTE}`;
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
let totalPages = 1 + isRequestingAccounts;
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
totalPages += isSnap;
|
|
///: END:ONLY_INCLUDE_IN
|
|
totalPages = totalPages.toString();
|
|
|
|
let page = '';
|
|
if (pathname === connectPath) {
|
|
page = '1';
|
|
} else if (pathname === confirmPermissionPath) {
|
|
page = isRequestingAccounts ? '2' : '1';
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
} else if (
|
|
pathname === snapInstallPath ||
|
|
pathname === snapUpdatePath ||
|
|
pathname === snapResultPath
|
|
) {
|
|
page = isRequestingAccounts ? '3' : '2';
|
|
///: END:ONLY_INCLUDE_IN
|
|
} else {
|
|
throw new Error('Incorrect path for permissions-connect component');
|
|
}
|
|
|
|
return {
|
|
isRequestingAccounts,
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
requestType,
|
|
snapInstallPath,
|
|
snapUpdatePath,
|
|
snapResultPath,
|
|
requestState,
|
|
isSnap,
|
|
///: END:ONLY_INCLUDE_IN
|
|
permissionsRequest,
|
|
permissionsRequestId,
|
|
accounts: accountsWithLabels,
|
|
currentAddress,
|
|
origin,
|
|
newAccountNumber: accountsWithLabels.length + 1,
|
|
nativeCurrency,
|
|
addressLastConnectedMap,
|
|
lastConnectedInfo,
|
|
connectPath,
|
|
confirmPermissionPath,
|
|
totalPages,
|
|
page,
|
|
targetSubjectMetadata,
|
|
};
|
|
};
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
return {
|
|
approvePermissionsRequest: (request) =>
|
|
dispatch(approvePermissionsRequest(request)),
|
|
rejectPermissionsRequest: (requestId) =>
|
|
dispatch(rejectPermissionsRequest(requestId)),
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
approvePendingApproval: (id, value) =>
|
|
dispatch(resolvePendingApproval(id, value)),
|
|
rejectPendingApproval: (id, error) =>
|
|
dispatch(rejectPendingApproval(id, error)),
|
|
///: END:ONLY_INCLUDE_IN
|
|
showNewAccountModal: ({ onCreateNewAccount, newAccountNumber }) => {
|
|
return dispatch(
|
|
showModal({
|
|
name: 'NEW_ACCOUNT',
|
|
onCreateNewAccount,
|
|
newAccountNumber,
|
|
}),
|
|
);
|
|
},
|
|
getRequestAccountTabIds: () => dispatch(getRequestAccountTabIds()),
|
|
};
|
|
};
|
|
|
|
const PermissionApprovalContainer = connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps,
|
|
)(PermissionApproval);
|
|
|
|
PermissionApprovalContainer.propTypes = {
|
|
history: PropTypes.object.isRequired,
|
|
match: PropTypes.shape({
|
|
params: PropTypes.shape({
|
|
id: PropTypes.string,
|
|
}).isRequired,
|
|
}).isRequired,
|
|
};
|
|
|
|
export default PermissionApprovalContainer;
|