Skip to content

Commit ca879ec

Browse files
committed
Add SelectedMethod type and remove unnecessary getSelectedMethodObject function
1 parent 7599470 commit ca879ec

File tree

6 files changed

+20
-29
lines changed

6 files changed

+20
-29
lines changed

app/components/verification/CompilerSelector.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import React, { useState } from "react";
22
import { useCompilerVersions } from "../../contexts/CompilerVersionsContext";
33
import type { SolidityVersion, VyperVersion } from "../../contexts/CompilerVersionsContext";
4-
import type { Language, VerificationMethodObject, FrameworkMethodObject } from "../../types/verification";
4+
import type { Language, SelectedMethod } from "../../types/verification";
55

66
interface CompilerSelectorProps {
77
language: Language | null;
8-
verificationMethod: VerificationMethodObject | FrameworkMethodObject | null;
8+
selectedMethod: SelectedMethod | "";
99
selectedVersion?: string;
1010
onVersionSelect: (version: string) => void;
1111
}
1212

1313
export default function CompilerSelector({
1414
language,
15-
verificationMethod,
15+
selectedMethod,
1616
selectedVersion,
1717
onVersionSelect,
1818
}: CompilerSelectorProps) {
@@ -31,14 +31,14 @@ export default function CompilerSelector({
3131
const [showPrereleases, setShowPrereleases] = useState(false);
3232

3333
// Don't show if language is null or if using metadata/framework methods
34-
if (!language || !verificationMethod) {
34+
if (!language || !selectedMethod) {
3535
return null;
3636
}
3737

3838
if (
39-
verificationMethod.id === "metadata-json" ||
40-
verificationMethod.id === "hardhat" ||
41-
verificationMethod.id === "foundry"
39+
selectedMethod === "metadata-json" ||
40+
selectedMethod === "hardhat" ||
41+
selectedMethod === "foundry"
4242
) {
4343
return null;
4444
}

app/components/verification/VerificationMethodSelector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Tooltip as ReactTooltip } from "react-tooltip";
22
import { verificationMethods, frameworkMethods, frameworkMessages } from "../../data/verificationMethods";
3-
import type { Language } from "../../types/verification";
3+
import type { Language, SelectedMethod } from "../../types/verification";
44
import VerificationWarning from "./VerificationWarning";
55

66
interface VerificationMethodSelectorProps {
77
selectedLanguage: Language | null;
8-
selectedMethod: string;
9-
onMethodSelect: (method: string) => void;
8+
selectedMethod: SelectedMethod | "";
9+
onMethodSelect: (method: SelectedMethod) => void;
1010
}
1111

1212
export default function VerificationMethodSelector({

app/hooks/useFormValidation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useMemo, useCallback, useState, useEffect } from "react";
2-
import type { Language } from "../types/verification";
2+
import type { Language, SelectedMethod } from "../types/verification";
33

44
interface ValidationParams {
55
isAddressValid: boolean;
66
selectedChainId: string;
77
contractAddress: string;
88
selectedLanguage: Language | null;
9-
selectedMethod: string;
9+
selectedMethod: SelectedMethod | "";
1010
selectedCompilerVersion: string;
1111
contractIdentifier: string;
1212
uploadedFiles: File[];

app/hooks/useVerificationState.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useState } from "react";
2-
import type { Language, SubmissionResult } from "../types/verification";
2+
import type { Language, SubmissionResult, SelectedMethod } from "../types/verification";
33

44
export function useVerificationState() {
55
const [selectedChainId, setSelectedChainId] = useState<string>("");
66
const [contractAddress, setContractAddress] = useState<string>("");
77
const [selectedLanguage, setSelectedLanguage] = useState<Language | null>(null);
8-
const [selectedMethod, setSelectedMethod] = useState<string>("");
8+
const [selectedMethod, setSelectedMethod] = useState<SelectedMethod | "">("");
99
const [selectedCompilerVersion, setSelectedCompilerVersion] = useState<string>("");
1010
const [uploadedFiles, setUploadedFiles] = useState<File[]>([]);
1111
const [metadataFile, setMetadataFile] = useState<File | null>(null);
@@ -39,7 +39,7 @@ export function useVerificationState() {
3939
setContractIdentifier(""); // Reset contract identifier when language changes
4040
};
4141

42-
const handleMethodSelect = (method: string) => {
42+
const handleMethodSelect = (method: SelectedMethod) => {
4343
setSelectedMethod(method);
4444
setSelectedCompilerVersion(""); // Reset compiler version when method changes
4545
setUploadedFiles([]); // Reset files when method changes

app/routes/home.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import FileUpload from "../components/verification/FileUpload";
1212
import CompilerSettings from "../components/verification/CompilerSettings";
1313
import ContractIdentifier from "../components/verification/ContractIdentifier";
1414
import OptionalFields from "../components/verification/OptionalFields";
15-
import { verificationMethods, frameworkMethods } from "../data/verificationMethods";
15+
import { frameworkMethods } from "../data/verificationMethods";
1616
import type { VerificationMethod } from "../types/verification";
1717
import { assembleAndSubmitStandardJson, submitStdJsonFile, submitMetadataVerification } from "../utils/sourcifyApi";
1818
import { buildMetadataSubmissionSources } from "../utils/metadataValidation";
@@ -313,18 +313,6 @@ export default function Home() {
313313
return "Submit verification";
314314
};
315315

316-
// Helper function to get the method object from the selected method ID
317-
const getSelectedMethodObject = () => {
318-
if (!selectedMethod || !selectedLanguage) return null;
319-
320-
// Check verification methods first
321-
const verificationMethod = verificationMethods[selectedLanguage]?.find((m) => m.id === selectedMethod);
322-
if (verificationMethod) return verificationMethod;
323-
324-
// Check framework methods
325-
const frameworkMethod = frameworkMethods.find((m) => m.id === selectedMethod);
326-
return frameworkMethod || null;
327-
};
328316

329317
return (
330318
<div className="pb-12 bg-cerulean-blue-50 pt-1">
@@ -424,7 +412,7 @@ export default function Home() {
424412

425413
<CompilerSelector
426414
language={selectedLanguage}
427-
verificationMethod={getSelectedMethodObject()}
415+
selectedMethod={selectedMethod}
428416
selectedVersion={selectedCompilerVersion}
429417
onVersionSelect={handleCompilerVersionSelect}
430418
/>

app/types/verification.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export type VerificationMethod = "single-file" | "multiple-files" | "std-json" |
66
// Framework method IDs
77
export type FrameworkVerificationMethod = "hardhat" | "foundry";
88

9+
// Combined type for selectedMethod that includes both verification and framework methods
10+
export type SelectedMethod = VerificationMethod | FrameworkVerificationMethod;
11+
912
// Method objects with full details
1013
export interface VerificationMethodObject {
1114
id: VerificationMethod;

0 commit comments

Comments
 (0)