on 41620df help sign in
bridge/src/components/InlineEthereumTransaction.js
94 lines 2.2 kB history raw
1import React from 'react';
2import { Grid, ToggleInput, ErrorText } from 'indigo-react';
3import { GenerateButton, ForwardButton } from './Buttons';
4import { useCheckboxInput } from 'lib/useInputs';
5import Blinky from './Blinky';
7export default function InlineEthereumTransaction({
8 initializing,
9 construct,
10 constructed,
11 canSign,
12 generateAndSign,
13 signed,
14 broadcast,
15 broadcasted,
16 confirmed,
17 reset,
18 error,
19 setGasPrice,
20 className,
21}) {
22 const [configureInput, { data: configurationOpen }] = useCheckboxInput({
23 name: 'configure',
24 label: 'Configure Transaction',
25 disabled: signed || broadcasted || confirmed,
26 });
28 const [
29 viewSignedTransaction,
30 { data: signedTransactionOpen },
31 ] = useCheckboxInput({
32 name: 'viewsigned',
33 label: 'View Signed Transaction',
34 disabled: !signed,
35 });
37 const renderButton = () => {
38 if (confirmed) {
39 // some sort of next button or nothing at all
40 return null;
41 } else if (broadcasted) {
42 return (
43 <Grid.Item
44 full
45 as={ForwardButton}
46 solid
47 success
48 disabled
49 accessory={<Blinky />}>
50 Sending Transaction...
51 </Grid.Item>
52 );
53 } else if (signed) {
54 return (
55 <Grid.Item
56 full
57 as={ForwardButton}
58 solid
59 success
60 onClick={() => broadcast()}>
61 Send Transaction
62 </Grid.Item>
63 );
64 } else {
65 return (
66 <Grid.Item
67 full
68 as={GenerateButton}
69 onClick={generateAndSign}
70 disabled={!canSign}
71 accessory={!canSign && initializing ? <Blinky /> : undefined}>
72 Generate & Sign Transaction
73 </Grid.Item>
74 );
75 }
76 };
78 return (
79 <Grid className={className}>
80 {renderButton()}
82 {error && (
83 <Grid.Item full as={ErrorText} className="mt1">
84 {error.message}
85 </Grid.Item>
86 )}
87 <Grid.Item full as={ToggleInput} {...configureInput} />
89 {!broadcasted && !confirmed && (
90 <Grid.Item full as={ToggleInput} {...viewSignedTransaction} />
91 )}
92 </Grid>
93 );