@@ -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'
7−import { ledgerSignTransaction } from '../../lib/ledger'
8−import { WALLET_NAMES, addressFromSecp256k1Public } from '../../lib/wallet'
9−import { BRIDGE_ERROR } from '../../lib/error'
11−class Signer extends React.Component {
19− // gasLimit: '600000'
22− const dummy = new Web3()
23− this.toHex = dummy.utils.toHex
24− this.toWei = dummy.utils.toWei
25− this.fromWei = dummy.utils.fromWei
27− this.handleNonceInput = this.handleNonceInput.bind(this)
28− this.handleChainIdInput = this.handleChainIdInput.bind(this)
29− this.handleGasPriceInput = this.handleGasPriceInput.bind(this)
30− this.handleGasLimitInput = this.handleGasLimitInput.bind(this)
31− this.signTransaction = this.signTransaction.bind(this)
34− componentDidMount() {
35− const { web3, wallet } = this.props
37− const addr = wallet.matchWith({
38− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
40− throw BRIDGE_ERROR.MISSING_WALLET
45− this.getTxnInfo(w3, addr)
46− .then(txInfo => this.setState(txInfo))
50− getTxnInfo = async (web3, addr) => {
51− let nonce = await web3.eth.getTransactionCount(addr)
52− let chainId = await web3.eth.net.getId()
53− let gasPrice = await web3.eth.getGasPrice()
57− gasPrice: this.fromWei(gasPrice, 'gwei')
61− handleNonceInput(nonce) {
62− this.setState({ nonce })
65− handleChainIdInput(chainId) {
66− this.setState({ chainId })
69− handleGasPriceInput(gasPrice) {
70− this.setState({ gasPrice })
73− handleGasLimitInput(gasLimit) {
74− this.setState({ gasLimit })
77− async signTransaction(signingArgs) {
78− const { wallet, walletType, txn, setSignedTransaction } = this.props
80− let { nonce, chainId, gasPrice, gasLimit } = signingArgs
81− nonce = this.toHex(nonce)
82− chainId = this.toHex(chainId)
83− gasPrice = this.toHex(this.toWei(gasPrice, 'gwei'))
84− gasLimit = this.toHex(gasLimit)
86− const wal = wallet.matchWith({
87− Just: (w) => w.value,
89− throw BRIDGE_ERROR.MISSING_WALLET
93− const sec = wal.privateKey
95− const utx = txn.matchWith({
97− Object.assign(tx.value, { nonce, chainId, gasPrice, gasLimit }),
99− throw BRIDGE_ERROR.MISSING_TXN
103− const stx = new Tx(utx)
105− if (walletType === WALLET_NAMES.LEDGER) {
106− await ledgerSignTransaction(stx)
111− setSignedTransaction(stx)
116− const { state, props } = this
118− const signingArgs = {
120− gasPrice: props.gasPrice,
121− gasLimit: props.gasLimit,
122− chainId: props.chainId,
130− className='mono mt-4'
132− prop-format='innerLabel'
133− value={ props.gasPrice }
134− onChange={ v => this.handleGasPriceInput(v) }>
136− { 'Gas Price (gwei)' }
141− className='mono mt-4'
143− prop-format='innerLabel'
144− value={ props.gasLimit }
145− onChange={ v => this.handleGasLimitInput(v) }>
152− props.web3.matchWith({
153− Just: () => <div />,
159− prop-format='innerLabel'
160− value={ props.nonce }
161− onChange={ v => this.handleNonceInput(v) }>
168− className='mono mt-4 mb-8'
170− prop-format='innerLabel'
171− value={ props.chainId }
172− onChange={ v => this.handleChainIdInput(v) }>
183− disabled={ props.disabled }
184− prop-size={'lg wide'}
185− prop-color={this.props['prop-color']}
186− onClick={ () => this.signTransaction(signingArgs) }>
187− { 'Sign Transaction' }
194−export default Signer