1import { Nothing } from 'folktale/maybe'
2import React from 'react'
4import { Code, H3 } from './Base'
5import { Button } from './Base'
6import { CheckboxButton, Input, InnerLabel } from './Base'
8import { renderSignedTx, signTransaction } from '../lib/txn'
10const 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
18 // setState doesn't seem to work in SetProxy/handleSubmit, so just
19 // modifying the DOM manually here. (https://imgur.com/a/i0Qsyq1)
21 const sendTxn = (e) => {
22 e.target.setAttribute("disabled", true);
23 let spinner = e.target.querySelectorAll('.btn-spinner')[0];
24 spinner.classList.remove('hide');
28 const generateButtonColor =
29 Nothing.hasInstance(txn)
33 const signerButtonColor =
34 Nothing.hasInstance(stx)
38 const generateTxnButton =
41 disabled={ !canGenerate }
42 prop-color={ generateButtonColor }
43 prop-size={ 'lg wide' }
44 onClick={ createUnsignedTxn }
46 { 'Generate Transaction' }
49 const unsignedTxnDisplay = txn.matchWith({
53 <H3 className={ 'mt-8' }>
54 { 'Unsigned Transaction' }
57 { JSON.stringify(tx.value, null, 2) }
62 const gasPriceDialogue =
64 className={ 'mono mt-4' }
66 prop-format={ 'innerLabel' }
68 onChange={ setGasPrice }
71 { 'Gas Price (gwei)' }
75 const gasLimitDialogue =
77 className={ 'mono mt-4' }
79 prop-format={ 'innerLabel' }
81 onChange={ setGasLimit }>
89 className={ 'mono mt-4' }
91 prop-format={ 'innerLabel' }
100 const chainDialogue =
102 className={ 'mono mt-4 mb-8' }
104 prop-format={ 'innerLabel' }
106 onChange={ setChainId }
113 const onlineParamsDialogue = web3.matchWith({
122 const signTxnButton =
124 disabled={ !canSign }
126 prop-size={ 'lg wide' }
127 prop-color={ signerButtonColor }
128 onClick={ () => signTransaction(props) }
130 { 'Sign Transaction' }
133 const signedTxnDisplay = stx.matchWith({
137 <H3 className={ 'mt-8' }>
138 { 'Signed Transaction' }
141 { JSON.stringify(renderSignedTx(tx.value), null, 2) }
146 const confirmButton =
149 disabled={ !canApprove }
150 onClick={ setUserApproval }
151 state={ userApproval }
154 { `I approve this transaction and wish to send.` }
158 const sendTxnButton =
160 prop-size={ 'xl wide' }
162 disabled={ !canSend }
165 <span className="relative">
166 <span className="btn-spinner hide"></span>
167 { 'Send Transaction' }
171 const sendDialogue = web3.matchWith({
182 { generateTxnButton }
183 { unsignedTxnDisplay }
187 { onlineParamsDialogue }
197export default StatelessTransaction
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