Skip to content

Commit

Permalink
05 24 fix OFAC compliance (#4337)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraeth-eth authored May 24, 2024
1 parent 1781a9d commit d88f40b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useCurrencyConverter } from 'hooks/useCurrencyConverter'
import { useProjectLogoSrc } from 'hooks/useProjectLogoSrc'
import { useETHReceivedFromTokens } from 'hooks/v2v3/contractReader/useETHReceivedFromTokens'
import { useRedeemTokensTx } from 'hooks/v2v3/transactor/useRedeemTokensTx'
import { usePayProjectDisabled } from 'hooks/v2v3/usePayProjectDisabled'
import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react'
import { twMerge } from 'tailwind-merge'
import { formatAmount } from 'utils/format/formatAmount'
Expand Down Expand Up @@ -415,6 +416,7 @@ const PayConfiguration: React.FC<PayConfigurationProps> = ({
projectHasErc20Token,
payerIssuanceRate,
}) => {
const { payDisabled, message } = usePayProjectDisabled()
const { tokenSymbol } = useProjectContext()
const chosenNftRewards = useProjectSelector(
state => state.projectCart.chosenNftRewards,
Expand Down Expand Up @@ -484,8 +486,13 @@ const PayConfiguration: React.FC<PayConfigurationProps> = ({

const payButtonDisabled = useMemo(() => {
if (!walletConnected) return false
return insufficientBalance || cartPayAmount === 0 || !cartPayAmount
}, [cartPayAmount, insufficientBalance, walletConnected])
return (
insufficientBalance ||
cartPayAmount === 0 ||
!cartPayAmount ||
payDisabled
)
}, [cartPayAmount, insufficientBalance, payDisabled, walletConnected])

return (
<div>
Expand Down Expand Up @@ -533,23 +540,26 @@ const PayConfiguration: React.FC<PayConfigurationProps> = ({
</div>
</div>

<Button
type="primary"
className="mt-6 w-full"
size="large"
disabled={payButtonDisabled}
onClick={payProject}
>
{walletConnected ? (
insufficientBalance ? (
<Trans>Insufficient balance</Trans>
<Tooltip className="w-full flex-1" title={message}>
<Button
style={{ display: 'block', width: '100%' }}
type="primary"
className="mt-6"
size="large"
disabled={payButtonDisabled}
onClick={payProject}
>
{walletConnected ? (
insufficientBalance ? (
<Trans>Insufficient balance</Trans>
) : (
<Trans>Pay project</Trans>
)
) : (
<Trans>Pay project</Trans>
)
) : (
<Trans>Connect wallet</Trans>
)}
</Button>
<Trans>Connect wallet</Trans>
)}
</Button>
</Tooltip>
</div>
)
}
Expand Down
29 changes: 29 additions & 0 deletions src/hooks/v2v3/transactor/usePayETHPaymentTerminalTx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { t } from '@lingui/macro'
import { useProjectIsOFACListed } from 'components/v2v3/V2V3Project/ProjectDashboard/hooks/useProjectIsOFACListed'
import { DEFAULT_MIN_RETURNED_TOKENS } from 'constants/transactionDefaults'
import { ETH_TOKEN_ADDRESS } from 'constants/v2v3/juiceboxTokens'
import { TransactionContext } from 'contexts/Transaction/TransactionContext'
Expand All @@ -7,6 +8,7 @@ import { V2V3ProjectContractsContext } from 'contexts/v2v3/ProjectContracts/V2V3
import { BigNumber } from 'ethers'
import { TransactorInstance } from 'hooks/useTransactor'
import { useContext } from 'react'
import { useV2V3BlockedProject } from '../useBlockedProject'
import { useV2ProjectTitle } from '../useProjectTitle'

const DEFAULT_DELEGATE_METADATA = 0
Expand All @@ -26,6 +28,12 @@ export function usePayETHPaymentTerminalTx(): PayV2ProjectTx {

const projectTitle = useV2ProjectTitle()

// Blocked project
const isBlockedProject = useV2V3BlockedProject()
// OFAC Compliance
const { isAddressListedInOFAC, isLoading: isOFACLoading } =
useProjectIsOFACListed()

return (
{ memo, preferClaimedTokens, beneficiary, value, delegateMetadata },
txOpts,
Expand All @@ -40,6 +48,27 @@ export function usePayETHPaymentTerminalTx(): PayV2ProjectTx {
return Promise.resolve(false)
}

if (isBlockedProject) {
txOpts?.onError?.(
new Error(t`This project has been delisted and can't be paid.`),
)
return Promise.resolve(false)
}
if (isOFACLoading) {
txOpts?.onError?.(
new Error(t`Compliance check is in progress. Please try again shortly`),
)
return Promise.resolve(false)
}
if (isAddressListedInOFAC) {
txOpts?.onError?.(
new Error(
t`You can't pay this project because your wallet address failed a compliance check set up by the project owner.`,
),
)
return Promise.resolve(false)
}

return transactor(
contracts.JBETHPaymentTerminal,
'pay',
Expand Down
3 changes: 3 additions & 0 deletions src/locales/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4637,6 +4637,9 @@ msgstr ""
msgid "Do not include .eth"
msgstr ""

msgid "Compliance check is in progress. Please try again shortly"
msgstr ""

msgid "Collection symbol"
msgstr ""

Expand Down
8 changes: 4 additions & 4 deletions src/styles/antd-overrides/tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
}

.ant-tooltip-arrow-content::before {
background: theme('colors.slate.600');
background: theme('colors.slate.600');
}

.dark .ant-tooltip-arrow-content::before {
background: theme('colors.smoke.100')
background: theme('colors.smoke.100');
}

.ant-tooltip-disabled-compatible-wrapper.block {
display: block !important;
}

.ant-tooltip-content a {
@apply text-bluebs-300 dark:text-bluebs-600 hover:text-bluebs-400 dark:hover:text-bluebs-500 hover:underline;
}
@apply text-bluebs-300 hover:text-bluebs-400 hover:underline dark:text-bluebs-600 dark:hover:text-bluebs-500;
}

0 comments on commit d88f40b

Please sign in to comment.