From e6fc70b9c0819e1c8cb950a5e18bbdc340e5e43d Mon Sep 17 00:00:00 2001 From: Jaco Date: Mon, 5 Dec 2022 11:26:56 +0200 Subject: [PATCH] Prettify hash displays (#8476) * Prettify hash displays * Adjust app ordering --- packages/apps-routing/src/index.ts | 14 +++--- .../page-preimages/src/Preimages/Hash.tsx | 45 +++++++++++++++++++ .../page-preimages/src/Preimages/Preimage.tsx | 9 ++-- .../src/Referenda/RefOngoing.tsx | 2 +- packages/page-whitelist/src/Hashes/Call.tsx | 38 ++++++++++++++++ packages/page-whitelist/src/Hashes/Hash.tsx | 23 ---------- packages/page-whitelist/src/Hashes/index.tsx | 7 +-- 7 files changed, 102 insertions(+), 36 deletions(-) create mode 100644 packages/page-preimages/src/Preimages/Hash.tsx create mode 100644 packages/page-whitelist/src/Hashes/Call.tsx delete mode 100644 packages/page-whitelist/src/Hashes/Hash.tsx diff --git a/packages/apps-routing/src/index.ts b/packages/apps-routing/src/index.ts index 7490a5671e..6f64f24756 100644 --- a/packages/apps-routing/src/index.ts +++ b/packages/apps-routing/src/index.ts @@ -54,18 +54,22 @@ export default function create (t: TFunction): Routes { teleport(t), staking(t), collator(t), - democracy(t), + // governance v2 referenda(t), - council(t), - treasury(t), - bounties(t), - techcomm(t), membership(t), alliance(t), fellowship(t), ranked(t), preimages(t), whitelist(t), + // old v1 governance + democracy(t), + council(t), + techcomm(t), + // other governance-related + treasury(t), + bounties(t), + // others parachains(t), gilt(t), assets(t), diff --git a/packages/page-preimages/src/Preimages/Hash.tsx b/packages/page-preimages/src/Preimages/Hash.tsx new file mode 100644 index 0000000000..cbbc65d78b --- /dev/null +++ b/packages/page-preimages/src/Preimages/Hash.tsx @@ -0,0 +1,45 @@ +// Copyright 2017-2022 @polkadot/app-preimages authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { HexString } from '@polkadot/util/types'; + +import React, { useMemo } from 'react'; +import styled from 'styled-components'; + +import { CopyButton } from '@polkadot/react-components'; + +interface Props { + className?: string; + value: HexString; +} + +function Hash ({ className, value }: Props): React.ReactElement { + const shortHash = useMemo( + () => `${value.slice(0, 10)}…${value.slice(-8)}`, + [value] + ); + + return ( + +
{shortHash}
+ + + ); +} + +export default React.memo(styled(Hash)` + white-space: nowrap; + + > div { + display: inline-block; + vertical-align: middle; + } + + .shortHash { + font: var(--font-mono); + + + div { + margin-left: 0.5rem; + } + } +`); diff --git a/packages/page-preimages/src/Preimages/Preimage.tsx b/packages/page-preimages/src/Preimages/Preimage.tsx index 88f8a3e547..fac31a4789 100644 --- a/packages/page-preimages/src/Preimages/Preimage.tsx +++ b/packages/page-preimages/src/Preimages/Preimage.tsx @@ -10,6 +10,7 @@ import { formatNumber } from '@polkadot/util'; import { useTranslation } from '../translate'; import usePreimage from '../usePreimage'; +import Hash from './Hash'; interface Props { className?: string; @@ -22,9 +23,9 @@ function Preimage ({ className, value }: Props): React.ReactElement { return ( - {value} + - {info && info.proposal && ( + {info?.proposal && ( ('proposal')} value={info.proposal} @@ -32,10 +33,10 @@ function Preimage ({ className, value }: Props): React.ReactElement { )} - {info && info.bytes && formatNumber(info.bytes.length)} + {info?.bytes && formatNumber(info.bytes.length)} - {info && info.status && info.status.type} + {info?.status?.type} {info && info.count !== 0 && formatNumber(info.count)} diff --git a/packages/page-referenda/src/Referenda/RefOngoing.tsx b/packages/page-referenda/src/Referenda/RefOngoing.tsx index 70dc16a619..84b13f363e 100644 --- a/packages/page-referenda/src/Referenda/RefOngoing.tsx +++ b/packages/page-referenda/src/Referenda/RefOngoing.tsx @@ -66,7 +66,7 @@ function expandOngoing (info: Referendum['info'], track?: PalletReferendaTrackIn prepareEnd }, proposalHash, - shortHash: `${proposalHash.slice(0, 8)}…${proposalHash.slice(-6)}`, + shortHash: `${proposalHash.slice(0, 10)}…${proposalHash.slice(-8)}`, tallyTotal: ongoing.tally.ayes.add(ongoing.tally.nays) }; } diff --git a/packages/page-whitelist/src/Hashes/Call.tsx b/packages/page-whitelist/src/Hashes/Call.tsx new file mode 100644 index 0000000000..5eb49b73ed --- /dev/null +++ b/packages/page-whitelist/src/Hashes/Call.tsx @@ -0,0 +1,38 @@ +// Copyright 2017-2022 @polkadot/app-whitelist authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { HexString } from '@polkadot/util/types'; + +import React from 'react'; + +import Hash from '@polkadot/app-preimages/Preimages/Hash'; +import usePreimage from '@polkadot/app-preimages/usePreimage'; +import { CallExpander } from '@polkadot/react-components'; + +import { useTranslation } from '../translate'; + +interface Props { + className?: string; + value: HexString; +} + +function Call ({ className, value }: Props): React.ReactElement { + const { t } = useTranslation(); + const info = usePreimage(value); + + return ( + + + + {info?.proposal && ( + ('call')} + value={info.proposal} + /> + )} + + + ); +} + +export default React.memo(Call); diff --git a/packages/page-whitelist/src/Hashes/Hash.tsx b/packages/page-whitelist/src/Hashes/Hash.tsx deleted file mode 100644 index c3833c2b92..0000000000 --- a/packages/page-whitelist/src/Hashes/Hash.tsx +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017-2022 @polkadot/app-whitelist authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { HexString } from '@polkadot/util/types'; - -import React from 'react'; - -interface Props { - className?: string; - value: HexString; -} - -function Hash ({ className, value }: Props): React.ReactElement { - return ( - - - {value} - - - ); -} - -export default React.memo(Hash); diff --git a/packages/page-whitelist/src/Hashes/index.tsx b/packages/page-whitelist/src/Hashes/index.tsx index ced930e3d6..8e16641154 100644 --- a/packages/page-whitelist/src/Hashes/index.tsx +++ b/packages/page-whitelist/src/Hashes/index.tsx @@ -9,7 +9,7 @@ import { Table } from '@polkadot/react-components'; import { useTranslation } from '../translate'; import useHashes from '../useHashes'; -import Hash from './Hash'; +import Call from './Call'; import Summary from './Summary'; interface Props { @@ -23,7 +23,8 @@ function Hashes ({ className }: Props): React.ReactElement { const hashes = useHashes(); const headerRef = useRef([ - [t('hashes'), 'start'] + [t('calls'), 'start'], + [undefined, 'all'] ]); return ( @@ -35,7 +36,7 @@ function Hashes ({ className }: Props): React.ReactElement { header={headerRef.current} > {hashes && hashes.map((h) => ( -