-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { ReactNode } from "react"; | ||
import IPData from "ipdata"; | ||
import Tenant from "@/lib/tenant/tenant"; | ||
import Image from "next/image"; | ||
import { Button } from "@/components/ui/button"; | ||
|
||
// Cuba, Iran, North Korea, Syria, and Russia are blocked from participating in the airdrop | ||
const BLOCKED_COUNTRIES = ["CU", "IR", "KP", "SY", "RU"]; | ||
|
||
// The following ISO 3166-2 codes are for Crimea, Donetsk and Luhansk regions of occupied Ukraine | ||
// https://www.iso.org/obp/ui/#iso:code:3166:UA | ||
const BLOCKED_REGIONS = ["UA-43", "UA-14", "UA-09"]; | ||
|
||
interface Props { | ||
children: ReactNode; | ||
enabled: boolean; | ||
} | ||
|
||
const ipData = new IPData(process.env.IP_DATA_API_KEY!, { | ||
maxAge: 3600, | ||
}); | ||
|
||
export const IPBlocker = async ({ children, enabled }: Props) => { | ||
if (!enabled) { | ||
return <>{children}</>; | ||
} | ||
|
||
try { | ||
const ip = await ipData.lookup(); | ||
if ( | ||
BLOCKED_COUNTRIES.includes(ip.country_code) || | ||
(ip.region_code && BLOCKED_REGIONS.includes(ip.region_code)) | ||
) { | ||
return <AccessRestricted />; | ||
} | ||
} catch (error) { | ||
return ( | ||
<>Error determining your location. Please come back later to try again.</> | ||
); | ||
} | ||
return <>{children}</>; | ||
}; | ||
|
||
const AccessRestricted = () => { | ||
const { ui } = Tenant.current(); | ||
|
||
return ( | ||
<div className="flex flex-col w-full h-screen items-center justify-center gap-2"> | ||
<Image src={ui.logo} alt="logo" width="68" height="68" /> | ||
|
||
<div className="font-semibold text-xl mt-4">Access Restricted</div> | ||
<div className="text-sm"> | ||
Unfortunately, the airdrop is not available in your region. | ||
</div> | ||
<Button className="mt-4" variant="outline"> | ||
Learn more | ||
</Button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2889,7 +2889,7 @@ | |
"@opentelemetry/resources" "1.22.0" | ||
"@opentelemetry/semantic-conventions" "1.22.0" | ||
|
||
"@opentelemetry/[email protected]", "@opentelemetry/[email protected]", "@opentelemetry/semantic-conventions@^1.19.0": | ||
"@opentelemetry/[email protected]": | ||
version "1.19.0" | ||
resolved "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.19.0.tgz" | ||
integrity sha512-14jRpC8f5c0gPSwoZ7SbEJni1PqI+AhAE8m1bMz6v+RPM4OlP1PT2UHBJj5Qh/ALLPjhVU/aZUK3YyjTUqqQVg== | ||
|
@@ -2906,6 +2906,11 @@ | |
"@opentelemetry/sdk-trace-base" "1.22.0" | ||
semver "^7.5.2" | ||
|
||
"@opentelemetry/[email protected]", "@opentelemetry/semantic-conventions@^1.19.0": | ||
version "1.19.0" | ||
resolved "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.19.0.tgz" | ||
integrity sha512-14jRpC8f5c0gPSwoZ7SbEJni1PqI+AhAE8m1bMz6v+RPM4OlP1PT2UHBJj5Qh/ALLPjhVU/aZUK3YyjTUqqQVg== | ||
|
||
"@opentelemetry/[email protected]", "@opentelemetry/semantic-conventions@^1.0.0", "@opentelemetry/semantic-conventions@^1.22.0": | ||
version "1.22.0" | ||
resolved "https://registry.npmjs.org/@opentelemetry/semantic-conventions/-/semantic-conventions-1.22.0.tgz" | ||
|
@@ -6400,6 +6405,13 @@ axe-core@=4.7.0: | |
resolved "https://registry.npmjs.org/axe-core/-/axe-core-4.7.0.tgz" | ||
integrity sha512-M0JtH+hlOL5pLQwHOLNYZaXuhqmvS8oExsqB1SBYgA4Dk7u/xx+YdGHXaK5pyUfed5mYXdlYiphWq3G8cRi5JQ== | ||
|
||
axios@^0.21.1: | ||
version "0.21.4" | ||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575" | ||
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg== | ||
dependencies: | ||
follow-redirects "^1.14.0" | ||
|
||
axios@^1.4.0: | ||
version "1.6.8" | ||
resolved "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz" | ||
|
@@ -8553,7 +8565,7 @@ flatted@^3.2.9: | |
resolved "https://registry.npmjs.org/flatted/-/flatted-3.2.9.tgz" | ||
integrity sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ== | ||
|
||
follow-redirects@^1.15.6: | ||
follow-redirects@^1.14.0, follow-redirects@^1.15.6: | ||
version "1.15.6" | ||
resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz" | ||
integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== | ||
|
@@ -9457,6 +9469,23 @@ ioredis@^5.3.2: | |
redis-parser "^3.0.0" | ||
standard-as-callback "^2.1.0" | ||
|
||
ip-regex@^4.0.0: | ||
version "4.3.0" | ||
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-4.3.0.tgz#687275ab0f57fa76978ff8f4dddc8a23d5990db5" | ||
integrity sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q== | ||
|
||
ipdata@^2.2.4: | ||
version "2.2.4" | ||
resolved "https://registry.yarnpkg.com/ipdata/-/ipdata-2.2.4.tgz#6732f24675c23f22d3797e62b8c8ffda68611123" | ||
integrity sha512-iYUGyzbbgY+8P+5vyzyR+7aY6l33fSxP8h7cBUiXXZ1yI2nM0AcKWfXoRBl48GyIVOuO4zTvS8MQ46spthnSGQ== | ||
dependencies: | ||
axios "^0.21.1" | ||
is-ip "^3.1.0" | ||
lodash "^4.17.21" | ||
lru-cache "^5.1.1" | ||
tslib "^1.10.0" | ||
url-join "^4.0.1" | ||
|
||
iron-webcrypto@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.npmjs.org/iron-webcrypto/-/iron-webcrypto-1.0.0.tgz" | ||
|
@@ -9654,6 +9683,13 @@ is-installed-globally@~0.4.0: | |
global-dirs "^3.0.0" | ||
is-path-inside "^3.0.2" | ||
|
||
is-ip@^3.1.0: | ||
version "3.1.0" | ||
resolved "https://registry.yarnpkg.com/is-ip/-/is-ip-3.1.0.tgz#2ae5ddfafaf05cb8008a62093cf29734f657c5d8" | ||
integrity sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q== | ||
dependencies: | ||
ip-regex "^4.0.0" | ||
|
||
is-map@^2.0.1: | ||
version "2.0.2" | ||
resolved "https://registry.npmjs.org/is-map/-/is-map-2.0.2.tgz" | ||
|
@@ -14360,7 +14396,7 @@ tsconfig-paths@^3.14.2: | |
minimist "^1.2.6" | ||
strip-bom "^3.0.0" | ||
|
||
[email protected], tslib@^1.11.1, tslib@^1.8.1, tslib@^1.9.0: | ||
[email protected], tslib@^1.10.0, tslib@^1.11.1, tslib@^1.8.1, tslib@^1.9.0: | ||
version "1.14.1" | ||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" | ||
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== | ||
|
@@ -14802,6 +14838,11 @@ uri-js@^4.2.2, uri-js@^4.4.1: | |
dependencies: | ||
punycode "^2.1.0" | ||
|
||
url-join@^4.0.1: | ||
version "4.0.1" | ||
resolved "https://registry.yarnpkg.com/url-join/-/url-join-4.0.1.tgz#b642e21a2646808ffa178c4c5fda39844e12cde7" | ||
integrity sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA== | ||
|
||
url-parse@^1.5.10, url-parse@^1.5.3: | ||
version "1.5.10" | ||
resolved "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz" | ||
|