Adjust storage startValue extraction (#6843)

* Adjust storage startValue extraction

* substrate default
This commit is contained in:
Jaco 2022-01-18 10:39:42 +01:00 committed by GitHub
parent d8e62bf215
commit d182398b07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 11 deletions

View File

@ -122,6 +122,15 @@ function Modules ({ onAdd }: Props): React.ReactElement<Props> {
const [{ isValid, values }, setValues] = useState<ValState>(() => ({ isValid: true, values: [] }));
const [{ blockHash, textHash }, setBlockHash] = useState<BlockHash>({ 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<Props> {
<section className='storage--actionrow'>
<div className='storage--actionrow-value'>
<InputStorage
defaultValue={api.query.timestamp?.now || api.query.system.events}
help={meta?.docs.join(' ')}
defaultValue={startValue}
help={meta && meta.docs.join(' ')}
label={t<string>('selected state query')}
onChange={_onChangeKey}
/>

View File

@ -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';

View File

@ -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';

View File

@ -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) {

View File

@ -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
}));
}