diff --git a/src/components/settings/FallbackHandler/__tests__/index.test.tsx b/src/components/settings/FallbackHandler/__tests__/index.test.tsx index 3d7abd727f..4e5d144a6d 100644 --- a/src/components/settings/FallbackHandler/__tests__/index.test.tsx +++ b/src/components/settings/FallbackHandler/__tests__/index.test.tsx @@ -1,3 +1,4 @@ +import { TWAP_FALLBACK_HANDLER } from '@/features/swap/helpers/utils' import { chainBuilder } from '@/tests/builders/chains' import { render, waitFor } from '@/tests/test-utils' @@ -238,4 +239,50 @@ describe('FallbackHandler', () => { expect(fbHandler.container).toBeEmptyDOMElement() }) + + it('should display a message in case it is a TWAP fallback handler', () => { + jest.spyOn(useSafeInfoHook, 'default').mockImplementation( + () => + ({ + safe: { + version: '1.3.0', + chainId: '1', + fallbackHandler: { + value: TWAP_FALLBACK_HANDLER, + }, + }, + } as unknown as ReturnType), + ) + + const { getByText } = render() + + expect( + getByText( + "This is CoW's fallback handler. It is needed for this Safe to be able to use the TWAP feature for Swaps.", + ), + ).toBeInTheDocument() + }) + + it('should not display a message in case it is a TWAP fallback handler on an unsupported network', () => { + jest.spyOn(useSafeInfoHook, 'default').mockImplementation( + () => + ({ + safe: { + version: '1.3.0', + chainId: '10', + fallbackHandler: { + value: TWAP_FALLBACK_HANDLER, + }, + }, + } as unknown as ReturnType), + ) + + const { queryByText } = render() + + expect( + queryByText( + "This is CoW's fallback handler. It is needed for this Safe to be able to use the TWAP feature for Swaps.", + ), + ).not.toBeInTheDocument() + }) }) diff --git a/src/components/settings/FallbackHandler/index.tsx b/src/components/settings/FallbackHandler/index.tsx index 7aa77ac6ec..3bdd6f8ff2 100644 --- a/src/components/settings/FallbackHandler/index.tsx +++ b/src/components/settings/FallbackHandler/index.tsx @@ -1,4 +1,5 @@ -import { TWAP_FALLBACK_HANDLER } from '@/features/swap/helpers/utils' +import { TWAP_FALLBACK_HANDLER, TWAP_FALLBACK_HANDLER_NETWORKS } from '@/features/swap/helpers/utils' +import { getCompatibilityFallbackHandlerDeployments } from '@safe-global/safe-deployments' import NextLink from 'next/link' import { Typography, Box, Grid, Paper, Link, Alert } from '@mui/material' import semverSatisfies from 'semver/functions/satisfies' @@ -7,7 +8,6 @@ import type { ReactElement } from 'react' import EthHashInfo from '@/components/common/EthHashInfo' import useSafeInfo from '@/hooks/useSafeInfo' -import { getFallbackHandlerContractDeployment } from '@/services/contracts/deployments' import { HelpCenterArticle } from '@/config/constants' import ExternalLink from '@/components/common/ExternalLink' import { useTxBuilderApp } from '@/hooks/safe-apps/useTxBuilderApp' @@ -22,11 +22,12 @@ export const FallbackHandler = (): ReactElement | null => { const supportsFallbackHandler = !!safe.version && semverSatisfies(safe.version, FALLBACK_HANDLER_VERSION) - const fallbackHandlerDeployment = useMemo(() => { - if (!chain) { + const fallbackHandlerDeployments = useMemo(() => { + if (!chain || !safe.version) { return undefined } - return getFallbackHandlerContractDeployment(chain, safe.version) + + return getCompatibilityFallbackHandlerDeployments({ network: chain?.chainId, version: safe.version }) }, [safe.version, chain]) if (!supportsFallbackHandler) { @@ -35,8 +36,10 @@ export const FallbackHandler = (): ReactElement | null => { const hasFallbackHandler = !!safe.fallbackHandler const isOfficial = - hasFallbackHandler && safe.fallbackHandler?.value === fallbackHandlerDeployment?.networkAddresses[safe.chainId] - const isTWAPFallbackHandler = safe.fallbackHandler?.value === TWAP_FALLBACK_HANDLER + safe.fallbackHandler && + fallbackHandlerDeployments?.networkAddresses[safe.chainId].includes(safe.fallbackHandler.value) + const isTWAPFallbackHandler = + safe.fallbackHandler?.value === TWAP_FALLBACK_HANDLER && TWAP_FALLBACK_HANDLER_NETWORKS.includes(safe.chainId) const warning = !hasFallbackHandler ? ( <> @@ -101,7 +104,7 @@ export const FallbackHandler = (): ReactElement | null => { {safe.fallbackHandler && ( , ): number => {