Skip to content

Commit

Permalink
Issue #656 (app PR): country.is failure (#660)
Browse files Browse the repository at this point in the history
* add geoblock

* no ip call

* consolidate calls
  • Loading branch information
jahabeebs authored Jul 25, 2024
1 parent 14e8471 commit df40578
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 58 deletions.
77 changes: 21 additions & 56 deletions src/containers/Shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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(
<ToastPayload
icon={'AlertTriangle'}
iconSize={40}
iconColor={'orange'}
textColor={'#ffffff'}
text={`${t('sanctioned_wallet')}`}
/>,
{ 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(<ToastBannerNetwork />, { 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(
<ToastPayload
icon={'AlertTriangle'}
iconSize={40}
iconColor={'orange'}
textColor={'#ffffff'}
text={`${t('sanctioned_wallet')}`}
/>,
{ autoClose: false, type: 'warning', toastId: sanctionsToastId }
)
} else {
return true
}
Expand Down Expand Up @@ -300,8 +267,7 @@ const Shared = ({ children, ...rest }: Props) => {
settingsActions.setBlockBody(false)
connectWalletActions.setIsWrongNetwork(false)
if (account) {
sanctionsCheck()
geoBlockCheck()
sanctionsAndGeoBlockCheck()
connectWalletActions.setStep(1)
accountChecker()
}
Expand Down Expand Up @@ -340,8 +306,7 @@ const Shared = ({ children, ...rest }: Props) => {
settingsActions.setBlockBody(false)
connectWalletActions.setIsWrongNetwork(false)
if (account) {
sanctionsCheck()
geoBlockCheck()
sanctionsAndGeoBlockCheck()
accountChecker()
}
checkAndSwitchMetamaskNetwork()
Expand Down
Original file line number Diff line number Diff line change
@@ -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}`
Expand All @@ -16,4 +16,4 @@ async function checkSanctions(address: string) {
}
}

export default checkSanctions
export default checkGeoBlockAndSanctions

0 comments on commit df40578

Please sign in to comment.