on master help sign in
Assorted formatting fixes.
commit3e0531288a72656076ec16b39fc359b88ff0d67a authorJared Tobin <jared@jtobin.io> dateTue 26 Feb 2019, 13:37 (8 years ago) parent9de325a
4 files changed+50−88
src/components/StatelessTransaction.js+39−38 src/lib/ledger.js+1−1 src/lib/txn.js+5−5 src/views/AcceptTransfer.js+5−44
src/components/StatelessTransaction.js+39−38
@@ -3,37 +3,40 @@ import React from 'react'
33
44import { Code, H3 } from './Base'
55import { Button } from './Base'
6−import { CheckboxButton, Input, InnerLabel } from './Base'
6+import { CheckboxButton, Input, InnerLabel } from './Base'
77
8−import {
9− renderSignedTx,
10− signTransaction,
11− } from '../lib/txn'
8+import { renderSignedTx, signTransaction } from '../lib/txn'
129
1310const 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
1417
1518 const generateButtonColor =
16− Nothing.hasInstance(props.txn)
19+ Nothing.hasInstance(txn)
1720 ? 'blue'
1821 : 'green'
1922
2023 const signerButtonColor =
21− Nothing.hasInstance(props.stx)
24+ Nothing.hasInstance(stx)
2225 ? 'blue'
2326 : 'green'
2427
2528 const generateTxnButton =
2629 <Button
2730 className={ 'mt-8' }
28− disabled={ !props.canGenerate }
31+ disabled={ !canGenerate }
2932 prop-color={ generateButtonColor }
3033 prop-size={ 'lg wide' }
31− onClick={ () => props.createUnsignedTxn() }
34+ onClick={ createUnsignedTxn }
3235 >
3336 { 'Generate Transaction' }
3437 </Button>
3538
36− const unsignedTxnDisplay = props.txn.matchWith({
39+ const unsignedTxnDisplay = txn.matchWith({
3740 Nothing: _ => '',
3841 Just: tx =>
3942 <React.Fragment>
@@ -51,8 +54,8 @@ const StatelessTransaction = props => {
5154 className={ 'mono mt-4' }
5255 prop-size={ 'md' }
5356 prop-format={ 'innerLabel' }
54− value={ props.gasPrice }
55− onChange={ props.setGasPrice }
57+ value={ gasPrice }
58+ onChange={ setGasPrice }
5659 >
5760 <InnerLabel>
5861 { 'Gas Price (gwei)' }
@@ -64,8 +67,8 @@ const StatelessTransaction = props => {
6467 className={ 'mono mt-4' }
6568 prop-size={ 'md' }
6669 prop-format={ 'innerLabel' }
67− value={ props.gasLimit }
68− onChange={ props.setGasLimit }>
70+ value={ gasLimit }
71+ onChange={ setGasLimit }>
6972 <InnerLabel>
7073 { 'Gas Limit' }
7174 </InnerLabel>
@@ -76,8 +79,8 @@ const StatelessTransaction = props => {
7679 className={ 'mono mt-4' }
7780 prop-size={ 'md' }
7881 prop-format={ 'innerLabel' }
79− value={ props.nonce }
80− onChange={ props.setNonce }
82+ value={ nonce }
83+ onChange={ setNonce }
8184 >
8285 <InnerLabel>
8386 { 'Nonce' }
@@ -89,15 +92,15 @@ const StatelessTransaction = props => {
8992 className={ 'mono mt-4 mb-8' }
9093 prop-size={ 'md' }
9194 prop-format={ 'innerLabel' }
92− value={ props.chainId }
93− onChange={ props.setChainId }
95+ value={ chainId }
96+ onChange={ setChainId }
9497 >
9598 <InnerLabel>
9699 { 'Chain ID' }
97100 </InnerLabel>
98101 </Input>
99102
100− const onlineParamsDialogue = props.web3.matchWith({
103+ const onlineParamsDialogue = web3.matchWith({
101104 Just: _ => <div />,
102105 Nothing: _ =>
103106 <React.Fragment>
@@ -108,7 +111,7 @@ const StatelessTransaction = props => {
108111
109112 const signTxnButton =
110113 <Button
111− disabled={ !props.canSign }
114+ disabled={ !canSign }
112115 className={ 'mt-8' }
113116 prop-size={ 'lg wide' }
114117 prop-color={ signerButtonColor }
@@ -117,7 +120,7 @@ const StatelessTransaction = props => {
117120 { 'Sign Transaction' }
118121 </Button>
119122
120− const signedTxnDisplay = props.stx.matchWith({
123+ const signedTxnDisplay = stx.matchWith({
121124 Nothing: _ => '',
122125 Just: tx =>
123126 <React.Fragment>
@@ -133,9 +136,9 @@ const StatelessTransaction = props => {
133136 const confirmButton =
134137 <CheckboxButton
135138 className={ 'mt-8' }
136− disabled={ !props.canApprove }
137− onClick={ props.setUserApproval }
138− state={ props.userApproval }
139+ disabled={ !canApprove }
140+ onClick={ setUserApproval }
141+ state={ userApproval }
139142 >
140143 <div>
141144 { `I approve this transaction and wish to send.` }
@@ -146,13 +149,13 @@ const StatelessTransaction = props => {
146149 <Button
147150 prop-size={ 'xl wide' }
148151 className={ 'mt-8' }
149− disabled={ !props.canSend }
150− onClick={ props.handleSubmit }
152+ disabled={ !canSend }
153+ onClick={ handleSubmit }
151154 >
152155 { 'Send Transaction' }
153156 </Button>
154157
155− const sendDialogue = props.web3.matchWith({
158+ const sendDialogue = web3.matchWith({
156159 Nothing: _ => '',
157160 Just: _ =>
158161 <React.Fragment>
@@ -162,22 +165,20 @@ const StatelessTransaction = props => {
162165 })
163166
164167 return (
165− <React.Fragment>
166− { generateTxnButton }
167− { unsignedTxnDisplay }
168+ <React.Fragment>
169+ { generateTxnButton }
170+ { unsignedTxnDisplay }
168171
169− { gasPriceDialogue }
170− { gasLimitDialogue }
171− { onlineParamsDialogue }
172+ { gasPriceDialogue }
173+ { gasLimitDialogue }
174+ { onlineParamsDialogue }
172175
173− { signTxnButton }
176+ { signTxnButton }
174177
175− { signedTxnDisplay }
176− { sendDialogue }
178+ { signedTxnDisplay }
179+ { sendDialogue }
177180 </React.Fragment>
178181 )
179182}
180183
181−
182−
183184export default StatelessTransaction
src/lib/ledger.js+1−1
@@ -11,8 +11,8 @@ const chopHdPrefix = str =>
1111const ledgerSignTransaction = async (txn, hdpath) => {
1212 const transport = await Transport.create()
1313 const eth = new Eth(transport)
14− const path = chopHdPrefix(hdpath)
1514
15+ const path = chopHdPrefix(hdpath)
1616 const serializedTx = txn.serialize().toString('hex')
1717 const sig = await eth.signTransaction(path, serializedTx)
1818
src/lib/txn.js+5−5
@@ -1,6 +1,6 @@
11import * as ob from 'urbit-ob'
2−import Maybe from 'folktale/maybe'
3−import Result from 'folktale/result'
2+import { Just } from 'folktale/maybe'
3+import { Ok, Error } from 'folktale/result'
44import Tx from 'ethereumjs-tx'
55import Web3 from 'web3'
66
@@ -134,7 +134,7 @@ const signTransaction = async config => {
134134 stx.sign(sec)
135135 }
136136
137− setStx(Maybe.Just(stx))
137+ setStx(Just(stx))
138138}
139139
140140const sendSignedTransaction = (web3, stx) => {
@@ -150,10 +150,10 @@ const sendSignedTransaction = (web3, stx) => {
150150 return new Promise((resolve, reject) => {
151151 web3.eth.sendSignedTransaction(serializedTx)
152152 .on('receipt', txn =>
153− resolve(Maybe.Just(Result.Ok(txn)))
153+ resolve(Just(Ok(txn)))
154154 )
155155 .on('error', err => {
156− reject(Maybe.Just(Result.Error(err.message)))
156+ reject(Just(Error(err.message)))
157157 })
158158 })
159159}
src/views/AcceptTransfer.js+5−44
@@ -9,17 +9,8 @@ import StatelessTransaction from '../components/StatelessTransaction'
99import { BRIDGE_ERROR } from '../lib/error'
1010import { NETWORK_NAMES } from '../lib/network'
1111import { ROUTE_NAMES } from '../lib/router'
12−
13−import {
14− sendSignedTransaction,
15− fromWei,
16− } from '../lib/txn'
17−
18−import {
19− isValidAddress,
20− addressFromSecp256k1Public,
21−} from '../lib/wallet'
22−
12+import { sendSignedTransaction, fromWei } from '../lib/txn'
13+import { isValidAddress, addressFromSecp256k1Public } from '../lib/wallet'
2314
2415class AcceptTransfer extends React.Component {
2516 constructor(props) {
@@ -51,8 +42,8 @@ class AcceptTransfer extends React.Component {
5142 gasLimit: '600000',
5243 stx: Nothing(),
5344 }
45+
5446 this.handleAddressInput = this.handleAddressInput.bind(this)
55− // Transaction
5647 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
5748 this.handleSubmit = this.handleSubmit.bind(this)
5849 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
@@ -99,33 +90,25 @@ class AcceptTransfer extends React.Component {
9990 });
10091 }
10192
102−
103−
10493 handleAddressInput(proxyAddress) {
10594 this.setState({ proxyAddress })
10695 this.handleClearTxn()
10796 }
10897
109−
11098 handleCreateUnsignedTxn() {
11199 const txn = this.createUnsignedTxn()
112100 this.setState({ txn })
113101 }
114102
115−
116103 handleSetUserApproval(){
117104 const {state} = this
118105 this.setState({ userApproval: !state.userApproval })
119106 }
120107
121−
122−
123108 handleSetTxn(txn){
124109 this.setState({ txn })
125110 }
126111
127−
128−
129112 handleSetStx(stx){
130113 this.setState({
131114 stx,
@@ -133,36 +116,26 @@ class AcceptTransfer extends React.Component {
133116 })
134117 }
135118
136−
137−
138119 handleSetNonce(nonce){
139120 this.setState({ nonce })
140121 this.handleClearStx()
141122 }
142123
143−
144−
145124 handleSetChainId(chainId){
146125 this.setState({ chainId })
147126 this.handleClearStx()
148127 }
149128
150−
151−
152129 handleSetGasPrice(gasPrice){
153130 this.setState({ gasPrice })
154131 this.handleClearStx()
155132 }
156133
157−
158−
159134 handleSetGasLimit(gasLimit){
160135 this.setState({ gasLimit })
161136 this.handleClearStx()
162137 }
163138
164−
165−
166139 handleClearStx() {
167140 this.setState({
168141 userApproval: false,
@@ -170,8 +143,6 @@ class AcceptTransfer extends React.Component {
170143 })
171144 }
172145
173−
174−
175146 handleClearTxn() {
176147 this.setState({
177148 userApproval: false,
@@ -180,18 +151,6 @@ class AcceptTransfer extends React.Component {
180151 })
181152 }
182153
183−
184−
185− handleClearTransaction() {
186− this.setState({
187− userApproval: false,
188− txn: Nothing(),
189− stx: Nothing(),
190− })
191− }
192−
193−
194−
195154 handleSubmit() {
196155 const { props, state } = this
197156 sendSignedTransaction(props.web3.value, state.stx)
@@ -265,6 +224,7 @@ class AcceptTransfer extends React.Component {
265224 "as. But you can transfer to any address you like."
266225 }
267226 </P>
227+
268228 <AddressInput
269229 className='mono mt-8'
270230 prop-size='lg'
@@ -329,6 +289,7 @@ class AcceptTransfer extends React.Component {
329289 { state.txError.value }
330290 </Warning>
331291 }
292+
332293 </Col>
333294 </Row>
334295 )