2021-04-02 11:26:21 -07:00
|
|
|
import { useEffect, useState } from 'react'
|
2022-01-20 09:48:42 -08:00
|
|
|
import { CLUSTER } from '../stores/useMangoStore'
|
2021-04-02 11:26:21 -07:00
|
|
|
|
2021-06-10 08:18:13 -07:00
|
|
|
const SANCTIONED_COUNTRIES = [
|
2021-09-10 13:10:22 -07:00
|
|
|
['AG', 'Antigua and Barbuda'],
|
|
|
|
['DZ', 'Algeria'],
|
|
|
|
['BD', 'Bangladesh'],
|
|
|
|
['BO', 'Bolivia'],
|
|
|
|
['BY', 'Belarus'],
|
|
|
|
['BI', 'Burundi'],
|
|
|
|
['MM', 'Burma (Myanmar)'],
|
|
|
|
['CI', "Cote D'Ivoire (Ivory Coast)"],
|
|
|
|
['CU', 'Cuba'],
|
|
|
|
['CD', 'Democratic Republic of Congo'],
|
|
|
|
['EC', 'Ecuador'],
|
2021-11-23 05:36:48 -08:00
|
|
|
//['GB', 'United Kingdom'],
|
2021-09-10 13:10:22 -07:00
|
|
|
['IR', 'Iran'],
|
|
|
|
['IQ', 'Iraq'],
|
|
|
|
['LR', 'Liberia'],
|
|
|
|
['LY', 'Libya'],
|
|
|
|
['ML', 'Mali'],
|
|
|
|
['MA', 'Morocco'],
|
|
|
|
['NP', 'Nepal'],
|
|
|
|
['KP', 'North Korea'],
|
|
|
|
['SO', 'Somalia'],
|
|
|
|
['SD', 'Sudan'],
|
|
|
|
['SY', 'Syria'],
|
|
|
|
['VE', 'Venezuela'],
|
|
|
|
['YE', 'Yemen'],
|
|
|
|
['ZW', 'Zimbabwe'],
|
|
|
|
['US', 'United States'],
|
2021-06-10 08:18:13 -07:00
|
|
|
]
|
|
|
|
|
2021-09-10 13:10:22 -07:00
|
|
|
const SANCTIONED_COUNTRY_CODES = SANCTIONED_COUNTRIES.map(
|
|
|
|
(country) => country[0]
|
|
|
|
)
|
2021-06-10 08:18:13 -07:00
|
|
|
|
2021-11-22 15:54:51 -08:00
|
|
|
const SPOT_ALLOWED = ['GB']
|
|
|
|
|
2021-04-02 11:26:21 -07:00
|
|
|
export default function useIpAddress() {
|
2021-09-10 13:10:22 -07:00
|
|
|
const [ipAllowed, setIpAllowed] = useState(false)
|
2021-11-22 15:54:51 -08:00
|
|
|
const [spotAllowed, setSpotAllowed] = useState(false)
|
2021-04-02 11:26:21 -07:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const checkIpLocation = async () => {
|
2021-09-10 13:10:22 -07:00
|
|
|
const response = await fetch(
|
|
|
|
`https://country-code.mangomarkets.workers.dev`
|
|
|
|
)
|
|
|
|
const parsedResponse = await response.json()
|
|
|
|
const ipCountryCode = parsedResponse ? parsedResponse?.country : ''
|
2021-04-02 11:26:21 -07:00
|
|
|
|
|
|
|
if (ipCountryCode) {
|
2021-06-10 08:18:13 -07:00
|
|
|
setIpAllowed(!SANCTIONED_COUNTRY_CODES.includes(ipCountryCode))
|
2021-11-22 15:54:51 -08:00
|
|
|
setSpotAllowed(SPOT_ALLOWED.includes(ipCountryCode))
|
2021-04-02 11:26:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkIpLocation()
|
|
|
|
}, [])
|
|
|
|
|
2022-01-20 09:48:42 -08:00
|
|
|
if (CLUSTER === 'mainnet') {
|
|
|
|
return { ipAllowed, spotAllowed }
|
|
|
|
} else {
|
|
|
|
return { ipAllowed: true, spotAllowed: true }
|
|
|
|
}
|
2021-04-02 11:26:21 -07:00
|
|
|
}
|