1import Maybe from 'folktale/maybe'
2import Result from 'folktale/result'
3import React from 'react'
4import { Row, Col, Code, H3 } from './Base'
5import { Button } from './Base'
6import { CheckboxButton } from './Base'
8import Signer from './Transaction/Signer'
9import { ROUTE_NAMES } from '../lib/router'
10import { renderTxnPurpose } from '../lib/txn'
11import { addHexPrefix } from '../lib/wallet'
12import { BRIDGE_ERROR } from '../lib/error'
15 addHexPrefix(val.toString('hex'))
17const renderSignedTx = stx => ({
18 messageHash: hexify(stx.hash()),
22 rawTransaction: hexify(stx.serialize())
25class Transaction extends React.Component {
30 purposeConfirmed: false,
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)
43 // createUnsignedTxn() {
44 // const { props, state } = this
45 // const txn = props.createUnsignedTxn()
46 // this.setState({ txn })
49 setSignedTransaction(stx) {
57 handlePurposeConfirmation() {
58 this.setState({ purposeConfirmed: !this.state.purposeConfirmed })
62 this.setState({ looksGood: !this.state.looksGood })
65 async sendSignedTransaction(web3, stx) {
66 const txn = stx.matchWith({
67 Just: (tx) => tx.value,
69 throw BRIDGE_ERROR.MISSING_TXN
73 const serializedTx = addHexPrefix(txn.serialize().toString('hex'))
75 return new Promise((resolve, _) => {
76 web3.eth.sendSignedTransaction(serializedTx)
78 resolve(Maybe.Just(Result.Ok(txn)))
81 resolve(Maybe.Just(Result.Error(err.message)))
87 const { state, props } = this
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
95 <Row className={`${className}`}>
100 prop-size={'lg wide'}
102 disabled={ props.disabled }
103 onClick={ () => this.createUnsignedTxn()}
105 { 'Generate Transaction' }
110 // className={'mt-8'}
111 // disabled={ Maybe.Nothing.hasInstance(txn) }
112 // onClick={ this.handlePurposeConfirmation }
113 // state={purposeConfirmed}>
115 // { `Yes, I am sure I want to ${renderTxnPurpose(purpose)}.` }
125 walletType={ walletType }
127 setSignedTransaction={ this.setSignedTransaction }
128 disabled={ Maybe.Nothing.hasInstance(txn) } />
135 const rendered = renderSignedTx(tx.value)
138 <H3 className={'mt-8'}>{'Signed Transaction'}</H3>
139 <Code> {JSON.stringify(rendered, null, 2)} </Code>
147 Nothing: () => <div />,
150 className={'mt-8 mb-4'}
151 disabled={ !(!Maybe.Nothing.hasInstance(stx) && isSigned && purposeConfirmed)}
152 onClick={ this.handleLooksGood }
155 { `I approve this transaction and wish to send.` }
164 Nothing: _ => <div />,
167 prop-size={'xl wide'}
169 disabled={ !looksGood }
171 this.sendSignedTransaction(w3.value, stx)
175 pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
179 { 'Send Transaction' }
191export default Transaction
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list