From 152ba5285d1d4cc3463d3906d10beefa60968617 Mon Sep 17 00:00:00 2001 From: mohammad-rework Date: Mon, 3 Jan 2022 15:21:06 +0330 Subject: [PATCH] convert endpoint page to TS --- src/pages/endpoint/{index.js => index.tsx} | 21 ++++++++++++++++----- src/store/index.tsx | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) rename src/pages/endpoint/{index.js => index.tsx} (94%) diff --git a/src/pages/endpoint/index.js b/src/pages/endpoint/index.tsx similarity index 94% rename from src/pages/endpoint/index.js rename to src/pages/endpoint/index.tsx index 25d93373b14..f66c151d5a5 100644 --- a/src/pages/endpoint/index.js +++ b/src/pages/endpoint/index.tsx @@ -14,6 +14,17 @@ import { getAppId } from 'common/websocket/config' import { DerivStore } from 'store' import { useLocalStorageState } from 'components/hooks/use-localstorage-state' +type ValuesType = { + server_url?: string + app_id?: string + clients_country?: string +} + +type ActionsType = { + setSubmitting: (arg0: boolean) => void + setStatus: (arg0: { message?: string }) => void +} + const StyledInput = styled(Input)` & ~ label { transform: translate(-0.6rem, -2rem) scale(0.7); @@ -52,8 +63,8 @@ const StyledButton = styled(Button)` margin: 0.8rem 0.4rem; ` -const endpointValidation = (values) => { - let errors = {} +const endpointValidation = (values: ValuesType) => { + const errors: ValuesType = {} const server_url = trimSpaces(values ? values.server_url : '') const app_id = trimSpaces(values ? values.app_id.toString() : '') @@ -90,13 +101,13 @@ const Endpoint = () => { const STATUS_TIMEOUT_DELAY = 1500 const RESET_TIMEOUT_DELAY = 500 - const handleStatus = (setStatus, message) => { + const handleStatus = (setStatus: (arg0: { message?: string }) => void, message: string) => { setStatus({ message }) setTimeout(() => { setStatus({}) }, STATUS_TIMEOUT_DELAY) } - const resetEndpointSettings = (setStatus) => { + const resetEndpointSettings = (setStatus: (status?: unknown) => void) => { // reset local storage values setResetLoading(true) setServerUrl() @@ -113,7 +124,7 @@ const Endpoint = () => { // TODO: if there is a change requires reload in the future // window.location.reload() } - const endpointSubmission = (values, actions) => { + const endpointSubmission = (values: ValuesType, actions: ActionsType) => { actions.setSubmitting(true) setServerUrl(values.server_url) setAppId(values.app_id) diff --git a/src/store/index.tsx b/src/store/index.tsx index 96850f56a73..6092a04fba8 100644 --- a/src/store/index.tsx +++ b/src/store/index.tsx @@ -6,7 +6,7 @@ type DerivProviderProps = { children?: React.ReactNode } -export const DerivStore = React.createContext() +export const DerivStore = React.createContext() export const DerivProvider = ({ children }: DerivProviderProps) => { const [website_status, setWebsiteStatus, website_status_loading] = useWebsiteStatus()