1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 15:50:28 +01:00
metamask-extension/ui/components/app/signature-request-original/signature-request-original.container.js
Mark Stacey 88ae10418b
Expand usage of getProviderConfig selector (#18906)
The `getProviderConfig` selector is now used anywhere the `provider`
state was previously referenced directly. This was done to simplify
renaming this state from `provider` to `providerConfig` in a later PR.

Note that there are many opportunities left to use more-specific
selectors (e.g. `getChainId()` over `getProviderConfig().chainId`), but
that was intentionally omitted from this PR to reduce the size. I
started going down this path and it quickly exploded in scope.

Relates to #18902
2023-05-02 10:06:24 -02:30

138 lines
3.9 KiB
JavaScript

import { connect } from 'react-redux';
import { compose } from 'redux';
import { withRouter } from 'react-router-dom';
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
import { goHome, cancelMsgs, showModal } from '../../../store/actions';
import {
accountsWithSendEtherInfoSelector,
conversionRateSelector,
getSubjectMetadata,
doesAddressRequireLedgerHidConnection,
unconfirmedMessagesHashSelector,
getTotalUnapprovedMessagesCount,
getPreferences,
getCurrentCurrency,
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
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,
getNativeCurrency,
getProviderConfig,
} from '../../../ducks/metamask/metamask';
import SignatureRequestOriginal from './signature-request-original.component';
function mapStateToProps(state, ownProps) {
const {
msgParams: { from },
} = ownProps.txData;
const provider = getProviderConfig(state);
const hardwareWalletRequiresConnection =
doesAddressRequireLedgerHidConnection(state, from);
const isLedgerWallet = isAddressLedger(state, from);
const messagesList = unconfirmedMessagesHashSelector(state);
const messagesCount = getTotalUnapprovedMessagesCount(state);
const { useNativeCurrencyAsPrimaryCurrency } = getPreferences(state);
return {
requester: null,
requesterAddress: null,
mostRecentOverviewPage: getMostRecentOverviewPage(state),
hardwareWalletRequiresConnection,
isLedgerWallet,
nativeCurrency: getNativeCurrency(state),
currentCurrency: getCurrentCurrency(state),
conversionRate: useNativeCurrencyAsPrimaryCurrency
? null
: conversionRateSelector(state),
// not passed to component
allAccounts: accountsWithSendEtherInfoSelector(state),
subjectMetadata: getSubjectMetadata(state),
messagesList,
messagesCount,
provider,
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
selectedAccount: getSelectedAccount(state),
///: END:ONLY_INCLUDE_IN
};
}
function mapDispatchToProps(dispatch) {
return {
goHome: () => dispatch(goHome()),
clearConfirmTransaction: () => dispatch(clearConfirmTransaction()),
showRejectTransactionsConfirmationModal: ({
onSubmit,
unapprovedTxCount: messagesCount,
}) => {
return dispatch(
showModal({
name: 'REJECT_TRANSACTIONS',
onSubmit,
unapprovedTxCount: messagesCount,
isRequestType: true,
}),
);
},
cancelAll: (messagesList) => dispatch(cancelMsgs(messagesList)),
};
}
function mergeProps(stateProps, dispatchProps, ownProps) {
const {
signPersonalMessage,
signTypedMessage,
cancelPersonalMessage,
cancelTypedMessage,
signMessage,
cancelMessage,
txData,
} = ownProps;
const { allAccounts, messagesList, ...otherStateProps } = stateProps;
const {
type,
msgParams: { from },
} = txData;
const fromAccount = getAccountByAddress(allAccounts, from);
const { cancelAll: dispatchCancelAll } = dispatchProps;
let cancel;
let sign;
if (type === MESSAGE_TYPE.PERSONAL_SIGN) {
cancel = cancelPersonalMessage;
sign = signPersonalMessage;
} else if (type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA) {
cancel = cancelTypedMessage;
sign = signTypedMessage;
} else if (type === MESSAGE_TYPE.ETH_SIGN) {
cancel = cancelMessage;
sign = signMessage;
}
return {
...ownProps,
...otherStateProps,
...dispatchProps,
fromAccount,
txData,
cancel,
sign,
cancelAll: () => dispatchCancelAll(valuesFor(messagesList)),
};
}
export default compose(
withRouter,
connect(mapStateToProps, mapDispatchToProps, mergeProps),
)(SignatureRequestOriginal);