diff --git a/packages/arb-token-bridge-ui/.env.local.sample b/packages/arb-token-bridge-ui/.env.local.sample index f1b1d7ea73..9ccb08c10a 100644 --- a/packages/arb-token-bridge-ui/.env.local.sample +++ b/packages/arb-token-bridge-ui/.env.local.sample @@ -26,5 +26,6 @@ SELF_HOSTED_SUBGRAPH_API_KEY= SCREENING_API_ENDPOINT= SCREENING_API_KEY= +NEXT_PUBLIC_SCREENING_API_ENDPOINT= NEXT_PUBLIC_POSTHOG_KEY= diff --git a/packages/arb-token-bridge-ui/src/hooks/useAccountIsBlocked.ts b/packages/arb-token-bridge-ui/src/hooks/useAccountIsBlocked.ts index d93791cfc4..81f5a677d6 100644 --- a/packages/arb-token-bridge-ui/src/hooks/useAccountIsBlocked.ts +++ b/packages/arb-token-bridge-ui/src/hooks/useAccountIsBlocked.ts @@ -2,29 +2,48 @@ import { useMemo } from 'react' import { useAccount } from 'wagmi' import useSWRImmutable from 'swr/immutable' -import { ApiResponseSuccess } from '../pages/api/screenings' import { trackEvent } from '../util/AnalyticsUtils' import { Address } from '../util/AddressUtils' +import { captureSentryErrorWithExtraData } from '../util/SentryUtils' +/** + * Checks if an address is blocked using the external Screenings API service. + * @param {Address} address - The address to check. + * @returns {Promise} true if blocked or the request fails + */ async function isBlocked(address: Address): Promise { - if ( - process.env.NODE_ENV !== 'production' || - process.env.NEXT_PUBLIC_IS_E2E_TEST - ) { - return false - } + try { + if ( + process.env.NODE_ENV !== 'production' || + process.env.NEXT_PUBLIC_IS_E2E_TEST + ) { + return false + } + + const url = new URL(process.env.NEXT_PUBLIC_SCREENING_API_ENDPOINT ?? '') + url.searchParams.set('address', address) - const searchParams = new URLSearchParams({ address }) - const response = await fetch('/api/screenings?' + searchParams, { - method: 'GET', - headers: { 'Content-Type': 'application/json' } - }) + const response = await fetch(url, { + method: 'GET', + headers: { 'Content-Type': 'application/json' } + }) + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + + const { blocked } = await response.json() + return blocked + } catch (error) { + console.error('Failed to check if address is blocked', error) + captureSentryErrorWithExtraData({ + error, + originFunction: 'isBlocked', + additionalData: { address } + }) - if (!response.ok) { return false } - - return ((await response.json()) as ApiResponseSuccess).blocked } async function fetcher(address: Address): Promise {