Skip to content

Commit

Permalink
feat: select compiler version
Browse files Browse the repository at this point in the history
  • Loading branch information
markjung96 committed Oct 17, 2024
1 parent 73d7312 commit 59f0681
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/components/project/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const Project = ({}: ProjectProps) => {
<div className="flex flex-col gap-3">
<Form className="flex flex-col gap-2">
<Network />
<CompilerVersion />
<Account />
<Balance />
<NewProject />
Expand Down Expand Up @@ -143,6 +144,43 @@ const Network = () => {
);
};

const CompilerVersion = () => {
const { compilerVersion, setCompilerVersion, compilerVersions } = useStore(
useShallow((state) => ({
client: state.global.client,
compilerVersion: state.project.compilerVersion.data,
setCompilerVersion: state.project.setCompilerVersion,
compilerVersions: state.project.compilerVersions.data,
}))
);

const handleCompilerVersionOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setCompilerVersion(event.target.value);
};

return (
<Form.Group>
<Form.Label>Compiler Version</Form.Label>
<Form.Control
as="select"
className="disabled:!text-gray-400 disabled:cursor-not-allowed"
value={compilerVersion}
size="sm"
onChange={handleCompilerVersionOnChange}
>
{compilerVersions &&
compilerVersions.map((item, index) => {
return (
<option value={item} key={index}>
{item}
</option>
);
})}
</Form.Control>
</Form.Group>
);
};

const Account = () => {
const { address } = useStore(useShallow((state) => ({ address: state.account.address.data })));
return (
Expand Down
16 changes: 16 additions & 0 deletions src/zustand/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ const initial = {
error: false,
data: ARBITRUM_NETWORK,
},
compilerVersion: {
loading: false,
error: false,
data: "v0.5.3",
},
compilerVersions: {
loading: false,
error: false,
data: ["v0.5.1", "v0.5.3"],
},
projects: {
loading: false,
error: false,
Expand Down Expand Up @@ -75,6 +85,12 @@ export const createProjectStore: StateCreator<ProjectState & GlobalState, [], []
state.project.project.data = project;
})
),
setCompilerVersion: (compilerVersion: string) =>
set(
produce((state: ProjectState) => {
state.project.compilerVersion.data = compilerVersion;
})
),
fetchProjects: async () => {
const client = get().global.client;
if (!client) {
Expand Down
3 changes: 3 additions & 0 deletions src/zustand/project.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface ProjectState {
projects: DataType<string[]>;
networks: NonNullableDataType<typeof ARBITRUM_NETWORK>;
network: NonNullableDataType<typeof ARBITRUM_ONE>;
compilerVersion: NonNullableDataType<string>;
compilerVersions: NonNullableDataType<string[]>;
upload: NonNullableDataType<boolean>;
setErrorMsg: (msg: string | null) => void;
setName: (name: string) => void;
Expand All @@ -19,6 +21,7 @@ export interface ProjectState {
fetchProjects: () => Promise<void>;
setProject: (project: string) => void;
setNetwork: (network: typeof ARBITRUM_ONE) => void;
setCompilerVersion: (compilerVersion: string) => void;
setUpload: (upload: boolean) => void;
reset: () => void;
};
Expand Down

0 comments on commit 59f0681

Please sign in to comment.