From 8350957496045c7a63e4c99eb230b317850fa4ac Mon Sep 17 00:00:00 2001 From: Mark_Jeong <81726531+markjung96@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:34:40 +0900 Subject: [PATCH] fix: remove unused var --- src/components/project/index.tsx | 25 ++------- src/const/chain.ts | 7 +-- src/const/endpoint.ts | 85 ++++--------------------------- src/const/helper.ts | 14 ++--- src/utils/editor.ts | 47 +++++++---------- src/utils/socket.ts | 63 ++--------------------- src/utils/wait-for-transaction.ts | 22 -------- src/utils/wrap-promise.ts | 33 ------------ 8 files changed, 41 insertions(+), 255 deletions(-) delete mode 100644 src/utils/wait-for-transaction.ts delete mode 100644 src/utils/wrap-promise.ts diff --git a/src/components/project/index.tsx b/src/components/project/index.tsx index c93b49c..c450993 100644 --- a/src/components/project/index.tsx +++ b/src/components/project/index.tsx @@ -6,7 +6,6 @@ import { Button, Form, InputGroup } from "react-bootstrap"; import { useShallow } from "zustand/react/shallow"; import { useStore } from "../../zustand"; -import wrapPromise from "../../utils/wrap-promise"; import { log } from "../../utils/logger"; import { sendCustomEvent } from "../../utils/send-custom-event"; import { CustomTooltip } from "../common/custom-tooltip"; @@ -192,15 +191,13 @@ const NewProject = () => { } }; - const wrappedIsExists = (dir: string) => wrapPromise(isExists(dir), client); - const createProject = async () => { if (!client || !name) return; sendCustomEvent("new_project", { event_category: "arbitrum", method: "new_project", }); - if (await wrappedIsExists(name)) { + if (await isExists(name)) { await client.terminal.log({ type: "error", value: 'The folder "arbitrum/' + name + '" already exists', @@ -221,8 +218,6 @@ const NewProject = () => { } }; - const wrappedCreateProject = () => wrapPromise(createProject(), client); - const handleNameOnChange = (event: React.ChangeEvent) => { setName(event.target.value); }; @@ -241,13 +236,7 @@ const NewProject = () => { if (event.key === "Enter") event.preventDefault(); }} /> - @@ -330,8 +319,6 @@ const Template = () => { } }; - const wrappedCreateTemplate = () => wrapPromise(createTemplate(), client); - const handleTemplateOnChange = (event: React.ChangeEvent) => { setTemplate(event.target.value); }; @@ -356,13 +343,7 @@ const Template = () => { ); })} - diff --git a/src/const/chain.ts b/src/const/chain.ts index c172a5b..ec0f811 100644 --- a/src/const/chain.ts +++ b/src/const/chain.ts @@ -1,8 +1,3 @@ export const CHAIN_NAME = { - aptos: 'aptos', - arbitrum: 'arbitrum', - sui: 'sui', - neutron: 'neutron', - juno: 'juno', - injective: 'injective', + arbitrum: "arbitrum", }; diff --git a/src/const/endpoint.ts b/src/const/endpoint.ts index 01ab72d..624b5de 100644 --- a/src/const/endpoint.ts +++ b/src/const/endpoint.ts @@ -1,86 +1,23 @@ -import { STAGE } from './stage'; +import { STAGE } from "./stage"; const COMPILER_API_ENDPOINT_POOL = { - local: 'http://localhost:8000', - dev: 'https://dev.compiler.welldonestudio.io', - prod: 'https://verify.welldonestudio.io', + local: "http://localhost:8000", + dev: "https://dev.compiler.welldonestudio.io", + prod: "https://verify.welldonestudio.io", }; export const COMPILER_API_ENDPOINT = COMPILER_API_ENDPOINT_POOL[STAGE]; -const NEAR_COMPILER_CONSUMER_ENDPOINT_POOL = { - local: 'ws://localhost:8000', - dev: 'wss://dev.compiler.welldonestudio.io', - prod: 'wss://prod.near.compiler.welldonestudio.io', -}; -export const NEAR_COMPILER_CONSUMER_ENDPOINT = NEAR_COMPILER_CONSUMER_ENDPOINT_POOL[STAGE]; - -const JUNO_COMPILER_CONSUMER_ENDPOINT_POOL = { - local: 'ws://localhost:8000', - dev: 'wss://dev.neutron.compiler.welldonestudio.io', - prod: 'wss://prod.neutron.compiler.welldonestudio.io', -}; -export const JUNO_COMPILER_CONSUMER_ENDPOINT = JUNO_COMPILER_CONSUMER_ENDPOINT_POOL[STAGE]; - -const APTOS_COMPILER_CONSUMER_ENDPOINT_POOL = { - local: 'ws://localhost:8000', - dev: 'wss://dev.compiler.welldonestudio.io', - // prod: 'wss://prod.aptos.compiler.welldonestudio.io', - prod: 'wss://prod.near.compiler.welldonestudio.io', -}; -export const APTOS_COMPILER_CONSUMER_ENDPOINT = APTOS_COMPILER_CONSUMER_ENDPOINT_POOL[STAGE]; - -const SUI_COMPILER_CONSUMER_ENDPOINT_POOL = { - local: 'ws://localhost:8000', - dev: 'wss://dev.compiler.welldonestudio.io', - // prod: 'wss://prod.aptos.compiler.welldonestudio.io', - prod: 'wss://prod.near.compiler.welldonestudio.io', -}; -export const SUI_COMPILER_CONSUMER_ENDPOINT = SUI_COMPILER_CONSUMER_ENDPOINT_POOL[STAGE]; - -const NEUTRON_COMPILER_CONSUMER_ENDPOINT_POOL = { - local: 'ws://localhost:8000', - dev: 'wss://dev.neutron.compiler.welldonestudio.io', - prod: 'wss://prod.neutron.compiler.welldonestudio.io', -}; -export const NEUTRON_COMPILER_CONSUMER_ENDPOINT = NEUTRON_COMPILER_CONSUMER_ENDPOINT_POOL[STAGE]; - -const NEUTRON_COMPILER_CONSUMER_API_ENDPOINT_POOL = { - local: 'http://localhost:8000', - dev: 'https://dev.neutron.compiler.welldonestudio.io', - prod: 'https://prod.neutron.compiler.welldonestudio.io', -}; - -export const NEUTRON_COMPILER_CONSUMER_API_ENDPOINT = - NEUTRON_COMPILER_CONSUMER_API_ENDPOINT_POOL[STAGE]; -// --- -const INJECTIVE_COMPILER_CONSUMER_ENDPOINT_POOL = { - local: 'ws://localhost:8000', - dev: 'wss://dev.compiler.welldonestudio.io', - prod: 'wss://prod.compiler.welldonestudio.io', -}; -export const INJECTIVE_COMPILER_CONSUMER_ENDPOINT = INJECTIVE_COMPILER_CONSUMER_ENDPOINT_POOL[STAGE]; - -const INJECTIVE_COMPILER_CONSUMER_API_ENDPOINT_POOL = { - local: 'http://localhost:8000', - dev: 'https://dev.compiler.welldonestudio.io', - prod: 'https://prod.compiler.welldonestudio.io/', -}; - -export const INJECTIVE_COMPILER_CONSUMER_API_ENDPOINT = - INJECTIVE_COMPILER_CONSUMER_API_ENDPOINT_POOL[STAGE]; - const ARBITRUM_COMPILER_CONSUMER_ENDPOINT_POOL = { - local: 'ws://localhost:8000', - dev: 'wss://dev.compiler.welldonestudio.io', - prod: 'wss://prod.near.compiler.welldonestudio.io', + local: "ws://localhost:8000", + dev: "wss://dev.compiler.welldonestudio.io", + prod: "wss://prod.near.compiler.welldonestudio.io", }; export const ARBITRUM_COMPILER_CONSUMER_ENDPOINT = ARBITRUM_COMPILER_CONSUMER_ENDPOINT_POOL[STAGE]; const ARBITRUM_COMPILER_CONSUMER_API_ENDPOINT_POOL = { - local: 'http://localhost:8000', - dev: 'https://dev.compiler.welldonestudio.io', - prod: 'https://verify.welldonestudio.io', + local: "http://localhost:8000", + dev: "https://dev.compiler.welldonestudio.io", + prod: "https://verify.welldonestudio.io", }; -export const ARBITRUM_COMPILER_CONSUMER_API_ENDPOINT = - ARBITRUM_COMPILER_CONSUMER_API_ENDPOINT_POOL[STAGE]; +export const ARBITRUM_COMPILER_CONSUMER_API_ENDPOINT = ARBITRUM_COMPILER_CONSUMER_API_ENDPOINT_POOL[STAGE]; diff --git a/src/const/helper.ts b/src/const/helper.ts index 0efd916..9b1f8b9 100644 --- a/src/const/helper.ts +++ b/src/const/helper.ts @@ -1,5 +1,4 @@ import { Annotation, HighlightPosition } from "@remixproject/plugin-api"; -import { PROD, STAGE } from "../const/stage"; import { log } from "../utils/logger"; export interface PositionDetails { @@ -55,9 +54,7 @@ export const getPositionDetails = (msg: string): PositionDetails => { }; }; -export const isRealError = (pos: Annotation) => { - return pos.row !== -1 && pos.column !== -1; -}; +export const isRealError = (pos: Annotation) => pos.row !== -1 && pos.column !== -1; export const readFile = (file: File): Promise => { return new Promise((resolve, reject) => { @@ -76,13 +73,8 @@ export const readFile = (file: File): Promise => { }); }; -export const stringify = (data: any) => { - return JSON.stringify(data, null, 2); -}; +export const stringify = (data: any) => JSON.stringify(data, null, 2); + export const shortenHexString = (address: string, first: number, last: number) => { return address === "" ? "" : `${address.slice(0, first)}...${address.slice(-last)}`; }; - -export const enableAptosProve = () => STAGE !== PROD; -export const enableJuno = () => STAGE !== PROD; -export const enableSui = () => STAGE !== PROD; diff --git a/src/utils/editor.ts b/src/utils/editor.ts index e291d9d..3ccf113 100644 --- a/src/utils/editor.ts +++ b/src/utils/editor.ts @@ -1,7 +1,7 @@ -import { Client } from '@remixproject/plugin'; -import { HighlightPosition, Annotation, IRemixApi } from '@remixproject/plugin-api'; -import { Api } from '@remixproject/plugin-utils'; -import { log } from './logger'; +import { Client } from "@remixproject/plugin"; +import { HighlightPosition, Annotation, IRemixApi } from "@remixproject/plugin-api"; +import { Api } from "@remixproject/plugin-utils"; +import { log } from "./logger"; export class EditorClient { client; @@ -12,75 +12,64 @@ export class EditorClient { } getFile = async (name: string) => { - let path = name.startsWith('./') ? name.substr(2) : name; - return this.client.call('fileManager', 'getFile', this.getBrowserPath(path)); + let path = name.startsWith("./") ? name.substr(2) : name; + return this.client.call("fileManager", "getFile", this.getBrowserPath(path)); }; getFolder = async () => { - return this.client.call('fileManager', 'getFolder', '/browser'); + return this.client.call("fileManager", "getFolder", "/browser"); }; getCurrentFile = async () => { - return this.client.call('fileManager', 'getCurrentFile'); + return this.client.call("fileManager", "getCurrentFile"); }; createFile = async (name: string, content: string) => { try { - await this.client.call('fileManager', 'setFile', name, content); - await this.client.call('fileManager', 'switchFile', name); + await this.client.call("fileManager", "setFile", name, content); + await this.client.call("fileManager", "switchFile", name); } catch (err) { log.error(err); } }; currentFileChanged = async () => { - this.client.on('fileManager', 'currentFileChanged', (file) => { + this.client.on("fileManager", "currentFileChanged", (file) => { // this.discardHighlight(); // this.clearAnnotations(); }); }; highlight = async (position: HighlightPosition, file: string, color: string) => { - await this.client.call('editor', 'highlight', position, this.getBrowserPath(file), color, { + await this.client.call("editor", "highlight", position, this.getBrowserPath(file), color, { focus: true, }); }; discardHighlight = async () => { - await this.client.call('editor', 'discardHighlight'); + await this.client.call("editor", "discardHighlight"); }; gotoLine = async (row: number, col: number) => { - await this.client.call('editor', 'gotoLine', row, col); + await this.client.call("editor", "gotoLine", row, col); }; addAnnotation = async (annotatioin: Annotation) => { - await this.client.call('editor', 'addAnnotation', annotatioin); + await this.client.call("editor", "addAnnotation", annotatioin); }; clearAnnotations = async () => { - await this.client.call('editor', 'clearAnnotations'); + await this.client.call("editor", "clearAnnotations"); }; switchFile = async (file: string) => { - await this.client.call('fileManager', 'switchFile', this.getBrowserPath(file)); + await this.client.call("fileManager", "switchFile", this.getBrowserPath(file)); }; private getBrowserPath = (path: string) => { - if (path.startsWith('browser')) { + if (path.startsWith("browser")) { return path; } return `browser/${path}`; }; } - -export const addErrorNotation = async ( - annotation: Annotation, - highlightPosition: HighlightPosition, - positionDetail: Record, - client: any, -) => { - await client.editor.gotoLine(positionDetail.row, positionDetail.col); - await client.editor.addAnnotation(annotation); - await client.editor.highlightPosition(highlightPosition); -}; diff --git a/src/utils/socket.ts b/src/utils/socket.ts index e3a0f7a..648d911 100644 --- a/src/utils/socket.ts +++ b/src/utils/socket.ts @@ -1,68 +1,15 @@ -import { Socket } from 'socket.io-client'; +import { Socket } from "socket.io-client"; import { COMPILER_ARBITRUM_COMPILE_COMPLETED_V1, COMPILER_ARBITRUM_COMPILE_ERROR_OCCURRED_V1, COMPILER_ARBITRUM_COMPILE_LOGGED_V1, - COMPILER_INJECTIVE_COMPILE_COMPLETED_V1, - COMPILER_INJECTIVE_COMPILE_ERROR_OCCURRED_V1, - COMPILER_INJECTIVE_COMPILE_LOGGED_V1, - COMPILER_JUNO_COMPILE_COMPLETED_V1, - COMPILER_JUNO_COMPILE_ERROR_OCCURRED_V1, - COMPILER_JUNO_COMPILE_LOGGED_V1, - COMPILER_NEUTRON_COMPILE_COMPLETED_V1, - COMPILER_NEUTRON_COMPILE_ERROR_OCCURRED_V1, - COMPILER_NEUTRON_COMPILE_LOGGED_V1, -} from 'wds-event'; - -export function cleanupSocketJuno(socketJuno: Socket) { - const events = [ - 'connect', - 'disconnect', - 'connect_error', - COMPILER_JUNO_COMPILE_ERROR_OCCURRED_V1, - COMPILER_JUNO_COMPILE_LOGGED_V1, - COMPILER_JUNO_COMPILE_COMPLETED_V1, - ]; - - for (const event of events) { - socketJuno.off(event); - } -} - -export function cleanupSocketNeutron(socketNeutron: Socket) { - const events = [ - 'connect', - 'disconnect', - 'connect_error', - COMPILER_NEUTRON_COMPILE_ERROR_OCCURRED_V1, - COMPILER_NEUTRON_COMPILE_LOGGED_V1, - COMPILER_NEUTRON_COMPILE_COMPLETED_V1, - ]; - - for (const event of events) { - socketNeutron.off(event); - } -} - -export function cleanupSocketInjective(socketInjective: Socket) { - const events = [ - 'connect', - 'disconnect', - 'connect_error', - COMPILER_INJECTIVE_COMPILE_ERROR_OCCURRED_V1, - COMPILER_INJECTIVE_COMPILE_LOGGED_V1, - COMPILER_INJECTIVE_COMPILE_COMPLETED_V1, - ]; - for (const event of events) { - socketInjective.off(event); - } -} +} from "wds-event"; export function cleanupSocketArbitrum(socketNeutron: Socket) { const events = [ - 'connect', - 'disconnect', - 'connect_error', + "connect", + "disconnect", + "connect_error", COMPILER_ARBITRUM_COMPILE_ERROR_OCCURRED_V1, COMPILER_ARBITRUM_COMPILE_LOGGED_V1, COMPILER_ARBITRUM_COMPILE_COMPLETED_V1, diff --git a/src/utils/wait-for-transaction.ts b/src/utils/wait-for-transaction.ts deleted file mode 100644 index 506faa2..0000000 --- a/src/utils/wait-for-transaction.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Note: temporary helper utils. delete after wallet update. -export function delay(ms: number) { - return new Promise((resolve) => setTimeout(resolve, ms)); -} - -export const waitForTransaction = async (txHash: string, address: string, near: any) => { - let isPending = true; - let count = 0; - while (isPending) { - if (count >= 10) { - break; - } - try { - const receipt = await near.connection.provider.txStatus(txHash, address); - return receipt; - } catch (e) { - await delay(1000); - count += 1; - } - } - throw new Error(`Waiting for transaction ${txHash} timed out!`); -}; diff --git a/src/utils/wrap-promise.ts b/src/utils/wrap-promise.ts deleted file mode 100644 index 62062bf..0000000 --- a/src/utils/wrap-promise.ts +++ /dev/null @@ -1,33 +0,0 @@ -export default async function wrapPromise(promise: Promise, client: any) { - // let status = 'pending'; - let result: any; - // await client?.terminal.log('Loading...'); - - // let suspender = promise.then( - // async (r) => { - // // await client?.terminal.log('Success!'); - // status = 'success'; - // result = r; - // }, - // async (e) => { - // await client?.terminal.log({ type: 'error', value: e?.message?.toString() }); - // status = 'error'; - // result = e; - // }, - // ); - - // 컴포넌트 단으로 상태를 전파시킨다면 쓸 코드 - // return { - // read() { - // switch (status) { - // case 'pending': - // throw suspender; - // case 'error': - // throw result; - // default: - // return result; - // } - // }, - // }; - return result; -}