Skip to content

Commit

Permalink
fix: proxy ofac (#4191)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomquirk authored Jan 13, 2024
1 parent 05b4232 commit 448945b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
1 change: 0 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const CONNECT_SRC = [
'wss://*.hotjar.com',
'https://*.safe.global',
'https://*.snapshot.org',
'https://api.wewantjusticedao.org', // OFAC check
'https://*.wallet.coinbase.com',
...WALLET_CONNECT_URLS,
'https://*.supabase.co',
Expand Down
4 changes: 1 addition & 3 deletions src/contexts/v2v3/V2V3ProjectOFACProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { useWallet } from 'hooks/Wallet'
import { ReactNode, createContext } from 'react'
import { useQuery } from 'react-query'

const OFAC_API = 'https://api.wewantjusticedao.org/donation/validate'

interface ProjectOFACContextType {
isLoading?: boolean
isAddressListedInOFAC?: boolean
Expand Down Expand Up @@ -35,7 +33,7 @@ export default function V2V3ProjectOFACProvider({

try {
const { data } = await axios.get<{ isGoodAddress: boolean }>(
`${OFAC_API}?address=${userAddress}`,
`/api/ofac/validate/${userAddress}`,
)

return !data.isGoodAddress
Expand Down
32 changes: 32 additions & 0 deletions src/pages/api/ofac/validate/[address].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import axios from 'axios'
import { isAddress } from 'ethers/lib/utils'
import { getLogger } from 'lib/logger'
import { NextApiRequest, NextApiResponse } from 'next'

const OFAC_API = 'https://api.wewantjusticedao.org/donation/validate'

const logger = getLogger('api/ofac/validate/[address]')

/**
* Get project data from project handle
*/
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
const { address } = req.query as { address: string }
if (!address || !isAddress(address)) {
return res.status(400).json({ error: 'address is required' })
}

const {
data: { isGoodAddress },
} = await axios.get<{ isGoodAddress: boolean }>(
`${OFAC_API}?address=${address}`,
)

// cache for a day
// res.setHeader('Cache-Control', 's-maxage=86400, stale-while-revalidate')
logger.info({ data: { address, isGoodAddress } })
return res.status(200).json({ isGoodAddress })
}

2 comments on commit 448945b

@vercel
Copy link

@vercel vercel bot commented on 448945b Jan 13, 2024

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 448945b Jan 13, 2024

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.