forked from OpenZeppelin/safe-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectInputWizard.tsx
More file actions
163 lines (149 loc) · 4.9 KB
/
Copy pathDirectInputWizard.tsx
File metadata and controls
163 lines (149 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import * as React from "react";
import { useState, useEffect } from "react";
import { UseFormReturn } from "react-hook-form";
import { Button } from "@/components/ui/button";
import { StepProgressIndicator } from "@/components/ui/step-progress-indicator";
import { FormData } from "@/types/form-types";
import BasicInfoStep from "@/components/transaction/BasicInfoStep";
import TransactionDetailsStep from "@/components/transaction/TransactionDetailsStep";
import AdvancedParamsStep from "@/components/transaction/AdvancedParamsStep";
import PasteTransactionDetails from "@/components/transaction/PasteTransactionDetails";
import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";
interface DirectInputWizardProps {
form: UseFormReturn<FormData>;
step: number;
nextStep: () => boolean;
prevStep: () => void
isSubmitting: boolean;
calculationSubmit: (e?: React.BaseSyntheticEvent) => Promise<void>;
}
export default function DirectInputWizard({
form,
step,
nextStep,
prevStep,
isSubmitting,
calculationSubmit
}: DirectInputWizardProps) {
const [submitting, setSubmitting] = useState(false);
const [showPasteOption, setShowPasteOption] = useState(false);
const steps = ["Basic Information", "Transaction Details", "Advanced Parameters"];
useEffect(() => {
if (!isSubmitting) {
setSubmitting(false);
}
}, [isSubmitting]);
const visualStep = submitting ? 4 : step;
const handleBack = () => {
if (step >= 3) {
if (step === 4) {
prevStep();
prevStep();
} else {
prevStep();
}
} else {
prevStep();
}
};
const handlePastedSuccess = () => {
// If we're already at step 2 or 3 no need to advance, otherwise go to step 2
if (step === 1) {
nextStep();
}
};
return (
<div className="space-y-6">
<StepProgressIndicator
steps={steps}
currentStep={visualStep}
/>
{/* Toggle for paste option */}
<div className="flex items-center justify-end space-x-2 mb-2">
<Label htmlFor="paste-mode" className="text-sm cursor-pointer">Paste from Safe</Label>
<Switch
id="paste-mode"
checked={showPasteOption}
onCheckedChange={setShowPasteOption}
/>
</div>
<div className="min-h-[320px]">
{showPasteOption ? (
<PasteTransactionDetails form={form} onParsed={handlePastedSuccess} />
) : (
<>
{step === 1 && <BasicInfoStep form={form} />}
{step === 2 && <TransactionDetailsStep form={form} />}
{(step === 3 || step === 4) && <AdvancedParamsStep form={form} />}
</>
)}
</div>
{!showPasteOption && (
<div className="flex justify-between pt-4">
{step > 1 ? (
<Button
type="button"
variant="outline"
onClick={handleBack}
className="px-6 rounded-full border-button text-button hover:bg-transparent dark:bg-white dark:hover:bg-gray-100 h-[48px]"
>
Back
</Button>
) : (
<div />
)}
{step < 3 && (
<Button
type="button"
onClick={() => {
nextStep();
}}
className="bg-button hover:bg-button-hover active:bg-button-active text-white rounded-full px-6 h-[48px]"
>
Continue
</Button>
)}
{step >= 3 && (
<Button
type="button"
disabled={isSubmitting}
onClick={async (e) => {
setSubmitting(true);
await calculationSubmit(e);
}}
className="bg-button hover:bg-button-hover active:bg-button-active text-white rounded-full px-6 h-[48px]"
>
{isSubmitting ? "Calculating..." : "Calculate Hash"}
</Button>
)}
</div>
)}
{showPasteOption && (
<div className="flex justify-between pt-4">
<Button
type="button"
variant="outline"
onClick={() => setShowPasteOption(false)}
className="px-6 rounded-full border-button text-button hover:bg-transparent dark:bg-white dark:hover:bg-gray-100 h-[48px]"
>
Back to Form
</Button>
{step >= 3 && (
<Button
type="button"
disabled={isSubmitting}
onClick={async (e) => {
setSubmitting(true);
await calculationSubmit(e);
}}
className="bg-button hover:bg-button-hover active:bg-button-active text-white rounded-full px-6 h-[48px]"
>
{isSubmitting ? "Calculating..." : "Calculate Hash"}
</Button>
)}
</div>
)}
</div>
);
}