From d88f40bb9e37ab47f4816919661bdec107828efc Mon Sep 17 00:00:00 2001 From: wraeth-eth <104132113+wraeth-eth@users.noreply.github.com> Date: Fri, 24 May 2024 12:35:36 +1000 Subject: [PATCH] 05 24 fix OFAC compliance (#4337) --- .../components/PayRedeemCard.tsx | 46 +++++++++++-------- .../transactor/usePayETHPaymentTerminalTx.ts | 29 ++++++++++++ src/locales/messages.pot | 3 ++ src/styles/antd-overrides/tooltip.scss | 8 ++-- 4 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/components/v2v3/V2V3Project/ProjectDashboard/components/PayRedeemCard.tsx b/src/components/v2v3/V2V3Project/ProjectDashboard/components/PayRedeemCard.tsx index 9647864f09..280e1c28bf 100644 --- a/src/components/v2v3/V2V3Project/ProjectDashboard/components/PayRedeemCard.tsx +++ b/src/components/v2v3/V2V3Project/ProjectDashboard/components/PayRedeemCard.tsx @@ -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' @@ -415,6 +416,7 @@ const PayConfiguration: React.FC = ({ projectHasErc20Token, payerIssuanceRate, }) => { + const { payDisabled, message } = usePayProjectDisabled() const { tokenSymbol } = useProjectContext() const chosenNftRewards = useProjectSelector( state => state.projectCart.chosenNftRewards, @@ -484,8 +486,13 @@ const PayConfiguration: React.FC = ({ 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 (
@@ -533,23 +540,26 @@ const PayConfiguration: React.FC = ({
- + Connect wallet + )} + + ) } diff --git a/src/hooks/v2v3/transactor/usePayETHPaymentTerminalTx.ts b/src/hooks/v2v3/transactor/usePayETHPaymentTerminalTx.ts index 63a21075d8..92b29a2fcb 100644 --- a/src/hooks/v2v3/transactor/usePayETHPaymentTerminalTx.ts +++ b/src/hooks/v2v3/transactor/usePayETHPaymentTerminalTx.ts @@ -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' @@ -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 @@ -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, @@ -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', diff --git a/src/locales/messages.pot b/src/locales/messages.pot index c97df468b9..a8e55d9e0a 100644 --- a/src/locales/messages.pot +++ b/src/locales/messages.pot @@ -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 "" diff --git a/src/styles/antd-overrides/tooltip.scss b/src/styles/antd-overrides/tooltip.scss index a6a5a8c0f3..32ae888c8d 100644 --- a/src/styles/antd-overrides/tooltip.scss +++ b/src/styles/antd-overrides/tooltip.scss @@ -8,11 +8,11 @@ } .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 { @@ -20,5 +20,5 @@ } .ant-tooltip-content a { - @apply text-bluebs-300 dark:text-bluebs-600 hover:text-bluebs-400 dark:hover:text-bluebs-500 hover:underline; -} \ No newline at end of file + @apply text-bluebs-300 hover:text-bluebs-400 hover:underline dark:text-bluebs-600 dark:hover:text-bluebs-500; +}