Skip to content

Commit b5aec81

Browse files
Merge pull request #286 from deriv-com/mayuran/diel-country-block
fix: diel country block
2 parents b896e0d + 96ec923 commit b5aec81

File tree

9 files changed

+112
-16
lines changed

9 files changed

+112
-16
lines changed

i18n/en/code.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,6 @@
11751175
"Demo account": {
11761176
"message": "Demo account"
11771177
},
1178-
11791178
"Deriv.com": {
11801179
"message": "Deriv.com"
11811180
},
@@ -1193,5 +1192,14 @@
11931192
},
11941193
"Get real account": {
11951194
"message": "Get real account"
1195+
},
1196+
"Not available in your region": {
1197+
"message": "Not available in your region"
1198+
},
1199+
"You can still use our other products and services.": {
1200+
"message": "You can still use our other products and services."
1201+
},
1202+
"Go to home": {
1203+
"message": "Go to home"
11961204
}
11971205
}

i18n/fr/code.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"message": "Tableau de bord"
1313
},
1414
"API explorer": {
15-
"message": "Explorateur d'API"
15+
"message": "API explorer"
1616
},
1717
"Deriv Tech": {
1818
"message": "Deriv Tech"
@@ -1192,5 +1192,14 @@
11921192
},
11931193
"Get real account": {
11941194
"message": "Obtenir un compte réel"
1195+
},
1196+
"Not available in your region": {
1197+
"message": "N'est pas disponible dans votre région"
1198+
},
1199+
"You can still use our other products and services.": {
1200+
"message": "Vous pouvez toujours utiliser nos autres produits et services."
1201+
},
1202+
"Go to home": {
1203+
"message": "Rentrez à la page d'accueil"
11951204
}
11961205
}

src/contexts/app-manager/app-manager.context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type TAppManagerContext = {
2020
setIsDashboard: Dispatch<SetStateAction<boolean>>;
2121
app_register_modal_open: boolean;
2222
setAppRegisterModalOpen: Dispatch<SetStateAction<boolean>>;
23+
is_dashboard_blocked: boolean;
2324
};
2425

2526
export const AppManagerContext = createContext<TAppManagerContext | null>(null);

src/contexts/app-manager/app-manager.provider.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ const AppManagerContextProvider = ({ children }: TAppManagerContextProps) => {
1414
const [is_dashboard, setIsDashboard] = useState(false);
1515
const [app_register_modal_open, setAppRegisterModalOpen] = useState(false);
1616
const [current_updating_item, setCurrentUpdateItem] = useState({});
17-
const { getAllApps, apps: updatedApps } = useGetApps();
17+
const { getAllApps, apps: updatedApps, error } = useGetApps();
1818
const { is_authorized } = useAuthContext();
19+
const [is_dashboard_blocked, setIsDashboardBlocked] = useState(false);
1920

2021
const getApps = useCallback(() => {
2122
if (is_authorized) {
@@ -32,6 +33,12 @@ const AppManagerContextProvider = ({ children }: TAppManagerContextProps) => {
3233
}
3334
}, []);
3435

36+
useEffect(() => {
37+
if (error?.error?.code === 'AppList') {
38+
setIsDashboardBlocked(true);
39+
}
40+
}, [error]);
41+
3542
const handleCurrentUpdatingItem = useCallback((item: ApplicationObject) => {
3643
setCurrentUpdateItem(item);
3744
}, []);
@@ -52,6 +59,7 @@ const AppManagerContextProvider = ({ children }: TAppManagerContextProps) => {
5259
app_register_modal_open,
5360
handleCurrentUpdatingItem,
5461
current_updating_item,
62+
is_dashboard_blocked,
5563
};
5664
}, [
5765
apps,
@@ -64,6 +72,7 @@ const AppManagerContextProvider = ({ children }: TAppManagerContextProps) => {
6472
setAppRegisterModalOpen,
6573
handleCurrentUpdatingItem,
6674
current_updating_item,
75+
is_dashboard_blocked,
6776
]);
6877

6978
return <AppManagerContext.Provider value={context_object}>{children}</AppManagerContext.Provider>;

src/contexts/auth/auth.provider.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,20 @@ const AuthProvider = ({ children }: TAuthProviderProps) => {
8181

8282
const updateAuthorize = useCallback(async () => {
8383
if (currentLoginAccount.token) {
84-
const { authorize } = await apiManager.authorize(
85-
currentLoginAccount.token,
86-
setIsConnected,
87-
setIsAuthorized,
88-
);
89-
setIsAuthorized(true);
90-
setisSwitchingAccount(false);
91-
const { account_list, ...user } = authorize;
92-
setUserAccounts(account_list);
93-
setUser(user);
84+
try {
85+
const { authorize } = await apiManager.authorize(
86+
currentLoginAccount.token,
87+
setIsConnected,
88+
setIsAuthorized,
89+
);
90+
setIsAuthorized(true);
91+
setisSwitchingAccount(false);
92+
const { account_list, ...user } = authorize;
93+
setUserAccounts(account_list);
94+
setUser(user);
95+
} catch (error) {
96+
console.error('Failed to authorize:', error);
97+
}
9498
}
9599
}, [currentLoginAccount.token, setUser, setUserAccounts]);
96100

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.permission-denied-container {
2+
display: flex;
3+
flex-direction: column;
4+
align-items: center;
5+
justify-content: center;
6+
min-height: 60vh;
7+
padding: 2rem;
8+
text-align: center;
9+
}
10+
11+
.permission-denied-content {
12+
max-width: 600px;
13+
margin: 0 auto;
14+
15+
h1 {
16+
margin-bottom: 1rem;
17+
color: var(--ifm-color-danger);
18+
}
19+
20+
p {
21+
margin-bottom: 2rem;
22+
font-size: 1.2rem;
23+
}
24+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
import { translate } from '@docusaurus/Translate';
3+
import { Button } from '@deriv-com/quill-ui';
4+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
5+
import './permission-denied-error.scss';
6+
7+
const PermissionDeniedError = () => {
8+
const {
9+
i18n: { currentLocale },
10+
} = useDocusaurusContext();
11+
12+
const is_en = currentLocale === 'en';
13+
const homeUrl = `${!is_en ? `/${currentLocale}` : ''}/`;
14+
15+
const handleGoHome = () => {
16+
window.location.href = homeUrl;
17+
};
18+
19+
return (
20+
<div className='permission-denied-container'>
21+
<div className='permission-denied-content'>
22+
<h1>{translate({ message: 'Not available in your region' })}</h1>
23+
<p>
24+
{translate({
25+
message: 'You can still use our other products and services.',
26+
})}
27+
</p>
28+
<Button variant='primary' onClick={handleGoHome} size='lg'>
29+
{translate({ message: 'Go to home' })}
30+
</Button>
31+
</div>
32+
</div>
33+
);
34+
};
35+
36+
export default PermissionDeniedError;

src/features/dashboard/dashboard.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import ManageDashboard from './manage-dashboard';
55
import { Login } from '../Login/Login';
66
import BrowserOnly from '@docusaurus/BrowserOnly';
77
import { Fallback } from '../Fallback';
8+
import PermissionDeniedError from './components/permission-denied-error/permission-denied-error';
89

910
const Dashboard = () => {
1011
const { is_logged_in, siteActive } = useAuthContext();
11-
const { setIsDashboard } = useAppManager();
12+
const { setIsDashboard, is_dashboard_blocked } = useAppManager();
1213

1314
useEffect(() => {
1415
setIsDashboard(true);
@@ -18,6 +19,10 @@ const Dashboard = () => {
1819
}, [setIsDashboard]);
1920

2021
if (!siteActive) return <Fallback />;
22+
23+
// Show permission denied error if the flag is set
24+
if (is_logged_in && is_dashboard_blocked) return <PermissionDeniedError />;
25+
2126
if (is_logged_in) return <ManageDashboard />;
2227
return <BrowserOnly>{() => <Login />}</BrowserOnly>;
2328
};

src/features/dashboard/hooks/useGetApp/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import useWS from '@site/src/hooks/useWs';
22
import { useCallback } from 'react';
33

44
const useGetApps = () => {
5-
const { send, data, is_loading } = useWS('app_list');
5+
const { send, data, is_loading, error } = useWS('app_list');
66

77
const getAllApps = useCallback(() => {
88
send();
99
}, [send]);
1010

11-
return { getAllApps, apps: data, is_loading };
11+
return { getAllApps, apps: data, is_loading, error };
1212
};
1313

1414
export default useGetApps;

0 commit comments

Comments
 (0)