flow fixes

This commit is contained in:
Jaco Greeff 2018-04-19 14:29:07 +02:00
parent 0484805619
commit c13a12c1a7
29 changed files with 153 additions and 78 deletions

27
flow-typed/semantic-ui-react.js vendored Normal file
View File

@ -0,0 +1,27 @@
// @flow
declare module 'semantic-ui-react/dist/es/collections/Menu' {
declare module.exports: React$StatelessFunctionalComponent<*> & {
Item: React$StatelessFunctionalComponent<*>
}
}
declare module 'semantic-ui-react/dist/es/elements/Button' {
declare module.exports: React$StatelessFunctionalComponent<*>
}
declare module 'semantic-ui-react/dist/es/elements/Icon' {
declare module.exports: React$StatelessFunctionalComponent<*>
}
declare module 'semantic-ui-react/dist/es/elements/Input' {
declare module.exports: React$StatelessFunctionalComponent<*>
}
declare module 'semantic-ui-react/dist/es/elements/Label' {
declare module.exports: React$StatelessFunctionalComponent<*>
}
declare module 'semantic-ui-react/dist/es/modules/Dropdown' {
declare module.exports: React$StatelessFunctionalComponent<*>
}

View File

@ -13,7 +13,7 @@
"test": "react-scripts test --env=jsdom --coverage"
},
"devDependencies": {
"@polkadot/rx-react": "^0.2.8",
"@polkadot/rx-react": "^0.2.9",
"@polkadot/util": "^0.19.1",
"react": "^16.3.1",
"react-dom": "^16.3.1",

View File

@ -13,7 +13,7 @@
"test": "react-scripts test --env=jsdom --coverage"
},
"devDependencies": {
"@polkadot/rx-react": "^0.2.8",
"@polkadot/rx-react": "^0.2.9",
"@polkadot/ui-react": "^0.9.10",
"@polkadot/util": "^0.19.1",
"@polkadot/util-keyring": "^0.19.1",

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps } from '@polkadot/portal/types';
import type { BaseProps } from './types';
import React from 'react';
import Label from 'semantic-ui-react/dist/es/elements/Label';
@ -14,7 +14,7 @@ import InputAddress from './InputAddress';
type Props = BaseProps & {
label: string,
subject: rxjs$BehaviorSubject
subject: rxjs$BehaviorSubject<*>
};
export default function Account ({ className, label, subject, style }: Props) {

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps } from '@polkadot/portal/types';
import type { BaseProps } from './types';
import React from 'react';

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps } from '@polkadot/portal/types';
import type { BaseProps } from '../types';
import './CallDisplay.css';

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps, BaseContext } from '@polkadot/portal/types';
import type { BaseProps, BaseContext } from '../types';
import './CallDisplay.css';
@ -17,6 +17,10 @@ import { extrinsicName } from '../subjects';
import ErrorComponent from './Error';
import submitExtrinsic from './submit';
type ValueGetter = {
getValues: () => Array<mixed>
}
type Props = BaseProps & {
value?: string;
};
@ -26,13 +30,15 @@ const COMPONENTS = {
};
function CallDisplay ({ className, style, value }: Props, { api }: BaseContext) {
// flowlint-next-line sketchy-null-string:off
if (!value) {
return null;
}
const Component = COMPONENTS[value] || ErrorComponent;
const onSubmit = () => {
submitExtrinsic(api, value, Component.getValues());
// flowlint-next-line unclear-type:off
submitExtrinsic(api, value, ((Component: any): ValueGetter).getValues());
};
return (

View File

@ -10,15 +10,15 @@ import extrinsics from '../extrinsics';
import keyring from '../keyring';
import { senderAddr, senderIndex } from '../subjects';
export default function submit (api: RxApiInterface, method: string, values: Array<mixed>): Promise<void> {
// TODO: Handle result
// TODO: Display some progress
export default function submit (api: RxApiInterface, method: string, values: Array<mixed>): void {
// TODO: Display some progress once we have a subscription
api.author
.submitExtrinsic(
encode(
extrinsics[method],
keyring.getPair(senderAddr.getValue()),
senderIndex.getValue(),
// flowlint-next-line unclear-type:off
keyring.getPair(((senderAddr.getValue(): any): Uint8Array)),
senderIndex.getValue() || 0,
values
)
)

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps } from '@polkadot/portal/types';
import type { BaseProps } from './types';
import React from 'react';
import Dropdown from 'semantic-ui-react/dist/es/modules/Dropdown';

View File

@ -3,8 +3,8 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps } from '@polkadot/portal/types';
import type { KeyringPair } from '@poladot/util-keyring/types';
import type { KeyringPair } from '@polkadot/util-keyring/types';
import type { BaseProps } from '../types';
import './PairDisplay.css';

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps } from '@polkadot/portal/types';
import type { BaseProps } from '../types';
import './InputAddress.css';
@ -14,7 +14,7 @@ import PairDisplay from './PairDisplay';
import keyring from '../keyring';
type Props = BaseProps & {
subject: rxjs$Subject
subject: rxjs$Subject<*>
};
const testOptions = keyring.getPairs().map((pair) => {

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps } from '@polkadot/portal/types';
import type { BaseProps } from './types';
import React from 'react';
import Label from 'semantic-ui-react/dist/es/elements/Label';
@ -16,13 +16,15 @@ import { senderAddr, senderIndex } from './subjects';
type Props = BaseProps & {};
const SenderNonce = withObservableParams(RxNonce, senderAddr);
const onNonceChange = (value: Uint8Array) => {
const onNonceChange = (value) => {
// flowlint-next-line sketchy-null-mixed:off
if (!value || value.length !== 8) {
return;
}
senderIndex.next(
u8aToBn(value, 64, true)
// flowlint-next-line unclear-type:off
u8aToBn(((value: any): Uint8Array), true)
);
};

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps } from '@polkadot/portal/types';
import type { BaseProps } from './types';
import React from 'react';

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps } from '@polkadot/portal/types';
import type { BaseProps } from './types';
import React from 'react';

View File

@ -0,0 +1,40 @@
// 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 { BaseProps } from '../types';
import BN from 'bn.js';
import React from 'react';
import Input from 'semantic-ui-react/dist/es/elements/Input';
import Label from 'semantic-ui-react/dist/es/elements/Label';
import { amount } from './subjects';
type Props = BaseProps & {};
const onChange = (event, { value }) => {
amount.next(
new BN(value || 0)
);
};
export default function Amount ({ className, style }: Props) {
return (
<div
className={['testing--split', className].join(' ')}
style={style}
>
<div className='small'>
<Label>sending an amount of</Label>
<Input
defaultValue={0}
min={0}
onChange={onChange}
type='number'
/>
</div>
</div>
);
}

View File

@ -3,45 +3,25 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps } from '@polkadot/portal/types';
import type { BaseProps } from '../types';
import './StakingTransfer.css';
import BN from 'bn.js';
import React from 'react';
import Input from 'semantic-ui-react/dist/es/elements/Input';
import Label from 'semantic-ui-react/dist/es/elements/Label';
import Recipient from '../Recipient';
import Amount from './Amount';
import getValues from './getValues';
import { amount } from './subjects';
type Props = BaseProps & {};
const onChangeAmount = (event, { value }) => {
amount.next(
new BN(value || 0)
);
};
function StakingTransfer ({ className, style }: Props) {
return (
<div
className={['testing--StakingTransfer', className].join(' ')}
style={style}
>
<div className='testing--split'>
<div className='small'>
<Label>sending an amount of</Label>
<Input
defaultValue={0}
min={0}
onChange={onChangeAmount}
type='number'
/>
</div>
</div>
<Amount />
<Recipient />
</div>
);

View File

@ -6,22 +6,27 @@
// TODO: Move to API
import type BN from 'bn.js';
import type { KeyringPair } from '@polkadot/util-keyring/types';
import type { Extrinsic } from '../extrinsics/types';
const assert = require('@polkadot/util/assert');
const bnToU8a = require('@polkadot/util/bn/toU8a');
const u8aConcat = require('@polkadot/util/u8a/concat');
const encodeParams = require('./params');
module.exports = function encode (extrinsic: Extrinsic, sender: KeyringPair, nonce: number | BN, values: Array<mixed>): Uint8Array {
const { index, params } = extrinsic;
module.exports = function encode ({ index, params }: Extrinsic, sender?: ?KeyringPair, nonce: number | BN, values: Array<mixed>): Uint8Array {
assert(sender, 'Expected a valid sender to extrinsic encode');
const encodedParams = encodeParams(values, params);
const message = u8aConcat(
// $FlowFixMe sender checked above
sender.publicKey(),
bnToU8a(nonce, 64, true),
index,
encodedParams
);
// $FlowFixMe sender checked above
const signature = sender.sign(message);
return u8aConcat(message, signature);

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { Extrinsic$Type } from '../../extrinsics/types';
import type { Extrinsic$Type } from '../extrinsics/types';
const bnToU8a = require('@polkadot/util/bn/toU8a');

View File

@ -3,13 +3,12 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { Extrinsic$Params } from '../../extrinsics/types';
import type { Extrinsic$Params } from '../extrinsics/types';
const u8aConcat = require('@polkadot/util/u8a/concat');
const encodeParam = require('./param');
// flowlint-next-line unclear-type:off
module.exports = function encodeParams (values: Array<mixed>, params: Extrinsic$Params): Uint8Array {
return u8aConcat.apply(null, values.map((value, index) => {
return encodeParam(value, params[index]);

View File

@ -33,25 +33,24 @@ const flattenned: Extrinsics = Object
const section = all[sectionName];
const sectionIndex = bnToU8a(_index, 8);
Object
return Object
.keys(section)
.reduce((flat, method, _index) => {
const name = `${sectionName}_${method}`;
const methodIndex = bnToU8a(_index, 8);
const index = u8aConcat(sectionIndex, methodIndex);
const indexHex = u8aToHex(index, 16);
const expanded = Object.assign(({
const indexHex = u8aToHex(index);
flat[name] = {
index,
indexHex,
name
}: $Shape<Extrinsic>), section[method]);
flat[name] = expanded;
name,
// flowlint-next-line inexact-spread:off
...section[method]
};
return flat;
}, flat);
return flat;
}, ({}: $Shape<Extrinsics>));
module.exports = flattenned;

View File

@ -0,0 +1,17 @@
// 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 { RxApiInterface } from '@polkadot/rx-api/types';
export type BaseProps = {
className?: string,
style?: {
[string]: string
}
};
export type BaseContext = {
api: RxApiInterface
};

View File

@ -16,7 +16,7 @@
"devDependencies": {
"@polkadot/app-home": "^0.1.0",
"@polkadot/app-testing": "^0.1.0",
"@polkadot/rx-react": "^0.2.8",
"@polkadot/rx-react": "^0.2.9",
"@polkadot/ui-react": "^0.9.10",
"i18next": "^11.1.1",
"i18next-browser-languagedetector": "^2.2.0",

View File

@ -23,11 +23,11 @@ export default translate(['portal'])(
style={style}
>
{
routes.map(({ component, isExact, key, path }) => (
routes.map(({ component, isExact, name, path }) => (
<Route
component={component}
exact={isExact}
key={key}
key={name}
path={path}
/>
))

View File

@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.
// @flow
import type { BaseProps, Routes } from '../types';
import type { BaseProps, Route } from '../types';
import './Item.css';
@ -12,7 +12,7 @@ import { NavLink } from 'react-router-dom';
import Icon from 'semantic-ui-react/dist/es/elements/Icon';
import Menu from 'semantic-ui-react/dist/es/collections/Menu';
type Props = BaseProps & Routes & {};
type Props = BaseProps & Route & {};
export default function Item ({ className, i18n, icon, isExact, name, path, style, t }: Props) {
return (

View File

@ -30,7 +30,7 @@ export default translate(['portal'])(
{
routes.map((props) => (
<Item
name={props.key}
key={props.name}
t={t}
{...props}
/>

View File

@ -16,7 +16,7 @@ export default ([
icon: 'home',
isExact: true,
isHidden: false,
key: 'home',
name: 'home',
path: '/'
}
]: Routes);

View File

@ -16,7 +16,7 @@ export default ([
icon: 'braille',
isExact: false,
isHidden: false,
key: 'testing',
name: 'testing',
path: '/testing'
}
]: Routes);

View File

@ -19,8 +19,8 @@ export type BaseContext = {
export type Route = {
component: React$StatelessFunctionalComponent<*>,
i18n: I18Nex$tTranslate$Config,
icon: React$StatelessFunctionalComponent<*>,
i18n: I18Next$Translate$Config,
icon: React$StatelessFunctionalComponent<*> | string,
isExact: boolean,
isHidden: boolean,
name: string,

View File

@ -1299,20 +1299,20 @@
"@polkadot/util" "^0.18.4"
babel-runtime "^6.26.0"
"@polkadot/rx-api@^0.2.8":
version "0.2.8"
resolved "https://registry.yarnpkg.com/@polkadot/rx-api/-/rx-api-0.2.8.tgz#12e08d62afc4eb623c37279bba5927b790be8e2a"
"@polkadot/rx-api@^0.2.9":
version "0.2.9"
resolved "https://registry.yarnpkg.com/@polkadot/rx-api/-/rx-api-0.2.9.tgz#b495cab218fd80bd7d8090b0898b689fcca16e4f"
dependencies:
"@polkadot/api" "^0.8.14"
"@polkadot/api-provider" "^0.8.14"
rxjs "^5.5.10"
"@polkadot/rx-react@^0.2.8":
version "0.2.8"
resolved "https://registry.yarnpkg.com/@polkadot/rx-react/-/rx-react-0.2.8.tgz#75fdaf5dab36b11ae92f98c8d29be41753668d73"
"@polkadot/rx-react@^0.2.9":
version "0.2.9"
resolved "https://registry.yarnpkg.com/@polkadot/rx-react/-/rx-react-0.2.9.tgz#55a37178d47bc53b42fbe948c136483b2e9e7377"
dependencies:
"@polkadot/rx-api" "^0.2.8"
"@polkadot/util" "^0.18.6"
"@polkadot/rx-api" "^0.2.9"
"@polkadot/util" "^0.19.1"
"@polkadot/ui-identicon@^0.9.10":
version "0.9.10"