Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Block payment for sanctioned address #4167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
import { Trans } from '@lingui/macro'
import { Button } from 'antd'
import { useMemo } from 'react'
import { Button, Tooltip } from 'antd'
import { t, Trans } from '@lingui/macro'

import { useCartSummary } from '../hooks/useCartSummary'
import { useProjectIsOFACListed } from '../../../hooks/useProjectIsOFACListed'

export const SummaryPayButton = ({ className }: { className?: string }) => {
const { payProject, walletConnected } = useCartSummary()
const { isAddressListedInOFAC, isLoading: isOFACChecking } =
useProjectIsOFACListed()

const isLoading = useMemo(() => {
return Boolean(walletConnected && isOFACChecking)
}, [walletConnected, isOFACChecking])

const isDisabled = useMemo(() => {
return Boolean(walletConnected && isAddressListedInOFAC)
}, [isAddressListedInOFAC, walletConnected])

return (
<Button className={className} type="primary" onClick={payProject}>
<span>
{walletConnected ? (
<Trans>Pay project</Trans>
) : (
<Trans>Connect wallet</Trans>
)}
</span>
</Button>
<Tooltip
title={t`You can't pay this project because your wallet address failed compliance check.`}
placement="top"
open={isDisabled ? undefined : false}
>
<Button
className={className}
type="primary"
onClick={payProject}
loading={isLoading}
disabled={isDisabled}
>
<span>
{walletConnected ? (
<Trans>Pay project</Trans>
) : (
<Trans>Connect wallet</Trans>
)}
</span>
</Button>
</Tooltip>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export const MessageSection = () => {
<div className="font-medium text-bluebs-700 dark:text-bluebs-300">
<Trans>Notice from {projectName}</Trans>
</div>
<p className="mt-2 mb-0">{projectPayDisclosure}</p>
<p className="mt-2 mb-0 whitespace-pre-wrap">
{projectPayDisclosure}
</p>
</div>
</Callout>
)}
Expand Down
6 changes: 4 additions & 2 deletions src/contexts/v2v3/V2V3ProjectOFACProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { useQuery } from 'react-query'
const OFAC_API = 'https://api.wewantjusticedao.org/donation/validate'

interface ProjectOFACContextType {
isLoading?: boolean
isAddressListedInOFAC?: boolean
}

export const ProjectOFACContext = createContext<ProjectOFACContextType>({
isLoading: false,
isAddressListedInOFAC: undefined,
})

Expand All @@ -22,7 +24,7 @@ export default function V2V3ProjectOFACProvider({
const { userAddress, isConnected } = useWallet()
const { projectMetadata } = useProjectMetadata()

const { data: isAddressListedInOFAC } = useQuery(
const { data: isAddressListedInOFAC, isLoading } = useQuery(
['isAddressListedInOFAC', userAddress],
async () => {
if (!(projectMetadata?.projectRequiredOFACCheck && isConnected)) {
Expand All @@ -47,7 +49,7 @@ export default function V2V3ProjectOFACProvider({
)

return (
<ProjectOFACContext.Provider value={{ isAddressListedInOFAC }}>
<ProjectOFACContext.Provider value={{ isAddressListedInOFAC, isLoading }}>
{children}
</ProjectOFACContext.Provider>
)
Expand Down