Skip to content

Commit

Permalink
feat: add ofac blocking for the stake page
Browse files Browse the repository at this point in the history
  • Loading branch information
compojoom committed Sep 19, 2024
1 parent ac04fba commit bf53aea
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/common/BlockedAddress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useRouter } from 'next/router'
import Disclaimer from '@/components/common/Disclaimer'
import { AppRoutes } from '@/config/routes'

export const BlockedAddress = ({ address }: { address?: string }): ReactElement => {
export const BlockedAddress = ({ address, featureTitle }: { address: string; featureTitle: string }): ReactElement => {
const theme = useTheme()
const isMobile = useMediaQuery(theme.breakpoints.down('sm'))
const displayAddress = address && isMobile ? shortenAddress(address) : address
Expand All @@ -19,7 +19,7 @@ export const BlockedAddress = ({ address }: { address?: string }): ReactElement
<Disclaimer
title="Blocked address"
subtitle={displayAddress}
content="The above address is part of the OFAC SDN list and the embedded swaps feature with CoW Swap is unavailable for sanctioned addresses."
content={`The above address is part of the OFAC SDN list and the ${featureTitle} is unavailable for sanctioned addresses.`}
onAccept={handleAccept}
/>
)
Expand Down
26 changes: 26 additions & 0 deletions src/features/stake/components/StakePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,38 @@ import WidgetDisclaimer from '@/components/common/WidgetDisclaimer'
import useStakeConsent from '@/features/stake/useStakeConsent'
import StakingWidget from '../StakingWidget'
import { useRouter } from 'next/router'
import { useGetIsSanctionedQuery } from '@/store/ofac'
import { skipToken } from '@reduxjs/toolkit/query/react'
import useWallet from '@/hooks/wallets/useWallet'
import useSafeInfo from '@/hooks/useSafeInfo'
import { getKeyWithTrueValue } from '@/utils/helpers'
import BlockedAddress from '@/components/common/BlockedAddress'

const StakePage = () => {
const { isConsentAccepted, onAccept } = useStakeConsent()
const router = useRouter()
const { asset } = router.query

const { safeAddress } = useSafeInfo()
const wallet = useWallet()

const { data: isSafeAddressBlocked } = useGetIsSanctionedQuery(safeAddress || skipToken)
const { data: isWalletAddressBlocked } = useGetIsSanctionedQuery(wallet?.address || skipToken)
const blockedAddresses = {
[safeAddress]: !!isSafeAddressBlocked,
[wallet?.address || '']: !!isWalletAddressBlocked,
}

const blockedAddress = getKeyWithTrueValue(blockedAddresses)

if (blockedAddress) {
return (
<Stack direction="column" alignItems="center" justifyContent="center" flex={1}>
<BlockedAddress address={blockedAddress} featureTitle="stake feature with Kiln" />
</Stack>
)
}

return (
<>
{isConsentAccepted === undefined ? null : isConsentAccepted ? (
Expand Down
2 changes: 1 addition & 1 deletion src/features/swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ const SwapWidget = ({ sell }: Params) => {
useCustomAppCommunicator(iframeRef, appData, chain)

if (blockedAddress) {
return <BlockedAddress address={blockedAddress} />
return <BlockedAddress address={blockedAddress} featureTitle="embedded swaps feature with CoW Swap" />
}

if (!isConsentAccepted) {
Expand Down

0 comments on commit bf53aea

Please sign in to comment.