on master help sign in
Assorted formatting fixes.
3e05312Jared Tobin
src/components/StatelessTransaction.js+39−38
@@ -3,37 +3,40 @@ import React from 'react'
3
3
4import { Code, H3 } from './Base'
4import { Code, H3 } from './Base'
5import { Button } from './Base'
5import { Button } from './Base'
6−import { CheckboxButton, Input, InnerLabel } from './Base'
6+import { CheckboxButton, Input, InnerLabel } from './Base'
7
7
8−import {
9− renderSignedTx,
10− signTransaction,
8+import { renderSignedTx, signTransaction } from '../lib/txn'
11− } from '../lib/txn'
12
9
13const StatelessTransaction = props => {
10const StatelessTransaction = props => {
11+ const { web3, gasPrice, gasLimit, nonce, chainId } = props
12+ const { setNonce, setChainId, setGasLimit, setGasPrice } = props
13+ const { txn, stx, createUnsignedTxn } = props
14+ const { canSign, canGenerate, canApprove } = props
15+ const { setUserApproval, userApproval } = props
16+ const { canSend, handleSubmit } = props
14
17
15 const generateButtonColor =
18 const generateButtonColor =
16− Nothing.hasInstance(props.txn)
19+ Nothing.hasInstance(txn)
17 ? 'blue'
20 ? 'blue'
18 : 'green'
21 : 'green'
19
22
20 const signerButtonColor =
23 const signerButtonColor =
21− Nothing.hasInstance(props.stx)
24+ Nothing.hasInstance(stx)
22 ? 'blue'
25 ? 'blue'
23 : 'green'
26 : 'green'
24
27
25 const generateTxnButton =
28 const generateTxnButton =
26 <Button
29 <Button
27 className={ 'mt-8' }
30 className={ 'mt-8' }
28− disabled={ !props.canGenerate }
31+ disabled={ !canGenerate }
29 prop-color={ generateButtonColor }
32 prop-color={ generateButtonColor }
30 prop-size={ 'lg wide' }
33 prop-size={ 'lg wide' }
31− onClick={ () => props.createUnsignedTxn() }
34+ onClick={ createUnsignedTxn }
32 >
35 >
33 { 'Generate Transaction' }
36 { 'Generate Transaction' }
34 </Button>
37 </Button>
35
38
36− const unsignedTxnDisplay = props.txn.matchWith({
39+ const unsignedTxnDisplay = txn.matchWith({
37 Nothing: _ => '',
40 Nothing: _ => '',
38 Just: tx =>
41 Just: tx =>
39 <React.Fragment>
42 <React.Fragment>
@@ -51,8 +54,8 @@ const StatelessTransaction = props => {
51 className={ 'mono mt-4' }
54 className={ 'mono mt-4' }
52 prop-size={ 'md' }
55 prop-size={ 'md' }
53 prop-format={ 'innerLabel' }
56 prop-format={ 'innerLabel' }
54− value={ props.gasPrice }
57+ value={ gasPrice }
55− onChange={ props.setGasPrice }
58+ onChange={ setGasPrice }
56 >
59 >
57 <InnerLabel>
60 <InnerLabel>
58 { 'Gas Price (gwei)' }
61 { 'Gas Price (gwei)' }
@@ -64,8 +67,8 @@ const StatelessTransaction = props => {
64 className={ 'mono mt-4' }
67 className={ 'mono mt-4' }
65 prop-size={ 'md' }
68 prop-size={ 'md' }
66 prop-format={ 'innerLabel' }
69 prop-format={ 'innerLabel' }
67− value={ props.gasLimit }
70+ value={ gasLimit }
68− onChange={ props.setGasLimit }>
71+ onChange={ setGasLimit }>
69 <InnerLabel>
72 <InnerLabel>
70 { 'Gas Limit' }
73 { 'Gas Limit' }
71 </InnerLabel>
74 </InnerLabel>
@@ -76,8 +79,8 @@ const StatelessTransaction = props => {
76 className={ 'mono mt-4' }
79 className={ 'mono mt-4' }
77 prop-size={ 'md' }
80 prop-size={ 'md' }
78 prop-format={ 'innerLabel' }
81 prop-format={ 'innerLabel' }
79− value={ props.nonce }
82+ value={ nonce }
80− onChange={ props.setNonce }
83+ onChange={ setNonce }
81 >
84 >
82 <InnerLabel>
85 <InnerLabel>
83 { 'Nonce' }
86 { 'Nonce' }
@@ -89,15 +92,15 @@ const StatelessTransaction = props => {
89 className={ 'mono mt-4 mb-8' }
92 className={ 'mono mt-4 mb-8' }
90 prop-size={ 'md' }
93 prop-size={ 'md' }
91 prop-format={ 'innerLabel' }
94 prop-format={ 'innerLabel' }
92− value={ props.chainId }
95+ value={ chainId }
93− onChange={ props.setChainId }
96+ onChange={ setChainId }
94 >
97 >
95 <InnerLabel>
98 <InnerLabel>
96 { 'Chain ID' }
99 { 'Chain ID' }
97 </InnerLabel>
100 </InnerLabel>
98 </Input>
101 </Input>
99
102
100− const onlineParamsDialogue = props.web3.matchWith({
103+ const onlineParamsDialogue = web3.matchWith({
101 Just: _ => <div />,
104 Just: _ => <div />,
102 Nothing: _ =>
105 Nothing: _ =>
103 <React.Fragment>
106 <React.Fragment>
@@ -108,7 +111,7 @@ const StatelessTransaction = props => {
108
111
109 const signTxnButton =
112 const signTxnButton =
110 <Button
113 <Button
111− disabled={ !props.canSign }
114+ disabled={ !canSign }
112 className={ 'mt-8' }
115 className={ 'mt-8' }
113 prop-size={ 'lg wide' }
116 prop-size={ 'lg wide' }
114 prop-color={ signerButtonColor }
117 prop-color={ signerButtonColor }
@@ -117,7 +120,7 @@ const StatelessTransaction = props => {
117 { 'Sign Transaction' }
120 { 'Sign Transaction' }
118 </Button>
121 </Button>
119
122
120− const signedTxnDisplay = props.stx.matchWith({
123+ const signedTxnDisplay = stx.matchWith({
121 Nothing: _ => '',
124 Nothing: _ => '',
122 Just: tx =>
125 Just: tx =>
123 <React.Fragment>
126 <React.Fragment>
@@ -133,9 +136,9 @@ const StatelessTransaction = props => {
133 const confirmButton =
136 const confirmButton =
134 <CheckboxButton
137 <CheckboxButton
135 className={ 'mt-8' }
138 className={ 'mt-8' }
136− disabled={ !props.canApprove }
139+ disabled={ !canApprove }
137− onClick={ props.setUserApproval }
140+ onClick={ setUserApproval }
138− state={ props.userApproval }
141+ state={ userApproval }
139 >
142 >
140 <div>
143 <div>
141 { `I approve this transaction and wish to send.` }
144 { `I approve this transaction and wish to send.` }
@@ -146,13 +149,13 @@ const StatelessTransaction = props => {
146 <Button
149 <Button
147 prop-size={ 'xl wide' }
150 prop-size={ 'xl wide' }
148 className={ 'mt-8' }
151 className={ 'mt-8' }
149− disabled={ !props.canSend }
152+ disabled={ !canSend }
150− onClick={ props.handleSubmit }
153+ onClick={ handleSubmit }
151 >
154 >
152 { 'Send Transaction' }
155 { 'Send Transaction' }
153 </Button>
156 </Button>
154
157
155− const sendDialogue = props.web3.matchWith({
158+ const sendDialogue = web3.matchWith({
156 Nothing: _ => '',
159 Nothing: _ => '',
157 Just: _ =>
160 Just: _ =>
158 <React.Fragment>
161 <React.Fragment>
@@ -162,22 +165,20 @@ const StatelessTransaction = props => {
162 })
165 })
163
166
164 return (
167 return (
165− <React.Fragment>
168+ <React.Fragment>
166− { generateTxnButton }
169+ { generateTxnButton }
167− { unsignedTxnDisplay }
170+ { unsignedTxnDisplay }
168
171
169− { gasPriceDialogue }
172+ { gasPriceDialogue }
170− { gasLimitDialogue }
173+ { gasLimitDialogue }
171− { onlineParamsDialogue }
174+ { onlineParamsDialogue }
172
175
173− { signTxnButton }
176+ { signTxnButton }
174
177
175− { signedTxnDisplay }
178+ { signedTxnDisplay }
176− { sendDialogue }
179+ { sendDialogue }
177 </React.Fragment>
180 </React.Fragment>
178 )
181 )
179}
182}
180
183
181−
182−
183export default StatelessTransaction
184export default StatelessTransaction
src/lib/ledger.js+1−1
@@ -11,8 +11,8 @@ const chopHdPrefix = str =>
11const ledgerSignTransaction = async (txn, hdpath) => {
11const ledgerSignTransaction = async (txn, hdpath) => {
12 const transport = await Transport.create()
12 const transport = await Transport.create()
13 const eth = new Eth(transport)
13 const eth = new Eth(transport)
14− const path = chopHdPrefix(hdpath)
15
14
15+ const path = chopHdPrefix(hdpath)
16 const serializedTx = txn.serialize().toString('hex')
16 const serializedTx = txn.serialize().toString('hex')
17 const sig = await eth.signTransaction(path, serializedTx)
17 const sig = await eth.signTransaction(path, serializedTx)
18
18
src/lib/txn.js+5−5
@@ -1,6 +1,6 @@
1import * as ob from 'urbit-ob'
1import * as ob from 'urbit-ob'
2−import Maybe from 'folktale/maybe'
2+import { Just } from 'folktale/maybe'
3−import Result from 'folktale/result'
3+import { Ok, Error } from 'folktale/result'
4import Tx from 'ethereumjs-tx'
4import Tx from 'ethereumjs-tx'
5import Web3 from 'web3'
5import Web3 from 'web3'
6
6
@@ -134,7 +134,7 @@ const signTransaction = async config => {
134 stx.sign(sec)
134 stx.sign(sec)
135 }
135 }
136
136
137− setStx(Maybe.Just(stx))
137+ setStx(Just(stx))
138}
138}
139
139
140const sendSignedTransaction = (web3, stx) => {
140const sendSignedTransaction = (web3, stx) => {
@@ -150,10 +150,10 @@ const sendSignedTransaction = (web3, stx) => {
150 return new Promise((resolve, reject) => {
150 return new Promise((resolve, reject) => {
151 web3.eth.sendSignedTransaction(serializedTx)
151 web3.eth.sendSignedTransaction(serializedTx)
152 .on('receipt', txn =>
152 .on('receipt', txn =>
153− resolve(Maybe.Just(Result.Ok(txn)))
153+ resolve(Just(Ok(txn)))
154 )
154 )
155 .on('error', err => {
155 .on('error', err => {
156− reject(Maybe.Just(Result.Error(err.message)))
156+ reject(Just(Error(err.message)))
157 })
157 })
158 })
158 })
159}
159}
src/views/AcceptTransfer.js+5−44
@@ -9,17 +9,8 @@ import StatelessTransaction from '../components/StatelessTransaction'
9import { BRIDGE_ERROR } from '../lib/error'
9import { BRIDGE_ERROR } from '../lib/error'
10import { NETWORK_NAMES } from '../lib/network'
10import { NETWORK_NAMES } from '../lib/network'
11import { ROUTE_NAMES } from '../lib/router'
11import { ROUTE_NAMES } from '../lib/router'
12−
13−import {
14− sendSignedTransaction,
12+import { sendSignedTransaction, fromWei } from '../lib/txn'
15− fromWei,
16− } from '../lib/txn'
17−
18−import {
19− isValidAddress,
20− addressFromSecp256k1Public,
13+import { isValidAddress, addressFromSecp256k1Public } from '../lib/wallet'
21−} from '../lib/wallet'
22−
23
14
24class AcceptTransfer extends React.Component {
15class AcceptTransfer extends React.Component {
25 constructor(props) {
16 constructor(props) {
@@ -51,8 +42,8 @@ class AcceptTransfer extends React.Component {
51 gasLimit: '600000',
42 gasLimit: '600000',
52 stx: Nothing(),
43 stx: Nothing(),
53 }
44 }
45+
54 this.handleAddressInput = this.handleAddressInput.bind(this)
46 this.handleAddressInput = this.handleAddressInput.bind(this)
55− // Transaction
56 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
47 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
57 this.handleSubmit = this.handleSubmit.bind(this)
48 this.handleSubmit = this.handleSubmit.bind(this)
58 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
49 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
@@ -99,33 +90,25 @@ class AcceptTransfer extends React.Component {
99 });
90 });
100 }
91 }
101
92
102−
103−
104 handleAddressInput(proxyAddress) {
93 handleAddressInput(proxyAddress) {
105 this.setState({ proxyAddress })
94 this.setState({ proxyAddress })
106 this.handleClearTxn()
95 this.handleClearTxn()
107 }
96 }
108
97
109−
110 handleCreateUnsignedTxn() {
98 handleCreateUnsignedTxn() {
111 const txn = this.createUnsignedTxn()
99 const txn = this.createUnsignedTxn()
112 this.setState({ txn })
100 this.setState({ txn })
113 }
101 }
114
102
115−
116 handleSetUserApproval(){
103 handleSetUserApproval(){
117 const {state} = this
104 const {state} = this
118 this.setState({ userApproval: !state.userApproval })
105 this.setState({ userApproval: !state.userApproval })
119 }
106 }
120
107
121−
122−
123 handleSetTxn(txn){
108 handleSetTxn(txn){
124 this.setState({ txn })
109 this.setState({ txn })
125 }
110 }
126
111
127−
128−
129 handleSetStx(stx){
112 handleSetStx(stx){
130 this.setState({
113 this.setState({
131 stx,
114 stx,
@@ -133,36 +116,26 @@ class AcceptTransfer extends React.Component {
133 })
116 })
134 }
117 }
135
118
136−
137−
138 handleSetNonce(nonce){
119 handleSetNonce(nonce){
139 this.setState({ nonce })
120 this.setState({ nonce })
140 this.handleClearStx()
121 this.handleClearStx()
141 }
122 }
142
123
143−
144−
145 handleSetChainId(chainId){
124 handleSetChainId(chainId){
146 this.setState({ chainId })
125 this.setState({ chainId })
147 this.handleClearStx()
126 this.handleClearStx()
148 }
127 }
149
128
150−
151−
152 handleSetGasPrice(gasPrice){
129 handleSetGasPrice(gasPrice){
153 this.setState({ gasPrice })
130 this.setState({ gasPrice })
154 this.handleClearStx()
131 this.handleClearStx()
155 }
132 }
156
133
157−
158−
159 handleSetGasLimit(gasLimit){
134 handleSetGasLimit(gasLimit){
160 this.setState({ gasLimit })
135 this.setState({ gasLimit })
161 this.handleClearStx()
136 this.handleClearStx()
162 }
137 }
163
138
164−
165−
166 handleClearStx() {
139 handleClearStx() {
167 this.setState({
140 this.setState({
168 userApproval: false,
141 userApproval: false,
@@ -170,8 +143,6 @@ class AcceptTransfer extends React.Component {
170 })
143 })
171 }
144 }
172
145
173−
174−
175 handleClearTxn() {
146 handleClearTxn() {
176 this.setState({
147 this.setState({
177 userApproval: false,
148 userApproval: false,
@@ -180,18 +151,6 @@ class AcceptTransfer extends React.Component {
180 })
151 })
181 }
152 }
182
153
183−
184−
185− handleClearTransaction() {
186− this.setState({
187− userApproval: false,
188− txn: Nothing(),
189− stx: Nothing(),
190− })
191− }
192−
193−
194−
195 handleSubmit() {
154 handleSubmit() {
196 const { props, state } = this
155 const { props, state } = this
197 sendSignedTransaction(props.web3.value, state.stx)
156 sendSignedTransaction(props.web3.value, state.stx)
@@ -265,6 +224,7 @@ class AcceptTransfer extends React.Component {
265 "as. But you can transfer to any address you like."
224 "as. But you can transfer to any address you like."
266 }
225 }
267 </P>
226 </P>
227+
268 <AddressInput
228 <AddressInput
269 className='mono mt-8'
229 className='mono mt-8'
270 prop-size='lg'
230 prop-size='lg'
@@ -329,6 +289,7 @@ class AcceptTransfer extends React.Component {
329 { state.txError.value }
289 { state.txError.value }
330 </Warning>
290 </Warning>
331 }
291 }
292+
332 </Col>
293 </Col>
333 </Row>
294 </Row>
334 )
295 )