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

Issue #656 (app PR): country.is failure #660

Merged
merged 3 commits into from
Jul 25, 2024
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
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
Loading