From c13a12c1a7798bf7cf68e6ca98513e56bfa78e80 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 19 Apr 2018 14:29:07 +0200 Subject: [PATCH] flow fixes --- flow-typed/semantic-ui-react.js | 27 +++++++++++++ packages/app-home/package.json | 2 +- packages/app-testing/package.json | 2 +- packages/app-testing/src/Account.js | 4 +- packages/app-testing/src/App.js | 2 +- packages/app-testing/src/CallDisplay/Error.js | 2 +- packages/app-testing/src/CallDisplay/index.js | 10 ++++- .../app-testing/src/CallDisplay/submit.js | 10 ++--- packages/app-testing/src/CallSelect.js | 2 +- .../src/InputAddress/PairDisplay.js | 4 +- .../app-testing/src/InputAddress/index.js | 4 +- packages/app-testing/src/Nonce.js | 8 ++-- packages/app-testing/src/Recipient.js | 2 +- packages/app-testing/src/Sender.js | 2 +- .../app-testing/src/StakingTransfer/Amount.js | 40 +++++++++++++++++++ .../app-testing/src/StakingTransfer/index.js | 26 ++---------- packages/app-testing/src/encode/index.js | 9 ++++- packages/app-testing/src/encode/param.js | 2 +- packages/app-testing/src/encode/params.js | 3 +- packages/app-testing/src/extrinsics/index.js | 17 ++++---- packages/app-testing/src/types.js | 17 ++++++++ packages/portal/package.json | 2 +- packages/portal/src/Content/index.js | 4 +- packages/portal/src/SideBar/Item.js | 4 +- packages/portal/src/SideBar/index.js | 2 +- packages/portal/src/routes/home.js | 2 +- packages/portal/src/routes/testing.js | 2 +- packages/portal/src/types.js | 4 +- yarn.lock | 16 ++++---- 29 files changed, 153 insertions(+), 78 deletions(-) create mode 100644 flow-typed/semantic-ui-react.js create mode 100644 packages/app-testing/src/StakingTransfer/Amount.js create mode 100644 packages/app-testing/src/types.js diff --git a/flow-typed/semantic-ui-react.js b/flow-typed/semantic-ui-react.js new file mode 100644 index 0000000000..cbf05a20cc --- /dev/null +++ b/flow-typed/semantic-ui-react.js @@ -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<*> +} diff --git a/packages/app-home/package.json b/packages/app-home/package.json index 0cb128f83a..a817e59530 100644 --- a/packages/app-home/package.json +++ b/packages/app-home/package.json @@ -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", diff --git a/packages/app-testing/package.json b/packages/app-testing/package.json index a39b614ead..2899613d6e 100644 --- a/packages/app-testing/package.json +++ b/packages/app-testing/package.json @@ -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", diff --git a/packages/app-testing/src/Account.js b/packages/app-testing/src/Account.js index 98aaccbd7c..7ad1a3b37b 100644 --- a/packages/app-testing/src/Account.js +++ b/packages/app-testing/src/Account.js @@ -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) { diff --git a/packages/app-testing/src/App.js b/packages/app-testing/src/App.js index aebfad11d2..309acb1f14 100644 --- a/packages/app-testing/src/App.js +++ b/packages/app-testing/src/App.js @@ -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'; diff --git a/packages/app-testing/src/CallDisplay/Error.js b/packages/app-testing/src/CallDisplay/Error.js index 67049c1064..b596981001 100644 --- a/packages/app-testing/src/CallDisplay/Error.js +++ b/packages/app-testing/src/CallDisplay/Error.js @@ -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'; diff --git a/packages/app-testing/src/CallDisplay/index.js b/packages/app-testing/src/CallDisplay/index.js index 7dc82fd14b..abb7b19176 100644 --- a/packages/app-testing/src/CallDisplay/index.js +++ b/packages/app-testing/src/CallDisplay/index.js @@ -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 +} + 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 ( diff --git a/packages/app-testing/src/CallDisplay/submit.js b/packages/app-testing/src/CallDisplay/submit.js index f634aa1887..6b9f784e81 100644 --- a/packages/app-testing/src/CallDisplay/submit.js +++ b/packages/app-testing/src/CallDisplay/submit.js @@ -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): Promise { - // TODO: Handle result - // TODO: Display some progress +export default function submit (api: RxApiInterface, method: string, values: Array): 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 ) ) diff --git a/packages/app-testing/src/CallSelect.js b/packages/app-testing/src/CallSelect.js index c79b9a3b37..d63ac0666d 100644 --- a/packages/app-testing/src/CallSelect.js +++ b/packages/app-testing/src/CallSelect.js @@ -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'; diff --git a/packages/app-testing/src/InputAddress/PairDisplay.js b/packages/app-testing/src/InputAddress/PairDisplay.js index 3220551fc6..831511d121 100644 --- a/packages/app-testing/src/InputAddress/PairDisplay.js +++ b/packages/app-testing/src/InputAddress/PairDisplay.js @@ -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'; diff --git a/packages/app-testing/src/InputAddress/index.js b/packages/app-testing/src/InputAddress/index.js index 2f5d92e1e2..9b541dd17b 100644 --- a/packages/app-testing/src/InputAddress/index.js +++ b/packages/app-testing/src/InputAddress/index.js @@ -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) => { diff --git a/packages/app-testing/src/Nonce.js b/packages/app-testing/src/Nonce.js index d45ab62faf..2aabc011f8 100644 --- a/packages/app-testing/src/Nonce.js +++ b/packages/app-testing/src/Nonce.js @@ -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) ); }; diff --git a/packages/app-testing/src/Recipient.js b/packages/app-testing/src/Recipient.js index 99e0fc930e..a1b26a6ede 100644 --- a/packages/app-testing/src/Recipient.js +++ b/packages/app-testing/src/Recipient.js @@ -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'; diff --git a/packages/app-testing/src/Sender.js b/packages/app-testing/src/Sender.js index d7f7632e1f..27d78c97b6 100644 --- a/packages/app-testing/src/Sender.js +++ b/packages/app-testing/src/Sender.js @@ -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'; diff --git a/packages/app-testing/src/StakingTransfer/Amount.js b/packages/app-testing/src/StakingTransfer/Amount.js new file mode 100644 index 0000000000..7d0ee4346f --- /dev/null +++ b/packages/app-testing/src/StakingTransfer/Amount.js @@ -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 ( +
+
+ + +
+
+ ); +} diff --git a/packages/app-testing/src/StakingTransfer/index.js b/packages/app-testing/src/StakingTransfer/index.js index 1409885afe..7074b45a6f 100644 --- a/packages/app-testing/src/StakingTransfer/index.js +++ b/packages/app-testing/src/StakingTransfer/index.js @@ -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 (
-
-
- - -
-
- +
); diff --git a/packages/app-testing/src/encode/index.js b/packages/app-testing/src/encode/index.js index 8b967e6a2f..fd7cd2e96e 100644 --- a/packages/app-testing/src/encode/index.js +++ b/packages/app-testing/src/encode/index.js @@ -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): Uint8Array { - const { index, params } = extrinsic; +module.exports = function encode ({ index, params }: Extrinsic, sender?: ?KeyringPair, nonce: number | BN, values: Array): 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); diff --git a/packages/app-testing/src/encode/param.js b/packages/app-testing/src/encode/param.js index 524c30b3d7..cc1a3088f2 100644 --- a/packages/app-testing/src/encode/param.js +++ b/packages/app-testing/src/encode/param.js @@ -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'); diff --git a/packages/app-testing/src/encode/params.js b/packages/app-testing/src/encode/params.js index b63de0908b..10fb0870e1 100644 --- a/packages/app-testing/src/encode/params.js +++ b/packages/app-testing/src/encode/params.js @@ -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, params: Extrinsic$Params): Uint8Array { return u8aConcat.apply(null, values.map((value, index) => { return encodeParam(value, params[index]); diff --git a/packages/app-testing/src/extrinsics/index.js b/packages/app-testing/src/extrinsics/index.js index 93c2876824..5bbf969063 100644 --- a/packages/app-testing/src/extrinsics/index.js +++ b/packages/app-testing/src/extrinsics/index.js @@ -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), section[method]); - - flat[name] = expanded; + name, + // flowlint-next-line inexact-spread:off + ...section[method] + }; return flat; }, flat); - - return flat; }, ({}: $Shape)); module.exports = flattenned; diff --git a/packages/app-testing/src/types.js b/packages/app-testing/src/types.js new file mode 100644 index 0000000000..b76391d084 --- /dev/null +++ b/packages/app-testing/src/types.js @@ -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 +}; diff --git a/packages/portal/package.json b/packages/portal/package.json index b4530eded3..8bd92c6c95 100644 --- a/packages/portal/package.json +++ b/packages/portal/package.json @@ -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", diff --git a/packages/portal/src/Content/index.js b/packages/portal/src/Content/index.js index 3baac23b83..fc84c92123 100644 --- a/packages/portal/src/Content/index.js +++ b/packages/portal/src/Content/index.js @@ -23,11 +23,11 @@ export default translate(['portal'])( style={style} > { - routes.map(({ component, isExact, key, path }) => ( + routes.map(({ component, isExact, name, path }) => ( )) diff --git a/packages/portal/src/SideBar/Item.js b/packages/portal/src/SideBar/Item.js index bf3c8c7231..bc3dcb9c43 100644 --- a/packages/portal/src/SideBar/Item.js +++ b/packages/portal/src/SideBar/Item.js @@ -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 ( diff --git a/packages/portal/src/SideBar/index.js b/packages/portal/src/SideBar/index.js index 66159cd726..994f95faff 100644 --- a/packages/portal/src/SideBar/index.js +++ b/packages/portal/src/SideBar/index.js @@ -30,7 +30,7 @@ export default translate(['portal'])( { routes.map((props) => ( diff --git a/packages/portal/src/routes/home.js b/packages/portal/src/routes/home.js index 52754f4c68..0632f77019 100644 --- a/packages/portal/src/routes/home.js +++ b/packages/portal/src/routes/home.js @@ -16,7 +16,7 @@ export default ([ icon: 'home', isExact: true, isHidden: false, - key: 'home', + name: 'home', path: '/' } ]: Routes); diff --git a/packages/portal/src/routes/testing.js b/packages/portal/src/routes/testing.js index d8d74f0a89..3b256fb6b3 100644 --- a/packages/portal/src/routes/testing.js +++ b/packages/portal/src/routes/testing.js @@ -16,7 +16,7 @@ export default ([ icon: 'braille', isExact: false, isHidden: false, - key: 'testing', + name: 'testing', path: '/testing' } ]: Routes); diff --git a/packages/portal/src/types.js b/packages/portal/src/types.js index 2d5a7273d6..15c2e5adeb 100644 --- a/packages/portal/src/types.js +++ b/packages/portal/src/types.js @@ -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, diff --git a/yarn.lock b/yarn.lock index 73edddaef2..d28c78ad2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"