diff --git a/api/geoblock.js b/api/geoblock.js new file mode 100644 index 0000000000..38855d30fd --- /dev/null +++ b/api/geoblock.js @@ -0,0 +1,46 @@ +export const config = { + runtime: 'edge', +}; + +const blockedCountries = [ + 'AL', + 'BS', + 'BB', + 'BW', + 'KH', + 'KP', + 'GH', + 'JM', + 'MY', + 'MU', + 'MM', + 'NI', + 'ID', + 'IR', + 'AF', + 'PK', + 'CN', + 'PA', + 'AM', + 'GN', + 'IQ', + 'RW', + 'RS', + 'SY', + 'TH', + 'UG', + 'TZ', + 'US', + 'YE', + 'ZW' +]; + +function isGeoblocked(req) { + // https://vercel.com/docs/concepts/edge-network/headers#x-vercel-ip-country + const countryCode = req.headers.get('x-vercel-ip-country') + return blockedCountries.includes(countryCode) +} + +export default (req) => { + return new Response(null, { status: isGeoblocked(req) ? 403 : 200 }) +}; \ No newline at end of file diff --git a/package.json b/package.json index 82a98a690d..a7a04ec4d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "interbtc-ui", - "version": "2.31.2", + "version": "2.31.3", "private": true, "dependencies": { "@craco/craco": "^6.1.1", diff --git a/src/utils/hooks/api/use-get-prices.tsx b/src/utils/hooks/api/use-get-prices.tsx index 0e9cbb817f..6526f96a65 100644 --- a/src/utils/hooks/api/use-get-prices.tsx +++ b/src/utils/hooks/api/use-get-prices.tsx @@ -9,6 +9,7 @@ import { StoreType } from '@/common/types/util.types'; import { PRICES_API, REFETCH_INTERVAL } from '@/utils/constants/api'; import { COINGECKO_ID_BY_CURRENCY_TICKER } from '@/utils/constants/currency'; +import { FeatureFlags, useFeatureFlag } from '../use-feature-flag'; import { useGetCurrencies } from './use-get-currencies'; // MEMO: Returns `undefined` for currencies without coingecko ID. @@ -71,7 +72,10 @@ const getPricesByTicker = (currencies: CurrencyExt[], prices: Prices, lendTokenP return { ...acc, [currency.ticker]: prices[coingeckoId] }; }, {}); -const getPrices = async (currencies?: CurrencyExt[]): Promise => { +const getPrices = async ( + currencies: CurrencyExt[] | undefined, + isLendingEnabled: boolean +): Promise => { if (!currencies) { return; } @@ -82,7 +86,7 @@ const getPrices = async (currencies?: CurrencyExt[]): Promise { const { bridgeLoaded } = useSelector((state: StoreType) => state.general); const { data: currencies, isSuccess: isGetCurrenciesSuccess } = useGetCurrencies(bridgeLoaded); + const isLendingEnabled = useFeatureFlag(FeatureFlags.LENDING); // TODO: error prone because the key computation is not complete - const { data, error } = useQuery(['prices'], () => getPrices(currencies), { - enabled: isGetCurrenciesSuccess, - refetchInterval: REFETCH_INTERVAL.MINUTE - }); + const { data, error } = useQuery( + ['prices'], + () => getPrices(currencies, isLendingEnabled), + { + enabled: isGetCurrenciesSuccess, + refetchInterval: REFETCH_INTERVAL.MINUTE + } + ); useEffect(() => { if (!error) return; diff --git a/vercel.json b/vercel.json index 8d328b305c..26b9642e89 100644 --- a/vercel.json +++ b/vercel.json @@ -25,6 +25,10 @@ { "source": "/terms/(.*)", "destination": "/api/terms.js" + }, + { + "source": "/check_access", + "destination": "/api/geoblock.js" } ], "headers": [