Skip to content

Commit

Permalink
feat: stake OFAC check (#4203)
Browse files Browse the repository at this point in the history
* feat: add ofac blocking for the stake page

* fix: keep ofac query data for 24h

Currently once we do the ofac check the data will be discarded after 60s
(if no active listeners) and whenever we navigate to a page that needs
that data a new call to the rpc is going to be made. With this change
the data will be kept for up to 24h (if no active listener).
  • Loading branch information
compojoom authored Sep 19, 2024
1 parent 7165aea commit e5cad45
Show file tree
Hide file tree
Showing 4 changed files with 30 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
1 change: 1 addition & 0 deletions src/store/ofac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const ofacApi = createApi({
return { error: { status: 'CUSTOM_ERROR', data: (error as Error).message } }
}
},
keepUnusedDataFor: 24 * 60 * 60, // 24 hours
}),
}),
})
Expand Down

0 comments on commit e5cad45

Please sign in to comment.