diff options
author | Sergey Ukustov <sergey@ukstv.me> | 2017-09-30 00:24:08 +0800 |
---|---|---|
committer | Sergey Ukustov <sergey@ukstv.me> | 2017-09-30 00:40:46 +0800 |
commit | c2b8dada91c90788dcd81a0318c52a66b4b769d1 (patch) | |
tree | 599c21d3ff09e5ac1c01062940337d6eb2c5d4fb /ui/app/components | |
parent | cdf41c28573822c7c4d50efe7dfa34a062825d7f (diff) | |
download | tangerine-wallet-browser-c2b8dada91c90788dcd81a0318c52a66b4b769d1.tar tangerine-wallet-browser-c2b8dada91c90788dcd81a0318c52a66b4b769d1.tar.gz tangerine-wallet-browser-c2b8dada91c90788dcd81a0318c52a66b4b769d1.tar.bz2 tangerine-wallet-browser-c2b8dada91c90788dcd81a0318c52a66b4b769d1.tar.lz tangerine-wallet-browser-c2b8dada91c90788dcd81a0318c52a66b4b769d1.tar.xz tangerine-wallet-browser-c2b8dada91c90788dcd81a0318c52a66b4b769d1.tar.zst tangerine-wallet-browser-c2b8dada91c90788dcd81a0318c52a66b4b769d1.zip |
Add eth_signTypedData handler
Diffstat (limited to 'ui/app/components')
-rw-r--r-- | ui/app/components/pending-typed-msg-details.js | 59 | ||||
-rw-r--r-- | ui/app/components/pending-typed-msg.js | 46 | ||||
-rw-r--r-- | ui/app/components/typed-message-renderer.js | 42 |
3 files changed, 147 insertions, 0 deletions
diff --git a/ui/app/components/pending-typed-msg-details.js b/ui/app/components/pending-typed-msg-details.js new file mode 100644 index 000000000..b5fd29f71 --- /dev/null +++ b/ui/app/components/pending-typed-msg-details.js @@ -0,0 +1,59 @@ +const Component = require('react').Component +const h = require('react-hyperscript') +const inherits = require('util').inherits + +const AccountPanel = require('./account-panel') +const TypedMessageRenderer = require('./typed-message-renderer') + +module.exports = PendingMsgDetails + +inherits(PendingMsgDetails, Component) +function PendingMsgDetails () { + Component.call(this) +} + +PendingMsgDetails.prototype.render = function () { + var state = this.props + var msgData = state.txData + + var msgParams = msgData.msgParams || {} + var address = msgParams.from || state.selectedAddress + var identity = state.identities[address] || { address: address } + var account = state.accounts[address] || { address: address } + + var { data } = msgParams + + return ( + h('div', { + key: msgData.id, + style: { + margin: '10px 20px', + }, + }, [ + + // account that will sign + h(AccountPanel, { + showFullAddress: true, + identity: identity, + account: account, + imageifyIdenticons: state.imageifyIdenticons, + }), + + // message data + h('div', { + style: { + height: '260px', + }, + }, [ + h('label.font-small', { style: { display: 'block' } }, 'YOU ARE SIGNING'), + h(TypedMessageRenderer, { + value: data, + style: { + height: '215px', + }, + }), + ]), + + ]) + ) +} diff --git a/ui/app/components/pending-typed-msg.js b/ui/app/components/pending-typed-msg.js new file mode 100644 index 000000000..f8926d0a3 --- /dev/null +++ b/ui/app/components/pending-typed-msg.js @@ -0,0 +1,46 @@ +const Component = require('react').Component +const h = require('react-hyperscript') +const inherits = require('util').inherits +const PendingTxDetails = require('./pending-typed-msg-details') + +module.exports = PendingMsg + +inherits(PendingMsg, Component) +function PendingMsg () { + Component.call(this) +} + +PendingMsg.prototype.render = function () { + var state = this.props + var msgData = state.txData + + return ( + + h('div', { + key: msgData.id, + }, [ + + // header + h('h3', { + style: { + fontWeight: 'bold', + textAlign: 'center', + }, + }, 'Sign Message'), + + // message details + h(PendingTxDetails, state), + + // sign + cancel + h('.flex-row.flex-space-around', [ + h('button', { + onClick: state.cancelTypedMessage, + }, 'Cancel'), + h('button', { + onClick: state.signTypedMessage, + }, 'Sign'), + ]), + ]) + + ) +} diff --git a/ui/app/components/typed-message-renderer.js b/ui/app/components/typed-message-renderer.js new file mode 100644 index 000000000..50e8da02c --- /dev/null +++ b/ui/app/components/typed-message-renderer.js @@ -0,0 +1,42 @@ +const Component = require('react').Component +const h = require('react-hyperscript') +const inherits = require('util').inherits +const ethUtil = require('ethereumjs-util') +const extend = require('xtend') + +module.exports = TypedMessageRenderer + +inherits(TypedMessageRenderer, Component) +function TypedMessageRenderer () { + Component.call(this) +} + +TypedMessageRenderer.prototype.render = function () { + const props = this.props + const { value, style } = props + const text = renderTypedData(value) + + const defaultStyle = extend({ + width: '315px', + maxHeight: '210px', + resize: 'none', + border: 'none', + background: 'white', + padding: '3px', + }, style) + + return ( + h('div.font-small', { + style: defaultStyle, + }, text) + ) +} + +function renderTypedData(values) { + return values.map(function (value) { + return h('div', {}, [ + h('strong', {style: {display: 'block', fontWeight: 'bold', textTransform: 'capitalize'}}, String(value.name) + ':'), + h('div', {}, value.value) + ]) + }) +}
\ No newline at end of file |