1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-21 17:37:01 +01:00
metamask-extension/ui/hooks/useMMICustodySignMessage.js
António Regadas 8ee733c0d5
[MMI] Handle personal sign and sign typed operations (#20087)
* adds listeners for signatureControll and adds the handleSigningEvents method

* clean up

* updates signature request containers files

* adds necessary methods

* wip

* signing flow with core methods

* yarn lint

* updates logic to fit latest signatureCOntroller

* updates mmi extension package

* updates signature-controller and message-manager packages

* checkout develop lock file and run yarn

* checkout develop lock file and package.json to test circleci

* test fix

* adds signature-controller new version

* updates mmi extension package

* tx-list update and runs lavamoat auto

* lint fix

* runs lavamoat auto

* resets lavamoat/build-system/policy.jsono to develop

* Update LavaMoat policies

* adds back the dispatch

* lint

* clean up

* clean up

* applies patch for signature controller

* clean patch file

---------

Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
2023-07-21 16:52:47 +01:00

74 lines
2.3 KiB
JavaScript

import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { showCustodianDeepLink } from '@metamask-institutional/extension';
import { showCustodyConfirmLink } from '../store/institutional/institution-actions';
import { mmiActionsFactory } from '../store/institutional/institution-background';
import {
accountsWithSendEtherInfoSelector,
getAccountType,
} from '../selectors';
import {
resolvePendingApproval,
completedTx,
showModal,
} from '../store/actions';
import { getAccountByAddress } from '../helpers/utils/util';
import { getEnvironmentType } from '../../app/scripts/lib/util';
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 custodySignFn = async (_msgData) => {
const {
msgParams: { from },
} = _msgData;
const fromAccount = getAccountByAddress(allAccounts, from);
if (accountType === 'custody') {
try {
await dispatch(resolvePendingApproval(_msgData.id));
completedTx(_msgData.id);
showCustodianDeepLink({
dispatch,
mmiActions,
txId: undefined,
custodyId: null,
fromAddress: fromAccount.address,
isSignature: true,
closeNotification: isNotification,
onDeepLinkFetched: () => undefined,
onDeepLinkShown: () => undefined,
showCustodyConfirmLink,
});
await dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(true));
} catch (err) {
await dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(true));
await dispatch(
showModal({
name: 'TRANSACTION_FAILED',
errorMessage: err.message,
closeNotification: true,
operationFailed: true,
}),
);
}
} else {
// Non Custody accounts follow normal flow
await dispatch(resolvePendingApproval(_msgData.id));
completedTx(_msgData.id);
}
};
return { custodySignFn };
}