Skip to content

Commit d9c1faa

Browse files
committed
Don't deselect Hardhat or Foundry when going back from build-info
1 parent fe1a39b commit d9c1faa

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

app/components/verification/VerificationMethodSelector.tsx

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Tooltip as ReactTooltip } from "react-tooltip";
2+
import { useState, useEffect } from "react";
23
import { verificationMethods, frameworkMethods, frameworkMessages } from "../../data/verificationMethods";
34
import type { Language, SelectedMethod } from "../../types/verification";
45
import VerificationWarning from "./VerificationWarning";
@@ -14,9 +15,25 @@ export default function VerificationMethodSelector({
1415
selectedMethod,
1516
onMethodSelect,
1617
}: VerificationMethodSelectorProps) {
18+
// Keep track of the last selected framework method so we can return to it
19+
const [lastFrameworkMethod, setLastFrameworkMethod] = useState<"hardhat" | "foundry">("hardhat");
20+
1721
if (!selectedLanguage) return null;
1822

1923
const methods = verificationMethods[selectedLanguage as keyof typeof verificationMethods];
24+
25+
// Update lastFrameworkMethod when a framework method is selected
26+
useEffect(() => {
27+
if (frameworkMethods.some(method => method.id === selectedMethod)) {
28+
setLastFrameworkMethod(selectedMethod as "hardhat" | "foundry");
29+
}
30+
}, [selectedMethod]);
31+
32+
// Check if selected method is a framework method
33+
const isFrameworkMethod = frameworkMethods.some((method) => method.id === selectedMethod);
34+
35+
// Check if we're in build-info mode (selected method is build-info)
36+
const isBuildInfoMode = selectedMethod === "build-info";
2037

2138
// Get the warning for the selected method
2239
const selectedMethodWarning =
@@ -25,14 +42,12 @@ export default function VerificationMethodSelector({
2542
?.warning
2643
: null;
2744

28-
// Get the framework message for the selected framework
29-
const selectedFrameworkMessage = selectedMethod && frameworkMessages[selectedMethod];
30-
31-
// Check if selected method is a framework method
32-
const isFrameworkMethod = frameworkMethods.some((method) => method.id === selectedMethod);
45+
// Get the framework message for the selected framework (or the active framework in build-info mode)
46+
const selectedFrameworkMessage = (isFrameworkMethod && frameworkMessages[selectedMethod]) ||
47+
(isBuildInfoMode && frameworkMessages[lastFrameworkMethod]);
3348

34-
// Check if we're in build-info mode (selected method is build-info)
35-
const isBuildInfoMode = selectedMethod === "build-info";
49+
// Get the currently active framework method for visual selection purposes
50+
const activeFrameworkMethod = isBuildInfoMode ? lastFrameworkMethod : (isFrameworkMethod ? selectedMethod : null);
3651

3752
return (
3853
<div>
@@ -91,15 +106,15 @@ export default function VerificationMethodSelector({
91106
type="button"
92107
onClick={() => onMethodSelect(method.id)}
93108
className={`relative flex items-center justify-center gap-2 p-3 border-2 rounded-lg text-center transition-all duration-200 w-36 ${
94-
selectedMethod === method.id
109+
activeFrameworkMethod === method.id
95110
? "border-cerulean-blue-500 bg-cerulean-blue-50"
96111
: "border-gray-300 hover:border-cerulean-blue-300 hover:bg-gray-50"
97112
}`}
98113
>
99114
<img src={method.icon} alt={method.title} className="w-6 h-6" />
100115
<h3
101116
className={`text-base font-medium ${
102-
selectedMethod === method.id ? "text-cerulean-blue-600" : "text-gray-700"
117+
activeFrameworkMethod === method.id ? "text-cerulean-blue-600" : "text-gray-700"
103118
}`}
104119
>
105120
{method.title}
@@ -109,51 +124,34 @@ export default function VerificationMethodSelector({
109124
</div>
110125

111126
{/* Framework Build-Info Toggle */}
112-
{isFrameworkMethod && (
127+
{(isFrameworkMethod || isBuildInfoMode) && (
113128
<div className="mt-4 mb-4 flex items-center gap-2">
114129
<span className="text-sm text-gray-700">Show Commands</span>
115130
<label className="relative inline-flex items-center">
116131
<input
117132
type="checkbox"
118-
checked={false}
133+
checked={isBuildInfoMode}
119134
onChange={(e) => {
120135
if (e.target.checked) {
121136
onMethodSelect("build-info");
137+
} else {
138+
onMethodSelect(lastFrameworkMethod);
122139
}
123140
}}
124141
className="sr-only"
125142
/>
126-
<div className="w-11 h-6 rounded-full relative transition-colors bg-gray-200">
127-
<div className="absolute top-[2px] left-[2px] bg-white border border-gray-300 rounded-full h-5 w-5 transition-transform"></div>
143+
<div className={`w-11 h-6 rounded-full relative transition-colors ${
144+
isBuildInfoMode ? "bg-cerulean-blue-600" : "bg-gray-200"
145+
}`}>
146+
<div className={`absolute top-[2px] left-[2px] bg-white border border-gray-300 rounded-full h-5 w-5 transition-transform ${
147+
isBuildInfoMode ? "translate-x-full" : ""
148+
}`}></div>
128149
</div>
129150
</label>
130151
<span className="text-sm text-gray-700">Upload build-info file</span>
131152
</div>
132153
)}
133154

134-
{/* Build-info back to framework toggle */}
135-
{isBuildInfoMode && (
136-
<div className="mt-4 mb-4 flex items-center gap-2">
137-
<span className="text-sm text-gray-700">Show Commands</span>
138-
<label className="relative inline-flex items-center">
139-
<input
140-
type="checkbox"
141-
checked={true}
142-
onChange={(e) => {
143-
if (!e.target.checked) {
144-
// Go back to hardhat as default - we could make this smarter by remembering the previous framework
145-
onMethodSelect("hardhat");
146-
}
147-
}}
148-
className="sr-only"
149-
/>
150-
<div className="w-11 h-6 rounded-full relative transition-colors bg-cerulean-blue-600">
151-
<div className="absolute top-[2px] left-[2px] bg-white border border-gray-300 rounded-full h-5 w-5 transition-transform translate-x-full"></div>
152-
</div>
153-
</label>
154-
<span className="text-sm text-gray-700">Upload build-info file</span>
155-
</div>
156-
)}
157155

158156
{/* Verification Warnings */}
159157
{selectedMethodWarning && (

0 commit comments

Comments
 (0)