mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-25 11:28:51 +01:00
0c203d0518
* refactoring signature-request and adding test coverage * adding storybook and removing the reduntant files: * adding new components from * replacing <SiteOrigin/> with <TagUrl/> * updating review comments from Jyoti and George * adding the hook * refactoring in the changes from #18770 MMI PR * adding new hook for the MMISign changes * updating lavamoat * updating lavamoat * removing a commeted line * updating the sign check with accountType conditional * fixing build issues * updating the review comments on the hooks * updating signatureRequestHeader * lint fix * fixing test failure * lint fix * updating review comments * adding the renamed hook * updating the origin url * fixing test failure * migrating changes from #19184 * updating snapshot * fixing e2e failure * fixing e2e failure * addressing review comments from Joao * migrating chnages from #19892 * moving shallowEqual inside of mmi build * migrating changes from #19881 * fixing build failure * migrating changes from #19949 * migrating changes from #19468 * updating snapshot * updating snapshot * updating QA review comments * fixing full screen height issue from develop * migrating changes from #20083 * fixing snapshot
78 lines
2.5 KiB
JavaScript
78 lines
2.5 KiB
JavaScript
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
|
|
import { showCustodianDeepLink } from '@metamask-institutional/extension';
|
|
import {
|
|
showCustodyConfirmLink,
|
|
checkForUnapprovedMessages,
|
|
} from '../store/institutional/institution-actions';
|
|
import {
|
|
mmiActionsFactory,
|
|
setTypedMessageInProgress,
|
|
} from '../store/institutional/institution-background';
|
|
import {
|
|
accountsWithSendEtherInfoSelector,
|
|
getAccountType,
|
|
unapprovedTypedMessagesSelector,
|
|
} from '../selectors';
|
|
import { getAccountByAddress } from '../helpers/utils/util';
|
|
import { getEnvironmentType } from '../../app/scripts/lib/util';
|
|
import { goHome, showModal } from '../store/actions';
|
|
import { ENVIRONMENT_TYPE_NOTIFICATION } from '../../shared/constants/app';
|
|
|
|
export function useMMICustodySignMessage() {
|
|
const dispatch = useDispatch();
|
|
const mmiActions = mmiActionsFactory();
|
|
const envType = getEnvironmentType();
|
|
const accountType = useSelector(getAccountType);
|
|
const isNotification = envType === ENVIRONMENT_TYPE_NOTIFICATION;
|
|
const allAccounts = useSelector(
|
|
accountsWithSendEtherInfoSelector,
|
|
shallowEqual,
|
|
);
|
|
const unapprovedTypedMessages = useSelector(unapprovedTypedMessagesSelector);
|
|
|
|
const custodySignFn = async (_msgData) => {
|
|
if (accountType === 'custody') {
|
|
const { address: fromAddress } =
|
|
getAccountByAddress(allAccounts, _msgData.msgParams.from) || {};
|
|
try {
|
|
let msgData = _msgData;
|
|
let id = _msgData.custodyId;
|
|
if (!_msgData.custodyId) {
|
|
msgData = checkForUnapprovedMessages(
|
|
_msgData,
|
|
unapprovedTypedMessages,
|
|
);
|
|
id = msgData.custodyId;
|
|
}
|
|
showCustodianDeepLink({
|
|
dispatch,
|
|
mmiActions,
|
|
txId: undefined,
|
|
custodyId: id,
|
|
fromAddress,
|
|
isSignature: true,
|
|
closeNotification: isNotification,
|
|
onDeepLinkFetched: () => undefined,
|
|
onDeepLinkShown: () => undefined,
|
|
showCustodyConfirmLink,
|
|
});
|
|
await dispatch(setTypedMessageInProgress(msgData.metamaskId));
|
|
await dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(true));
|
|
await dispatch(goHome());
|
|
} catch (err) {
|
|
await dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(true));
|
|
await dispatch(
|
|
showModal({
|
|
name: 'TRANSACTION_FAILED',
|
|
errorMessage: err.message,
|
|
closeNotification: true,
|
|
operationFailed: true,
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
};
|
|
|
|
return { custodySignFn };
|
|
}
|