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,
|
2021-10-21 21:17:03 +02:00
|
|
|
} from '../../../selectors';
|
|
|
|
import { isAddressLedger } from '../../../ducks/metamask/metamask';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { getAccountByAddress } from '../../../helpers/utils/util';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
|
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-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);
|
|
|
|
const subjectMetadata = getSubjectMetadata(state);
|
|
|
|
|
|
|
|
const { iconUrl: siteImage = '' } =
|
|
|
|
subjectMetadata[txData.msgParams.origin] || {};
|
2021-10-21 21:17:03 +02:00
|
|
|
|
2019-11-04 13:40:46 +01:00
|
|
|
return {
|
2021-10-21 21:17:03 +02:00
|
|
|
isLedgerWallet,
|
|
|
|
hardwareWalletRequiresConnection,
|
2022-11-21 18:19:49 +01:00
|
|
|
chainId,
|
|
|
|
rpcPrefs,
|
|
|
|
siteImage,
|
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
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
siteImage,
|
|
|
|
} = 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
|
|
|
|
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,
|
|
|
|
siteImage,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
|
2021-11-15 17:13:51 +01:00
|
|
|
export default connect(mapStateToProps, null, mergeProps)(SignatureRequest);
|