mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
8ee733c0d5
* 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>
136 lines
3.4 KiB
TypeScript
136 lines
3.4 KiB
TypeScript
import { ThunkAction, ThunkDispatch } from 'redux-thunk';
|
|
import { AnyAction } from 'redux';
|
|
import {
|
|
closeCurrentNotificationWindow,
|
|
hideModal,
|
|
showModal,
|
|
} from '../actions';
|
|
import {
|
|
CombinedBackgroundAndReduxState,
|
|
MetaMaskReduxState,
|
|
TemporaryMessageDataType,
|
|
MessagesIndexedById,
|
|
} from '../store';
|
|
import { toChecksumHexAddress } from '../../../shared/modules/hexstring-utils';
|
|
|
|
export function showInteractiveReplacementTokenModal(): ThunkAction<
|
|
void,
|
|
MetaMaskReduxState,
|
|
unknown,
|
|
AnyAction
|
|
> {
|
|
return (dispatch) => {
|
|
dispatch(
|
|
showModal({
|
|
name: 'INTERACTIVE_REPLACEMENT_TOKEN_MODAL',
|
|
}),
|
|
);
|
|
};
|
|
}
|
|
|
|
export function showCustodyConfirmLink({
|
|
link,
|
|
address,
|
|
closeNotification,
|
|
custodyId,
|
|
}: {
|
|
link: string;
|
|
address: string;
|
|
closeNotification: boolean;
|
|
custodyId: string;
|
|
}): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
|
return (dispatch) => {
|
|
dispatch(
|
|
showModal({
|
|
name: 'CUSTODY_CONFIRM_LINK',
|
|
link,
|
|
address,
|
|
closeNotification,
|
|
custodyId,
|
|
}),
|
|
);
|
|
};
|
|
}
|
|
|
|
export function updateCustodyState(
|
|
dispatch: ThunkDispatch<CombinedBackgroundAndReduxState, unknown, AnyAction>,
|
|
newState: MetaMaskReduxState['metamask'],
|
|
state: CombinedBackgroundAndReduxState & any,
|
|
) {
|
|
if (!newState.currentNetworkTxList || !state.metamask.currentNetworkTxList) {
|
|
return;
|
|
}
|
|
|
|
const differentTxs = newState.currentNetworkTxList.filter(
|
|
(item) =>
|
|
state.metamask.currentNetworkTxList.filter(
|
|
(tx: { [key: string]: any }) =>
|
|
tx.custodyId === item.custodyId &&
|
|
tx.custodyStatus !== item.custodyStatus,
|
|
).length > 0,
|
|
);
|
|
|
|
const txStateSaysDeepLinkShouldClose = Boolean(
|
|
differentTxs.find((tx) => {
|
|
const custodyAccountDetails =
|
|
state.metamask.custodyAccountDetails[
|
|
toChecksumHexAddress(tx.txParams.from)
|
|
];
|
|
const custody = custodyAccountDetails?.custodyType
|
|
.split(' - ')[1]
|
|
.toLowerCase();
|
|
if (!custody) {
|
|
return false;
|
|
}
|
|
|
|
return (
|
|
tx.custodyId === state.appState.modal.modalState.props?.custodyId &&
|
|
(state.metamask.custodyStatusMaps[custody][tx.custodyStatus]
|
|
?.mmStatus !== 'approved' ||
|
|
tx.custodyStatus === 'created')
|
|
);
|
|
}),
|
|
);
|
|
|
|
if (
|
|
state.appState.modal.open &&
|
|
state.appState.modal.modalState.name === 'CUSTODY_CONFIRM_LINK' &&
|
|
txStateSaysDeepLinkShouldClose
|
|
) {
|
|
if (state.appState.modal.modalState.props?.closeNotification) {
|
|
dispatch(closeCurrentNotificationWindow());
|
|
}
|
|
dispatch(hideModal());
|
|
}
|
|
|
|
if (
|
|
state.appState.modal.open &&
|
|
state.appState.modal.modalState.name ===
|
|
'INTERACTIVE_REPLACEMENT_TOKEN_MODAL'
|
|
) {
|
|
if (state.appState.modal.modalState.props?.closeNotification) {
|
|
dispatch(closeCurrentNotificationWindow());
|
|
}
|
|
}
|
|
}
|
|
|
|
export function checkForUnapprovedMessages(
|
|
msgData: TemporaryMessageDataType,
|
|
unapprovedMessages: MessagesIndexedById,
|
|
) {
|
|
const custodianUnapprovedMessages = Object.keys(unapprovedMessages)
|
|
.map((key) => unapprovedMessages[key])
|
|
.filter((message) => {
|
|
return message.metadata?.custodyId && message.status === 'unapproved';
|
|
});
|
|
|
|
if (custodianUnapprovedMessages && custodianUnapprovedMessages.length > 0) {
|
|
return {
|
|
...msgData,
|
|
custodyId: unapprovedMessages[msgData.id]?.metadata?.custodyId,
|
|
};
|
|
}
|
|
|
|
return msgData;
|
|
}
|