1
1
import { Tooltip as ReactTooltip } from "react-tooltip" ;
2
+ import { useState , useEffect } from "react" ;
2
3
import { verificationMethods , frameworkMethods , frameworkMessages } from "../../data/verificationMethods" ;
3
4
import type { Language , SelectedMethod } from "../../types/verification" ;
4
5
import VerificationWarning from "./VerificationWarning" ;
@@ -14,9 +15,25 @@ export default function VerificationMethodSelector({
14
15
selectedMethod,
15
16
onMethodSelect,
16
17
} : 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
+
17
21
if ( ! selectedLanguage ) return null ;
18
22
19
23
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" ;
20
37
21
38
// Get the warning for the selected method
22
39
const selectedMethodWarning =
@@ -25,14 +42,12 @@ export default function VerificationMethodSelector({
25
42
?. warning
26
43
: null ;
27
44
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 ] ) ;
33
48
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 ) ;
36
51
37
52
return (
38
53
< div >
@@ -91,15 +106,15 @@ export default function VerificationMethodSelector({
91
106
type = "button"
92
107
onClick = { ( ) => onMethodSelect ( method . id ) }
93
108
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
95
110
? "border-cerulean-blue-500 bg-cerulean-blue-50"
96
111
: "border-gray-300 hover:border-cerulean-blue-300 hover:bg-gray-50"
97
112
} `}
98
113
>
99
114
< img src = { method . icon } alt = { method . title } className = "w-6 h-6" />
100
115
< h3
101
116
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"
103
118
} `}
104
119
>
105
120
{ method . title }
@@ -109,51 +124,34 @@ export default function VerificationMethodSelector({
109
124
</ div >
110
125
111
126
{ /* Framework Build-Info Toggle */ }
112
- { isFrameworkMethod && (
127
+ { ( isFrameworkMethod || isBuildInfoMode ) && (
113
128
< div className = "mt-4 mb-4 flex items-center gap-2" >
114
129
< span className = "text-sm text-gray-700" > Show Commands</ span >
115
130
< label className = "relative inline-flex items-center" >
116
131
< input
117
132
type = "checkbox"
118
- checked = { false }
133
+ checked = { isBuildInfoMode }
119
134
onChange = { ( e ) => {
120
135
if ( e . target . checked ) {
121
136
onMethodSelect ( "build-info" ) ;
137
+ } else {
138
+ onMethodSelect ( lastFrameworkMethod ) ;
122
139
}
123
140
} }
124
141
className = "sr-only"
125
142
/>
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 >
128
149
</ div >
129
150
</ label >
130
151
< span className = "text-sm text-gray-700" > Upload build-info file</ span >
131
152
</ div >
132
153
) }
133
154
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
- ) }
157
155
158
156
{ /* Verification Warnings */ }
159
157
{ selectedMethodWarning && (
0 commit comments