Skip to content

Commit

Permalink
feat: migrate to external screening api (#1990)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglance authored Oct 16, 2024
1 parent 4267958 commit a14da0d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/arb-token-bridge-ui/.env.local.sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ SELF_HOSTED_SUBGRAPH_API_KEY=

SCREENING_API_ENDPOINT=
SCREENING_API_KEY=
NEXT_PUBLIC_SCREENING_API_ENDPOINT=

NEXT_PUBLIC_POSTHOG_KEY=
49 changes: 34 additions & 15 deletions packages/arb-token-bridge-ui/src/hooks/useAccountIsBlocked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>} true if blocked or the request fails
*/
async function isBlocked(address: Address): Promise<boolean> {
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<boolean> {
Expand Down

0 comments on commit a14da0d

Please sign in to comment.