From d7bf5544efee5c74ee0b296e6ec7000960b42ef8 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 15 Feb 2018 12:54:23 +0100 Subject: [PATCH 1/2] Fix bug allow eth_sign and parity_decryptMessage --- .../SignerPending/RequestItem/requestItem.js | 253 +++++++++++------- src/Status/SignerPending/signerPending.js | 2 +- 2 files changed, 159 insertions(+), 96 deletions(-) diff --git a/src/Status/SignerPending/RequestItem/requestItem.js b/src/Status/SignerPending/RequestItem/requestItem.js index f96bd78..1427636 100644 --- a/src/Status/SignerPending/RequestItem/requestItem.js +++ b/src/Status/SignerPending/RequestItem/requestItem.js @@ -31,14 +31,12 @@ import EtherValue from '../EtherValue'; import styles from './requestItem.css'; @observer -@connect(({ tokens }, { transaction }) => ({ - token: Object.values(tokens).find(({ address }) => address === transaction.to) -})) +@connect(({ tokens }) => ({ tokens })) class RequestItem extends Component { static propTypes = { onClick: PropTypes.func.isRequired, - transaction: PropTypes.object.isRequired, - token: PropTypes.object + request: PropTypes.object.isRequired, + tokens: PropTypes.array }; static contextTypes = { @@ -52,7 +50,10 @@ class RequestItem extends Component { methodDecodingStore = MethodDecodingStore.get(this.context.api); componentWillMount () { - const { transaction } = this.props; + const { payload } = this.props.request; + const transaction = payload.sendTransaction || payload.signTransaction; + + if (!transaction) { return; } // Decode the transaction and put it into the state this.methodDecodingStore @@ -62,56 +63,153 @@ class RequestItem extends Component { })); } - renderDescription = () => { - // Decide what to display in the description, depending - // on what type of transaction we're dealing with - const { token } = this.props; - const { - inputs, - signature, - contract, - deploy - } = this.state.decoded; - - if (deploy) { - return this.renderDeploy(); + /** + * Get the author of a request + * TODO Duplicate code of https://github.com/Parity-JS/ui/blob/master/src/Signer/Request/request.js#L54-L69 + */ + getRequestAuthor = () => { + const { payload } = this.props.request; + + if (payload.sign) { + return payload.sign.address; + } + if (payload.decrypt) { + return payload.decrypt.address; } + const transaction = payload.sendTransaction || payload.signTransaction; - if (contract && signature) { - if (token && TOKEN_METHODS[signature] && inputs) { - return this.renderTokenTransfer(); - } - return this.renderContractMethod(); + if (transaction) { + return transaction.from; } + }; - return this.renderValueTransfer(); - } + render () { + const { onClick } = this.props; - renderDeploy = () => { return ( + + + + + + + + + {this.renderDescription()} + + + ); + } + + /** + * Render description when calling a contract method + */ + renderContractMethod = (transaction) => ( + - ); - }; + {this.renderRecipient(transaction.to)} + + ); - renderContractMethod = () => { - const { transaction } = this.props; + /** + * Render description when decrypting a message with parity_decrypt + */ + renderDecrypt = () => ( + + ); - return ( - - - {this.renderRecipient(transaction.to)} - - ); - }; + /** + * Render description when deploying a contract + */ + renderDeploy = () => ( + + ); + + /** + * Render the description of the request + */ + renderDescription = () => { + const { payload } = this.props.request; + + // Decide what to display in the description, depending + // on what type of transaction we're dealing with + if (payload.sign) { + return this.renderSign(); + } + if (payload.decrypt) { + return this.renderDecrypt(); + } + const transaction = payload.sendTransaction || payload.signTransaction; + + if (transaction) { + const { tokens } = this.props; + const token = Object.values(tokens).find(({ address }) => address === transaction.to); + + if (!this.state.decoded) { return null; } + + const { + inputs, + signature, + contract, + deploy + } = this.state.decoded; + + if (deploy) { + return this.renderDeploy(transaction); + } + + if (contract && signature) { + if (token && TOKEN_METHODS[signature] && inputs) { + return this.renderTokenTransfer(transaction, token); + } + return this.renderContractMethod(transaction); + } - renderTokenTransfer = () => { - const { token } = this.props; + return this.renderValueTransfer(transaction); + } + return null; + } + + /** + * Render recipient (of token transfer or eth transfer) + */ + renderRecipient = address => ( + + ); + + /** + * Render description when signing some data with eth_sign + */ + renderSign = () => ( + + ); + + /** + * Render description when transferring tokens + */ + renderTokenTransfer = (transaction, token) => { const { inputs } = this.state.decoded; const valueInput = inputs.find(({ name }) => name === '_value'); const toInput = inputs.find(({ name }) => name === '_to'); @@ -133,57 +231,22 @@ class RequestItem extends Component { ); }; - renderValueTransfer = () => { - const { transaction } = this.props; - - return ( - - - } - } - /> - {this.renderRecipient(transaction.to)} - - ); - }; - - renderRecipient = address => ( - + /** + * Render description when transferring ETH + */ + renderValueTransfer = (transaction) => ( + + + } + } + /> + {this.renderRecipient(transaction.to)} + ); - - render () { - const { transaction, onClick } = this.props; - - if (!this.state.decoded) { return null; } - - return ( - - - - - - - - - {this.renderDescription()} - - - ); - } } export default RequestItem; diff --git a/src/Status/SignerPending/signerPending.js b/src/Status/SignerPending/signerPending.js index 024e452..ab3b995 100644 --- a/src/Status/SignerPending/signerPending.js +++ b/src/Status/SignerPending/signerPending.js @@ -74,7 +74,7 @@ class SignerPending extends Component { {this.store.pending.map(request => ( -- GitLab From afd27297896bf2569fb0373d02da066418b77b6e Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 15 Feb 2018 12:58:42 +0100 Subject: [PATCH 2/2] Fix typo --- src/Status/SignerPending/RequestItem/requestItem.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Status/SignerPending/RequestItem/requestItem.js b/src/Status/SignerPending/RequestItem/requestItem.js index 1427636..9df359f 100644 --- a/src/Status/SignerPending/RequestItem/requestItem.js +++ b/src/Status/SignerPending/RequestItem/requestItem.js @@ -217,7 +217,7 @@ class RequestItem extends Component { return ( ( -- GitLab