ghost-portal/packages/ui-react-app/src/InputExtrinsic/options/method.js
Jaco Greeff da5c28faa6
Fix extrinsic proposals (#15)
* Fix file upload size

* Extrinsics should extrinsic again
2018-05-05 13:20:23 +02:00

49 lines
1.3 KiB
JavaScript

// Copyright 2017-2018 Jaco Greeff
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow
import type { ExtrinsicSectionName } from '@polkadot/extrinsics/types';
import React from 'react';
import map from '@polkadot/extrinsics-substrate';
// flowlint-next-line unclear-type:off
export default function createOptions (sectionName: any, type: 'private' | 'public'): Array<*> {
const section = map[(sectionName: ExtrinsicSectionName)];
if (!section) {
return [];
}
const methods = section.methods[type];
return Object
.keys(methods)
.sort()
.map((name) => {
const { description = '', params = {} } = methods[name];
const inputs = Object.keys(params).join(', ');
return {
className: 'ui--InputExtrinsic-SelectMethod-Item',
key: `${sectionName}_${name}`,
text: [
<div
className='ui--InputExtrinsic-SelectMethod-Item-text'
key={`${sectionName}_${name}:text`}
>
{description || name}
</div>,
<div
className='ui--InputExtrinsic-SelectMethod-Item-call'
key={`${sectionName}_${name}:call`}
>
{name}({inputs})
</div>
],
value: name
};
});
}