Skip to content

Commit

Permalink
feat: add os
Browse files Browse the repository at this point in the history
  • Loading branch information
markjung96 committed Oct 31, 2024
1 parent afca8f0 commit c413f75
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/components/interaction/activate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const Activate = ({}: ActivateProps) => {
provider,
network,
account,
os,
compileLoading,
deployLoading,
setLoading,
Expand All @@ -41,6 +42,7 @@ export const Activate = ({}: ActivateProps) => {
provider: state.account.provider.data,
network: state.account.network.data,
account: state.account.address.data,
os: state.project.os.data,
compileLoading: state.compile.loading,
deployLoading: state.deploy.loading,
activateLoading: state.activate.loading,
Expand Down Expand Up @@ -68,7 +70,7 @@ export const Activate = ({}: ActivateProps) => {

let tx = "";
try {
const res = await axios.get(COMPILER_API_ENDPOINT + `/arbitrum/activation-tx?contractAddr=${address}`);
const res = await axios.get(COMPILER_API_ENDPOINT(os) + `/arbitrum/activation-tx?contractAddr=${address}`);
tx = res.data?.tx;
if (!tx) {
await client.terminal.log({
Expand Down
13 changes: 9 additions & 4 deletions src/components/interaction/compile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const Compile = ({}: CompileProps) => {
setFileName,
setCompileErrorMsg,
compilerVersion,
os,
project,
upload,
deployLoading,
Expand All @@ -75,6 +76,7 @@ export const Compile = ({}: CompileProps) => {
setFileName: state.compile.setFileName,
setCompileErrorMsg: state.compile.setErrorMsg,
compilerVersion: state.project.compilerVersion.data,
os: state.project.os.data,
project: state.project.project,
upload: state.project.upload,
setDeployTransactionData: state.deploy.setTransactionData,
Expand Down Expand Up @@ -196,6 +198,7 @@ export const Compile = ({}: CompileProps) => {
timestamp: timestamp.toString() || "0",
fileType: "arbitrum",
zipFile: blob,
os,
});
if (!isSrcZipUploadSuccess) {
setLoading(false);
Expand Down Expand Up @@ -231,6 +234,7 @@ export const Compile = ({}: CompileProps) => {
account: account,
timestamp: timestamp.toString() || "0",
projFiles: projFiles_,
os,
});

if (uploadUrls.length === 0) {
Expand All @@ -239,7 +243,8 @@ export const Compile = ({}: CompileProps) => {
return;
}

const socket = io(COMPILER_WEBSOCKET_ENDPOINT, {
console.log("COMPILER_WEBSOCKET_ENDPOINT(os)", COMPILER_WEBSOCKET_ENDPOINT(os));
const socket = io(COMPILER_WEBSOCKET_ENDPOINT(os), {
reconnection: false,
transports: ["websocket"],
timeout: 120_000,
Expand Down Expand Up @@ -279,7 +284,7 @@ export const Compile = ({}: CompileProps) => {
try {
await axios.request({
method: "DELETE",
url: `${COMPILER_API_ENDPOINT}/s3Proxy`,
url: `${COMPILER_API_ENDPOINT(os)}/s3Proxy`,
params: {
chainName: CHAIN_NAME.arbitrum,
chainId: network,
Expand Down Expand Up @@ -353,7 +358,7 @@ export const Compile = ({}: CompileProps) => {

const res = await axios.request({
method: "GET",
url: `${COMPILER_API_ENDPOINT}/s3Proxy`,
url: `${COMPILER_API_ENDPOINT(os)}/s3Proxy`,
params: {
// bucket: S3Path.bucket(),
bucket: "wds-code-build",
Expand All @@ -367,7 +372,7 @@ export const Compile = ({}: CompileProps) => {
try {
await axios.request({
method: "DELETE",
url: `${COMPILER_API_ENDPOINT}/s3Proxy`,
url: `${COMPILER_API_ENDPOINT(os)}/s3Proxy`,
params: {
chainName: CHAIN_NAME.arbitrum,
chainId: network,
Expand Down
9 changes: 7 additions & 2 deletions src/components/interaction/deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export const Deploy = ({}: DeployProps) => {
provider,
network,
account,
fetchBalance,
project,
upload,
compilerVersion,
os,
compileLoading,
timestamp,
transactionData,
Expand All @@ -58,9 +60,11 @@ export const Deploy = ({}: DeployProps) => {
provider: state.account.provider.data,
network: state.account.network.data,
account: state.account.address.data,
fetchBalance: state.account.fetchBalance,
project: state.project.project.data,
upload: state.project.upload.data,
compilerVersion: state.project.compilerVersion.data,
os: state.project.os.data,
compileLoading: state.compile.loading,
timestamp: state.compile.timestamp,
transactionData: state.deploy.transactionData.data,
Expand Down Expand Up @@ -164,7 +168,7 @@ export const Deploy = ({}: DeployProps) => {
};
log.info("arbitrumContractCreateDto", arbitrumContractCreateDto);
try {
const res = await axios.post(COMPILER_API_ENDPOINT + "/arbitrum/contracts", arbitrumContractCreateDto);
const res = await axios.post(COMPILER_API_ENDPOINT(os) + "/arbitrum/contracts", arbitrumContractCreateDto);
log.info(`put arbitrum/contracts api res`, res);
} catch (e) {
log.error(`put arbitrum/contracts api error`);
Expand All @@ -190,6 +194,7 @@ export const Deploy = ({}: DeployProps) => {
type: "info",
value: JSON.stringify(txReceipt, (key, value) => (typeof value === "bigint" ? value.toString() : value), 2),
});
await fetchBalance();
setLoading(false);
};

Expand All @@ -198,7 +203,7 @@ export const Deploy = ({}: DeployProps) => {
if (!targetNetwork) return;
log.info("verifyContract", { network: targetNetwork.network, contractAddress, srcFileId, cliVersion });
try {
const res = await axios.post(COMPILER_API_ENDPOINT + "/arbitrum/verifications", {
const res = await axios.post(COMPILER_API_ENDPOINT(os) + "/arbitrum/verifications", {
network: targetNetwork.network,
contractAddress,
srcFileId,
Expand Down
44 changes: 43 additions & 1 deletion 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 />
<Os />
<CompilerVersion />
<Account />
<Balance />
Expand Down Expand Up @@ -144,10 +145,51 @@ const Network = () => {
);
};

const Os = () => {
const { os, oses, setOs, resetCompile, resetDeploy, resetActivate } = useStore(
useShallow((state) => ({
os: state.project.os.data,
oses: state.project.oses.data,
setOs: state.project.setOs,
resetCompile: state.compile.reset,
resetDeploy: state.deploy.reset,
resetActivate: state.activate.reset,
}))
);

const handleOsOnChange = (event: React.ChangeEvent<HTMLInputElement>) => {
resetCompile();
resetDeploy();
resetActivate();
setOs(event.target.value);
};

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

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,
Expand Down
18 changes: 12 additions & 6 deletions src/const/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ import { STAGE } from "./stage";

const COMPILER_API_ENDPOINT_POOL = {
local: "http://localhost:8000",
// local: "https://cargo-test.veriwell.dev",
// local: "https://arbitrum.compiler.welldonestudio.io",
dev: "https://dev.compiler.welldonestudio.io",
prod: "https://arbitrum.compiler.welldonestudio.io",
};
export const COMPILER_API_ENDPOINT = COMPILER_API_ENDPOINT_POOL[STAGE];
export const COMPILER_API_ENDPOINT = (os?: string) =>
STAGE === "prod"
? os === "darwin"
? "https://mac-arm-compiler.welldonestudio.io"
: "https://arbitrum.compiler.welldonestudio.io"
: COMPILER_API_ENDPOINT_POOL[STAGE];

const COMPILER_WEBSOCKET_ENDPOINT_POOL = {
local: "ws://localhost:8000",
// local: "wss://arbitrum.compiler.welldonestudio.io",
dev: "wss://dev.compiler.welldonestudio.io",
prod: "wss://arbitrum.compiler.welldonestudio.io",
};
export const COMPILER_WEBSOCKET_ENDPOINT = COMPILER_WEBSOCKET_ENDPOINT_POOL[STAGE];
export const COMPILER_WEBSOCKET_ENDPOINT = (os?: string) =>
STAGE === "prod"
? os === "darwin"
? "wss://mac-arm-compiler.welldonestudio.io"
: "wss://arbitrum.compiler.welldonestudio.io"
: COMPILER_WEBSOCKET_ENDPOINT_POOL[STAGE];
3 changes: 2 additions & 1 deletion src/const/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const LOCAL: Stage = "local";
export const DEVELOP: Stage = "dev";
export const PROD: Stage = "prod";

let stage = process.env.REACT_APP_STAGE;
// let stage = process.env.REACT_APP_STAGE;
let stage = "prod";
if (stage === PROD) {
stage = PROD;
} else if (stage === DEVELOP) {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class FileUtil {
timestamp: string;
fileType: string;
zipFile: Blob;
os: string;
}) {
const formData = new FormData();
formData.append("chainName", srcZipUploadReq.chainName);
Expand All @@ -91,7 +92,7 @@ export class FileUtil {
formData.append("timestamp", srcZipUploadReq.timestamp);
formData.append("fileType", srcZipUploadReq.fileType);
formData.append("zipFile", srcZipUploadReq.zipFile);
const res = await axios.post(COMPILER_API_ENDPOINT + "/s3Proxy/src-v2", formData, {
const res = await axios.post(COMPILER_API_ENDPOINT(srcZipUploadReq.os) + "/s3Proxy/src-v2", formData, {
headers: {
"Content-Type": "multipart/form-data",
Accept: "application/json",
Expand All @@ -107,8 +108,9 @@ export class FileUtil {
account: string;
timestamp: string;
projFiles: FileInfo[];
os: string;
}): Promise<UploadUrlDto[]> {
const uploadUrlsRes = await axios.post(COMPILER_API_ENDPOINT + "/s3Proxy/upload-urls", {
const uploadUrlsRes = await axios.post(COMPILER_API_ENDPOINT(srcZipUploadReq.os) + "/s3Proxy/upload-urls", {
chainName: srcZipUploadReq.chainName,
chainId: srcZipUploadReq.chainId,
account: srcZipUploadReq.account || "noaddress",
Expand Down
16 changes: 16 additions & 0 deletions src/zustand/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ const initial = {
error: false,
data: ["0.5.1", "0.5.3"],
},
os: {
loading: false,
error: false,
data: "linux",
},
oses: {
loading: false,
error: false,
data: ["linux", "darwin"],
},
projects: {
loading: false,
error: false,
Expand Down Expand Up @@ -91,6 +101,12 @@ export const createProjectStore: StateCreator<ProjectState & GlobalState, [], []
state.project.compilerVersion.data = compilerVersion;
})
),
setOs: (os: string) =>
set(
produce((state: ProjectState) => {
state.project.os.data = os;
})
),
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 @@ -13,6 +13,8 @@ export interface ProjectState {
network: NonNullableDataType<typeof ARBITRUM_ONE>;
compilerVersion: NonNullableDataType<string>;
compilerVersions: NonNullableDataType<string[]>;
os: NonNullableDataType<string>;
oses: NonNullableDataType<string[]>;
upload: NonNullableDataType<boolean>;
setErrorMsg: (msg: string | null) => void;
setName: (name: string) => void;
Expand All @@ -22,6 +24,7 @@ export interface ProjectState {
setProject: (project: string) => void;
setNetwork: (network: typeof ARBITRUM_ONE) => void;
setCompilerVersion: (compilerVersion: string) => void;
setOs: (os: string) => void;
setUpload: (upload: boolean) => void;
reset: () => void;
};
Expand Down

0 comments on commit c413f75

Please sign in to comment.