diff --git a/packages/page-explorer/src/index.tsx b/packages/page-explorer/src/index.tsx index af9063e03596..92d35214592f 100644 --- a/packages/page-explorer/src/index.tsx +++ b/packages/page-explorer/src/index.tsx @@ -1,9 +1,11 @@ // Copyright 2017-2022 @polkadot/app-explorer authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { TFunction } from 'i18next'; +import type { TabItem } from '@polkadot/react-components/Tabs/types'; import type { KeyedEvent } from '@polkadot/react-query/types'; -import React, { useContext, useMemo, useRef } from 'react'; +import React, { useContext, useRef, useState } from 'react'; import { Route, Switch } from 'react-router'; import { Tabs } from '@polkadot/react-components'; @@ -23,13 +25,20 @@ interface Props { newEvents?: KeyedEvent[]; } -function ExplorerApp ({ basePath, className }: Props): React.ReactElement { - const { t } = useTranslation(); - const { api } = useApi(); - const { lastHeaders } = useContext(BlockAuthorsContext); - const { eventCount, events } = useContext(EventsContext); +function createPathRef (basePath: string): Record { + return { + forks: `${basePath}/forks`, + latency: `${basePath}/latency`, + node: `${basePath}/node`, + query: [ + `${basePath}/query/:value`, + `${basePath}/query/` + ] + }; +} - const itemsRef = useRef([ +function createItemsRef (t: TFunction): TabItem[] { + return [ { isRoot: true, name: 'chain', @@ -52,12 +61,17 @@ function ExplorerApp ({ basePath, className }: Props): React.ReactElement name: 'node', text: t('Node info') } - ]); + ]; +} - const hidden = useMemo( - () => api.query.babe ? [] : ['forks'], - [api] - ); +function ExplorerApp ({ basePath, className }: Props): React.ReactElement { + const { t } = useTranslation(); + const { api } = useApi(); + const { lastHeaders } = useContext(BlockAuthorsContext); + const { eventCount, events } = useContext(EventsContext); + const itemsRef = useRef(createItemsRef(t)); + const pathRef = useRef(createPathRef(basePath)); + const hidden = useState(() => api.query.babe ? [] : ['forks']); return (
@@ -67,11 +81,10 @@ function ExplorerApp ({ basePath, className }: Props): React.ReactElement items={itemsRef.current} /> - - - - - + + + +
{ - const { value: encoded } = useParams<{ value: string }>(); + const { encoded } = useParams<{ encoded: string }>(); const [initialValue] = useState(() => defaultValue || encoded); const { t } = useTranslation(); const { api } = useApi(); diff --git a/packages/page-extrinsics/src/index.tsx b/packages/page-extrinsics/src/index.tsx index 87d7937501b8..0ae16d78d8c2 100644 --- a/packages/page-extrinsics/src/index.tsx +++ b/packages/page-extrinsics/src/index.tsx @@ -1,6 +1,8 @@ // Copyright 2017-2022 @polkadot/app-extrinsics authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { TFunction } from 'i18next'; +import type { TabItem } from '@polkadot/react-components/Tabs/types'; import type { AppProps as Props } from '@polkadot/react-components/types'; import type { DecodedExtrinsic } from './types'; @@ -13,11 +15,17 @@ import Decoder from './Decoder'; import Submission from './Submission'; import { useTranslation } from './translate'; -function ExtrinsicsApp ({ basePath }: Props): React.ReactElement { - const { t } = useTranslation(); - const [decoded, setDecoded] = useState(null); +function createPathRef (basePath: string): Record { + return { + decode: [ + `${basePath}/decode/:encoded`, + `${basePath}/decode` + ] + }; +} - const itemsRef = useRef([ +function createItemsRef (t: TFunction): TabItem[] { + return [ { isRoot: true, name: 'create', @@ -28,7 +36,14 @@ function ExtrinsicsApp ({ basePath }: Props): React.ReactElement { name: 'decode', text: t('Decode') } - ]); + ]; +} + +function ExtrinsicsApp ({ basePath }: Props): React.ReactElement { + const { t } = useTranslation(); + const [decoded, setDecoded] = useState(null); + const itemsRef = useRef(createItemsRef(t)); + const pathRef = useRef(createPathRef(basePath)); return (
@@ -37,7 +52,7 @@ function ExtrinsicsApp ({ basePath }: Props): React.ReactElement { items={itemsRef.current} /> - + { + return { + bags: `${basePath}/bags`, + payout: `${basePath}/payout`, + pools: `${basePath}/pools`, + query: [ + `${basePath}/query/:value`, + `${basePath}/query` + ], + slashes: `${basePath}/slashes`, + targets: `${basePath}/targets` + }; +} + function StakingApp ({ basePath, className = '' }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); @@ -65,6 +79,7 @@ function StakingApp ({ basePath, className = '' }: Props): React.ReactElement hasAccounts && !!(api.query.imOnline?.authoredBlocks) && !!(api.query.staking.activeEra), @@ -143,29 +158,29 @@ function StakingApp ({ basePath, className = '' }: Props): React.ReactElement - + - + - + - + - + - +