From 770ff05cb2ca41b514137c309542b1c94857f1f4 Mon Sep 17 00:00:00 2001 From: katspaugh Date: Thu, 14 Dec 2023 15:03:56 +0100 Subject: [PATCH 1/3] Fix: use SAFE_APPS feature toggle --- src/components/sidebar/SidebarNavigation/index.tsx | 11 +++++++++-- src/pages/apps/index.tsx | 5 +++++ src/pages/apps/open.tsx | 5 ++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/sidebar/SidebarNavigation/index.tsx b/src/components/sidebar/SidebarNavigation/index.tsx index f2d5649007..62e40d9459 100644 --- a/src/components/sidebar/SidebarNavigation/index.tsx +++ b/src/components/sidebar/SidebarNavigation/index.tsx @@ -1,4 +1,4 @@ -import React, { type ReactElement } from 'react' +import React, { useMemo, type ReactElement } from 'react' import { useRouter } from 'next/router' import ListItem from '@mui/material/ListItem' import { ImplementationVersionState } from '@safe-global/safe-gateway-typescript-sdk' @@ -14,6 +14,8 @@ import { type NavItem, navItems } from './config' import useSafeInfo from '@/hooks/useSafeInfo' import { AppRoutes } from '@/config/routes' import { useQueuedTxsLength } from '@/hooks/useTxQueue' +import { useHasFeature } from '@/hooks/useChains' +import { FEATURES } from '@/utils/chains' const getSubdirectory = (pathname: string): string => { return pathname.split('/')[1] @@ -24,6 +26,11 @@ const Navigation = (): ReactElement => { const { safe } = useSafeInfo() const currentSubdirectory = getSubdirectory(router.pathname) const queueSize = useQueuedTxsLength() + const isSafeAppsEnabled = useHasFeature(FEATURES.SAFE_APPS) + + const enabledNavItems = useMemo(() => { + return isSafeAppsEnabled ? navItems : navItems.filter((item) => item.href !== AppRoutes.apps.index) + }, [isSafeAppsEnabled]) const getBadge = (item: NavItem) => { // Indicate whether the current Safe needs an upgrade @@ -49,7 +56,7 @@ const Navigation = (): ReactElement => { return ( - {navItems.map((item) => { + {enabledNavItems.map((item) => { const isSelected = currentSubdirectory === getSubdirectory(item.href) return ( diff --git a/src/pages/apps/index.tsx b/src/pages/apps/index.tsx index 07ebb69530..fe5aba8d53 100644 --- a/src/pages/apps/index.tsx +++ b/src/pages/apps/index.tsx @@ -10,6 +10,8 @@ import SafeAppList from '@/components/safe-apps/SafeAppList' import { AppRoutes } from '@/config/routes' import useSafeAppsFilters from '@/hooks/safe-apps/useSafeAppsFilters' import SafeAppsFilters from '@/components/safe-apps/SafeAppsFilters' +import { useHasFeature } from '@/hooks/useChains' +import { FEATURES } from '@/utils/chains' const SafeApps: NextPage = () => { const router = useRouter() @@ -17,6 +19,7 @@ const SafeApps: NextPage = () => { const { filteredApps, query, setQuery, setSelectedCategories, setOptimizedWithBatchFilter, selectedCategories } = useSafeAppsFilters(remoteSafeApps) const isFiltered = filteredApps.length !== remoteSafeApps.length + const isSafeAppsEnabled = useHasFeature(FEATURES.SAFE_APPS) const nonPinnedApps = useMemo( () => remoteSafeApps.filter((app) => !pinnedSafeAppIds.has(app.id)), @@ -31,6 +34,8 @@ const SafeApps: NextPage = () => { } }, [router]) + if (!isSafeAppsEnabled) return <> + return ( <> diff --git a/src/pages/apps/open.tsx b/src/pages/apps/open.tsx index 1c669c9ab5..b83e0c57dc 100644 --- a/src/pages/apps/open.tsx +++ b/src/pages/apps/open.tsx @@ -16,6 +16,8 @@ import useChainId from '@/hooks/useChainId' import { AppRoutes } from '@/config/routes' import { getOrigin } from '@/components/safe-apps/utils' import { WalletConnectContext } from '@/services/walletconnect/WalletConnectContext' +import { useHasFeature } from '@/hooks/useChains' +import { FEATURES } from '@/utils/chains' // TODO: Remove this once we properly deprecate the WC app const WC_SAFE_APP = /wallet-connect/ @@ -25,6 +27,7 @@ const SafeApps: NextPage = () => { const router = useRouter() const appUrl = useSafeAppUrl() const { safeApp, isLoading } = useSafeAppFromManifest(appUrl || '', chainId) + const isSafeAppsEnabled = useHasFeature(FEATURES.SAFE_APPS) const { remoteSafeApps, remoteSafeAppsLoading } = useSafeApps() @@ -56,7 +59,7 @@ const SafeApps: NextPage = () => { }, [router]) // appUrl is required to be present - if (!appUrl || !router.isReady) return null + if (!isSafeAppsEnabled || !appUrl || !router.isReady) return null if (WC_SAFE_APP.test(appUrl)) { setOpen(true) From 71737ee44cf72de75cbb5a2e14f2b0b29fc3f645 Mon Sep 17 00:00:00 2001 From: katspaugh Date: Thu, 14 Dec 2023 15:09:57 +0100 Subject: [PATCH 2/3] v1.25.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b60df5855e..57c0c78ed4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "safe-wallet-web", "homepage": "https://github.com/safe-global/safe-wallet-web", "license": "GPL-3.0", - "version": "1.25.0", + "version": "1.25.1", "type": "module", "scripts": { "dev": "next dev", From 2b36a312c7245e826964c9436db50143739167a0 Mon Sep 17 00:00:00 2001 From: katspaugh Date: Fri, 15 Dec 2023 08:28:26 +0100 Subject: [PATCH 3/3] Tests: fix safe apps unit tests --- src/tests/pages/apps.test.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/pages/apps.test.tsx b/src/tests/pages/apps.test.tsx index 77954d192f..84e0d11298 100644 --- a/src/tests/pages/apps.test.tsx +++ b/src/tests/pages/apps.test.tsx @@ -18,6 +18,7 @@ import AppsPage from '@/pages/apps' import CustomSafeAppsPage from '@/pages/apps/custom' import * as safeAppsService from '@/services/safe-apps/manifest' import { LS_NAMESPACE } from '@/config/constants' +import * as chainHooks from '@/hooks/useChains' jest.mock('@safe-global/safe-gateway-typescript-sdk', () => ({ ...jest.requireActual('@safe-global/safe-gateway-typescript-sdk'), @@ -33,6 +34,7 @@ describe('AppsPage', () => { beforeEach(() => { jest.restoreAllMocks() window.localStorage.clear() + jest.spyOn(chainHooks, 'useHasFeature').mockImplementation(() => true) }) describe('Safe Apps List Page', () => {