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

Feat: Block custom swap recipients if the are in the ofac block list #3654

Merged
merged 3 commits into from
May 6, 2024
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
3 changes: 1 addition & 2 deletions src/components/common/BlockedAddress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export const BlockedAddress = ({ address }: { address?: string }): ReactElement
<Disclaimer
title="Blocked Address"
subtitle={displayAddress}
content="This signer address is blocked by the Safe interface, due to being associated with the blocked activities by
the U.S. Department of Treasury in the Specially Designated Nationals (SDN) list."
content="The above address is part of the OFAC SDN list and the embedded swaps feature with CoW Swap is unavailable for sanctioned addresses."
onAccept={handleAccept}
/>
)
Expand Down
26 changes: 18 additions & 8 deletions src/features/swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import css from './styles.module.css'
import useSafeInfo from '@/hooks/useSafeInfo'
import useWallet from '@/hooks/wallets/useWallet'
import BlockedAddress from '@/components/common/BlockedAddress'
import { isBlockedAddress } from '@/services/ofac'
import useSwapConsent from './useSwapConsent'
import Disclaimer from '@/components/common/Disclaimer'
import LegalDisclaimerContent from '@/components/common/LegalDisclaimerContent'
import { isBlockedAddress } from '@/services/ofac'
import { selectSwapParams, setSwapParams, type SwapState } from './store/swapParamsSlice'
import { setSwapOrder } from '@/store/swapOrderSlice'

Expand All @@ -50,11 +50,20 @@ const SwapWidget = ({ sell }: Params) => {
const isSwapFeatureEnabled = useHasFeature(FEATURES.NATIVE_SWAPS)
const swapParams = useAppSelector(selectSwapParams)
const { tradeType } = swapParams

const { safeAddress, safeLoading } = useSafeInfo()
const [blockedAddress, setBlockedAddress] = useState('')
const wallet = useWallet()
const { isConsentAccepted, onAccept } = useSwapConsent()

useEffect(() => {
if (isBlockedAddress(safeAddress)) {
setBlockedAddress(safeAddress)
}
if (wallet?.address && isBlockedAddress(wallet.address)) {
setBlockedAddress(wallet.address)
}
}, [safeAddress, wallet?.address])

const appData: SafeAppData = useMemo(
() => ({
id: 1,
Expand Down Expand Up @@ -127,8 +136,12 @@ const SwapWidget = ({ sell }: Params) => {
{
event: CowEvents.ON_CHANGE_TRADE_PARAMS,
handler: (newTradeParams) => {
const { orderType: tradeType } = newTradeParams
const { orderType: tradeType, recipient } = newTradeParams
dispatch(setSwapParams({ tradeType }))

if (recipient && isBlockedAddress(recipient)) {
setBlockedAddress(recipient)
}
},
},
]
Expand Down Expand Up @@ -203,11 +216,8 @@ const SwapWidget = ({ sell }: Params) => {
return null
}

if (isBlockedAddress(safeAddress)) {
return <BlockedAddress address={safeAddress} />
}
if (wallet?.address && isBlockedAddress(wallet.address)) {
return <BlockedAddress address={wallet.address} />
if (blockedAddress) {
return <BlockedAddress address={blockedAddress} />
}

if (!isConsentAccepted) {
Expand Down
Loading