Skip to content

Commit 57035f5

Browse files
committed
feat: improve ofac v4 security
1 parent afe61bb commit 57035f5

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/packages/v4/components/ProjectDashboard/V4PayRedeemCard/PayProjectModal/PayProjectModal.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
usePayProjectModal,
55
} from './hooks/usePayProjectModal/usePayProjectModal'
66
import { Trans, t } from '@lingui/macro'
7+
import { emitErrorNotification, emitInfoNotification } from 'utils/notifications'
78
import { useEffect, useState } from 'react'
89
import { useProjectDispatch, useProjectSelector } from '../../redux/hooks'
910

@@ -15,11 +16,11 @@ import Image from 'next/legacy/image'
1516
import { JuiceModal } from 'components/modals/JuiceModal'
1617
import { MessageSection } from './components/MessageSection'
1718
import { ReceiveSection } from './components/ReceiveSection'
18-
import { emitInfoNotification } from 'utils/notifications'
1919
import { helpPagePath } from 'utils/helpPagePath'
2020
import { payRedeemActions } from '../../redux/payRedeemSlice'
2121
import { twMerge } from 'tailwind-merge'
2222
import { usePayAmounts } from './hooks/usePayAmounts'
23+
import { useProjectIsOFACListed } from 'hooks/useProjectIsOFACListed'
2324
import { useSuckers } from 'juice-sdk-react'
2425
import { useV4UserNftCredits } from 'packages/v4/contexts/V4UserNftCreditsProvider'
2526
import { useWallet } from 'hooks/Wallet'
@@ -44,6 +45,8 @@ export const PayProjectModal: React.FC = () => {
4445
useState<JBChainId>(defaultChainId)
4546
const dispatch = useProjectDispatch()
4647
const { data: suckers } = useSuckers()
48+
const { isAddressListedInOFAC, isLoading: isOFACLoading } =
49+
useProjectIsOFACListed()
4750

4851
useEffect(() => {
4952
setSelectedChainId(defaultChainId)
@@ -70,6 +73,12 @@ export const PayProjectModal: React.FC = () => {
7073
}}
7174
validationSchema={validationSchema}
7275
onSubmit={async (values, actions) => {
76+
if (isAddressListedInOFAC) {
77+
emitErrorNotification(
78+
t`You can't pay this project because your wallet address failed a compliance check set up by the project owner.`,
79+
)
80+
return
81+
}
7382
const walletConnectedToWrongChain = selectedChainId !== walletChainId
7483
if (walletConnectedToWrongChain) {
7584
await changeNetworks(selectedChainId as JBChainId)
@@ -99,7 +108,7 @@ export const PayProjectModal: React.FC = () => {
99108
buttonPosition="stretch"
100109
title={t`Pay ${projectName}`}
101110
position="top"
102-
okLoading={props.isSubmitting || isTransactionPending}
111+
okLoading={props.isSubmitting || isTransactionPending || isOFACLoading}
103112
okButtonForm="PayProjectModalForm"
104113
okText={
105114
walletConnectedToWrongChain
@@ -118,6 +127,7 @@ export const PayProjectModal: React.FC = () => {
118127
setOpen(false)
119128
setTimeout(() => props.resetForm(), 300)
120129
}}
130+
disableOkButton={Boolean(isAddressListedInOFAC)}
121131
>
122132
{isTransactionPending ? (
123133
<div className="flex h-full w-full flex-col items-center justify-center">

src/packages/v4/hooks/usePayProjectDisabled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useJBChainId, useJBProjectId, useJBRuleset } from 'juice-sdk-react'
22

33
import { t } from '@lingui/macro'
4-
import { useProjectMetadataContext } from 'contexts/ProjectMetadataContext'
54
import { useProjectIsOFACListed } from 'hooks/useProjectIsOFACListed'
5+
import { useProjectMetadataContext } from 'contexts/ProjectMetadataContext'
66

77
export enum PayDisabledReason {
88
BLOCKED = 'BLOCKED',

0 commit comments

Comments
 (0)