enable ip block
This commit is contained in:
parent
1b406f4b7e
commit
58b10d3822
|
@ -19,6 +19,7 @@ import usePool from '../hooks/usePool'
|
|||
import styled from '@emotion/styled'
|
||||
import 'twin.macro'
|
||||
import { notify } from '../utils/notifications'
|
||||
import useIpAddress from '../hooks/useIpAddress'
|
||||
|
||||
const SmallButton = styled.button``
|
||||
|
||||
|
@ -29,6 +30,7 @@ const ContributionModal = () => {
|
|||
const largestAccounts = useLargestAccounts()
|
||||
//const vaults = useVaults()
|
||||
const { endIdo, endDeposits } = usePool()
|
||||
const { ipAllowed } = useIpAddress()
|
||||
|
||||
const usdcBalance = largestAccounts.usdc?.balance || 0
|
||||
const redeemableBalance = largestAccounts.redeemable?.balance || 0
|
||||
|
@ -310,6 +312,7 @@ const ContributionModal = () => {
|
|||
</div>
|
||||
)}
|
||||
</div>
|
||||
{ipAllowed || !connected ? (
|
||||
<Button
|
||||
onClick={() => handleSetContribution()}
|
||||
className="w-full py-2.5"
|
||||
|
@ -321,6 +324,13 @@ const ContributionModal = () => {
|
|||
: 'Set Contribution'}
|
||||
</div>
|
||||
</Button>
|
||||
) : (
|
||||
<Button className="w-full py-2.5" disabled>
|
||||
<div className={`flex items-center justify-center`}>
|
||||
Country Not Allowed
|
||||
</div>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center justify-center">
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
|
||||
const SANCTIONED_COUNTRIES = [
|
||||
{ country: 'Antigua and Barbuda', code: 'AG' },
|
||||
{ country: 'Algeria', code: 'DZ' },
|
||||
{ country: 'Bangladesh', code: 'BD' },
|
||||
{ country: 'Bolivia', code: 'BO' },
|
||||
{ country: 'Belarus', code: 'BY' },
|
||||
{ country: 'Burundi', code: 'BI' },
|
||||
{ country: 'Burma (Myanmar)', code: 'MM' },
|
||||
{ country: "Cote D'Ivoire (Ivory Coast)", code: 'CI' },
|
||||
{ country: 'Cuba', code: 'CU' },
|
||||
{ country: 'Democratic Republic of Congo', code: 'CD' },
|
||||
{ country: 'Ecuador', code: 'EC' },
|
||||
{ country: 'Iran', code: 'IR' },
|
||||
{ country: 'Iraq', code: 'IQ' },
|
||||
{ country: 'Liberia', code: 'LR' },
|
||||
{ country: 'Libya', code: 'LY' },
|
||||
{ country: 'Mali', code: 'ML' },
|
||||
{ country: 'Morocco', code: 'MA' },
|
||||
{ country: 'Nepal', code: 'NP' },
|
||||
{ country: 'North Korea', code: 'KP' },
|
||||
{ country: 'Somalia', code: 'SO' },
|
||||
{ country: 'Sudan', code: 'SD' },
|
||||
{ country: 'Syria', code: 'SY' },
|
||||
{ country: 'Venezuela', code: 'VE' },
|
||||
{ country: 'Yemen', code: 'YE' },
|
||||
{ country: 'Zimbabwe', code: 'ZW' },
|
||||
{ country: 'United States', code: 'US' },
|
||||
]
|
||||
|
||||
const SANCTIONED_COUNTRY_CODES = SANCTIONED_COUNTRIES.map(({ code }) => code)
|
||||
|
||||
export default function useIpAddress() {
|
||||
const [ipAllowed, setIpAllowed] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
const checkIpLocation = async () => {
|
||||
const response = await fetch(`https://www.cloudflare.com/cdn-cgi/trace`)
|
||||
const parsedResponse = await response.text()
|
||||
const ipLocation = parsedResponse.match(/loc=(.+)/)
|
||||
const ipCountryCode = ipLocation ? ipLocation[1] : ''
|
||||
|
||||
if (ipCountryCode) {
|
||||
setIpAllowed(!SANCTIONED_COUNTRY_CODES.includes(ipCountryCode))
|
||||
}
|
||||
}
|
||||
|
||||
checkIpLocation()
|
||||
}, [])
|
||||
|
||||
return { ipAllowed }
|
||||
}
|
Loading…
Reference in New Issue