ghost-portal/packages/react-components/src/InputConsts/options/key.tsx
Jaco Greeff e7e4efebeb
Enable validator overview (#1872)
* Enable validator overview

* CallDiv indicator for consts
2019-11-12 14:39:38 +01:00

45 lines
1.3 KiB
TypeScript

// Copyright 2017-2019 @polkadot/react-components 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/metadata/Decorated/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
};
});
}