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, showGasDetails, toggleGasDetails } = 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 handleRangeChange = (e) => {
22 setGasPrice(e.target.value);
25 const sendTxn = (e) => {
26 e.target.setAttribute("disabled", true);
27 let spinner = e.target.querySelectorAll('.btn-spinner')[0];
28 spinner.classList.remove('hide');
32 const generateButtonColor =
33 Nothing.hasInstance(txn)
37 const signerButtonColor =
38 Nothing.hasInstance(stx)
42 const generateTxnButton =
45 disabled={ !canGenerate }
46 prop-color={ generateButtonColor }
47 prop-size={ 'lg wide' }
48 onClick={ createUnsignedTxn }
50 { 'Generate Transaction' }
53 const unsignedTxnDisplay = txn.matchWith({
57 <H3 className={ 'mt-8' }>
58 { 'Unsigned Transaction' }
61 { JSON.stringify(tx.value, null, 2) }
66 const gasPriceRangeDialogue = (
68 <div className="mt-8">Gas Price: <span className="ml-4 text-700 text-sm">{gasPrice} gwei</span></div>
77 onChange={handleRangeChange}
80 <div className="flex space-between text-sm mb-8">
87 const toggleGasDetailsDialogue = (
88 <a href="javascript:void(0)" onClick={toggleGasDetails}>Gas Details</a>
91 const gasPriceDialogue =
93 className={ 'mono mt-4' }
95 prop-format={ 'innerLabel' }
97 onChange={ setGasPrice }
100 { 'Gas Price (gwei)' }
104 const gasLimitDialogue =
106 className={ 'mono mt-4' }
108 prop-format={ 'innerLabel' }
110 onChange={ setGasLimit }>
116 const nonceDialogue =
118 className={ 'mono mt-4' }
120 prop-format={ 'innerLabel' }
122 onChange={ setNonce }
129 const chainDialogue =
131 className={ 'mono mt-4 mb-8' }
133 prop-format={ 'innerLabel' }
135 onChange={ setChainId }
142 const onlineParamsDialogue = web3.matchWith({
151 const signTxnButton =
153 disabled={ !canSign }
155 prop-size={ 'lg wide' }
156 prop-color={ signerButtonColor }
157 onClick={ () => signTransaction(props) }
159 { 'Sign Transaction' }
162 const signedTxnDisplay = stx.matchWith({
166 <H3 className={ 'mt-8' }>
167 { 'Signed Transaction' }
170 { JSON.stringify(renderSignedTx(tx.value), null, 2) }
175 const confirmButton =
178 disabled={ !canApprove }
179 onClick={ setUserApproval }
180 state={ userApproval }
183 { `I approve this transaction and wish to send.` }
187 const sendTxnButton =
189 prop-size={ 'xl wide' }
191 disabled={ !canSend }
194 <span className="relative">
195 <span className="btn-spinner hide"></span>
196 { 'Send Transaction' }
200 const sendDialogue = web3.matchWith({
211 { generateTxnButton }
212 { unsignedTxnDisplay }
214 { gasPriceRangeDialogue }
215 { toggleGasDetailsDialogue }
223 { onlineParamsDialogue }
233export 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