2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
2021-10-21 21:17:03 +02:00
|
|
|
import {
|
|
|
|
accountsWithSendEtherInfoSelector,
|
|
|
|
doesAddressRequireLedgerHidConnection,
|
2022-11-21 18:19:49 +01:00
|
|
|
getCurrentChainId,
|
|
|
|
getRpcPrefsForCurrentProvider,
|
|
|
|
getSubjectMetadata,
|
2023-01-31 16:29:23 +01:00
|
|
|
unconfirmedMessagesHashSelector,
|
|
|
|
getTotalUnapprovedMessagesCount,
|
2023-03-02 13:40:07 +01:00
|
|
|
getCurrentCurrency,
|
|
|
|
getPreferences,
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRateSelector,
|
2021-10-21 21:17:03 +02:00
|
|
|
} from '../../../selectors';
|
2022-11-30 19:11:36 +01:00
|
|
|
import {
|
|
|
|
isAddressLedger,
|
|
|
|
getNativeCurrency,
|
|
|
|
} from '../../../ducks/metamask/metamask';
|
2023-01-31 16:29:23 +01:00
|
|
|
import { getAccountByAddress, valuesFor } from '../../../helpers/utils/util';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
|
2023-01-31 16:29:23 +01:00
|
|
|
import { cancelMsgs, showModal } from '../../../store/actions';
|
|
|
|
import { getMostRecentOverviewPage } from '../../../ducks/history/history';
|
|
|
|
import { clearConfirmTransaction } from '../../../ducks/confirm-transaction/confirm-transaction.duck';
|
2021-02-04 19:15:23 +01:00
|
|
|
import SignatureRequest from './signature-request.component';
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2021-10-21 21:17:03 +02:00
|
|
|
function mapStateToProps(state, ownProps) {
|
|
|
|
const { txData } = ownProps;
|
|
|
|
const {
|
|
|
|
msgParams: { from },
|
|
|
|
} = txData;
|
2022-11-30 19:11:36 +01:00
|
|
|
const { provider } = state.metamask;
|
|
|
|
|
2022-07-31 20:26:40 +02:00
|
|
|
const hardwareWalletRequiresConnection =
|
|
|
|
doesAddressRequireLedgerHidConnection(state, from);
|
2021-10-21 21:17:03 +02:00
|
|
|
const isLedgerWallet = isAddressLedger(state, from);
|
2022-11-21 18:19:49 +01:00
|
|
|
const chainId = getCurrentChainId(state);
|
|
|
|
const rpcPrefs = getRpcPrefsForCurrentProvider(state);
|
2023-01-31 16:29:23 +01:00
|
|
|
const unconfirmedMessagesList = unconfirmedMessagesHashSelector(state);
|
|
|
|
const unapprovedMessagesCount = getTotalUnapprovedMessagesCount(state);
|
2023-03-02 13:40:07 +01:00
|
|
|
const { useNativeCurrencyAsPrimaryCurrency } = getPreferences(state);
|
2022-11-21 18:19:49 +01:00
|
|
|
|
2019-11-04 13:40:46 +01:00
|
|
|
return {
|
2022-11-30 19:11:36 +01:00
|
|
|
provider,
|
2021-10-21 21:17:03 +02:00
|
|
|
isLedgerWallet,
|
|
|
|
hardwareWalletRequiresConnection,
|
2022-11-21 18:19:49 +01:00
|
|
|
chainId,
|
|
|
|
rpcPrefs,
|
2023-01-31 16:29:23 +01:00
|
|
|
unconfirmedMessagesList,
|
|
|
|
unapprovedMessagesCount,
|
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2022-11-30 19:11:36 +01:00
|
|
|
nativeCurrency: getNativeCurrency(state),
|
2023-03-02 13:40:07 +01:00
|
|
|
currentCurrency: getCurrentCurrency(state),
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate: useNativeCurrencyAsPrimaryCurrency
|
|
|
|
? null
|
|
|
|
: conversionRateSelector(state),
|
2022-11-30 19:11:36 +01:00
|
|
|
subjectMetadata: getSubjectMetadata(state),
|
2020-03-06 22:34:56 +01:00
|
|
|
// not forwarded to component
|
|
|
|
allAccounts: accountsWithSendEtherInfoSelector(state),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
|
2023-01-31 16:29:23 +01:00
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return {
|
|
|
|
clearConfirmTransaction: () => dispatch(clearConfirmTransaction()),
|
|
|
|
showRejectTransactionsConfirmationModal: ({
|
|
|
|
onSubmit,
|
|
|
|
unapprovedTxCount: unapprovedMessagesCount,
|
|
|
|
}) => {
|
|
|
|
return dispatch(
|
|
|
|
showModal({
|
|
|
|
name: 'REJECT_TRANSACTIONS',
|
|
|
|
onSubmit,
|
|
|
|
unapprovedTxCount: unapprovedMessagesCount,
|
|
|
|
isRequestType: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
cancelAll: (unconfirmedMessagesList) =>
|
|
|
|
dispatch(cancelMsgs(unconfirmedMessagesList)),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mergeProps(stateProps, dispatchProps, ownProps) {
|
2022-11-21 18:19:49 +01:00
|
|
|
const {
|
|
|
|
allAccounts,
|
|
|
|
isLedgerWallet,
|
|
|
|
hardwareWalletRequiresConnection,
|
|
|
|
chainId,
|
|
|
|
rpcPrefs,
|
2022-11-30 19:11:36 +01:00
|
|
|
nativeCurrency,
|
2023-03-02 13:40:07 +01:00
|
|
|
currentCurrency,
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate,
|
2022-11-30 19:11:36 +01:00
|
|
|
provider,
|
|
|
|
subjectMetadata,
|
2023-01-31 16:29:23 +01:00
|
|
|
unconfirmedMessagesList,
|
|
|
|
unapprovedMessagesCount,
|
|
|
|
mostRecentOverviewPage,
|
2022-11-21 18:19:49 +01:00
|
|
|
} = stateProps;
|
2019-11-04 13:40:46 +01:00
|
|
|
const {
|
|
|
|
signPersonalMessage,
|
|
|
|
signTypedMessage,
|
|
|
|
cancelPersonalMessage,
|
|
|
|
cancelTypedMessage,
|
|
|
|
signMessage,
|
|
|
|
cancelMessage,
|
|
|
|
txData,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = ownProps;
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2023-01-31 16:29:23 +01:00
|
|
|
const { cancelAll: dispatchCancelAll } = dispatchProps;
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
type,
|
|
|
|
msgParams: { from },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = txData;
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const fromAccount = getAccountByAddress(allAccounts, from);
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let cancel;
|
|
|
|
let sign;
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2020-06-04 21:22:45 +02:00
|
|
|
if (type === MESSAGE_TYPE.PERSONAL_SIGN) {
|
2021-02-04 19:15:23 +01:00
|
|
|
cancel = cancelPersonalMessage;
|
|
|
|
sign = signPersonalMessage;
|
2020-06-04 21:22:45 +02:00
|
|
|
} else if (type === MESSAGE_TYPE.ETH_SIGN_TYPED_DATA) {
|
2021-02-04 19:15:23 +01:00
|
|
|
cancel = cancelTypedMessage;
|
|
|
|
sign = signTypedMessage;
|
2020-06-04 21:22:45 +02:00
|
|
|
} else if (type === MESSAGE_TYPE.ETH_SIGN) {
|
2021-02-04 19:15:23 +01:00
|
|
|
cancel = cancelMessage;
|
|
|
|
sign = signMessage;
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...ownProps,
|
2020-03-06 22:34:56 +01:00
|
|
|
...dispatchProps,
|
|
|
|
fromAccount,
|
2019-11-04 13:40:46 +01:00
|
|
|
txData,
|
|
|
|
cancel,
|
|
|
|
sign,
|
2021-10-21 21:17:03 +02:00
|
|
|
isLedgerWallet,
|
|
|
|
hardwareWalletRequiresConnection,
|
2022-11-21 18:19:49 +01:00
|
|
|
chainId,
|
|
|
|
rpcPrefs,
|
2022-11-30 19:11:36 +01:00
|
|
|
nativeCurrency,
|
2023-03-02 13:40:07 +01:00
|
|
|
currentCurrency,
|
2023-03-08 17:05:55 +01:00
|
|
|
conversionRate,
|
2022-11-30 19:11:36 +01:00
|
|
|
provider,
|
|
|
|
subjectMetadata,
|
2023-01-31 16:29:23 +01:00
|
|
|
unapprovedMessagesCount,
|
|
|
|
mostRecentOverviewPage,
|
|
|
|
cancelAll: () => dispatchCancelAll(valuesFor(unconfirmedMessagesList)),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
|
2023-01-31 16:29:23 +01:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps,
|
|
|
|
mergeProps,
|
|
|
|
)(SignatureRequest);
|