Skip to content

Commit

Permalink
Merge branch 'master' into fix-build
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx authored Oct 17, 2024
2 parents 73f565f + a14da0d commit 973bb33
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 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=
60 changes: 36 additions & 24 deletions packages/arb-token-bridge-ui/src/hooks/useAccountIsBlocked.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
import { useMemo } from 'react'
import { useAccount, useNetwork } from 'wagmi'
import { useAccount } from 'wagmi'
import useSWRImmutable from 'swr/immutable'

import { ApiResponseSuccess } from '../pages/api/screenings'
import { trackEvent } from '../util/AnalyticsUtils'
import { isNetwork } from '../util/networks'
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 response = await fetch(url, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}

const searchParams = new URLSearchParams({ address })
const response = await fetch('/api/screenings?' + searchParams, {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
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 All @@ -40,21 +58,15 @@ async function fetcher(address: Address): Promise<boolean> {

export function useAccountIsBlocked() {
const { address } = useAccount()
const { chain } = useNetwork()

const queryKey = useMemo(() => {
if (typeof address === 'undefined') {
// Don't fetch
return null
}

if (isNetwork(chain?.id ?? 0).isTestnet) {
// Don't fetch
return null
}

return [address.toLowerCase(), 'useAccountIsBlocked']
}, [address, chain?.id])
}, [address])

const { data: isBlocked } = useSWRImmutable<boolean>(
queryKey,
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/src/util/fastBridges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ export const USDCFastBridges: USDCFastBridgeInfo[] = [
}: getHrefParams) => {
switch (transferMode) {
case 'deposit':
return `https://app.thevoyager.io/swap?fromChain=${from}&toChain=${to}&fromToken=${fromTokenAddress}&toToken=${toTokenAddress}`
return `https://app.routernitro.com/swap?fromChain=${from}&toChain=${to}&fromToken=${fromTokenAddress}&toToken=${toTokenAddress}`
case 'withdraw':
default:
return `https://app.thevoyager.io/swap?fromChain=${from}&toChain=${to}&fromToken=${fromTokenAddress}&toToken=${toTokenAddress}`
return `https://app.routernitro.com/swap?fromChain=${from}&toChain=${to}&fromToken=${fromTokenAddress}&toToken=${toTokenAddress}`
}
}
}
Expand Down

0 comments on commit 973bb33

Please sign in to comment.