From d182398b07137b1676f7125a70437f5bd571a5c2 Mon Sep 17 00:00:00 2001 From: Jaco Date: Tue, 18 Jan 2022 10:39:42 +0100 Subject: [PATCH] Adjust storage startValue extraction (#6843) * Adjust storage startValue extraction * substrate default --- packages/page-storage/src/Selection/Modules.tsx | 13 +++++++++++-- .../react-components/src/InputStorage/index.tsx | 3 +-- .../src/InputStorage/options/index.ts | 5 +++++ .../src/InputStorage/options/key.tsx | 2 +- .../src/InputStorage/options/section.ts | 12 ++++++------ 5 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 packages/react-components/src/InputStorage/options/index.ts diff --git a/packages/page-storage/src/Selection/Modules.tsx b/packages/page-storage/src/Selection/Modules.tsx index c17828724c..02e08d6d88 100644 --- a/packages/page-storage/src/Selection/Modules.tsx +++ b/packages/page-storage/src/Selection/Modules.tsx @@ -122,6 +122,15 @@ function Modules ({ onAdd }: Props): React.ReactElement { const [{ isValid, values }, setValues] = useState(() => ({ isValid: true, values: [] })); const [{ blockHash, textHash }, setBlockHash] = useState({ blockHash: null, textHash: '' }); + const startValue = useMemo( + () => ( + api.query.timestamp?.now || + api.query.system?.events || + api.query.substrate.changesTrieConfig + ), + [api] + ); + const _onAdd = useCallback( (): void => { const [params, isAtEnabled] = extractParams(isIterable, values); @@ -177,8 +186,8 @@ function Modules ({ onAdd }: Props): React.ReactElement {
('selected state query')} onChange={_onChangeKey} /> diff --git a/packages/react-components/src/InputStorage/index.tsx b/packages/react-components/src/InputStorage/index.tsx index d5df3bfeee..cab1f7d6d7 100644 --- a/packages/react-components/src/InputStorage/index.tsx +++ b/packages/react-components/src/InputStorage/index.tsx @@ -11,8 +11,7 @@ import React, { useCallback, useState } from 'react'; import { useApi } from '@polkadot/react-hooks'; import LinkedWrapper from '../InputExtrinsic/LinkedWrapper'; -import keyOptions from './options/key'; -import sectionOptions from './options/section'; +import { keyOptions, sectionOptions } from './options'; import SelectKey from './SelectKey'; import SelectSection from './SelectSection'; diff --git a/packages/react-components/src/InputStorage/options/index.ts b/packages/react-components/src/InputStorage/options/index.ts new file mode 100644 index 0000000000..8d49058bf2 --- /dev/null +++ b/packages/react-components/src/InputStorage/options/index.ts @@ -0,0 +1,5 @@ +// Copyright 2017-2022 @polkadot/react-components authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +export { keyOptions } from './key'; +export { sectionOptions } from './section'; diff --git a/packages/react-components/src/InputStorage/options/key.tsx b/packages/react-components/src/InputStorage/options/key.tsx index 8135668dce..36a548ba6c 100644 --- a/packages/react-components/src/InputStorage/options/key.tsx +++ b/packages/react-components/src/InputStorage/options/key.tsx @@ -10,7 +10,7 @@ import { ApiPromise } from '@polkadot/api'; import { getSiName } from '@polkadot/types/metadata/util'; import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey'; -export default function createOptions (api: ApiPromise, sectionName: string): DropdownOptions { +export function keyOptions (api: ApiPromise, sectionName: string): DropdownOptions { const section = api.query[sectionName]; if (!section || Object.keys(section).length === 0) { diff --git a/packages/react-components/src/InputStorage/options/section.ts b/packages/react-components/src/InputStorage/options/section.ts index 6a91e650e8..30dc791a4e 100644 --- a/packages/react-components/src/InputStorage/options/section.ts +++ b/packages/react-components/src/InputStorage/options/section.ts @@ -1,17 +1,17 @@ // Copyright 2017-2022 @polkadot/react-components authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { DropdownOptions } from '../../util/types'; +import type { DropdownOption, DropdownOptions } from '../../util/types'; import { ApiPromise } from '@polkadot/api'; -export default function createOptions (api: ApiPromise): DropdownOptions { +export function sectionOptions (api: ApiPromise): DropdownOptions { return Object .keys(api.query) .sort() - .filter((name): number => Object.keys(api.query[name]).length) - .map((name): { text: string; value: string } => ({ - text: name, - value: name + .filter((n) => Object.keys(api.query[n]).length) + .map((value): DropdownOption => ({ + text: value, + value })); }