diff --git a/packages/apps-routing/src/index.ts b/packages/apps-routing/src/index.ts index e74378f0b2..3ccd0beb2b 100644 --- a/packages/apps-routing/src/index.ts +++ b/packages/apps-routing/src/index.ts @@ -37,6 +37,7 @@ import teleport from './teleport'; import transfer from './transfer'; import treasury from './treasury'; import utilities from './utilities'; +import whitelist from './whitelist'; export default function create (t: TFunction): Routes { return [ @@ -56,6 +57,7 @@ export default function create (t: TFunction): Routes { techcomm(t), membership(t), alliance(t), + whitelist(t), parachains(t), gilt(t), assets(t), diff --git a/packages/apps-routing/src/whitelist.ts b/packages/apps-routing/src/whitelist.ts new file mode 100644 index 0000000000..fa476d6df5 --- /dev/null +++ b/packages/apps-routing/src/whitelist.ts @@ -0,0 +1,22 @@ +// Copyright 2017-2022 @polkadot/apps-routing authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { TFunction } from 'i18next'; +import type { Route } from './types'; + +import Component from '@polkadot/app-whitelist'; + +export default function create (t: TFunction): Route { + return { + Component, + display: { + needsApi: [ + 'tx.whitelist.removeWhitelistedCall' + ] + }, + group: 'governance', + icon: 'list-check', + name: 'whitelist', + text: t('nav.whitelist', 'Whitelist', { ns: 'apps-routing' }) + }; +} diff --git a/packages/page-whitelist/src/Hash.tsx b/packages/page-whitelist/src/Hash.tsx new file mode 100644 index 0000000000..c3833c2b92 --- /dev/null +++ b/packages/page-whitelist/src/Hash.tsx @@ -0,0 +1,23 @@ +// 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.tsx b/packages/page-whitelist/src/Hashes.tsx new file mode 100644 index 0000000000..cefa0ff7b7 --- /dev/null +++ b/packages/page-whitelist/src/Hashes.tsx @@ -0,0 +1,46 @@ +// Copyright 2017-2022 @polkadot/app-whitelist authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { SubmittableExtrinsicFunction } from '@polkadot/api/types'; + +import React, { useRef } from 'react'; + +import { Table } from '@polkadot/react-components'; + +import Hash from './Hash'; +import { useTranslation } from './translate'; +import useHashes from './useHashes'; + +interface Props { + className?: string; + defaultPropose?: SubmittableExtrinsicFunction<'promise'>; + filter?: (section: string, method?: string) => boolean; +} + +function Hashes ({ className }: Props): React.ReactElement { + const { t } = useTranslation(); + const hashes = useHashes(); + + const headerRef = useRef([ + [t('hashes'), 'start'] + ]); + + return ( +
+ ('No call hashes found')} + header={headerRef.current} + > + {hashes && hashes.map((h) => ( + + ))} +
+
+ ); +} + +export default React.memo(Hashes); diff --git a/packages/page-whitelist/src/index.tsx b/packages/page-whitelist/src/index.tsx index 1cde37cdf3..6b17fbc2f8 100644 --- a/packages/page-whitelist/src/index.tsx +++ b/packages/page-whitelist/src/index.tsx @@ -1,16 +1,37 @@ // Copyright 2017-2022 @polkadot/app-whitelist authors & contributors // SPDX-License-Identifier: Apache-2.0 -import React from 'react'; +import React, { useRef } from 'react'; + +import { Tabs } from '@polkadot/react-components'; + +import Hashes from './Hashes'; +import { useTranslation } from './translate'; interface Props { basePath: string; className?: string; } -function App ({ className }: Props): React.ReactElement { +function App ({ basePath, className }: Props): React.ReactElement { + const { t } = useTranslation(); + + const tabsRef = useRef([ + { + isRoot: true, + name: 'overview', + text: t('Overview') + } + ]); + return ( -
+
+ + +
); } diff --git a/packages/page-whitelist/src/useHashes.ts b/packages/page-whitelist/src/useHashes.ts new file mode 100644 index 0000000000..738b38348a --- /dev/null +++ b/packages/page-whitelist/src/useHashes.ts @@ -0,0 +1,47 @@ +// Copyright 2017-2022 @polkadot/app-preimages authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { Changes } from '@polkadot/react-hooks/useEventChanges'; +import type { StorageKey } from '@polkadot/types'; +import type { EventRecord, Hash } from '@polkadot/types/interfaces'; +import type { HexString } from '@polkadot/util/types'; + +import { useMemo } from 'react'; + +import { createNamedHook, useApi, useEventChanges, useMapKeys } from '@polkadot/react-hooks'; + +const OPT_HASH = { + transform: (keys: StorageKey<[Hash]>[]): Hash[] => + keys.map(({ args: [hash] }) => hash) +}; + +function filter (records: EventRecord[]): Changes { + const added: Hash[] = []; + const removed: Hash[] = []; + + records.forEach(({ event: { data: [hash], method } }): void => { + if (method === 'CallWhitelisted') { + added.push(hash as Hash); + } else { + removed.push(hash as Hash); + } + }); + + return { added, removed }; +} + +function useHashesImpl (): HexString[] | undefined { + const { api } = useApi(); + const startValue = useMapKeys(api.query.whitelist.whitelistedCall, OPT_HASH); + const hashes = useEventChanges([ + api.events.whitelist.CallWhitelisted, + api.events.whitelist.WhitelistedCallRemoved + ], filter, startValue); + + return useMemo( + () => hashes && hashes.map((h) => h.toHex()), + [hashes] + ); +} + +export default createNamedHook('useHashes', useHashesImpl);