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
19 // setState doesn't seem to work in SetProxy/handleSubmit;
20 // - TypeError: Cannot read property 'updater' of undefined
21 // so just modifying the DOM manually here. (https://imgur.com/a/i0Qsyq1)
23 const sendTxn = (e) => {
24 e.target.setAttribute("disabled", true);
25 let spinner = e.target.querySelectorAll('.btn-spinner')[0];
26 spinner.classList.remove('hide');
30 const generateButtonColor =
31 Nothing.hasInstance(txn)
35 const signerButtonColor =
36 Nothing.hasInstance(stx)
40 const generateTxnButton =
43 disabled={ !canGenerate }
44 prop-color={ generateButtonColor }
45 prop-size={ 'lg wide' }
46 onClick={ createUnsignedTxn }
48 { 'Generate Transaction' }
51 const unsignedTxnDisplay = txn.matchWith({
55 <H3 className={ 'mt-8' }>
56 { 'Unsigned Transaction' }
59 { JSON.stringify(tx.value, null, 2) }
64 const gasPriceDialogue =
66 className={ 'mono mt-4' }
68 prop-format={ 'innerLabel' }
70 onChange={ setGasPrice }
73 { 'Gas Price (gwei)' }
77 const gasLimitDialogue =
79 className={ 'mono mt-4' }
81 prop-format={ 'innerLabel' }
83 onChange={ setGasLimit }>
91 className={ 'mono mt-4' }
93 prop-format={ 'innerLabel' }
102 const chainDialogue =
104 className={ 'mono mt-4 mb-8' }
106 prop-format={ 'innerLabel' }
108 onChange={ setChainId }
115 const onlineParamsDialogue = web3.matchWith({
124 const signTxnButton =
126 disabled={ !canSign }
128 prop-size={ 'lg wide' }
129 prop-color={ signerButtonColor }
130 onClick={ () => signTransaction(props) }
132 { 'Sign Transaction' }
135 const signedTxnDisplay = stx.matchWith({
139 <H3 className={ 'mt-8' }>
140 { 'Signed Transaction' }
143 { JSON.stringify(renderSignedTx(tx.value), null, 2) }
148 const confirmButton =
151 disabled={ !canApprove }
152 onClick={ setUserApproval }
153 state={ userApproval }
156 { `I approve this transaction and wish to send.` }
160 const sendTxnButton =
162 prop-size={ 'xl wide' }
164 disabled={ !canSend }
167 <span className="relative">
168 <span className="btn-spinner hide"></span>
169 { 'Send Transaction' }
173 const sendDialogue = web3.matchWith({
184 { generateTxnButton }
185 { unsignedTxnDisplay }
189 { onlineParamsDialogue }
199export 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