mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
b5ece42ca1
* Sending showCustodyConfirmLink as a prop and fixing other issues * Upgraded MMI extension monrepo and trying to fix the issue * prevents deeplink from closing * Fixed styles of Custody view and changed the place of it * Fixed CI issues * fixing eslint issues * Update LavaMoat policies * fixing tests * Fixed test * updated snapshots * reorder, otherwise it won't make sense * adds necessary methods * removes duplicated key value * updated snapshot --------- Co-authored-by: Antonio Regadas <antonio.regadas@consensys.net> Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com> Co-authored-by: António Regadas <apregadas@gmail.com>
254 lines
7.4 KiB
JavaScript
254 lines
7.4 KiB
JavaScript
import { connect } from 'react-redux';
|
|
import { compose } from 'redux';
|
|
import { withRouter } from 'react-router-dom';
|
|
import {
|
|
goHome,
|
|
showModal,
|
|
resolvePendingApproval,
|
|
rejectPendingApproval,
|
|
rejectAllMessages,
|
|
completedTx,
|
|
} from '../../../store/actions';
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
// eslint-disable-next-line import/order
|
|
import { showCustodianDeepLink } from '@metamask-institutional/extension';
|
|
import {
|
|
mmiActionsFactory,
|
|
setPersonalMessageInProgress,
|
|
} from '../../../store/institutional/institution-background';
|
|
import { getEnvironmentType } from '../../../../app/scripts/lib/util';
|
|
import {
|
|
showCustodyConfirmLink,
|
|
checkForUnapprovedMessages,
|
|
} from '../../../store/institutional/institution-actions';
|
|
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../../../shared/constants/app';
|
|
///: END:ONLY_INCLUDE_IN
|
|
import {
|
|
accountsWithSendEtherInfoSelector,
|
|
getSubjectMetadata,
|
|
doesAddressRequireLedgerHidConnection,
|
|
unconfirmedMessagesHashSelector,
|
|
getTotalUnapprovedMessagesCount,
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
unapprovedPersonalMsgsSelector,
|
|
getAccountType,
|
|
getSelectedAccount,
|
|
///: END:ONLY_INCLUDE_IN
|
|
} from '../../../selectors';
|
|
import { getAccountByAddress, valuesFor } from '../../../helpers/utils/util';
|
|
import { clearConfirmTransaction } from '../../../ducks/confirm-transaction/confirm-transaction.duck';
|
|
import { getMostRecentOverviewPage } from '../../../ducks/history/history';
|
|
import { isAddressLedger } from '../../../ducks/metamask/metamask';
|
|
import SignatureRequestOriginal from './signature-request-original.component';
|
|
|
|
function mapStateToProps(state, ownProps) {
|
|
const {
|
|
msgParams: { from },
|
|
} = ownProps.txData;
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
const envType = getEnvironmentType();
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
const hardwareWalletRequiresConnection =
|
|
doesAddressRequireLedgerHidConnection(state, from);
|
|
const isLedgerWallet = isAddressLedger(state, from);
|
|
const messagesList = unconfirmedMessagesHashSelector(state);
|
|
const messagesCount = getTotalUnapprovedMessagesCount(state);
|
|
|
|
return {
|
|
requester: null,
|
|
requesterAddress: null,
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
|
hardwareWalletRequiresConnection,
|
|
isLedgerWallet,
|
|
// not passed to component
|
|
allAccounts: accountsWithSendEtherInfoSelector(state),
|
|
subjectMetadata: getSubjectMetadata(state),
|
|
messagesList,
|
|
messagesCount,
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
accountType: getAccountType(state),
|
|
isNotification: envType === ENVIRONMENT_TYPE_NOTIFICATION,
|
|
selectedAccount: getSelectedAccount(state),
|
|
unapprovedPersonalMessages: unapprovedPersonalMsgsSelector(state),
|
|
///: END:ONLY_INCLUDE_IN
|
|
};
|
|
}
|
|
|
|
let mapDispatchToProps = null;
|
|
|
|
mapDispatchToProps = function (dispatch) {
|
|
return {
|
|
goHome: () => dispatch(goHome()),
|
|
clearConfirmTransaction: () => dispatch(clearConfirmTransaction()),
|
|
showRejectTransactionsConfirmationModal: ({
|
|
onSubmit,
|
|
unapprovedTxCount: messagesCount,
|
|
}) => {
|
|
return dispatch(
|
|
showModal({
|
|
name: 'REJECT_TRANSACTIONS',
|
|
onSubmit,
|
|
unapprovedTxCount: messagesCount,
|
|
isRequestType: true,
|
|
}),
|
|
);
|
|
},
|
|
completedTx: (txId) => dispatch(completedTx(txId)),
|
|
resolvePendingApproval: (id) => {
|
|
dispatch(resolvePendingApproval(id));
|
|
},
|
|
rejectPendingApproval: (id, error) =>
|
|
dispatch(rejectPendingApproval(id, error)),
|
|
cancelAllApprovals: (messagesList) => {
|
|
dispatch(rejectAllMessages(messagesList));
|
|
},
|
|
};
|
|
};
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
function mmiMapDispatchToProps(dispatch) {
|
|
const mmiActions = mmiActionsFactory();
|
|
return {
|
|
setMsgInProgress: (msgId) => dispatch(setPersonalMessageInProgress(msgId)),
|
|
showCustodianDeepLink: ({
|
|
custodyId,
|
|
fromAddress,
|
|
closeNotification,
|
|
onDeepLinkFetched,
|
|
onDeepLinkShown,
|
|
}) =>
|
|
showCustodianDeepLink({
|
|
dispatch,
|
|
mmiActions,
|
|
txId: undefined,
|
|
fromAddress,
|
|
custodyId,
|
|
isSignature: true,
|
|
closeNotification,
|
|
onDeepLinkFetched,
|
|
onDeepLinkShown,
|
|
showCustodyConfirmLink,
|
|
}),
|
|
showTransactionsFailedModal: ({
|
|
errorMessage,
|
|
closeNotification,
|
|
operationFailed,
|
|
}) =>
|
|
dispatch(
|
|
showModal({
|
|
name: 'TRANSACTION_FAILED',
|
|
errorMessage,
|
|
closeNotification,
|
|
operationFailed,
|
|
}),
|
|
),
|
|
setWaitForConfirmDeepLinkDialog: (wait) =>
|
|
dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(wait)),
|
|
goHome: () => dispatch(goHome()),
|
|
clearConfirmTransaction: () => dispatch(clearConfirmTransaction()),
|
|
showRejectTransactionsConfirmationModal: ({
|
|
onSubmit,
|
|
unapprovedTxCount: messagesCount,
|
|
}) => {
|
|
return dispatch(
|
|
showModal({
|
|
name: 'REJECT_TRANSACTIONS',
|
|
onSubmit,
|
|
unapprovedTxCount: messagesCount,
|
|
isRequestType: true,
|
|
}),
|
|
);
|
|
},
|
|
completedTx: (txId) => dispatch(completedTx(txId)),
|
|
resolvePendingApproval: (id) => {
|
|
dispatch(resolvePendingApproval(id));
|
|
},
|
|
rejectPendingApproval: (id, error) =>
|
|
dispatch(rejectPendingApproval(id, error)),
|
|
cancelAllApprovals: (messagesList) => {
|
|
dispatch(rejectAllMessages(messagesList));
|
|
},
|
|
};
|
|
}
|
|
|
|
mapDispatchToProps = mmiMapDispatchToProps;
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
function mergeProps(stateProps, dispatchProps, ownProps) {
|
|
const { txData } = ownProps;
|
|
|
|
const {
|
|
allAccounts,
|
|
messagesList,
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
accountType,
|
|
isNotification,
|
|
unapprovedPersonalMessages,
|
|
///: END:ONLY_INCLUDE_IN
|
|
...otherStateProps
|
|
} = stateProps;
|
|
|
|
const {
|
|
msgParams: { from },
|
|
} = txData;
|
|
|
|
const fromAccount = getAccountByAddress(allAccounts, from);
|
|
|
|
const { cancelAllApprovals: dispatchCancelAllApprovals } = dispatchProps;
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
const mmiOnSignCallback = async (_msgData) => {
|
|
if (accountType === 'custody') {
|
|
try {
|
|
let msgData = _msgData;
|
|
let id = _msgData.custodyId;
|
|
if (!_msgData.custodyId) {
|
|
msgData = checkForUnapprovedMessages(
|
|
_msgData,
|
|
unapprovedPersonalMessages,
|
|
);
|
|
id = msgData.custodyId;
|
|
}
|
|
dispatchProps.showCustodianDeepLink({
|
|
custodyId: id,
|
|
fromAddress: fromAccount.address,
|
|
closeNotification: isNotification,
|
|
onDeepLinkFetched: () => undefined,
|
|
onDeepLinkShown: () => undefined,
|
|
});
|
|
await dispatchProps.setMsgInProgress(msgData.metamaskId);
|
|
await dispatchProps.setWaitForConfirmDeepLinkDialog(true);
|
|
await goHome();
|
|
} catch (err) {
|
|
await dispatchProps.setWaitForConfirmDeepLinkDialog(true);
|
|
await dispatchProps.showTransactionsFailedModal({
|
|
errorMessage: err.message,
|
|
closeNotification: true,
|
|
operationFailed: true,
|
|
});
|
|
}
|
|
}
|
|
};
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
return {
|
|
...ownProps,
|
|
...otherStateProps,
|
|
...dispatchProps,
|
|
fromAccount,
|
|
txData,
|
|
cancelAllApprovals: () =>
|
|
dispatchCancelAllApprovals(valuesFor(messagesList)),
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
|
mmiOnSignCallback,
|
|
///: END:ONLY_INCLUDE_IN
|
|
};
|
|
}
|
|
|
|
export default compose(
|
|
withRouter,
|
|
connect(mapStateToProps, mapDispatchToProps, mergeProps),
|
|
)(SignatureRequestOriginal);
|