-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into shazarre/delegatee_registration_form
- Loading branch information
Showing
20 changed files
with
797 additions
and
518 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 |
---|---|---|
@@ -1,5 +1,2 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn lint-staged | ||
yarn prettier | ||
yarn lint-staged --quiet | ||
yarn prettier |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,36 @@ | ||
import { headers } from 'next/headers'; | ||
import { NextResponse, type NextRequest } from 'next/server'; | ||
import { logger } from 'src/utils/logger'; | ||
|
||
export function GET(request: NextRequest) { | ||
const headerList = headers(); | ||
|
||
const country = request.geo?.country || (headerList.get('x-vercel-ip-country') as string); | ||
const region = request.geo?.region || (headerList.get('x-vercel-ip-country-region') as string); | ||
|
||
logger.info('country', country, region); | ||
|
||
if (isForbiddenLand(country, region)) { | ||
return new NextResponse(null, { status: 451 }); | ||
} | ||
|
||
return new NextResponse(null, { status: 202 }); | ||
} | ||
const RESTRICTED_COUNTRIES = new Set(['KP', 'IR', 'CU', 'SY']); | ||
|
||
// https://www.iso.org/obp/ui/#iso:code:3166:UA although listed with UA prefix. the header/api recieved that and just used the number | ||
const crimea = '43'; | ||
const luhansk = '09'; | ||
const donetska = '14'; | ||
//https://en.wikipedia.org/wiki/Russian-occupied_territories_of_Ukraine | ||
const RESTRICED_SUBREGION: Record<string, Set<string>> = { | ||
UA: new Set([crimea, luhansk, donetska]), | ||
}; | ||
|
||
function isForbiddenLand(iso3166Country: string, iso3166Region: string) { | ||
const iso3166CountryUppercase = iso3166Country?.toUpperCase(); | ||
return ( | ||
RESTRICTED_COUNTRIES.has(iso3166CountryUppercase) || | ||
RESTRICED_SUBREGION[iso3166CountryUppercase]?.has(iso3166Region) | ||
); | ||
} |
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,55 @@ | ||
import { OFAC_SANCTIONS_LIST_URL, SANCTIONED_ADDRESSES } from '@celo/compliance'; | ||
import { PropsWithChildren, useEffect } from 'react'; | ||
import { readFromCache, writeToCache } from 'src/utils/localSave'; | ||
import { useAccount, useDisconnect } from 'wagmi'; | ||
|
||
export function LegalRestrict(props: PropsWithChildren) { | ||
usePolice(); | ||
return props.children; | ||
} | ||
|
||
function usePolice() { | ||
const { address, isConnected } = useAccount(); | ||
const { disconnect } = useDisconnect(); | ||
|
||
useEffect(() => { | ||
if (isConnected && address) { | ||
isSanctionedAddress(address).then((isSanctioned) => { | ||
if (isSanctioned) { | ||
disconnect(); | ||
alert('The Address is under OFAC Sanctions'); | ||
} | ||
}); | ||
fetch('/police').then((response) => { | ||
if (response.status === 451) { | ||
disconnect(); | ||
alert('The Region is under Sanction'); | ||
} | ||
}); | ||
} | ||
}, [isConnected, address, disconnect]); | ||
} | ||
|
||
const DAY = 24 * 60 * 60 * 1000; | ||
|
||
export async function isSanctionedAddress(address: string): Promise<boolean> { | ||
const cache = readFromCache(OFAC_SANCTIONS_LIST_URL); | ||
if (cache && cache.ts + DAY > Date.now()) { | ||
return cache.data.includes(address.toLowerCase()); | ||
} | ||
|
||
const sanctionedAddresses: string[] = await fetch(OFAC_SANCTIONS_LIST_URL) | ||
.then((x) => x.json()) | ||
.catch(() => SANCTIONED_ADDRESSES); // fallback if github is down or something. | ||
|
||
if (process.env.NODE_ENV !== 'production' && process.env.TEST_SANCTIONED_ADDRESS) { | ||
sanctionedAddresses.push(process.env.TEST_SANCTIONED_ADDRESS); | ||
} | ||
|
||
writeToCache( | ||
OFAC_SANCTIONS_LIST_URL, | ||
sanctionedAddresses.map((x) => x.toLowerCase()), | ||
); | ||
|
||
return isSanctionedAddress(address); | ||
} |
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
Oops, something went wrong.