Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: redirect when access from forbidden country is detected #1209

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/components/Geoblock/Geoblock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { ReactNode } from 'react';

import { useGeoblocking } from '@/utils/hooks/use-geoblocking';

type Props = {
children: ReactNode;
};

const GeoblockingWrapper = ({ children }: Props): JSX.Element => {
useGeoblocking();
return <>{children}</>;
};

export { GeoblockingWrapper };
5 changes: 5 additions & 0 deletions src/config/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ const INTERLAY_DOS_AND_DONTS_DOCS_LINK = 'https://docs.interlay.io/#/vault/insta

const BANXA_LINK = 'http://talisman.banxa.com/';

const GEOBLOCK_API_ENDPOINT = '/check_access';
const GEOBLOCK_REDIRECTION_LINK = 'https://www.interlay.io/geoblock';

export {
BANXA_LINK,
GEOBLOCK_API_ENDPOINT,
GEOBLOCK_REDIRECTION_LINK,
INTERLAY_COMPANY_LINK,
INTERLAY_CROWDLOAN_LINK,
INTERLAY_DISCORD_LINK,
Expand Down
43 changes: 23 additions & 20 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ThemeWrapper from '@/parts/ThemeWrapper';
import { Subscriptions } from '@/utils/hooks/api/tokens/use-balances-subscription';

import App from './App';
import { GeoblockingWrapper } from './components/Geoblock/Geoblock';
import reportWebVitals from './reportWebVitals';
import { store } from './store';

Expand All @@ -30,26 +31,28 @@ const queryClient = new QueryClient();
// MEMO: temporarily removed React.StrictMode. We should add back when react-spectrum handles
// it across their library. (Issue: https://github.com/adobe/react-spectrum/issues/779#issuecomment-1353734729)
ReactDOM.render(
<Router>
<QueryClientProvider client={queryClient}>
<HelmetProvider>
<Provider store={store}>
<SubstrateProvider>
<ThemeWrapper>
<SubstrateLoadingAndErrorHandlingWrapper>
<Subscriptions>
<OverlayProvider>
<App />
</OverlayProvider>
</Subscriptions>
</SubstrateLoadingAndErrorHandlingWrapper>
</ThemeWrapper>
</SubstrateProvider>
</Provider>
</HelmetProvider>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</Router>,
<GeoblockingWrapper>
peterslany marked this conversation as resolved.
Show resolved Hide resolved
<Router>
<QueryClientProvider client={queryClient}>
<HelmetProvider>
<Provider store={store}>
<SubstrateProvider>
<ThemeWrapper>
<SubstrateLoadingAndErrorHandlingWrapper>
<Subscriptions>
<OverlayProvider>
<App />
</OverlayProvider>
</Subscriptions>
</SubstrateLoadingAndErrorHandlingWrapper>
</ThemeWrapper>
</SubstrateProvider>
</Provider>
</HelmetProvider>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</Router>
</GeoblockingWrapper>,
document.getElementById('root')
);

Expand Down
22 changes: 22 additions & 0 deletions src/utils/hooks/use-geoblocking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useEffect } from 'react';

import { GEOBLOCK_API_ENDPOINT, GEOBLOCK_REDIRECTION_LINK } from '@/config/links';

const useGeoblocking = (): void => {
useEffect(() => {
const checkCountry = async () => {
try {
const response = await fetch(GEOBLOCK_API_ENDPOINT);
if (response.status === 403) {
console.log('Access from forbidden country detected, user will be redirected.');
window.location.replace(GEOBLOCK_REDIRECTION_LINK);
}
} catch (error) {
console.log(error);
}
};
checkCountry();
}, []);
};

export { useGeoblocking };