diff --git a/package.json b/package.json index d0119a77..450d1720 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "scripts": { "build": "PUBLIC_PATH=https://suite.camino.network/ EXPLORER_PATH=https://suite.camino.network/explorer/ WALLET_PATH=https://suite.camino.network/wallet/ DAC_PATH=https://suite.camino.network/dac/ webpack --config webpack.prod.js", - "build:dev": "PUBLIC_PATH=https://dev.suite.camino.network/ EXPLORER_PATH=https://dev.suite.camino.network/explorer/ WALLET_PATH=https://dev.suite.camino.network/wallet/ DAC_PATH=https://suite.camino.network/dac/ webpack --config webpack.dev.js", + "build:dev": "PUBLIC_PATH=https://dev.suite.camino.network/ EXPLORER_PATH=https://dev.suite.camino.network/explorer/ WALLET_PATH=https://dev.suite.camino.network/wallet/ DAC_PATH=https://dev.suite.camino.network/dac/ webpack --config webpack.dev.js", "build:stage": "PUBLIC_PATH=https://stage.suite.camino.network/ EXPLORER_PATH=https://stage.suite.camino.network/explorer/ WALLET_PATH=https://stage.suite.camino.network/wallet/ DAC_PATH=https://suite.camino.network/dac/ webpack --config webpack.prod.js", "build:start": "cd dist && PORT=5001 npx serve", "start": "webpack-dev-server --config webpack.local.js", diff --git a/src/components/PlatformSwitcher.tsx b/src/components/PlatformSwitcher.tsx index dc2919ac..142e6371 100644 --- a/src/components/PlatformSwitcher.tsx +++ b/src/components/PlatformSwitcher.tsx @@ -5,6 +5,7 @@ import React, { useEffect, useState } from 'react' import { useDispatch } from 'react-redux' import { useNavigate } from 'react-router-dom' import { useAppSelector } from '../hooks/reduxHooks' +import useNetwork from '../hooks/useNetwork' import useWallet from '../hooks/useWallet' import useWidth from '../hooks/useWidth' import { @@ -27,24 +28,28 @@ export default function PlatformSwitcher() { const { isDesktop } = useWidth() const dispatch = useDispatch() const { getUpgradePhases } = useWallet() - const [featureEnabled, setFeatureEnabled] = useState(false) + const { status } = useNetwork() useEffect(() => { - checkFeature() + if (status === 'succeeded') { + checkFeature() + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [activeNetwork]) + }, [activeNetwork, status]) const checkFeature = async () => { - try { - const phases = await getUpgradePhases() - const enabled = await isFeatureEnabled('DACFeature', activeNetwork?.url, phases) - setFeatureEnabled(enabled) - } catch (error) { - setFeatureEnabled(false) - } + const phases = await getUpgradePhases() + const enabled = await isFeatureEnabled('DACFeature', activeNetwork?.url, phases) + setFeatureEnabled(enabled) } + useEffect(() => { + const currentApp = allApps[activeApp] + if (currentApp?.name === 'DAC' && !featureEnabled) { + dispatch(changeActiveApp('Network')) + } + }, [featureEnabled, allApps, activeApp, dispatch]) return ( navigate(app.url)} - data-cy={`app-selector-${app.name}`} - > - - - - {app.name} - - - + return ( + navigate(app.url)} + data-cy={`app-selector-${app.name}`} + > + + - {app.subText} + {app.name} + - - ) + + {app.subText} + + + + ) })} diff --git a/src/hooks/useWallet.ts b/src/hooks/useWallet.ts index d208530c..d9cf4bac 100644 --- a/src/hooks/useWallet.ts +++ b/src/hooks/useWallet.ts @@ -30,11 +30,11 @@ const useWallet = () => { } } - async function getUpgradePhases(): Promise { + async function getUpgradePhases() { return await caminoClient.PChain().getUpgradePhases() } - return { updateStore, getRegisteredNode, getAddress , getUpgradePhases} + return { updateStore, getRegisteredNode, getAddress, getUpgradePhases } } export default useWallet diff --git a/src/layout/RoutesSuite.tsx b/src/layout/RoutesSuite.tsx index bd23de82..4319dcd6 100644 --- a/src/layout/RoutesSuite.tsx +++ b/src/layout/RoutesSuite.tsx @@ -4,6 +4,7 @@ import { Navigate, Route, Routes, useNavigate } from 'react-router-dom' import { useDispatch } from 'react-redux' import { useLocation } from 'react-router-dom' import { useAppSelector } from '../hooks/reduxHooks' +import useNetwork from '../hooks/useNetwork' import useWallet from '../hooks/useWallet' import { changeActiveApp } from '../redux/slices/app-config' import { getActiveNetwork } from '../redux/slices/network' @@ -39,6 +40,7 @@ export default function RoutesSuite() { const activeNetwork = useAppSelector(getActiveNetwork) const location = useLocation() const { getUpgradePhases } = useWallet() + const { status } = useNetwork() const [lastUrlWithNewNetwork, setLastUrlWithNewNetwork] = useState('') const [networkAliasToUrl, setNetworkAliasToUrl] = useState('camino') @@ -81,18 +83,16 @@ export default function RoutesSuite() { }, [location]) useEffect(() => { - checkFeature() + if (status === 'succeeded') { + checkFeature() + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [activeNetwork]) + }, [activeNetwork, status]) const checkFeature = async () => { - try { - const phases = await getUpgradePhases() - const enabled = await isFeatureEnabled('DACFeature', activeNetwork?.url, phases) - setFeatureEnabled(enabled) - } catch (error) { - setFeatureEnabled(false) - } + const phases = await getUpgradePhases() + const enabled = await isFeatureEnabled('DACFeature', activeNetwork?.url, phases) + setFeatureEnabled(enabled) } return ( <> diff --git a/src/views/landing/LandingPage.tsx b/src/views/landing/LandingPage.tsx index 18c2b7b2..b80e3167 100644 --- a/src/views/landing/LandingPage.tsx +++ b/src/views/landing/LandingPage.tsx @@ -5,6 +5,7 @@ import React, { useEffect, useState } from 'react' import { useDispatch } from 'react-redux' import { useNavigate } from 'react-router' import { useAppSelector } from '../../hooks/reduxHooks' +import useNetwork from '../../hooks/useNetwork' import useWallet from '../../hooks/useWallet' import { getActiveNetwork } from '../../redux/slices/network' import { isFeatureEnabled } from '../../utils/featureFlags/featureFlagUtils' @@ -18,20 +19,19 @@ export default function LandingPage() { const isAuth = useAppSelector(state => state.appConfig.isAuth) const [featureEnabled, setFeatureEnabled] = useState(false) const { getUpgradePhases } = useWallet() + const { status } = useNetwork() useEffect(() => { - checkFeature() + if (status === 'succeeded') { + checkFeature() + } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [activeNetwork]) + }, [activeNetwork, status]) const checkFeature = async () => { - try { - const phases = await getUpgradePhases() - const enabled = await isFeatureEnabled('DACFeature', activeNetwork?.url, phases) - setFeatureEnabled(enabled) - } catch (error) { - setFeatureEnabled(false) - } + const phases = await getUpgradePhases() + const enabled = await isFeatureEnabled('DACFeature', activeNetwork?.url, phases) + setFeatureEnabled(enabled) } const handleWidgetClick = app => { @@ -51,8 +51,7 @@ export default function LandingPage() { Camino Suite - The Camino Suite unifies all network wide applications of the Camino Network The - Camino Suite unifies all network wide applications of the Camino Network + The Camino Suite unifies all network wide applications of the Camino Network