on master help sign in
Remove old transaction components.
commit62429174e758d53411dbdf076ca25cf5874eb8d4 authorJared Tobin <jared@jtobin.io> dateWed 27 Feb 2019, 06:58 (8 years ago) parent915baeb
2 files changed−385
src/components/Transaction.js−191 src/components/Transaction/Signer.js−194
src/components/Transaction.jsdeleted−191
@@ -1,191 +0,0 @@
1−import Maybe from 'folktale/maybe'
2−import Result from 'folktale/result'
3−import React from 'react'
4−import { Row, Col, Code, H3 } from './Base'
5−import { Button } from './Base'
6−import { CheckboxButton } from './Base'
7−
8−import Signer from './Transaction/Signer'
9−import { ROUTE_NAMES } from '../lib/router'
10−import { renderTxnPurpose } from '../lib/txn'
11−import { addHexPrefix } from '../lib/wallet'
12−import { BRIDGE_ERROR } from '../lib/error'
13−
14−const hexify = val =>
15− addHexPrefix(val.toString('hex'))
16−
17−const renderSignedTx = stx => ({
18− messageHash: hexify(stx.hash()),
19− v: hexify(stx.v),
20− s: hexify(stx.s),
21− r: hexify(stx.r),
22− rawTransaction: hexify(stx.serialize())
23−})
24−
25−class Transaction extends React.Component {
26− constructor(props) {
27− super(props)
28−
29− this.state = {
30− purposeConfirmed: false,
31− looksGood: false,
32− isSigned: false,
33− txn: Maybe.Nothing(),
34− stx: Maybe.Nothing()
35− }
36−
37− this.handlePurposeConfirmation = this.handlePurposeConfirmation.bind(this)
38− this.handleLooksGood = this.handleLooksGood.bind(this)
39− this.setSignedTransaction = this.setSignedTransaction.bind(this)
40− this.sendSignedTransaction = this.sendSignedTransaction.bind(this)
41− }
42−
43− // createUnsignedTxn() {
44− // const { props, state } = this
45− // const txn = props.createUnsignedTxn()
46− // this.setState({ txn })
47− // }
48−
49− setSignedTransaction(stx) {
50−
51− this.setState({
52− isSigned: true,
53− stx: Maybe.Just(stx)
54− })
55− }
56−
57− handlePurposeConfirmation() {
58− this.setState({ purposeConfirmed: !this.state.purposeConfirmed })
59− }
60−
61− handleLooksGood() {
62− this.setState({ looksGood: !this.state.looksGood })
63− }
64−
65− async sendSignedTransaction(web3, stx) {
66− const txn = stx.matchWith({
67− Just: (tx) => tx.value,
68− Nothing: () => {
69− throw BRIDGE_ERROR.MISSING_TXN
70− }
71− })
72−
73− const serializedTx = addHexPrefix(txn.serialize().toString('hex'))
74−
75− return new Promise((resolve, _) => {
76− web3.eth.sendSignedTransaction(serializedTx)
77− .on('receipt', txn =>
78− resolve(Maybe.Just(Result.Ok(txn)))
79− )
80− .on('error', err => {
81− resolve(Maybe.Just(Result.Error(err.message)))
82− })
83− })
84− }
85−
86− render() {
87− const { state, props } = this
88−
89− const { web3, wallet, walletType, purpose, setTxnCursor } = this.props
90− const { pushRoute, popRoute } = this.props
91− const { className } = this.props
92− const { purposeConfirmed, looksGood, stx, isSigned, txn } = this.state
93−
94− return (
95− <Row className={`${className}`}>
96− <Col>
97−
98−
99− <Button
100− prop-size={'lg wide'}
101− className={'mt-8'}
102− disabled={ props.disabled }
103− onClick={ () => this.createUnsignedTxn()}
104− >
105− { 'Generate Transaction' }
106− </Button>
107−
108− {
109− // <CheckboxButton
110− // className={'mt-8'}
111− // disabled={ Maybe.Nothing.hasInstance(txn) }
112− // onClick={ this.handlePurposeConfirmation }
113− // state={purposeConfirmed}>
114− // <div>
115− // { `Yes, I am sure I want to ${renderTxnPurpose(purpose)}.` }
116− // </div>
117− // </CheckboxButton>
118− }
119−
120−
121− <Signer
122− className={'mt-8'}
123− web3={ web3 }
124− wallet={ wallet }
125− walletType={ walletType }
126− txn={ txn }
127− setSignedTransaction={ this.setSignedTransaction }
128− disabled={ Maybe.Nothing.hasInstance(txn) } />
129−
130−
131−
132− { stx.matchWith({
133− Nothing: () => '',
134− Just: (tx) => {
135− const rendered = renderSignedTx(tx.value)
136− return (
137− <div>
138− <H3 className={'mt-8'}>{'Signed Transaction'}</H3>
139− <Code> {JSON.stringify(rendered, null, 2)} </Code>
140− </div>
141− )
142− }
143− }) }
144−
145− {
146− web3.matchWith({
147− Nothing: () => <div />,
148− Just: () =>
149− <CheckboxButton
150− className={'mt-8 mb-4'}
151− disabled={ !(!Maybe.Nothing.hasInstance(stx) && isSigned && purposeConfirmed)}
152− onClick={ this.handleLooksGood }
153− state={looksGood}>
154− <div>
155− { `I approve this transaction and wish to send.` }
156− </div>
157− </CheckboxButton>
158− })
159− }
160−
161−
162−
163− { web3.matchWith({
164− Nothing: _ => <div />,
165− Just: w3 =>
166− <Button
167− prop-size={'xl wide'}
168− className={'mt-8'}
169− disabled={ !looksGood }
170− onClick={ () => {
171− this.sendSignedTransaction(w3.value, stx)
172− .then(sent => {
173− setTxnCursor(sent)
174− popRoute()
175− pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
176− })
177− }}
178− >
179− { 'Send Transaction' }
180− </Button>
181− })
182− }
183− </Col>
184− </Row>
185− )
186− }
187−}
188−
189−
190−
191−export default Transaction
src/components/Transaction/Signer.jsdeleted−194
@@ -1,194 +0,0 @@
1−import Tx from 'ethereumjs-tx'
2−import React from 'react'
3−import Web3 from 'web3'
4−import { Button } from '../Base'
5−import { Input, InnerLabel } from '../Base'
6−
7−import { ledgerSignTransaction } from '../../lib/ledger'
8−import { trezorSignTransaction } from '../../lib/trezor'
9−import { WALLET_NAMES, addressFromSecp256k1Public } from '../../lib/wallet'
10−import { BRIDGE_ERROR } from '../../lib/error'
11−
12−class Signer extends React.Component {
13− constructor(props) {
14− super(props)
15−
16− this.state = {
17− nonce: '',
18− gasPrice: '5',
19− chainId: '',
20− gasLimit: '600000'
21− }
22−
23− const dummy = new Web3()
24− this.toHex = dummy.utils.toHex
25− this.toWei = dummy.utils.toWei
26− this.fromWei = dummy.utils.fromWei
27−
28− this.handleNonceInput = this.handleNonceInput.bind(this)
29− this.handleChainIdInput = this.handleChainIdInput.bind(this)
30− this.handleGasPriceInput = this.handleGasPriceInput.bind(this)
31− this.handleGasLimitInput = this.handleGasLimitInput.bind(this)
32− this.signTransaction = this.signTransaction.bind(this)
33− }
34−
35− componentDidMount() {
36− const { web3, wallet } = this.props
37−
38− const addr = wallet.matchWith({
39− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
40− Nothing: () => {
41− throw BRIDGE_ERROR.MISSING_WALLET
42− }
43− })
44−
45− web3.map(w3 =>
46− this.getTxnInfo(w3, addr)
47− .then(txInfo => this.setState(txInfo))
48− )
49− }
50−
51− getTxnInfo = async (web3, addr) => {
52− let nonce = await web3.eth.getTransactionCount(addr)
53− let chainId = await web3.eth.net.getId()
54− let gasPrice = await web3.eth.getGasPrice()
55− return {
56− nonce: nonce,
57− chainId: chainId,
58− gasPrice: this.fromWei(gasPrice, 'gwei')
59− }
60− }
61−
62− handleNonceInput(nonce) {
63− this.setState({ nonce })
64− }
65−
66− handleChainIdInput(chainId) {
67− this.setState({ chainId })
68− }
69−
70− handleGasPriceInput(gasPrice) {
71− this.setState({ gasPrice })
72− }
73−
74− handleGasLimitInput(gasLimit) {
75− this.setState({ gasLimit })
76− }
77−
78− async signTransaction(signingArgs) {
79− const { wallet, walletType, txn, walletHdPath } = this.props
80− const { setSignedTransaction } = this.props
81−
82− let { nonce, chainId, gasPrice, gasLimit } = signingArgs
83− nonce = this.toHex(nonce)
84− chainId = this.toHex(chainId)
85− gasPrice = this.toHex(this.toWei(gasPrice, 'gwei'))
86− gasLimit = this.toHex(gasLimit)
87−
88− const wal = wallet.matchWith({
89− Just: (w) => w.value,
90− Nothing: () => {
91− throw BRIDGE_ERROR.MISSING_WALLET
92− }
93− })
94−
95− const sec = wal.privateKey
96−
97− const utx = txn.matchWith({
98− Just: (tx) =>
99− Object.assign(tx.value, { nonce, chainId, gasPrice, gasLimit }),
100− Nothing: () => {
101− throw BRIDGE_ERROR.MISSING_TXN
102− }
103− })
104−
105− const stx = new Tx(utx)
106−
107− if (walletType === WALLET_NAMES.LEDGER) {
108− await ledgerSignTransaction(stx, walletHdPath)
109− } else if (walletType === WALLET_NAMES.TREZOR) {
110− await trezorSignTransaction(stx, walletHdPath)
111− } else {
112− stx.sign(sec)
113− }
114−
115− setSignedTransaction(stx)
116− }
117−
118− render() {
119−
120− const { state, props } = this
121−
122− const signingArgs = this.state
123− const { nonce, gasPrice, gasLimit, chainId } = signingArgs
124−
125− const signButton =
126− <Button
127− disabled={ props.disabled }
128− prop-size={'lg wide'}
129− prop-color={this.props['prop-color']}
130− onClick={ () => this.signTransaction(signingArgs) }
131− >
132− { 'Sign Transaction' }
133− </Button>
134−
135− const dialogue = props.web3.matchWith({
136− Just: () => <div />,
137− Nothing: () =>
138− <div>
139− <Input
140− className='mono'
141− prop-size='md'
142− prop-format='innerLabel'
143− value={ state.nonce }
144− onChange={ v => this.handleNonceInput(v) }>
145− <InnerLabel>
146− { 'Nonce' }
147− </InnerLabel>
148− </Input>
149−
150− <Input
151− className='mono mt-4 mb-8'
152− prop-size='md'
153− prop-format='innerLabel'
154− value={ state.chainId }
155− onChange={ v => this.handleChainIdInput(v) }>
156− <InnerLabel>
157− { 'Chain ID' }
158− </InnerLabel>
159− </Input>
160−
161− </div>
162− })
163−
164− return (
165− <div className={this.props.className}>
166− <Input
167− className='mono mt-4'
168− prop-size='md'
169− prop-format='innerLabel'
170− value={ state.gasPrice }
171− onChange={ v => this.handleGasPriceInput(v) }>
172− <InnerLabel>
173− { 'Gas Price (gwei)' }
174− </InnerLabel>
175− </Input>
176−
177− <Input
178− className='mono mt-4'
179− prop-size='md'
180− prop-format='innerLabel'
181− value={ state.gasLimit }
182− onChange={ v => this.handleGasLimitInput(v) }>
183− <InnerLabel>
184− { 'Gas Limit' }
185− </InnerLabel>
186− </Input>
187− { dialogue }
188− { signButton }
189− </div>
190− )
191− }
192−}
193−
194−export default Signer