Skip to content

Commit

Permalink
Merge pull request #1211 from interlay/tom/release/interlay/2.31.3
Browse files Browse the repository at this point in the history
[release] Interlay 2.31.3
  • Loading branch information
tomjeatt authored May 18, 2023
2 parents edb090a + 369cd26 commit b4ad444
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
46 changes: 46 additions & 0 deletions api/geoblock.js
Original file line number Diff line number Diff line change
@@ -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 })
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interbtc-ui",
"version": "2.31.2",
"version": "2.31.3",
"private": true,
"dependencies": {
"@craco/craco": "^6.1.1",
Expand Down
21 changes: 15 additions & 6 deletions src/utils/hooks/api/use-get-prices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -71,7 +72,10 @@ const getPricesByTicker = (currencies: CurrencyExt[], prices: Prices, lendTokenP
return { ...acc, [currency.ticker]: prices[coingeckoId] };
}, {});

const getPrices = async (currencies?: CurrencyExt[]): Promise<Prices | undefined> => {
const getPrices = async (
currencies: CurrencyExt[] | undefined,
isLendingEnabled: boolean
): Promise<Prices | undefined> => {
if (!currencies) {
return;
}
Expand All @@ -82,7 +86,7 @@ const getPrices = async (currencies?: CurrencyExt[]): Promise<Prices | undefined

const [pricesByCoingeckoId, lendTokenPrices] = await Promise.all([
fetchPricesFromCoingecko(endpoint),
window.bridge.loans.getLendTokenExchangeRates()
isLendingEnabled ? window.bridge.loans.getLendTokenExchangeRates() : {}
]);

return getPricesByTicker(allCurrencies, pricesByCoingeckoId, lendTokenPrices);
Expand All @@ -100,12 +104,17 @@ type Prices = {
const useGetPrices = (): Prices | undefined => {
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 | undefined, Error>(['prices'], () => getPrices(currencies), {
enabled: isGetCurrenciesSuccess,
refetchInterval: REFETCH_INTERVAL.MINUTE
});
const { data, error } = useQuery<Prices | undefined, Error>(
['prices'],
() => getPrices(currencies, isLendingEnabled),
{
enabled: isGetCurrenciesSuccess,
refetchInterval: REFETCH_INTERVAL.MINUTE
}
);

useEffect(() => {
if (!error) return;
Expand Down
4 changes: 4 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
{
"source": "/terms/(.*)",
"destination": "/api/terms.js"
},
{
"source": "/check_access",
"destination": "/api/geoblock.js"
}
],
"headers": [
Expand Down

1 comment on commit b4ad444

@vercel
Copy link

@vercel vercel bot commented on b4ad444 May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.