Skip to content

Commit

Permalink
feat: make network switcher non-demo
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed May 16, 2024
1 parent 8cc05d0 commit a56b161
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
15 changes: 11 additions & 4 deletions src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React from 'react';

import { Navigate, Route, Routes } from 'react-router-dom';

import { demoFeaturesEnabled } from '@hooks/demoFeaturesEnabled.ts';
import { NetworkLayout } from '@layouts/NetworkLayout';
import { NetworkName, useSubsquidNetwork } from '@network/useSubsquidNetwork.ts';
import { AssetsPage } from '@pages/AssetsPage/AssetsPage.tsx';
import { Vesting } from '@pages/AssetsPage/Vesting.tsx';
import { DashboardPage } from '@pages/DashboardPage/DashboardPage.tsx';
Expand All @@ -20,12 +22,17 @@ import { hideLoader } from './index.tsx';
export const AppRoutes = () => {
hideLoader(0);

const { network } = useSubsquidNetwork();

return (
<Routes>
<Route element={<NetworkLayout />} path="/dashboard">
<Route element={<DashboardPage />} index />
<Route element={<Worker backPath="/dashboard" />} path="workers/:peerId" />
</Route>
{demoFeaturesEnabled() || network === NetworkName.Testnet ? (
<Route element={<NetworkLayout />} path="/dashboard">
<Route element={<DashboardPage />} index />
<Route element={<Worker backPath="/dashboard" />} path="workers/:peerId" />
</Route>
) : null}

<Route element={<NetworkLayout />} path="/assets">
<Route element={<AssetsPage />} index />
<Route element={<Vesting backPath="/assets" />} path="vestings/:address" />
Expand Down
5 changes: 2 additions & 3 deletions src/layouts/NetworkLayout/NetworkLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { useDisconnect, useNetwork, useWalletClient } from 'wagmi';
import { Logo } from '@components/Logo';
import { NetworkSwitcher } from '@components/NetworkSwitcher';
import { TopBanner, useBannerHeight } from '@components/TopBanner';
import { demoFeaturesEnabled } from '@hooks/demoFeaturesEnabled';
import { MenuIcon } from '@icons/MenuIcon';
import { useAccount } from '@network/useAccount';
import { getChainId, getNetworkName, useSubsquidNetwork } from '@network/useSubsquidNetwork';
Expand Down Expand Up @@ -268,7 +267,7 @@ export const NetworkLayout = ({

if (chain?.id === getChainId(network)) return;

if (!chain?.unsupported && demoFeaturesEnabled()) {
if (!chain?.unsupported) {
switchAndReset(getNetworkName(chain?.id));
return;
}
Expand Down Expand Up @@ -307,7 +306,7 @@ export const NetworkLayout = ({
) : null}
</AppToolbarSidebar>
<AppToolbarContent />
{demoFeaturesEnabled() ? <NetworkSwitcher hideText={isMobile} /> : null}
<NetworkSwitcher hideText={isMobile} />
{/*{narrowXs ? null : <AppToolbarDivider />}*/}
{narrowXs ? <AppToolbarContent /> : null}
<UserMenu />
Expand Down
8 changes: 7 additions & 1 deletion src/layouts/NetworkLayout/NetworkMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import React, { ForwardedRef, forwardRef } from 'react';
import { Box, Button, buttonClasses, styled } from '@mui/material';
import { Link, useLocation } from 'react-router-dom';

import { demoFeaturesEnabled } from '@hooks/demoFeaturesEnabled';
import { AccountIcon } from '@icons/AccountIcon';
import { ComputersIcon } from '@icons/ComputersIcon';
import { ContactsIcon } from '@icons/ContactsIcon';
import { DashboardIcon } from '@icons/DashboardIcon';
import { DocumentIcon } from '@icons/DocumentIcon';
import { OpenInNewIcon } from '@icons/OpenInNewIcon';
import { NetworkName, useSubsquidNetwork } from '@network/useSubsquidNetwork';

interface NetworkMenuProps {
onItemClick: () => void;
Expand Down Expand Up @@ -131,6 +133,8 @@ export const Item = forwardRef(
);

export const NetworkMenu = ({ onItemClick }: NetworkMenuProps) => {
const { network } = useSubsquidNetwork();

return (
<>
<div style={{ height: '1.125rem' }} />
Expand All @@ -141,7 +145,9 @@ export const NetworkMenu = ({ onItemClick }: NetworkMenuProps) => {
{/* path="/network-dashboard"*/}
{/*/>*/}

<Item LeftIcon={DashboardIcon} label="Dashboard" onClick={onItemClick} path="/dashboard" />
{demoFeaturesEnabled() || network === NetworkName.Testnet ? (
<Item LeftIcon={DashboardIcon} label="Dashboard" onClick={onItemClick} path="/dashboard" />
) : null}
<Item LeftIcon={AccountIcon} label="Assets" onClick={onItemClick} path="/assets" />
<Item LeftIcon={ComputersIcon} label="Workers" onClick={onItemClick} path="/workers" />
<Item LeftIcon={AccountIcon} label="Delegations" onClick={onItemClick} path="/delegations" />
Expand Down
23 changes: 12 additions & 11 deletions src/network/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { arbitrumSepolia, arbitrum } from 'wagmi/chains';
import { jsonRpcProvider } from 'wagmi/providers/jsonRpc';
import { publicProvider } from 'wagmi/providers/public';

import { demoFeaturesEnabled } from '@hooks/demoFeaturesEnabled';

// export let CHAIN: Chain = arbitrumSepolia;
// if (process.env.NETWORK === 'hardhat') {
// CHAIN = {
Expand All @@ -25,15 +23,18 @@ const {
chains: configuredChains,
publicClient,
webSocketPublicClient,
} = configureChains(demoFeaturesEnabled() ? [arbitrumSepolia, arbitrum] : [arbitrumSepolia], [
privateNode
? jsonRpcProvider({
rpc: () => ({
http: privateNode,
}),
})
: publicProvider(),
]);
} = configureChains(
[arbitrumSepolia, arbitrum],
[
privateNode
? jsonRpcProvider({
rpc: () => ({
http: privateNode,
}),
})
: publicProvider(),
],
);

const connectors = connectorsForWallets([
{
Expand Down

0 comments on commit a56b161

Please sign in to comment.