2021-02-04 19:15:23 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Identicon from '../../ui/identicon';
|
2021-10-21 21:17:03 +02:00
|
|
|
import LedgerInstructionField from '../ledger-instruction-field';
|
2021-12-08 21:56:09 +01:00
|
|
|
import { sanitizeMessage } from '../../../helpers/utils/util';
|
2021-02-04 19:15:23 +01:00
|
|
|
import Header from './signature-request-header';
|
|
|
|
import Footer from './signature-request-footer';
|
|
|
|
import Message from './signature-request-message';
|
2019-11-04 13:40:46 +01:00
|
|
|
|
|
|
|
export default class SignatureRequest extends PureComponent {
|
|
|
|
static propTypes = {
|
2021-12-08 21:32:59 +01:00
|
|
|
/**
|
|
|
|
* The display content of transaction data
|
|
|
|
*/
|
2019-11-04 13:40:46 +01:00
|
|
|
txData: PropTypes.object.isRequired,
|
2021-12-08 21:32:59 +01:00
|
|
|
/**
|
|
|
|
* The display content of sender account
|
|
|
|
*/
|
2020-03-06 22:34:56 +01:00
|
|
|
fromAccount: PropTypes.shape({
|
|
|
|
address: PropTypes.string.isRequired,
|
2019-11-04 13:40:46 +01:00
|
|
|
balance: PropTypes.string,
|
|
|
|
name: PropTypes.string,
|
2020-03-06 22:34:56 +01:00
|
|
|
}).isRequired,
|
2021-12-08 21:32:59 +01:00
|
|
|
/**
|
|
|
|
* Check if the wallet is ledget wallet or not
|
|
|
|
*/
|
2021-10-21 21:17:03 +02:00
|
|
|
isLedgerWallet: PropTypes.bool,
|
2021-12-08 21:32:59 +01:00
|
|
|
/**
|
|
|
|
* Handler for cancel button
|
|
|
|
*/
|
2019-11-04 13:40:46 +01:00
|
|
|
cancel: PropTypes.func.isRequired,
|
2021-12-08 21:32:59 +01:00
|
|
|
/**
|
|
|
|
* Handler for sign button
|
|
|
|
*/
|
2019-11-04 13:40:46 +01:00
|
|
|
sign: PropTypes.func.isRequired,
|
2021-12-08 21:32:59 +01:00
|
|
|
/**
|
|
|
|
* Whether the hardware wallet requires a connection disables the sign button if true.
|
|
|
|
*/
|
2021-12-02 19:09:18 +01:00
|
|
|
hardwareWalletRequiresConnection: PropTypes.bool.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-04 13:40:46 +01:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2019-11-15 19:04:36 +01:00
|
|
|
metricsEvent: PropTypes.func,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
formatWallet(wallet) {
|
|
|
|
return `${wallet.slice(0, 8)}...${wallet.slice(
|
|
|
|
wallet.length - 8,
|
|
|
|
wallet.length,
|
2021-02-04 19:15:23 +01:00
|
|
|
)}`;
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
render() {
|
2019-11-04 13:40:46 +01:00
|
|
|
const {
|
2020-03-06 22:34:56 +01:00
|
|
|
fromAccount,
|
2020-11-03 00:41:28 +01:00
|
|
|
txData: {
|
2021-10-12 18:40:41 +02:00
|
|
|
msgParams: { data, origin, version },
|
|
|
|
type,
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2019-11-04 13:40:46 +01:00
|
|
|
cancel,
|
|
|
|
sign,
|
2021-10-21 21:17:03 +02:00
|
|
|
isLedgerWallet,
|
|
|
|
hardwareWalletRequiresConnection,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = this.props;
|
|
|
|
const { address: fromAddress } = fromAccount;
|
2021-12-08 21:56:09 +01:00
|
|
|
const { message, domain = {}, primaryType, types } = JSON.parse(data);
|
2021-10-12 18:40:41 +02:00
|
|
|
const { metricsEvent } = this.context;
|
2019-11-04 13:40:46 +01:00
|
|
|
|
2021-05-07 22:54:20 +02:00
|
|
|
const onSign = (event) => {
|
|
|
|
sign(event);
|
2021-10-12 18:40:41 +02:00
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Sign Request',
|
|
|
|
name: 'Confirm',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
type,
|
|
|
|
version,
|
|
|
|
},
|
|
|
|
});
|
2021-05-07 22:54:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const onCancel = (event) => {
|
|
|
|
cancel(event);
|
2021-10-12 18:40:41 +02:00
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Sign Request',
|
|
|
|
name: 'Cancel',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
type,
|
|
|
|
version,
|
|
|
|
},
|
|
|
|
});
|
2021-05-07 22:54:20 +02:00
|
|
|
};
|
|
|
|
|
2019-11-04 13:40:46 +01:00
|
|
|
return (
|
|
|
|
<div className="signature-request page-container">
|
2020-03-06 22:34:56 +01:00
|
|
|
<Header fromAccount={fromAccount} />
|
2019-11-04 13:40:46 +01:00
|
|
|
<div className="signature-request-content">
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="signature-request-content__title">
|
|
|
|
{this.context.t('sigRequest')}
|
|
|
|
</div>
|
2019-11-04 13:40:46 +01:00
|
|
|
<div className="signature-request-content__identicon-container">
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="signature-request-content__identicon-initial">
|
|
|
|
{domain.name && domain.name[0]}
|
|
|
|
</div>
|
2019-11-04 13:40:46 +01:00
|
|
|
<div className="signature-request-content__identicon-border" />
|
2020-11-03 00:41:28 +01:00
|
|
|
<Identicon address={fromAddress} diameter={70} />
|
|
|
|
</div>
|
|
|
|
<div className="signature-request-content__info--bolded">
|
|
|
|
{domain.name}
|
2019-11-04 13:40:46 +01:00
|
|
|
</div>
|
|
|
|
<div className="signature-request-content__info">{origin}</div>
|
2020-11-03 00:41:28 +01:00
|
|
|
<div className="signature-request-content__info">
|
|
|
|
{this.formatWallet(fromAddress)}
|
|
|
|
</div>
|
2019-11-04 13:40:46 +01:00
|
|
|
</div>
|
2021-10-21 21:17:03 +02:00
|
|
|
{isLedgerWallet ? (
|
|
|
|
<div className="confirm-approve-content__ledger-instruction-wrapper">
|
|
|
|
<LedgerInstructionField showDataInstruction />
|
|
|
|
</div>
|
|
|
|
) : null}
|
2021-12-08 21:56:09 +01:00
|
|
|
<Message data={sanitizeMessage(message, primaryType, types)} />
|
2021-10-21 21:17:03 +02:00
|
|
|
<Footer
|
|
|
|
cancelAction={onCancel}
|
|
|
|
signAction={onSign}
|
|
|
|
disabled={hardwareWalletRequiresConnection}
|
|
|
|
/>
|
2019-11-04 13:40:46 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-11-04 13:40:46 +01:00
|
|
|
}
|
|
|
|
}
|