Skip to content

Commit

Permalink
Merge pull request #280 from chain4travel/dac-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ysrbolles authored Nov 28, 2024
2 parents df7fc81 + 4d00832 commit 71c9612
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 70 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
90 changes: 43 additions & 47 deletions src/components/PlatformSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,24 +28,28 @@ export default function PlatformSwitcher() {
const { isDesktop } = useWidth()
const dispatch = useDispatch()
const { getUpgradePhases } = useWallet()

const [featureEnabled, setFeatureEnabled] = useState<boolean>(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 (
<Box
sx={{
Expand Down Expand Up @@ -109,48 +114,39 @@ export default function PlatformSwitcher() {
(!app.private || isAuth) &&
(app.name !== 'DAC' || featureEnabled)
)
if (
!app.hidden &&
(!app.private || isAuth) &&
(app.name !== 'DAC' || featureEnabled)
)
return (
<MenuItem
key={index}
value={app.name}
divider
onClick={() => navigate(app.url)}
data-cy={`app-selector-${app.name}`}
>
<Box sx={{ width: '100%' }}>
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}}
>
<Typography
variant="subtitle2"
component="span"
noWrap
fontWeight="500"
sx={{ color: '#149EED' }}
>
{app.name}
</Typography>
<Icon path={mdiChevronRight} size={0.9} />
</Box>
return (
<MenuItem
key={index}
value={app.name}
divider
onClick={() => navigate(app.url)}
data-cy={`app-selector-${app.name}`}
>
<Box sx={{ width: '100%' }}>
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}}
>
<Typography
variant="caption"
variant="subtitle2"
component="span"
fontWeight="300"
noWrap
fontWeight="500"
sx={{ color: '#149EED' }}
>
{app.subText}
{app.name}
</Typography>
<Icon path={mdiChevronRight} size={0.9} />
</Box>
</MenuItem>
)
<Typography variant="caption" component="span" fontWeight="300">
{app.subText}
</Typography>
</Box>
</MenuItem>
)
})}
</Select>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const useWallet = () => {
}
}

async function getUpgradePhases(): Promise<any> {
async function getUpgradePhases() {
return await caminoClient.PChain().getUpgradePhases()
}

return { updateStore, getRegisteredNode, getAddress , getUpgradePhases}
return { updateStore, getRegisteredNode, getAddress, getUpgradePhases }
}

export default useWallet
18 changes: 9 additions & 9 deletions src/layout/RoutesSuite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<string>('camino')
Expand Down Expand Up @@ -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 (
<>
Expand Down
21 changes: 10 additions & 11 deletions src/views/landing/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -18,20 +19,19 @@ export default function LandingPage() {
const isAuth = useAppSelector(state => state.appConfig.isAuth)
const [featureEnabled, setFeatureEnabled] = useState<boolean>(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 => {
Expand All @@ -51,8 +51,7 @@ export default function LandingPage() {
Camino Suite
</Typography>
<Typography textAlign={'center'}>
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
</Typography>
</Box>

Expand Down

0 comments on commit 71c9612

Please sign in to comment.