From 38d16fcff3427f1861e9a2ac4d8b2f105e139369 Mon Sep 17 00:00:00 2001 From: mayuran-deriv Date: Mon, 29 Sep 2025 11:08:53 +0400 Subject: [PATCH 1/2] fix: diel country block --- i18n/en/code.json | 10 +++++- .../app-manager/app-manager.context.tsx | 1 + .../app-manager/app-manager.provider.tsx | 11 +++++- src/contexts/auth/auth.provider.tsx | 24 +++++++------ .../permission-denied-error.scss | 24 +++++++++++++ .../permission-denied-error.tsx | 36 +++++++++++++++++++ src/features/dashboard/dashboard.tsx | 7 +++- .../dashboard/hooks/useGetApp/index.tsx | 4 +-- 8 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 src/features/dashboard/components/permission-denied-error/permission-denied-error.scss create mode 100644 src/features/dashboard/components/permission-denied-error/permission-denied-error.tsx diff --git a/i18n/en/code.json b/i18n/en/code.json index 64c240335..7e4f64204 100644 --- a/i18n/en/code.json +++ b/i18n/en/code.json @@ -1175,7 +1175,6 @@ "Demo account": { "message": "Demo account" }, - "Deriv.com": { "message": "Deriv.com" }, @@ -1193,5 +1192,14 @@ }, "Get real account": { "message": "Get real account" + }, + "Not available in your region": { + "message": "Not available in your region" + }, + "You can still use our other products and services.": { + "message": "You can still use our other products and services." + }, + "Go to home": { + "message": "Go to home" } } diff --git a/src/contexts/app-manager/app-manager.context.tsx b/src/contexts/app-manager/app-manager.context.tsx index 725ef96af..3c1c1b463 100644 --- a/src/contexts/app-manager/app-manager.context.tsx +++ b/src/contexts/app-manager/app-manager.context.tsx @@ -20,6 +20,7 @@ export type TAppManagerContext = { setIsDashboard: Dispatch>; app_register_modal_open: boolean; setAppRegisterModalOpen: Dispatch>; + is_dashboard_blocked: boolean; }; export const AppManagerContext = createContext(null); diff --git a/src/contexts/app-manager/app-manager.provider.tsx b/src/contexts/app-manager/app-manager.provider.tsx index 48eba0109..1ea8370fe 100644 --- a/src/contexts/app-manager/app-manager.provider.tsx +++ b/src/contexts/app-manager/app-manager.provider.tsx @@ -14,8 +14,9 @@ const AppManagerContextProvider = ({ children }: TAppManagerContextProps) => { const [is_dashboard, setIsDashboard] = useState(false); const [app_register_modal_open, setAppRegisterModalOpen] = useState(false); const [current_updating_item, setCurrentUpdateItem] = useState({}); - const { getAllApps, apps: updatedApps } = useGetApps(); + const { getAllApps, apps: updatedApps, error } = useGetApps(); const { is_authorized } = useAuthContext(); + const [is_dashboard_blocked, setIsDashboardBlocked] = useState(false); const getApps = useCallback(() => { if (is_authorized) { @@ -32,6 +33,12 @@ const AppManagerContextProvider = ({ children }: TAppManagerContextProps) => { } }, []); + useEffect(() => { + if (error?.error?.code === 'AppList') { + setIsDashboardBlocked(true); + } + }, [error]); + const handleCurrentUpdatingItem = useCallback((item: ApplicationObject) => { setCurrentUpdateItem(item); }, []); @@ -52,6 +59,7 @@ const AppManagerContextProvider = ({ children }: TAppManagerContextProps) => { app_register_modal_open, handleCurrentUpdatingItem, current_updating_item, + is_dashboard_blocked, }; }, [ apps, @@ -64,6 +72,7 @@ const AppManagerContextProvider = ({ children }: TAppManagerContextProps) => { setAppRegisterModalOpen, handleCurrentUpdatingItem, current_updating_item, + is_dashboard_blocked, ]); return {children}; diff --git a/src/contexts/auth/auth.provider.tsx b/src/contexts/auth/auth.provider.tsx index 7f2be7c57..ff80dacbf 100644 --- a/src/contexts/auth/auth.provider.tsx +++ b/src/contexts/auth/auth.provider.tsx @@ -81,16 +81,20 @@ const AuthProvider = ({ children }: TAuthProviderProps) => { const updateAuthorize = useCallback(async () => { if (currentLoginAccount.token) { - const { authorize } = await apiManager.authorize( - currentLoginAccount.token, - setIsConnected, - setIsAuthorized, - ); - setIsAuthorized(true); - setisSwitchingAccount(false); - const { account_list, ...user } = authorize; - setUserAccounts(account_list); - setUser(user); + try { + const { authorize } = await apiManager.authorize( + currentLoginAccount.token, + setIsConnected, + setIsAuthorized, + ); + setIsAuthorized(true); + setisSwitchingAccount(false); + const { account_list, ...user } = authorize; + setUserAccounts(account_list); + setUser(user); + } catch (error) { + console.error('Failed to authorize:', error); + } } }, [currentLoginAccount.token, setUser, setUserAccounts]); diff --git a/src/features/dashboard/components/permission-denied-error/permission-denied-error.scss b/src/features/dashboard/components/permission-denied-error/permission-denied-error.scss new file mode 100644 index 000000000..4d9b0adfc --- /dev/null +++ b/src/features/dashboard/components/permission-denied-error/permission-denied-error.scss @@ -0,0 +1,24 @@ +.permission-denied-container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + min-height: 60vh; + padding: 2rem; + text-align: center; +} + +.permission-denied-content { + max-width: 600px; + margin: 0 auto; + + h1 { + margin-bottom: 1rem; + color: var(--ifm-color-danger); + } + + p { + margin-bottom: 2rem; + font-size: 1.2rem; + } +} diff --git a/src/features/dashboard/components/permission-denied-error/permission-denied-error.tsx b/src/features/dashboard/components/permission-denied-error/permission-denied-error.tsx new file mode 100644 index 000000000..bea0e3790 --- /dev/null +++ b/src/features/dashboard/components/permission-denied-error/permission-denied-error.tsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { translate } from '@docusaurus/Translate'; +import { Button } from '@deriv-com/quill-ui'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; +import './permission-denied-error.scss'; + +const PermissionDeniedError = () => { + const { + i18n: { currentLocale }, + } = useDocusaurusContext(); + + const is_en = currentLocale === 'en'; + const homeUrl = `${!is_en ? `/${currentLocale}` : ''}/`; + + const handleGoHome = () => { + window.location.href = homeUrl; + }; + + return ( +
+
+

{translate({ message: 'Not available in your region' })}

+

+ {translate({ + message: 'You can still use our other products and services.', + })} +

+ +
+
+ ); +}; + +export default PermissionDeniedError; diff --git a/src/features/dashboard/dashboard.tsx b/src/features/dashboard/dashboard.tsx index 44d3b1fcb..411224bfb 100644 --- a/src/features/dashboard/dashboard.tsx +++ b/src/features/dashboard/dashboard.tsx @@ -5,10 +5,11 @@ import ManageDashboard from './manage-dashboard'; import { Login } from '../Login/Login'; import BrowserOnly from '@docusaurus/BrowserOnly'; import { Fallback } from '../Fallback'; +import PermissionDeniedError from './components/permission-denied-error/permission-denied-error'; const Dashboard = () => { const { is_logged_in, siteActive } = useAuthContext(); - const { setIsDashboard } = useAppManager(); + const { setIsDashboard, is_dashboard_blocked } = useAppManager(); useEffect(() => { setIsDashboard(true); @@ -18,6 +19,10 @@ const Dashboard = () => { }, [setIsDashboard]); if (!siteActive) return ; + + // Show permission denied error if the flag is set + if (is_logged_in && is_dashboard_blocked) return ; + if (is_logged_in) return ; return {() => }; }; diff --git a/src/features/dashboard/hooks/useGetApp/index.tsx b/src/features/dashboard/hooks/useGetApp/index.tsx index 92c22aa44..8665ef7ff 100644 --- a/src/features/dashboard/hooks/useGetApp/index.tsx +++ b/src/features/dashboard/hooks/useGetApp/index.tsx @@ -2,13 +2,13 @@ import useWS from '@site/src/hooks/useWs'; import { useCallback } from 'react'; const useGetApps = () => { - const { send, data, is_loading } = useWS('app_list'); + const { send, data, is_loading, error } = useWS('app_list'); const getAllApps = useCallback(() => { send(); }, [send]); - return { getAllApps, apps: data, is_loading }; + return { getAllApps, apps: data, is_loading, error }; }; export default useGetApps; From 96ec9236f6bccee4937d3ea6ef605fd175e32ca9 Mon Sep 17 00:00:00 2001 From: mayuran-deriv Date: Mon, 29 Sep 2025 11:57:56 +0400 Subject: [PATCH 2/2] fix: translation --- i18n/fr/code.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/i18n/fr/code.json b/i18n/fr/code.json index d7269ec66..83774b4a1 100644 --- a/i18n/fr/code.json +++ b/i18n/fr/code.json @@ -12,7 +12,7 @@ "message": "Tableau de bord" }, "API explorer": { - "message": "Explorateur d'API" + "message": "API explorer" }, "Deriv Tech": { "message": "Deriv Tech" @@ -1192,5 +1192,14 @@ }, "Get real account": { "message": "Obtenir un compte réel" + }, + "Not available in your region": { + "message": "N'est pas disponible dans votre région" + }, + "You can still use our other products and services.": { + "message": "Vous pouvez toujours utiliser nos autres produits et services." + }, + "Go to home": { + "message": "Rentrez à la page d'accueil" } }