diff --git a/components/ContributionModal.tsx b/components/ContributionModal.tsx
index bdc12dd..909e570 100644
--- a/components/ContributionModal.tsx
+++ b/components/ContributionModal.tsx
@@ -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,17 +312,25 @@ const ContributionModal = () => {
)}
-
+ {ipAllowed || !connected ? (
+
+ ) : (
+
+ )}
diff --git a/hooks/useIpAddress.tsx b/hooks/useIpAddress.tsx
new file mode 100644
index 0000000..5ce15ff
--- /dev/null
+++ b/hooks/useIpAddress.tsx
@@ -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 }
+}