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-12 flex space-between align-baseline">
70 <span>Gas Price:</span>
71 <span className="ml-4 text-700 text-sm">{gasPrice} gwei</span>
73 <div className="text-sm">
74 <span>Max transaction fee: </span>
75 <span className="text-700">{(gasPrice * gasLimit) / 1000000000} eth</span>
86 onChange={handleRangeChange}
89 <div className="flex space-between text-sm mb-8">
96 const toggleGasDetailsDialogue = (
97 <a href="javascript:void(0)" onClick={toggleGasDetails}>Gas Details</a>
100 const gasPriceDialogue =
102 className={ 'mono mt-4' }
104 prop-format={ 'innerLabel' }
106 onChange={ setGasPrice }
109 { 'Gas Price (gwei)' }
113 const gasLimitDialogue =
115 className={ 'mono mt-4' }
117 prop-format={ 'innerLabel' }
119 onChange={ setGasLimit }>
125 const nonceDialogue =
127 className={ 'mono mt-4' }
129 prop-format={ 'innerLabel' }
131 onChange={ setNonce }
138 const chainDialogue =
140 className={ 'mono mt-4 mb-8' }
142 prop-format={ 'innerLabel' }
144 onChange={ setChainId }
151 const onlineParamsDialogue = web3.matchWith({
160 const signTxnButton =
162 disabled={ !canSign }
164 prop-size={ 'lg wide' }
165 prop-color={ signerButtonColor }
166 onClick={ () => signTransaction(props) }
168 { 'Sign Transaction' }
171 const signedTxnDisplay = stx.matchWith({
175 <H3 className={ 'mt-8' }>
176 { 'Signed Transaction' }
179 { JSON.stringify(renderSignedTx(tx.value), null, 2) }
184 const confirmButton =
187 disabled={ !canApprove }
188 onClick={ setUserApproval }
189 state={ userApproval }
192 { `I approve this transaction and wish to send.` }
196 const sendTxnButton =
198 prop-size={ 'xl wide' }
200 disabled={ !canSend }
203 <span className="relative">
204 <span className="btn-spinner hide"></span>
205 { 'Send Transaction' }
209 const sendDialogue = web3.matchWith({
220 { generateTxnButton }
221 { unsignedTxnDisplay }
223 { gasPriceRangeDialogue }
224 { toggleGasDetailsDialogue }
232 { onlineParamsDialogue }
242export 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