Add basic whitelist support (#7942)
This commit is contained in:
parent
c20e79c579
commit
809b8f1b03
@ -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),
|
||||
|
||||
22
packages/apps-routing/src/whitelist.ts
Normal file
22
packages/apps-routing/src/whitelist.ts
Normal file
@ -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' })
|
||||
};
|
||||
}
|
||||
23
packages/page-whitelist/src/Hash.tsx
Normal file
23
packages/page-whitelist/src/Hash.tsx
Normal file
@ -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<Props> {
|
||||
return (
|
||||
<tr className={ className }>
|
||||
<td>
|
||||
{value}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(Hash);
|
||||
46
packages/page-whitelist/src/Hashes.tsx
Normal file
46
packages/page-whitelist/src/Hashes.tsx
Normal file
@ -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<Props> {
|
||||
const { t } = useTranslation();
|
||||
const hashes = useHashes();
|
||||
|
||||
const headerRef = useRef([
|
||||
[t('hashes'), 'start']
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<Table
|
||||
className={className}
|
||||
empty={hashes && t<string>('No call hashes found')}
|
||||
header={headerRef.current}
|
||||
>
|
||||
{hashes && hashes.map((h) => (
|
||||
<Hash
|
||||
key={h}
|
||||
value={h}
|
||||
/>
|
||||
))}
|
||||
</Table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(Hashes);
|
||||
@ -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<Props> {
|
||||
function App ({ basePath, className }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const tabsRef = useRef([
|
||||
{
|
||||
isRoot: true,
|
||||
name: 'overview',
|
||||
text: t<string>('Overview')
|
||||
}
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className={className} />
|
||||
<main className={className}>
|
||||
<Tabs
|
||||
basePath={basePath}
|
||||
items={tabsRef.current}
|
||||
/>
|
||||
<Hashes />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
47
packages/page-whitelist/src/useHashes.ts
Normal file
47
packages/page-whitelist/src/useHashes.ts
Normal file
@ -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<Hash> {
|
||||
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);
|
||||
Loading…
Reference in New Issue
Block a user