Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit fe30c9b

Browse files
MohammadH/Endpoint localstorage (#2755)
* update package-lock.json * update package lock * fix: add manual clients country to localstorage to prevent overwriting clients country by ip * fix: remove local storage manual country when press on reset button * fix: add isbrowser before using localstorage
1 parent 9af79fc commit fe30c9b

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/components/hooks/use-website-status.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, useLayoutEffect } from 'react'
22
import { useCookieState } from './use-cookie-state'
33
import { BinarySocketBase } from 'common/websocket/socket_base'
4-
import { getDateFromToday } from 'common/utility'
4+
import { getDateFromToday, isBrowser } from 'common/utility'
55

66
const WEBSITE_STATUS_COUNTRY_KEY = 'website_status'
77
const COOKIE_EXPIRY_DAYS = 7
@@ -11,6 +11,8 @@ export const useWebsiteStatus = () => {
1111
expires: getDateFromToday(COOKIE_EXPIRY_DAYS),
1212
})
1313

14+
const manual_clients_country = isBrowser() && localStorage.getItem('manual_clients_country')
15+
1416
const [is_loading, setLoading] = useState(true)
1517

1618
useLayoutEffect(() => {
@@ -32,7 +34,7 @@ export const useWebsiteStatus = () => {
3234
setLoading(false)
3335
binary_socket.close()
3436
}
35-
} else {
37+
} else if (!manual_clients_country) {
3638
const binary_socket = BinarySocketBase.init()
3739
binary_socket.onopen = () => {
3840
binary_socket.send(JSON.stringify({ website_status: 1 }))
@@ -50,6 +52,8 @@ export const useWebsiteStatus = () => {
5052
binary_socket.close()
5153
setLoading(false)
5254
}
55+
} else {
56+
setLoading(false)
5357
}
5458
}, [website_status])
5559

src/pages/endpoint/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Container, SEO } from 'components/containers'
88
import { Header, Text } from 'components/elements'
99
import { Input, Button } from 'components/form'
1010
import validation from 'common/validation'
11-
import { trimSpaces } from 'common/utility'
11+
import { trimSpaces, isBrowser } from 'common/utility'
1212
import { default_server_url } from 'common/constants'
1313
import { getAppId } from 'common/websocket/config'
1414
import { DerivStore } from 'store'
@@ -121,6 +121,7 @@ const Endpoint = () => {
121121
// reset website status values
122122
setWebsiteStatus()
123123
handleStatus(setStatus, 'Config has been reset successfully')
124+
isBrowser() && localStorage.removeItem('manual_clients_country')
124125
// TODO: if there is a change requires reload in the future
125126
// window.location.reload()
126127
}
@@ -131,6 +132,7 @@ const Endpoint = () => {
131132

132133
// handle website status changes
133134
const new_website_status = { ...website_status, clients_country: values.clients_country }
135+
isBrowser() && localStorage.setItem('manual_clients_country', values.clients_country)
134136
setWebsiteStatus(new_website_status)
135137
actions.setSubmitting(false)
136138
handleStatus(actions.setStatus, 'Config has been updated')

src/store/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type DerivStoreType = {
2323
is_uk_country: boolean
2424
LC_API: { open_chat_window: () => void }
2525
setFirstLoadOpenLc: React.Dispatch<React.SetStateAction<boolean>>
26-
setWebsiteStatus: Dispatch<WebsiteStatusType>
26+
setWebsiteStatus: Dispatch<WebsiteStatusType | void>
2727
user_country: string
2828
website_status_loading: boolean
2929
website_status: WebsiteStatusType

0 commit comments

Comments
 (0)