Constant queries (#1419)

* InputConsts dropdown

* Bumps

* 2. x Constants explorer
This commit is contained in:
Jaco Greeff 2019-07-18 18:01:36 +02:00 committed by GitHub
parent a668a04173
commit 77689fba59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 600 additions and 158 deletions

View File

@ -10,12 +10,12 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^0.82.0-beta.68",
"@polkadot/api-contract": "^0.82.0-beta.68",
"@polkadot/keyring": "^0.94.0-beta.14",
"@polkadot/types": "^0.82.0-beta.68",
"@polkadot/util": "^0.94.0-beta.14",
"@polkadot/util-crypto": "^0.94.0-beta.14",
"@polkadot/api": "^0.82.0-beta.70",
"@polkadot/api-contract": "^0.82.0-beta.70",
"@polkadot/keyring": "^0.94.0-beta.15",
"@polkadot/types": "^0.82.0-beta.70",
"@polkadot/util": "^0.94.0-beta.15",
"@polkadot/util-crypto": "^0.94.0-beta.15",
"@types/styled-components": "4.1.8",
"babel-core": "^7.0.0-bridge.0",
"typescript": "^3.5.3"

View File

@ -11,6 +11,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70"
}
}

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-app": "^0.34.0-beta.70",
"@types/file-saver": "^2.0.0",
"@types/yargs": "^13.0.0",
"babel-plugin-module-resolver": "^3.1.1",

View File

@ -11,6 +11,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70"
}
}

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/api-contract": "^0.82.0-beta.68",
"@polkadot/ui-app": "^0.34.0-beta.73"
"@polkadot/api-contract": "^0.82.0-beta.70",
"@polkadot/ui-app": "^0.34.0-beta.70"
}
}

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-reactive": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-reactive": "^0.34.0-beta.70"
}
}

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/apps-routing": "^0.34.0-beta.73",
"@polkadot/ui-app": "^0.34.0-beta.73"
"@polkadot/apps-routing": "^0.34.0-beta.70",
"@polkadot/ui-app": "^0.34.0-beta.70"
}
}

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-reactive": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-reactive": "^0.34.0-beta.70"
}
}

View File

@ -11,6 +11,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70"
}
}

View File

@ -11,8 +11,8 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-params": "^0.34.0-beta.73",
"@polkadot/ui-signer": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-params": "^0.34.0-beta.70",
"@polkadot/ui-signer": "^0.34.0-beta.70"
}
}

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-app": "^0.34.0-beta.70",
"snappyjs": "^0.6.0"
}
}

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.4.5",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-reactive": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-reactive": "^0.34.0-beta.70"
}
}

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-reactive": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-reactive": "^0.34.0-beta.70"
}
}

View File

@ -11,8 +11,8 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/app-explorer": "^0.34.0-beta.73",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-reactive": "^0.34.0-beta.73"
"@polkadot/app-explorer": "^0.34.0-beta.70",
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-reactive": "^0.34.0-beta.70"
}
}

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-params": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-params": "^0.34.0-beta.70"
}
}

View File

@ -16,6 +16,7 @@ import { isU8a, u8aToHex, u8aToString } from '@polkadot/util';
import translate from './translate';
import { RenderFn, DefaultProps, ComponentRenderer } from '@polkadot/ui-api/with/types';
import { ConstValue } from '@polkadot/ui-app/InputConsts/types';
interface Props extends I18nProps {
onRemove: (id: number) => void;
@ -40,26 +41,38 @@ class Query extends React.PureComponent<Props, State> {
public state: State = { spread: {} };
public static getCachedComponent (query: QueryTypes): CacheInstance {
const { id, key, params = [] } = query as StorageModuleQuery;
const { id, isConst, key, params = [] } = query as StorageModuleQuery;
if (!cache[id]) {
const values: any[] = params.map(({ value }): any => value);
const type = key.creator.meta
? key.creator.meta.type.toString()
: 'Data';
const defaultProps = { className: 'ui--output' };
let renderHelper;
let type: string;
// render function to create an element for the query results which is plugged to the api
const renderHelper = withCallDiv('subscribe', {
paramName: 'params',
paramValid: true,
params: [key, ...values]
});
if (isConst) {
const { meta, method, section } = key as unknown as ConstValue;
renderHelper = withCallDiv(`consts.${section}.${method}`);
type = meta.type.toString();
} else {
const values: any[] = params.map(({ value }): any => value);
// render function to create an element for the query results which is plugged to the api
renderHelper = withCallDiv('subscribe', {
paramName: 'params',
paramValid: true,
params: [key, ...values]
});
type = key.creator.meta
? key.creator.meta.type.toString()
: 'Data';
}
const defaultProps = { className: 'ui--output' };
const Component = renderHelper(
// By default we render a simple div node component with the query results in it
(value: any): React.ReactNode => valueToText(type, value, true, true),
defaultProps
);
cache[query.id] = Query.createComponent(type, Component, defaultProps, renderHelper);
}
@ -105,14 +118,16 @@ class Query extends React.PureComponent<Props, State> {
public render (): React.ReactNode {
const { className, value } = this.props;
const { Component } = this.state;
const { key } = value;
const type = isU8a(key)
? 'Data'
: (
key.creator.meta.modifier.isOptional
? `Option<${key.creator.meta.type}>`
: key.creator.meta.type.toString()
);
const { isConst, key } = value;
const type = isConst
? (key as unknown as ConstValue).meta.type.toString()
: isU8a(key)
? 'Data'
: (
(key as StorageEntryPromise).creator.meta.modifier.isOptional
? `Option<${(key as StorageEntryPromise).creator.meta.type}>`
: (key as StorageEntryPromise).creator.meta.type.toString()
);
if (!Component) {
return null;
@ -124,7 +139,7 @@ class Query extends React.PureComponent<Props, State> {
<Labelled
label={
<div className='ui--Param-text'>
{this.keyToName(key)}: {type}
{this.keyToName(isConst, key)}: {type}
</div>
}
>
@ -152,7 +167,7 @@ class Query extends React.PureComponent<Props, State> {
/>
];
if (key.creator.meta && ['Bytes', 'Data'].includes(key.creator.meta.type.toString())) {
if (key.creator && key.creator.meta && ['Bytes', 'Data'].includes(key.creator.meta.type.toString())) {
// TODO We are currently not performing a copy
// buttons.unshift(
// <Button
@ -172,7 +187,15 @@ class Query extends React.PureComponent<Props, State> {
return buttons;
}
private keyToName (key: Uint8Array | StorageEntryPromise): string {
private keyToName (isConst: boolean, _key: Uint8Array | StorageEntryPromise | ConstValue): string {
if (isConst) {
const key = _key as ConstValue;
return `const ${key.section}.${key.method}`;
}
const key = _key as Uint8Array | StorageEntryPromise;
if (isU8a(key)) {
const u8a = Compact.stripLengthPrefix(key);
@ -212,6 +235,10 @@ class Query extends React.PureComponent<Props, State> {
export default translate(styled(Query as React.ComponentClass<Props>)`
margin-bottom: 0.25em;
label {
text-transform: none !important;
}
.ui.disabled.dropdown.selection {
color: #aaa;
opacity: 1;

View File

@ -0,0 +1,88 @@
// Copyright 2017-2019 @polkadot/app-storage authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ConstantCodec } from '@polkadot/api-metadata/consts/types';
import { I18nProps } from '@polkadot/ui-app/types';
import { ConstValue } from '@polkadot/ui-app/InputConsts/types';
import { ApiProps } from '@polkadot/ui-api/types';
import { ComponentProps } from '../types';
import React from 'react';
import { Button, InputConsts, TxComponent } from '@polkadot/ui-app';
import { withApi, withMulti } from '@polkadot/ui-api';
import translate from '../translate';
type Props = ComponentProps & ApiProps & I18nProps;
interface State {
value: ConstValue;
}
class Consts extends TxComponent<Props, State> {
private defaultValue: ConstValue;
public state: State;
public constructor (props: Props) {
super(props);
const { api } = this.props;
const section = Object.keys(api.consts)[0];
const method = Object.keys(api.consts[section])[0];
this.defaultValue = {
meta: (api.consts[section][method] as ConstantCodec).meta,
method,
section
};
this.state = {
value: this.defaultValue
};
}
public render (): React.ReactNode {
const { api, t } = this.props;
const { value: { method, section } } = this.state;
const meta = (api.consts[section][method] as ConstantCodec).meta;
return (
<section className='storage--actionrow'>
<div className='storage--actionrow-value'>
<InputConsts
defaultValue={this.defaultValue}
label={t('selected constant query')}
onChange={this.onChangeConst}
help={meta && meta.documentation && meta.documentation.join(' ')}
/>
</div>
<div className='storage--actionrow-buttons'>
<Button
icon='plus'
isPrimary
onClick={this.onAdd}
ref={this.button}
/>
</div>
</section>
);
}
private onAdd = (): void => {
const { onAdd } = this.props;
const { value } = this.state;
onAdd({ isConst: true, key: value });
}
private onChangeConst = (value: ConstValue): void => {
this.setState({ value });
}
}
export default withMulti(
Consts,
translate,
withApi
);

View File

@ -110,6 +110,7 @@ class Modules extends TxComponent<Props, State> {
const { key, values } = this.state;
onAdd({
isConst: false,
key,
params: values
});

View File

@ -56,7 +56,7 @@ class Raw extends TxComponent<Props, State> {
const { onAdd } = this.props;
const { key } = this.state;
onAdd({ key });
onAdd({ isConst: false, key });
}
private onChangeKey = (key: string): void => {

View File

@ -2,6 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiProps } from '@polkadot/ui-api/types';
import { I18nProps } from '@polkadot/ui-app/types';
import { TabItem } from '@polkadot/ui-app/Tabs';
import { ComponentProps, QueryTypes, ParitalQueryTypes } from '../types';
@ -9,15 +10,17 @@ import { ComponentProps, QueryTypes, ParitalQueryTypes } from '../types';
import React from 'react';
import { Route, Switch } from 'react-router';
import { Tabs } from '@polkadot/ui-app';
import { withApi } from '@polkadot/ui-api';
import Consts from './Consts';
import Modules from './Modules';
import Raw from './Raw';
import translate from '../translate';
interface Props extends I18nProps {
type Props = ApiProps & I18nProps & {
basePath: string;
onAdd: (query: QueryTypes) => void;
}
};
interface State {
items: TabItem[];
@ -36,29 +39,36 @@ class Selection extends React.PureComponent<Props, State> {
{
isRoot: true,
name: 'modules',
text: t('Modules')
text: t('Storage')
},
{
name: 'constants',
text: t('Constants')
},
{
name: 'raw',
text: t('Raw key')
text: t('Raw storage')
}
]
};
}
public render (): React.ReactNode {
const { basePath } = this.props;
const { basePath, isSubstrateV2 } = this.props;
const { items } = this.state;
const hidden = isSubstrateV2 ? [] : ['constants'];
return (
<>
<header>
<Tabs
basePath={basePath}
hidden={hidden}
items={items}
/>
</header>
<Switch>
<Route path={`${basePath}/constants`} render={this.renderComponent(Consts)} />
<Route path={`${basePath}/raw`} render={this.renderComponent(Raw)} />
<Route render={this.renderComponent(Modules)} />
</Switch>
@ -84,4 +94,4 @@ class Selection extends React.PureComponent<Props, State> {
}
}
export default translate(Selection);
export default translate(withApi(Selection));

View File

@ -3,28 +3,39 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { StorageEntryPromise } from '@polkadot/api/types';
import { ConstValue } from '@polkadot/ui-app/InputConsts/types';
import { RawParams } from '@polkadot/ui-params/types';
interface IdQuery {
interface Base {
isConst: boolean;
}
interface IdQuery extends Base {
id: number;
}
export interface PartialModuleQuery {
export interface PartialModuleQuery extends Base {
key: StorageEntryPromise;
params: RawParams;
}
export type StorageModuleQuery = PartialModuleQuery & IdQuery;
export interface PartialRawQuery {
export interface PartialRawQuery extends Base {
key: Uint8Array;
}
export type StorageRawQuery = PartialRawQuery & IdQuery;
export type QueryTypes = StorageModuleQuery | StorageRawQuery;
export interface PartialConstQuery extends Base {
key: ConstValue;
}
export type ParitalQueryTypes = PartialModuleQuery | PartialRawQuery;
export type ConstQuery = PartialConstQuery & IdQuery;
export type QueryTypes = StorageModuleQuery | StorageRawQuery | ConstQuery;
export type ParitalQueryTypes = PartialModuleQuery | PartialRawQuery | PartialConstQuery;
export interface ComponentProps {
onAdd: (query: ParitalQueryTypes) => void;

View File

@ -12,6 +12,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70"
}
}

View File

@ -11,6 +11,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70"
}
}

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-reactive": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-reactive": "^0.34.0-beta.70"
}
}

View File

@ -12,7 +12,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-reactive": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-reactive": "^0.34.0-beta.70"
}
}

View File

@ -13,9 +13,9 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73",
"@polkadot/ui-app": "^0.34.0-beta.70",
"@polkadot/ui-assets": "^0.42.0-beta.13",
"@polkadot/ui-signer": "^0.34.0-beta.73",
"@polkadot/ui-signer": "^0.34.0-beta.70",
"query-string": "^6.8.1"
}
}

View File

@ -31,8 +31,8 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/api": "^0.82.0-beta.68",
"@polkadot/extension-dapp": "^0.4.0-beta.6",
"@polkadot/api": "^0.82.0-beta.70",
"@polkadot/extension-dapp": "^0.4.1",
"rxjs-compat": "^6.4.0"
}
}

View File

@ -11,11 +11,11 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/keyring": "^0.94.0-beta.14",
"@polkadot/ui-api": "^0.34.0-beta.73",
"@polkadot/keyring": "^0.94.0-beta.15",
"@polkadot/ui-api": "^0.34.0-beta.70",
"@polkadot/ui-identicon": "^0.42.0-beta.13",
"@polkadot/ui-keyring": "^0.42.0-beta.13",
"@polkadot/ui-reactive": "^0.34.0-beta.73",
"@polkadot/ui-reactive": "^0.34.0-beta.70",
"@polkadot/ui-settings": "^0.42.0-beta.13",
"@types/chart.js": "^2.7.55",
"@types/i18next": "^12.1.0",

View File

@ -0,0 +1,56 @@
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiProps } from '@polkadot/ui-api/types';
import { DropdownOptions } from '../util/types';
import { BareProps } from '../types';
import { ConstValueBase } from './types';
import React from 'react';
import { withApi } from '@polkadot/ui-api';
import Dropdown from '../Dropdown';
import { classes } from '../util';
type Props = ApiProps & BareProps & {
isError?: boolean;
onChange: (value: ConstValueBase) => void;
options: DropdownOptions;
value: ConstValueBase;
};
class SelectKey extends React.PureComponent<Props> {
public render (): React.ReactNode {
const { className, isError, onChange, options, style, value } = this.props;
if (!options.length) {
return null;
}
return (
<Dropdown
className={classes('ui--DropdownLinked-Items', className)}
isError={isError}
onChange={onChange}
options={options}
style={style}
transform={this.transform}
value={value.method}
withLabel={false}
/>
);
}
private transform = (method: string): ConstValueBase => {
const { value } = this.props;
const section = value.section;
return {
method,
section
};
}
}
export default withApi(SelectKey);

View File

@ -0,0 +1,40 @@
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { StorageEntryPromise } from '@polkadot/api/types';
import { DropdownOptions } from '../util/types';
import { BareProps } from '../types';
import { ConstValueBase } from './types';
import React from 'react';
import Dropdown from '../Dropdown';
import { classes } from '../util';
interface Props extends BareProps {
defaultValue?: StorageEntryPromise;
isError?: boolean;
onChange: (value: string) => void;
options: DropdownOptions;
value: ConstValueBase;
}
export default class SelectSection extends React.PureComponent<Props> {
public render (): React.ReactNode {
const { className, defaultValue, isError, onChange, options, style, value: { section } } = this.props;
return (
<Dropdown
className={classes('ui--DropdownLinked-Sections', className)}
defaultValue={defaultValue}
isError={isError}
onChange={onChange}
options={options}
style={style}
value={section}
withLabel={false}
/>
);
}
}

View File

@ -0,0 +1,132 @@
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ConstantCodec } from '@polkadot/api-metadata/consts/types';
import { ApiProps } from '@polkadot/ui-api/types';
import { DropdownOptions } from '../util/types';
import { I18nProps } from '../types';
import { ConstValue, ConstValueBase } from './types';
import '../InputExtrinsic/InputExtrinsic.css';
import React from 'react';
import { withApi, withMulti } from '@polkadot/ui-api';
import Labelled from '../Labelled';
import translate from '../translate';
import SelectKey from './SelectKey';
import SelectSection from './SelectSection';
import keyOptions from './options/key';
import sectionOptions from './options/section';
type Props = ApiProps & I18nProps & {
defaultValue: ConstValueBase;
help?: React.ReactNode;
isError?: boolean;
label: React.ReactNode;
onChange?: (value: ConstValue) => void;
withLabel?: boolean;
};
interface State {
optionsMethod: DropdownOptions;
optionsSection: DropdownOptions;
value: ConstValue;
}
class InputConsts extends React.PureComponent<Props, State> {
public state: State;
public constructor (props: Props) {
super(props);
const { api, defaultValue: { method, section } } = this.props;
const firstSec = Object.keys(api.consts)[0];
const firstMet = Object.keys(api.consts[firstSec])[0];
const value = (api.consts[section] && api.consts[section][method])
? { method, section }
: { method: firstMet, section: firstSec };
this.state = {
optionsMethod: keyOptions(api, section),
optionsSection: sectionOptions(api),
value: {
...value,
meta: (api.consts[value.section][value.method] as ConstantCodec).meta
}
};
}
public render (): React.ReactNode {
const { className, help, label, style, withLabel } = this.props;
const { optionsMethod, optionsSection, value } = this.state;
return (
<div
className={className}
style={style}
>
<Labelled
help={help}
label={label}
withLabel={withLabel}
>
<div className=' ui--DropdownLinked ui--row'>
<SelectSection
className='small'
onChange={this.onSectionChange}
options={optionsSection}
value={value}
/>
<SelectKey
className='large'
onChange={this.onKeyChange}
options={optionsMethod}
value={value}
/>
</div>
</Labelled>
</div>
);
}
private onKeyChange = (newValue: ConstValueBase): void => {
const { api, onChange } = this.props;
const { value: saveValue } = this.state;
if (saveValue.section === newValue.section && saveValue.method === newValue.method) {
return;
}
const { method, section } = newValue;
const meta = (api.consts[section][method] as ConstantCodec).meta;
const value = { meta, method, section };
this.setState({ value }, (): void =>
onChange && onChange(value)
);
}
private onSectionChange = (newSection: string): void => {
const { api } = this.props;
const { value } = this.state;
if (newSection === value.section) {
return;
}
const optionsMethod = keyOptions(api, newSection);
const newValue = { method: optionsMethod[0].value, section: newSection };
this.setState({ optionsMethod }, (): void =>
this.onKeyChange(newValue)
);
}
}
export default withMulti(
InputConsts,
translate,
withApi
);

View File

@ -0,0 +1,44 @@
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ConstantCodec } from '@polkadot/api-metadata/consts/types';
import { DropdownOptions, DropdownOption } from '../../util/types';
import React from 'react';
import ApiPromise from '@polkadot/api/promise';
export default function createOptions (api: ApiPromise, sectionName: string): DropdownOptions {
const section = api.consts[sectionName];
if (!section || Object.keys(section).length === 0) {
return [];
}
return Object
.keys(section)
.sort()
.map((value): DropdownOption => {
const method = (section[value] as ConstantCodec);
return {
className: 'ui--DropdownLinked-Item',
key: `${sectionName}_${value}`,
text: [
<div
className='ui--DropdownLinked-Item-call'
key={`${sectionName}_${value}:call`}
>
{value}: {method.meta.type.toString()}
</div>,
<div
className='ui--DropdownLinked-Item-text'
key={`${sectionName}_${value}:text`}
>
{(method.meta.documentation[0] || method.meta.name).toString()}
</div>
],
value
};
});
}

View File

@ -0,0 +1,18 @@
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { DropdownOptions } from '../../util/types';
import ApiPromise from '@polkadot/api/promise';
export default function createOptions (api: ApiPromise): DropdownOptions {
return Object
.keys(api.consts)
.sort()
.filter((name): number => Object.keys(api.consts[name]).length)
.map((name): { text: string; value: string } => ({
text: name,
value: name
}));
}

View File

@ -0,0 +1,14 @@
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ModuleConstantMetadata as MetaV6 } from '@polkadot/types/Metadata/v6/Constants';
export interface ConstValueBase {
method: string;
section: string;
}
export interface ConstValue extends ConstValueBase {
meta: MetaV6;
}

View File

@ -36,6 +36,7 @@ export { default as Input } from './Input';
export { default as InputAddress } from './InputAddress';
export { default as InputBalance } from './InputBalance';
export { default as InputBalanceBonded } from './InputBalanceBonded';
export { default as InputConsts } from './InputConsts';
export { default as InputError } from './InputError';
export { default as InputExtrinsic } from './InputExtrinsic';
export { default as InputFile } from './InputFile';

View File

@ -11,6 +11,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70"
}
}

View File

@ -11,6 +11,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.4",
"@polkadot/ui-app": "^0.34.0-beta.73"
"@polkadot/ui-app": "^0.34.0-beta.70"
}
}

154
yarn.lock
View File

@ -1871,47 +1871,47 @@
universal-user-agent "^3.0.0"
url-template "^2.0.8"
"@polkadot/api-contract@^0.82.0-beta.68":
version "0.82.0-beta.68"
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.82.0-beta.68.tgz#5c33d7653bbb5a75524ff42ad6d884e38f2a88cf"
integrity sha512-PPrkuWTD0iBuK/d69Psr2oACpiy19qZk+cUy5WW72a3AU/VbNLNeyBH5Lz4srwBhtHWakpB9jpV1PFCXzjV11Q==
"@polkadot/api-contract@^0.82.0-beta.70":
version "0.82.0-beta.70"
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.82.0-beta.70.tgz#a228878fdce42503cfd3ed1aaf96019318df1e2c"
integrity sha512-JK3y1Et6rdNCj1bsMD/oA0u8QujnQ+5O482/MCI4UdwyBTK6BKfy88Bfn+1OyJSME6xBVW9yH4dVmz1IahGWMA==
dependencies:
"@babel/runtime" "^7.5.4"
"@polkadot/types" "^0.82.0-beta.68"
"@polkadot/types" "^0.82.0-beta.70"
"@polkadot/api-derive@^0.82.0-beta.68":
version "0.82.0-beta.68"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.82.0-beta.68.tgz#fee6a5b3c9fda2bb47da9b56e206c95437429578"
integrity sha512-q/ss9IJVVl43kRdUadwqG+KwZrH0NezlX+qVpHGq2dXbZMOAQove/aP8lE9VCvgyzQQwVTG4+iyvJOwSNhaReA==
"@polkadot/api-derive@^0.82.0-beta.70":
version "0.82.0-beta.70"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.82.0-beta.70.tgz#e183e2a7aa969f9948db399de2a2bfe15ab27462"
integrity sha512-BqWT8bj50M0zhpXuT8XB1ZUs06lSs5z9zzTPc8Vmwoi1pJ3X3Zzkq5tNDpDQkvD2awRJ6FAzVV9zsZHrx987Cg==
dependencies:
"@babel/runtime" "^7.5.4"
"@polkadot/api" "^0.82.0-beta.68"
"@polkadot/types" "^0.82.0-beta.68"
"@polkadot/api" "^0.82.0-beta.70"
"@polkadot/types" "^0.82.0-beta.70"
"@types/memoizee" "^0.4.2"
memoizee "^0.4.14"
"@polkadot/api-metadata@^0.82.0-beta.68":
version "0.82.0-beta.68"
resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.82.0-beta.68.tgz#332a4a8ee745966818af67208c634aab2b53c009"
integrity sha512-Zz2KLq2lcuUdlzsuC3e7wzkavwrFJVb6lAs/uANEWQAE4F9dYB8GPKWI049Nz1hpj6VWLZp9Oo8X+8O01lNl5w==
"@polkadot/api-metadata@^0.82.0-beta.70":
version "0.82.0-beta.70"
resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.82.0-beta.70.tgz#bd267b24dcd2382f4f19e06577729ac000f8b5de"
integrity sha512-Z/Df/nqKy/SlSbEON8FEfygryUH+vJKG77i052SsHqIYuuPg4oaYSjQaNzuwzHeyrDfx9zF9CxRaEiJcAdiohg==
dependencies:
"@babel/runtime" "^7.5.4"
"@polkadot/types" "^0.82.0-beta.68"
"@polkadot/util" "^0.94.0-beta.12"
"@polkadot/util-crypto" "^0.94.0-beta.12"
"@polkadot/types" "^0.82.0-beta.70"
"@polkadot/util" "^0.94.0-beta.15"
"@polkadot/util-crypto" "^0.94.0-beta.15"
"@polkadot/api@^0.82.0-beta.68":
version "0.82.0-beta.68"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.82.0-beta.68.tgz#28027eece9f8c02d3977232b5529d9e79af59ea7"
integrity sha512-j++l4dWqZ47J4yGyNqmWFBLOPfhzidVdyBWkeJk6Mc7s0PB5d3+ZU/9iZHtGIx3xckKwYBHIJiSBP7Tg0LGGsA==
"@polkadot/api@^0.82.0-beta.70":
version "0.82.0-beta.70"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.82.0-beta.70.tgz#2665838b2a4f393b921e8110dd34b67735d12af9"
integrity sha512-FqG5uU4sXoGottMd+k70vKz5MIFggbNWSx04Tpj3YzuaZRkyIzaSlCP97+Ycq3a7Yq9XOhabKmYL4P23+w2QLQ==
dependencies:
"@babel/runtime" "^7.5.4"
"@polkadot/api-derive" "^0.82.0-beta.68"
"@polkadot/api-metadata" "^0.82.0-beta.68"
"@polkadot/rpc-core" "^0.82.0-beta.68"
"@polkadot/rpc-provider" "^0.82.0-beta.68"
"@polkadot/types" "^0.82.0-beta.68"
"@polkadot/util-crypto" "^0.94.0-beta.12"
"@polkadot/api-derive" "^0.82.0-beta.70"
"@polkadot/api-metadata" "^0.82.0-beta.70"
"@polkadot/rpc-core" "^0.82.0-beta.70"
"@polkadot/rpc-provider" "^0.82.0-beta.70"
"@polkadot/types" "^0.82.0-beta.70"
"@polkadot/util-crypto" "^0.94.0-beta.15"
"@polkadot/dev-react@^0.30.0-beta.22":
version "0.30.0-beta.22"
@ -1998,56 +1998,56 @@
typescript "^3.5.3"
vuepress "^1.0.2"
"@polkadot/extension-dapp@^0.4.0-beta.6":
version "0.4.0-beta.6"
resolved "https://registry.yarnpkg.com/@polkadot/extension-dapp/-/extension-dapp-0.4.0-beta.6.tgz#4449ba2da00dc97f37e4e7a171b2c2e525741596"
integrity sha512-gum8+6i/mLZ+vfdRLQJ/1emOUGF/sW0mtr+eb1jgucUehnX+kXh4HwUqsdwJnum3pZCy1Mc/XYAILJ6II7hQUw==
"@polkadot/extension-dapp@^0.4.1":
version "0.4.1"
resolved "https://registry.yarnpkg.com/@polkadot/extension-dapp/-/extension-dapp-0.4.1.tgz#c57db24f2a3849d600ef97b868825641924a0566"
integrity sha512-M3EAbY46uXReY8A5FvRllHCduRromNz2ATxjT1gCKPvMni0RAAdXf+zuUb+4ALnb8w2I5WJ5mT5Qc0GdSaDLdQ==
dependencies:
"@polkadot/extension-inject" "^0.4.0-beta.6"
"@polkadot/extension-inject" "^0.4.1"
"@polkadot/extension-inject@^0.4.0-beta.6":
version "0.4.0-beta.6"
resolved "https://registry.yarnpkg.com/@polkadot/extension-inject/-/extension-inject-0.4.0-beta.6.tgz#9d2ad4b15fab080c925afd16662c81184a101b3f"
integrity sha512-FitIT5rl44nyCtBGDJHyVM46cRxZy9knBTNYVBtjfWPOIWGjdrb0ZjZzIM+3dVsN3ERt7St/IsKsOaXqdfB+zw==
"@polkadot/extension-inject@^0.4.1":
version "0.4.1"
resolved "https://registry.yarnpkg.com/@polkadot/extension-inject/-/extension-inject-0.4.1.tgz#d95483b23376c7518b5b046260caa1e4d1dd9217"
integrity sha512-RYA2dF6y9mFwLqNSpVtgguBp1pzG1qY0J4MSEeHfWwkdK+dLo3LG8RBuYvxrzDJHVOYLVCV6tqgJsyPGucAmFw==
"@polkadot/jsonrpc@^0.82.0-beta.68":
version "0.82.0-beta.68"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.82.0-beta.68.tgz#6ed628a18f48f2d81bb419fc0e543bf5107f3753"
integrity sha512-XM6e5VmFBi8eArOwbUGFL79IE+Zr+Uio4b9xakKhlnfjqF9ApXyXOzQoOAH1AXLib2FYLX9wkLJSw4Zy00H+1A==
"@polkadot/jsonrpc@^0.82.0-beta.70":
version "0.82.0-beta.70"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.82.0-beta.70.tgz#83608785c44d63a5a32a6156c051072a43787b57"
integrity sha512-WputxLDX1r+/vkw3oNJLQ/RJ0qotJlAFagA2tZZiz90GX5Y6uLbo7hNo7jfi4gUXm48ajDjIMwYc/tRlNH70Eg==
dependencies:
"@babel/runtime" "^7.5.4"
"@polkadot/keyring@^0.94.0-beta.14":
version "0.94.0-beta.14"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.94.0-beta.14.tgz#f72278bedbe75d1cc18464bfea43fba9c7114243"
integrity sha512-h7Na29oHfmvnX+EiH2jY5mgMY2c+k2XPViJetpB3u5fA7D9hIhC9Y8/EyLDYMD0QEt4ex+5WnuTESVKXbkYfXg==
"@polkadot/keyring@^0.94.0-beta.15":
version "0.94.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.94.0-beta.15.tgz#13e31085b2e2d89c04b40c665292341413c18b77"
integrity sha512-8hG1YmZljPs2/Zip7GbFmhlGB5oUxSNzp12MQT83jujsRvDgtpG+ZORz8LumMVxXWhJR7L3nRY39xSHPO5CTvg==
dependencies:
"@babel/runtime" "^7.5.4"
"@polkadot/util" "^0.94.0-beta.14"
"@polkadot/util-crypto" "^0.94.0-beta.14"
"@polkadot/util" "^0.94.0-beta.15"
"@polkadot/util-crypto" "^0.94.0-beta.15"
"@polkadot/rpc-core@^0.82.0-beta.68":
version "0.82.0-beta.68"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.82.0-beta.68.tgz#68380bb8583d07e60e77c64b1cb225ad65de9d93"
integrity sha512-w2AUJE94bvueGRmugt3A93X4Gi+6yqBAU1AYNR9XDtcBjByXw0W9y1Nk4VO72P+fqqQLi/0Y5iBkBGzjHEJuZQ==
"@polkadot/rpc-core@^0.82.0-beta.70":
version "0.82.0-beta.70"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.82.0-beta.70.tgz#38f06c81f4f3fe705534c352c8d01ebe88443c8a"
integrity sha512-tnK2V2cyWADKFky2GdlRHul6v3IEJKsvy1ULvr+OuVY26Bn/dkoTXsgqmEOxnbdIXitCTj9AtphsWtjDT3Tklw==
dependencies:
"@babel/runtime" "^7.5.4"
"@polkadot/jsonrpc" "^0.82.0-beta.68"
"@polkadot/rpc-provider" "^0.82.0-beta.68"
"@polkadot/types" "^0.82.0-beta.68"
"@polkadot/util" "^0.94.0-beta.12"
"@polkadot/jsonrpc" "^0.82.0-beta.70"
"@polkadot/rpc-provider" "^0.82.0-beta.70"
"@polkadot/types" "^0.82.0-beta.70"
"@polkadot/util" "^0.94.0-beta.15"
memoizee "^0.4.14"
rxjs "^6.5.2"
"@polkadot/rpc-provider@^0.82.0-beta.68":
version "0.82.0-beta.68"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.82.0-beta.68.tgz#b8e80dd37839016284ecd58cdb0e979fda01847c"
integrity sha512-d1qNoJ0nPcVZPWfW3Xps/lTvAePX9Bl8xLxGmp+uV4JfktHHfWFzUo5P3K7dqtUpR22b/LWw1NPXCvKmTXN2lw==
"@polkadot/rpc-provider@^0.82.0-beta.70":
version "0.82.0-beta.70"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.82.0-beta.70.tgz#c274154467887b360a81e9b11128306162150816"
integrity sha512-agACKuvLrQpJw+CAk90m9PquZf5Prv8kDuNrMkCe7jlXUoCfl3FOvjUc004lyRaw+WAs0tV/pzZ+8PYEYdmmGw==
dependencies:
"@babel/runtime" "^7.5.4"
"@polkadot/api-metadata" "^0.82.0-beta.68"
"@polkadot/util" "^0.94.0-beta.12"
"@polkadot/util-crypto" "^0.94.0-beta.12"
"@polkadot/api-metadata" "^0.82.0-beta.70"
"@polkadot/util" "^0.94.0-beta.15"
"@polkadot/util-crypto" "^0.94.0-beta.15"
"@types/nock" "^10.0.3"
eventemitter3 "^4.0.0"
isomorphic-fetch "^2.2.1"
@ -2060,14 +2060,14 @@
dependencies:
"@types/chrome" "^0.0.86"
"@polkadot/types@^0.82.0-beta.68":
version "0.82.0-beta.68"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.82.0-beta.68.tgz#573e505828290dadb9ebabf6f733c61288d099ee"
integrity sha512-aLLRbyP+Ol8I+cx3ZjM/CYqV+KPTF8N3Tfknq6REfgdGvK087fxYf6lVFOXjlBDqPNwHyxhfelpwBGYBvV25mQ==
"@polkadot/types@^0.82.0-beta.70":
version "0.82.0-beta.70"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.82.0-beta.70.tgz#4d4cf4c06152d14b7b89a8b8d7cd936bba794e95"
integrity sha512-PBoPn6qVAzwtI4KS69gs9geleIbnrRXhQpaqjaI3NbNcYZCCOQdf5vc/6PQNQJI4YZJ4CFb1jjN937OxxjG5ew==
dependencies:
"@babel/runtime" "^7.5.4"
"@polkadot/util" "^0.94.0-beta.12"
"@polkadot/util-crypto" "^0.94.0-beta.12"
"@polkadot/util" "^0.94.0-beta.15"
"@polkadot/util-crypto" "^0.94.0-beta.15"
"@polkadot/ui-assets@^0.42.0-beta.13":
version "0.42.0-beta.13"
@ -2112,13 +2112,13 @@
"@types/store" "^2.0.2"
store "^2.0.12"
"@polkadot/util-crypto@^0.94.0-beta.12", "@polkadot/util-crypto@^0.94.0-beta.14":
version "0.94.0-beta.14"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.94.0-beta.14.tgz#252ba715f5ac62204a9d92bc5d162dcdead514be"
integrity sha512-Y+vWgP8XmyhtFaQFaJBA/cEcf6xmT5FlQDWqoA3yipdSFxVJ3Nwb7R5FwuME6rV97FjMt5mZjEn7y24iV4TZ3Q==
"@polkadot/util-crypto@^0.94.0-beta.15":
version "0.94.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.94.0-beta.15.tgz#e79178a89d2f2d4d2b35f2ca1c3fc4829cbec514"
integrity sha512-N5qFWYJKAtCXZURi7/TKb3cG8eyVYJTIupIRCdukl4QBqML8ZnpjbEDTMAW9IR9TzBnIlHxNkxFHT7ePXajUpw==
dependencies:
"@babel/runtime" "^7.5.4"
"@polkadot/util" "^0.94.0-beta.14"
"@polkadot/util" "^0.94.0-beta.15"
"@polkadot/wasm-crypto" "^0.12.1"
"@types/bip39" "^2.4.2"
"@types/bs58" "^4.0.0"
@ -2134,10 +2134,10 @@
tweetnacl "^1.0.1"
xxhashjs "^0.2.2"
"@polkadot/util@^0.94.0-beta.12", "@polkadot/util@^0.94.0-beta.14":
version "0.94.0-beta.14"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.94.0-beta.14.tgz#cd6ef56b867f6eebaf70d896bd6b6e825704aa34"
integrity sha512-1tLMhSPE6sbRfJch0m83RPETQoD+mvmXGAfucsmh1qSoZEznd5kbqPsk06bQr8q19h12x17O2jpFTvmQWMBKTA==
"@polkadot/util@^0.94.0-beta.15":
version "0.94.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.94.0-beta.15.tgz#c10656ee5b6bd8ed50387b9bff4e606a076a439d"
integrity sha512-sx3kWaqOf7oCMXhxg7Dd3d0GlboieyeVBOuShslwKBnEW720AMOCuh3XmQUyUPferTbxukzqudBv7ME8y7e/pg==
dependencies:
"@babel/runtime" "^7.5.4"
"@types/bn.js" "^4.11.5"