@@ -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 { trezorSignTransaction } from '../../lib/trezor'
9−import { WALLET_NAMES, addressFromSecp256k1Public } from '../../lib/wallet'
10−import { BRIDGE_ERROR } from '../../lib/error'
12−class Signer extends React.Component {
23− const dummy = new Web3()
24− this.toHex = dummy.utils.toHex
25− this.toWei = dummy.utils.toWei
26− this.fromWei = dummy.utils.fromWei
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)
35− componentDidMount() {
36− const { web3, wallet } = this.props
38− const addr = wallet.matchWith({
39− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
41− throw BRIDGE_ERROR.MISSING_WALLET
46− this.getTxnInfo(w3, addr)
47− .then(txInfo => this.setState(txInfo))
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()
58− gasPrice: this.fromWei(gasPrice, 'gwei')
62− handleNonceInput(nonce) {
63− this.setState({ nonce })
66− handleChainIdInput(chainId) {
67− this.setState({ chainId })
70− handleGasPriceInput(gasPrice) {
71− this.setState({ gasPrice })
74− handleGasLimitInput(gasLimit) {
75− this.setState({ gasLimit })
78− async signTransaction(signingArgs) {
79− const { wallet, walletType, txn, walletHdPath } = this.props
80− const { setSignedTransaction } = this.props
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)
88− const wal = wallet.matchWith({
89− Just: (w) => w.value,
91− throw BRIDGE_ERROR.MISSING_WALLET
95− const sec = wal.privateKey
97− const utx = txn.matchWith({
99− Object.assign(tx.value, { nonce, chainId, gasPrice, gasLimit }),
101− throw BRIDGE_ERROR.MISSING_TXN
105− const stx = new Tx(utx)
107− if (walletType === WALLET_NAMES.LEDGER) {
108− await ledgerSignTransaction(stx, walletHdPath)
109− } else if (walletType === WALLET_NAMES.TREZOR) {
110− await trezorSignTransaction(stx, walletHdPath)
115− setSignedTransaction(stx)
120− const { state, props } = this
122− const signingArgs = this.state
123− const { nonce, gasPrice, gasLimit, chainId } = signingArgs
127− disabled={ props.disabled }
128− prop-size={'lg wide'}
129− prop-color={this.props['prop-color']}
130− onClick={ () => this.signTransaction(signingArgs) }
132− { 'Sign Transaction' }
135− const dialogue = props.web3.matchWith({
136− Just: () => <div />,
142− prop-format='innerLabel'
143− value={ state.nonce }
144− onChange={ v => this.handleNonceInput(v) }>
151− className='mono mt-4 mb-8'
153− prop-format='innerLabel'
154− value={ state.chainId }
155− onChange={ v => this.handleChainIdInput(v) }>
165− <div className={this.props.className}>
167− className='mono mt-4'
169− prop-format='innerLabel'
170− value={ state.gasPrice }
171− onChange={ v => this.handleGasPriceInput(v) }>
173− { 'Gas Price (gwei)' }
178− className='mono mt-4'
180− prop-format='innerLabel'
181− value={ state.gasLimit }
182− onChange={ v => this.handleGasLimitInput(v) }>
194−export default Signer