const Component = require('react').Component const PropTypes = require('prop-types') const h = require('react-hyperscript') const inherits = require('util').inherits const Identicon = require('./identicon') const connect = require('react-redux').connect const ethUtil = require('ethereumjs-util') const classnames = require('classnames') const { compose } = require('recompose') const { withRouter } = require('react-router-dom') const AccountDropdownMini = require('./dropdowns/account-dropdown-mini') const actions = require('../actions') const { conversionUtil } = require('../conversion-util') const { getSelectedAccount, getCurrentAccountWithSendEtherInfo, getSelectedAddress, accountsWithSendEtherInfoSelector, conversionRateSelector, } = require('../selectors.js') const { DEFAULT_ROUTE } = require('../routes') function mapStateToProps (state) { return { balance: getSelectedAccount(state).balance, selectedAccount: getCurrentAccountWithSendEtherInfo(state), selectedAddress: getSelectedAddress(state), requester: null, requesterAddress: null, accounts: accountsWithSendEtherInfoSelector(state), conversionRate: conversionRateSelector(state), } } function mapDispatchToProps (dispatch) { return { goHome: () => dispatch(actions.goHome()), } } SignatureRequest.contextTypes = { t: PropTypes.func, } module.exports = compose( withRouter, connect(mapStateToProps, mapDispatchToProps) )(SignatureRequest) inherits(SignatureRequest, Component) function SignatureRequest (props) { Component.call(this) this.state = { selectedAccount: props.selectedAccount, accountDropdownOpen: false, } } SignatureRequest.prototype.renderHeader = function () { return h('div.request-signature__header', [ h('div.request-signature__header-background'), h('div.request-signature__header__text', this.context.t('sigRequest')), h('div.request-signature__header__tip-container', [ h('div.request-signature__header__tip'), ]), ]) } SignatureRequest.prototype.renderAccountDropdown = function () { const { selectedAccount, accountDropdownOpen, } = this.state const { accounts, } = this.props return h('div.request-signature__account', [ h('div.request-signature__account-text', [this.context.t('account') + ':']), h(AccountDropdownMini, { selectedAccount, accounts, onSelect: selectedAccount => this.setState({ selectedAccount }), dropdownOpen: accountDropdownOpen, openDropdown: () => this.setState({ accountDropdownOpen: true }), closeDropdown: () => this.setState({ accountDropdownOpen: false }), }), ]) } SignatureRequest.prototype.renderBalance = function () { const { balance, conversionRate } = this.props const balanceInEther = conversionUtil(balance, { fromNumericBase: 'hex', toNumericBase: 'dec', fromDenomination: 'WEI', numberOfDecimals: 6, conversionRate, }) return h('div.request-signature__balance', [ h('div.request-signature__balance-text', `${this.context.t('balance')}:`), h('div.request-signature__balance-value', `${balanceInEther} ETH`), ]) } SignatureRequest.prototype.renderAccountInfo = function () { return h('div.request-signature__account-info', [ this.renderAccountDropdown(), this.renderRequestIcon(), this.renderBalance(), ]) } SignatureRequest.prototype.renderRequestIcon = function () { const { requesterAddress } = this.props return h('div.request-signature__request-icon', [ h(Identicon, { diameter: 40, address: requesterAddress, }), ]) } SignatureRequest.prototype.renderRequestInfo = function () { return h('div.request-signature__request-info', [ h('div.request-signature__headline', [ this.context.t('yourSigRequested'), ]), ]) } SignatureRequest.prototype.msgHexToText = function (hex) { try { const stripped = ethUtil.stripHexPrefix(hex) const buff = Buffer.from(stripped, 'hex') return buff.toString('utf8') } catch (e) { return hex } } SignatureRequest.prototype.renderBody = function () { let rows let notice = this.context.t('youSign') + ':' const { txData } = this.props const { type, msgParams: { data } } = txData if (type === 'personal_sign') { rows = [{ name: this.context.t('message'), value: this.msgHexToText(data) }] } else if (type === 'eth_signTypedData') { rows = data } else if (type === 'eth_sign') { rows = [{ name: this.context.t('message'), value: data }] notice = [this.context.t('signNotice'), h('span.request-signature__help-link', { onClick: () => { global.platform.openWindow({ url: 'https://consensys.zendesk.com/hc/en-us/articles/360004427792', }) }, }, this.context.t('learnMore'))] } return h('div.request-signature__body', {}, [ this.renderAccountInfo(), this.renderRequestInfo(), h('div.request-signature__notice', { className: classnames({ 'request-signature__notice': type === 'personal_sign' || type === 'eth_signTypedData', 'request-signature__warning': type === 'eth_sign', }), }, [notice]), h('div.request-signature__rows', [ ...rows.map(({ name, value }) => { return h('div.request-signature__row', [ h('div.request-signature__row-title', [`${name}:`]), h('div.request-signature__row-value', value), ]) }), ]), ]) } SignatureRequest.prototype.renderFooter = function () { const { signPersonalMessage, signTypedMessage, cancelPersonalMessage, cancelTypedMessage, signMessage, cancelMessage, } = this.props const { txData } = this.props const { type } = txData let cancel let sign if (type === 'personal_sign') { cancel = cancelPersonalMessage sign = signPersonalMessage } else if (type === 'eth_signTypedData') { cancel = cancelTypedMessage sign = signTypedMessage } else if (type === 'eth_sign') { cancel = cancelMessage sign = signMessage } return h('div.request-signature__footer', [ h('button.btn-default.btn--large.request-signature__footer__cancel-button', { onClick: event => { cancel(event).then(() => this.props.history.push(DEFAULT_ROUTE)) }, }, this.context.t('cancel')), h('button.btn-primary.btn--large', { onClick: event => { sign(event).then(() => this.props.history.push(DEFAULT_ROUTE)) }, }, this.context.t('sign')), ]) } SignatureRequest.prototype.render = function () { return ( h('div.request-signature__container', [ this.renderHeader(), this.renderBody(), this.renderFooter(), ]) ) } tree</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/comms/ser2net?id=f3f8c20d6adba6294b4937a3296c125d4a44a920'>commit</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/diff/comms/ser2net?id=f3f8c20d6adba6294b4937a3296c125d4a44a920'>diff</a><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/stats/comms/ser2net'>stats</a></td><td class='form'><form class='right' method='get' action='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/comms/ser2net'> <input type='hidden' name='id' value='f3f8c20d6adba6294b4937a3296c125d4a44a920'/><select name='qt'> <option value='grep'>log msg</option> <option value='author'>author</option> <option value='committer'>committer</option> <option value='range'>range</option> </select> <input class='txt' type='search' size='10' name='q' value=''/> <input type='submit' value='search'/> </form> </td></tr></table> <div class='path'>path: <a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/?id=f3f8c20d6adba6294b4937a3296c125d4a44a920'>root</a>/<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/comms?id=f3f8c20d6adba6294b4937a3296c125d4a44a920'>comms</a>/<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/comms/ser2net?id=f3f8c20d6adba6294b4937a3296c125d4a44a920'>ser2net</a></div><div class='content'><table class='list nowrap'><tr class='nohover'><th></th><th class='left'>Commit message (<a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/log/comms/ser2net?id=f3f8c20d6adba6294b4937a3296c125d4a44a920&showmsg=1'>Expand</a>)</th><th class='left'>Author</th><th class='left'>Age</th><th class='left'>Files</th><th class='left'>Lines</th></tr> <tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/comms/ser2net?id=96998c6a224d934b8d937663652dc498c7e4cdfd'>- Update to version 2.9.1</a></td><td>Pawel Pekala</td><td><span title='2013-11-02 06:01:49 +0800'>2013-11-02</span></td><td>2</td><td><span class='deletions'>-17</span>/<span class='insertions'>+16</span></td></tr> <tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/comms/ser2net?id=2b300eeb3f3f12f89596c38ef5510f621dde4ca9'>Add NO_STAGE all over the place in preparation for the staging support (cat: ...</a></td><td>Baptiste Daroussin</td><td><span title='2013-09-21 00:03:29 +0800'>2013-09-21</span></td><td>1</td><td><span class='deletions'>-0</span>/<span class='insertions'>+1</span></td></tr> <tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/comms/ser2net?id=c6fef056eaa0beafaf60499a3926025537211f52'>- Update to 2.8</a></td><td>Martin Wilke</td><td><span title='2013-03-25 00:22:09 +0800'>2013-03-25</span></td><td>3</td><td><span class='deletions'>-8</span>/<span class='insertions'>+8</span></td></tr> <tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/comms/ser2net?id=d001dd4041d39b0fb8869678bf3e88ede2b512cf'>- Update to version 2.7</a></td><td>Pawel Pekala</td><td><span title='2012-11-01 23:30:59 +0800'>2012-11-01</span></td><td>4</td><td><span class='deletions'>-57</span>/<span class='insertions'>+29</span></td></tr> <tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/comms/ser2net?id=39d3c2d50f35384b419383119824e2e590892409'>- Reassign to the heap at maintainer's request</a></td><td>Thomas Abthorpe</td><td><span title='2012-09-22 23:38:49 +0800'>2012-09-22</span></td><td>1</td><td><span class='deletions'>-6</span>/<span class='insertions'>+2</span></td></tr> <tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/comms/ser2net?id=83eb2c37009874672764765ec3bf3b59286c7391'>In the rc.d scripts, change assignments to rcvar to use the</a></td><td>Doug Barton</td><td><span title='2012-01-14 16:57:23 +0800'>2012-01-14</span></td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+1</span></td></tr> <tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/comms/ser2net?id=bb86cbe5d232690f52a27fe9a2d7246e03eef9c4'>- Get Rid MD5 support</a></td><td>Martin Wilke</td><td><span title='2011-03-20 20:54:45 +0800'>2011-03-20</span></td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+0</span></td></tr> <tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/comms/ser2net?id=1d6b4b3f9145338f9413b8827d5fdb118ac9be1f'>Begin the process of deprecating sysutils/rc_subr by</a></td><td>Doug Barton</td><td><span title='2010-03-27 08:15:24 +0800'>2010-03-27</span></td><td>1</td><td><span class='deletions'>-1</span>/<span class='insertions'>+1</span></td></tr> <tr><td class='commitgraph'>* </td><td><a href='/~lantw44/cgit/cgit.cgi/freebsd-ports/commit/comms/ser2net?id=0175383f0a1f8b78ed514778532f0467a8ccc6dc'>Fix a few "bad example" problems in the rc.d scripts that have been</a></td><td>Doug Barton</td><td><span title='2009-07-16 00:56:10 +0800'>2009-07-16</span>