diff --git a/src/containers/Shared.tsx b/src/containers/Shared.tsx index 063c3e2c..01683950 100644 --- a/src/containers/Shared.tsx +++ b/src/containers/Shared.tsx @@ -19,14 +19,13 @@ import { IS_IN_IFRAME, timeout, } from '~/utils' -import axios from 'axios' import useTokenData from '~/hooks/useTokenData' import useSafeData from '~/hooks/useSafeData' import useCoinBalanceUpdate from '~/hooks/useCoinBalanceUpdate' import useAuctionDataUpdate from '~/hooks/useAuctionDataUpdate' import useAllowanceCheck from '~/hooks/useAllowanceCheck' -import checkSanctions from '~/services/checkSanctions' +import checkGeoBlockAndSanctions from '~/services/checkGeoBlockAndSanctions' import ToastPayload from '~/components/ToastPayload' import WalletModal, { checkAndSwitchMetamaskNetwork } from '~/components/WalletModal' import SideMenu from '~/components/SideMenu' @@ -89,7 +88,6 @@ const Shared = ({ children, ...rest }: Props) => { const toastId = 'networkToastHash' const sanctionsToastId = 'sanctionsToastHash' - const bannedCountryCodes = ['US', 'IR', 'KP'] const resetModals = () => { popupsActions.setIsConnectedWalletModalOpen(false) @@ -110,28 +108,6 @@ const Shared = ({ children, ...rest }: Props) => { connectWalletActions.setTokensData(tokensData) }, [connectWalletActions, tokensData]) - const fetchUserCountry = async () => { - try { - const response = await axios.get('https://api.country.is') - return response.data?.country - } catch (error) { - console.error('Error fetching country:', error) - return null - } - } - - const isUserGeoBlocked = async () => { - if (!isGeofenceEnabled) { - return false - } - - const userCountry = await fetchUserCountry() - if (userCountry && bannedCountryCodes.includes(userCountry)) { - return true - } - return false - } - async function accountChecker() { if (!account || !chainId || !provider || !geb) return @@ -184,45 +160,36 @@ const Shared = ({ children, ...rest }: Props) => { } } - async function sanctionsCheck() { - if (account && process.env.NODE_ENV === 'production') { - const response = await checkSanctions(account) - if (response?.identifications.length > 0) { - connectWalletActions.setIsWrongNetwork(true) - toast( - , - { autoClose: false, type: 'warning', toastId: sanctionsToastId } - ) - return false - } else { - return true - } - } - return true - } - async function haiUserCheck() { if (process.env.REACT_APP_NETWORK_ID === '10') { toast(, { autoClose: false, type: 'warning', toastId: sanctionsToastId }) } } - async function geoBlockCheck() { - if (account && isGeofenceEnabled) { - const isBlocked = await isUserGeoBlocked() - if (isBlocked) { + async function sanctionsAndGeoBlockCheck() { + if (account && (isGeofenceEnabled || process.env.NODE_ENV === 'production')) { + const botAPIResponse = await checkGeoBlockAndSanctions(account) + const isBlocked = botAPIResponse.data?.message?.includes('geoblocked') + const isSanctioned = botAPIResponse?.identifications.length > 0 + if (isBlocked && isGeofenceEnabled) { popupsActions.setIsConnectedWalletModalOpen(false) popupsActions.setIsConnectorsWalletOpen(false) navigate('/geoblock') connectWalletActions.setIsWrongNetwork(true) settingsActions.setBlockBody(true) return false + } else if (isSanctioned && process.env.NODE_ENV === 'production') { + connectWalletActions.setIsWrongNetwork(true) + toast( + , + { autoClose: false, type: 'warning', toastId: sanctionsToastId } + ) } else { return true } @@ -300,8 +267,7 @@ const Shared = ({ children, ...rest }: Props) => { settingsActions.setBlockBody(false) connectWalletActions.setIsWrongNetwork(false) if (account) { - sanctionsCheck() - geoBlockCheck() + sanctionsAndGeoBlockCheck() connectWalletActions.setStep(1) accountChecker() } @@ -340,8 +306,7 @@ const Shared = ({ children, ...rest }: Props) => { settingsActions.setBlockBody(false) connectWalletActions.setIsWrongNetwork(false) if (account) { - sanctionsCheck() - geoBlockCheck() + sanctionsAndGeoBlockCheck() accountChecker() } checkAndSwitchMetamaskNetwork() diff --git a/src/services/checkSanctions.ts b/src/services/checkGeoBlockAndSanctions.ts similarity index 79% rename from src/services/checkSanctions.ts rename to src/services/checkGeoBlockAndSanctions.ts index 14d54bdc..129c4158 100644 --- a/src/services/checkSanctions.ts +++ b/src/services/checkGeoBlockAndSanctions.ts @@ -1,7 +1,7 @@ import axios from 'axios' import { OD_API_URL } from '~/utils/constants' -async function checkSanctions(address: string) { +async function checkGeoBlockAndSanctions(address: string) { let res try { const BOT_API = `${OD_API_URL}/screen?address=${address}` @@ -16,4 +16,4 @@ async function checkSanctions(address: string) { } } -export default checkSanctions +export default checkGeoBlockAndSanctions