mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
8aa3263b82
* Fixed navigation through multiple unapproved transactions for ERC20 tokens * Fixed tx details activity-log currency * Fixed e2e test failure * Added navigation between multiple sign prompts and reject all sign prompts * Resolving conflicts * Creating SignatureRequestNavigation component and extracting the UI rendering part into a single component * Fixing e2e tests and updating snapshot * Using single component for navigation which shows both messages and transactions requests * Fixing test-unit-jest-main * Added more unit tests * Fixing test-storybook * Fixing test-storybook --------- Co-authored-by: Filip Sekulic <filip.sekulic@consensys.net>
157 lines
4.1 KiB
JavaScript
157 lines
4.1 KiB
JavaScript
import { connect } from 'react-redux';
|
|
import {
|
|
accountsWithSendEtherInfoSelector,
|
|
doesAddressRequireLedgerHidConnection,
|
|
getCurrentChainId,
|
|
getRpcPrefsForCurrentProvider,
|
|
conversionRateSelector,
|
|
getSubjectMetadata,
|
|
unconfirmedMessagesHashSelector,
|
|
getTotalUnapprovedMessagesCount,
|
|
} from '../../../selectors';
|
|
import {
|
|
isAddressLedger,
|
|
getNativeCurrency,
|
|
} from '../../../ducks/metamask/metamask';
|
|
import { getAccountByAddress, valuesFor } from '../../../helpers/utils/util';
|
|
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
|
|
import { cancelMsgs, showModal } from '../../../store/actions';
|
|
import { getMostRecentOverviewPage } from '../../../ducks/history/history';
|
|
import { clearConfirmTransaction } from '../../../ducks/confirm-transaction/confirm-transaction.duck';
|
|
import SignatureRequest from './signature-request.component';
|
|
|
|
function mapStateToProps(state, ownProps) {
|
|
const { txData } = ownProps;
|
|
const {
|
|
msgParams: { from },
|
|
} = txData;
|
|
const { provider } = state.metamask;
|
|
|
|
const hardwareWalletRequiresConnection =
|
|
doesAddressRequireLedgerHidConnection(state, from);
|
|
const isLedgerWallet = isAddressLedger(state, from);
|
|
const chainId = getCurrentChainId(state);
|
|
const rpcPrefs = getRpcPrefsForCurrentProvider(state);
|
|
const subjectMetadata = getSubjectMetadata(state);
|
|
const unconfirmedMessagesList = unconfirmedMessagesHashSelector(state);
|
|
const unapprovedMessagesCount = getTotalUnapprovedMessagesCount(state);
|
|
|
|
const { iconUrl: siteImage = '' } =
|
|
subjectMetadata[txData.msgParams.origin] || {};
|
|
|
|
return {
|
|
provider,
|
|
isLedgerWallet,
|
|
hardwareWalletRequiresConnection,
|
|
chainId,
|
|
rpcPrefs,
|
|
siteImage,
|
|
unconfirmedMessagesList,
|
|
unapprovedMessagesCount,
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
|
conversionRate: conversionRateSelector(state),
|
|
nativeCurrency: getNativeCurrency(state),
|
|
subjectMetadata: getSubjectMetadata(state),
|
|
// not forwarded to component
|
|
allAccounts: accountsWithSendEtherInfoSelector(state),
|
|
};
|
|
}
|
|
|
|
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)),
|
|
};
|
|
}
|
|
|
|
function mergeProps(stateProps, dispatchProps, ownProps) {
|
|
const {
|
|
allAccounts,
|
|
isLedgerWallet,
|
|
hardwareWalletRequiresConnection,
|
|
chainId,
|
|
rpcPrefs,
|
|
siteImage,
|
|
conversionRate,
|
|
nativeCurrency,
|
|
provider,
|
|
subjectMetadata,
|
|
unconfirmedMessagesList,
|
|
unapprovedMessagesCount,
|
|
mostRecentOverviewPage,
|
|
} = stateProps;
|
|
const {
|
|
signPersonalMessage,
|
|
signTypedMessage,
|
|
cancelPersonalMessage,
|
|
cancelTypedMessage,
|
|
signMessage,
|
|
cancelMessage,
|
|
txData,
|
|
} = ownProps;
|
|
|
|
const { cancelAll: dispatchCancelAll } = dispatchProps;
|
|
|
|
const {
|
|
type,
|
|
msgParams: { from },
|
|
} = txData;
|
|
|
|
const fromAccount = getAccountByAddress(allAccounts, from);
|
|
|
|
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,
|
|
...dispatchProps,
|
|
fromAccount,
|
|
txData,
|
|
cancel,
|
|
sign,
|
|
isLedgerWallet,
|
|
hardwareWalletRequiresConnection,
|
|
chainId,
|
|
rpcPrefs,
|
|
siteImage,
|
|
conversionRate,
|
|
nativeCurrency,
|
|
provider,
|
|
subjectMetadata,
|
|
unapprovedMessagesCount,
|
|
mostRecentOverviewPage,
|
|
cancelAll: () => dispatchCancelAll(valuesFor(unconfirmedMessagesList)),
|
|
};
|
|
}
|
|
|
|
export default connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps,
|
|
mergeProps,
|
|
)(SignatureRequest);
|