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 maxTxnPriceInEth = (
117 <div className="mt-8">
118 Max transaction price: <span className="text-700">{(gasPrice * gasLimit) / 1000000000} eth</span>
122 const nonceDialogue =
124 className={ 'mono mt-4' }
126 prop-format={ 'innerLabel' }
128 onChange={ setNonce }
135 const chainDialogue =
137 className={ 'mono mt-4 mb-8' }
139 prop-format={ 'innerLabel' }
141 onChange={ setChainId }
148 const onlineParamsDialogue = web3.matchWith({
157 const signTxnButton =
159 disabled={ !canSign }
161 prop-size={ 'lg wide' }
162 prop-color={ signerButtonColor }
163 onClick={ () => signTransaction(props) }
165 { 'Sign Transaction' }
168 const signedTxnDisplay = stx.matchWith({
172 <H3 className={ 'mt-8' }>
173 { 'Signed Transaction' }
176 { JSON.stringify(renderSignedTx(tx.value), null, 2) }
181 const confirmButton =
184 disabled={ !canApprove }
185 onClick={ setUserApproval }
186 state={ userApproval }
189 { `I approve this transaction and wish to send.` }
193 const sendTxnButton =
195 prop-size={ 'xl wide' }
197 disabled={ !canSend }
200 <span className="relative">
201 <span className="btn-spinner hide"></span>
202 { 'Send Transaction' }
206 const sendDialogue = web3.matchWith({
217 { generateTxnButton }
218 { unsignedTxnDisplay }
220 { gasPriceRangeDialogue }
221 { toggleGasDetailsDialogue }
230 { onlineParamsDialogue }
240export 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