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
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 handleRangeChange = (e) => {
24 setGasPrice(e.target.value);
27 const sendTxn = (e) => {
28 e.target.setAttribute("disabled", true);
29 let spinner = e.target.querySelectorAll('.btn-spinner')[0];
30 spinner.classList.remove('hide');
34 const generateButtonColor =
35 Nothing.hasInstance(txn)
39 const signerButtonColor =
40 Nothing.hasInstance(stx)
44 const generateTxnButton =
47 disabled={ !canGenerate }
48 prop-color={ generateButtonColor }
49 prop-size={ 'lg wide' }
50 onClick={ createUnsignedTxn }
52 { 'Generate Transaction' }
55 const unsignedTxnDisplay = txn.matchWith({
59 <H3 className={ 'mt-8' }>
60 { 'Unsigned Transaction' }
63 { JSON.stringify(tx.value, null, 2) }
68 const gasPriceRangeDialogue = (
70 <div className="mt-12 flex space-between align-baseline">
72 <span>Gas Price:</span>
73 <span className="ml-4 text-700 text-sm">{gasPrice} gwei</span>
75 <div className="text-sm">
76 <span>Max transaction fee: </span>
77 <span className="text-700">{(gasPrice * gasLimit) / 1000000000} eth</span>
88 onChange={handleRangeChange}
91 <div className="flex space-between text-sm mb-8">
98 const toggleGasDetailsDialogue = (
99 <a href="javascript:void(0)" onClick={toggleGasDetails}>Gas Details</a>
102 const gasPriceDialogue =
104 className={ 'mono mt-4' }
106 prop-format={ 'innerLabel' }
108 onChange={ setGasPrice }
111 { 'Gas Price (gwei)' }
115 const gasLimitDialogue =
117 className={ 'mono mt-4' }
119 prop-format={ 'innerLabel' }
121 onChange={ setGasLimit }>
127 const nonceDialogue =
129 className={ 'mono mt-4' }
131 prop-format={ 'innerLabel' }
133 onChange={ setNonce }
140 const chainDialogue =
142 className={ 'mono mt-4 mb-8' }
144 prop-format={ 'innerLabel' }
146 onChange={ setChainId }
153 const onlineParamsDialogue = web3.matchWith({
162 const signTxnButton =
164 disabled={ !canSign }
166 prop-size={ 'lg wide' }
167 prop-color={ signerButtonColor }
168 onClick={ () => signTransaction(props) }
170 { 'Sign Transaction' }
173 const signedTxnDisplay = stx.matchWith({
177 <H3 className={ 'mt-8' }>
178 { 'Signed Transaction' }
181 { JSON.stringify(renderSignedTx(tx.value), null, 2) }
186 const confirmButton =
189 disabled={ !canApprove }
190 onClick={ setUserApproval }
191 state={ userApproval }
194 { `I approve this transaction and wish to send.` }
198 const sendTxnButton =
200 prop-size={ 'xl wide' }
202 disabled={ !canSend }
205 <span className="relative">
206 <span className="btn-spinner hide"></span>
207 { 'Send Transaction' }
211 const sendDialogue = web3.matchWith({
222 { generateTxnButton }
223 { unsignedTxnDisplay }
225 { gasPriceRangeDialogue }
226 { toggleGasDetailsDialogue }
234 { onlineParamsDialogue }
244export 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