diff --git a/packages/app-storage/src/Selection/Modules.tsx b/packages/app-storage/src/Selection/Modules.tsx index c3caf51e8a..a6bb932d7f 100644 --- a/packages/app-storage/src/Selection/Modules.tsx +++ b/packages/app-storage/src/Selection/Modules.tsx @@ -23,6 +23,7 @@ type Props = ComponentProps & ApiProps & I18nProps; interface State { isValid: boolean; key: StorageEntryPromise; + defaultValues?: RawParams | null; values: RawParams; params: { type: TypeDef }[]; } @@ -48,7 +49,7 @@ class Modules extends TxComponent { public render (): React.ReactNode { const { t } = this.props; - const { isValid, key: { creator: { method, section, meta } }, params } = this.state; + const { isValid, key: { creator: { method, section, meta } }, defaultValues, params } = this.state; return (
@@ -64,6 +65,7 @@ class Modules extends TxComponent { onChange={this.onChangeParams} onEnter={this.submit} params={params} + values={defaultValues} />
@@ -83,29 +85,65 @@ class Modules extends TxComponent { this.setState( (prevState: State): Pick => { const { key = prevState.key, values = prevState.values } = newState; - const hasParam = key.creator.meta.type.isMap; - const isValid = values.length === (hasParam ? 1 : 0) && - values.reduce( - (isValid, value): boolean => + + const areParamsValid = (): boolean => { + return values.reduce( + (isValid: boolean, value): boolean => ( isValid && !isUndefined(value) && !isUndefined(value.value) && - value.isValid, + value.isValid), true ); + }; + + if (key.creator.meta.type.isDoubleMap) { + const key1 = key.creator.meta.type.asDoubleMap.key1.toString(); + const key2 = key.creator.meta.type.asDoubleMap.key2.toString(); + + return { + defaultValues: this.getDefaultValues(), + isValid: values.length === 2 && areParamsValid(), + key, + params: [ + { type: getTypeDef(key1) }, + { type: getTypeDef(key2) } + ], + values + }; + } + + const hasParam = key.creator.meta.type.isMap; + const isValid = values.length === (hasParam ? 1 : 0) && areParamsValid(); return { + defaultValues: null, isValid, key, - values, params: hasParam ? [{ type: getTypeDef(key.creator.meta.type.asMap.key.toString()) }] - : [] + : [], + values }; } ); } + private getDefaultValues = (): RawParams | null => { + const { api } = this.props; + const { key } = this.state; + + if (key.creator.section === 'session') { + return [ + { + isValid: true, + value: api.consts.session.dedupKeyPrefix.toHex() + } + ]; + } + return null; + } + private onAdd = (): void => { const { onAdd } = this.props; const { key, values } = this.state; diff --git a/packages/ui-app/src/InputStorage/options/key.tsx b/packages/ui-app/src/InputStorage/options/key.tsx index 4a09cfd3dd..a5c2809ec2 100644 --- a/packages/ui-app/src/InputStorage/options/key.tsx +++ b/packages/ui-app/src/InputStorage/options/key.tsx @@ -21,9 +21,23 @@ export default function createOptions (api: ApiPromise, sectionName: string): Dr .map((value): DropdownOption => { const method = section[value] as unknown as StorageEntry; const type = method.meta.type; - const input = type.isMap - ? type.asMap.key.toString() - : ''; + let input = ''; + + if (type.isMap) { + input = type.asMap.key.toString(); + } else if (type.isDoubleMap) { + input = type.asDoubleMap.key1.toString() + ', ' + type.asDoubleMap.key2.toString(); + } + + let output = type.toString(); + + if (type.isDoubleMap) { + output = `DoubleMap<${type.asDoubleMap.value.toString()}>`; + } + + if (method.meta.modifier.isOptional) { + output = `Option<${output}>`; + } return { className: 'ui--DropdownLinked-Item', @@ -33,11 +47,7 @@ export default function createOptions (api: ApiPromise, sectionName: string): Dr className='ui--DropdownLinked-Item-call' key={`${sectionName}_${value}:call`} > - {value}({input}): { - method.meta.modifier.isOptional - ? `Option<${type}>` - : type.toString() - } + {value}({input}): {output}
,
void; overrides?: ComponentMap; params: Param[]; - values?: RawParams; + values?: RawParams | null; } interface State { @@ -54,7 +54,16 @@ class Params extends React.PureComponent { return null; } - const values = createValues(props.params); + const values = props.params.reduce( + (result: RawParams, param, index): RawParams => [ + ...result, + props.values && props.values[index] + ? props.values[index] + : createValue(param) + ], + [] + ); + const handlers = values.map( (_, index): RawParamOnChange => (value: RawParamOnChangeValue): void => diff --git a/packages/ui-params/src/initValue.ts b/packages/ui-params/src/initValue.ts index faaeb70ccd..2c38573c07 100644 --- a/packages/ui-params/src/initValue.ts +++ b/packages/ui-params/src/initValue.ts @@ -88,6 +88,7 @@ export default function getInitValue (def: TypeDef): RawParamValue | RawParamVal case 'Signature': case 'SessionKey': case 'StorageKey': + case 'ValidatorId': return void 0; case 'Extrinsic': diff --git a/packages/ui-params/src/values.ts b/packages/ui-params/src/values.ts index 6812fd2e0c..f5aa2e33ed 100644 --- a/packages/ui-params/src/values.ts +++ b/packages/ui-params/src/values.ts @@ -9,13 +9,15 @@ import { isUndefined } from '@polkadot/util'; import getInitValue from './initValue'; -export default function values (params: { type: TypeDef }[]): RawParam[] { - return params.map(({ type }): RawParam => { - const value = getInitValue(type); +export function createValue (param: { type: TypeDef }): RawParam { + const value = getInitValue(param.type); - return { - isValid: !isUndefined(value), - value - }; - }); + return { + isValid: !isUndefined(value), + value + }; +} + +export default function createValues (params: { type: TypeDef }[]): RawParam[] { + return params.map(createValue); }