diff --git a/.flowconfig b/.flowconfig index 051845a5df..e6ffabb22e 100644 --- a/.flowconfig +++ b/.flowconfig @@ -12,5 +12,7 @@ all=warn [options] include_warnings=true -module.name_mapper='^@polkadot/app-\(accounts\|explorer\|extrinsics\|home\|settings\)\(.*\)$' -> '/packages/app-\1/src\2' -module.name_mapper='^@polkadot/portal\(.*\)$' -> '/packages/portal/src\1' +module.name_mapper='^@polkadot/app-\(accounts\|explorer\|extrinsics\|home\|rpc\|settings\|storage\)\(.*\)$' -> '/packages/app-\1/src\2' +module.name_mapper='^@polkadot/apps\(.*\)$' -> '/packages/apps/src\1' +module.name_mapper='^@polkadot/extrinsics-\(codec\|polkadot\|substrate\)\(.*\)$' -> '/packages/extrinsics-\1/src\2' +module.name_mapper='^@polkadot/extrinsics\(.*\)$' -> '/packages/extrinsics/src\1' diff --git a/flow-typed/semantic-ui-react.js b/flow-typed/semantic-ui-react.js index 53ca9071a4..3e1ddefb7b 100644 --- a/flow-typed/semantic-ui-react.js +++ b/flow-typed/semantic-ui-react.js @@ -23,7 +23,11 @@ declare module 'semantic-ui-react/dist/es/elements/Label' { } declare module 'semantic-ui-react/dist/es/modules/Dropdown' { - declare module.exports: React$StatelessFunctionalComponent<*> + declare module.exports: React$StatelessFunctionalComponent<*> & { + Divider: React$StatelessFunctionalComponent<*>, + Header: React$StatelessFunctionalComponent<*>, + Item: React$StatelessFunctionalComponent<*> + } } declare module 'semantic-ui-react/dist/es/modules/Modal' { diff --git a/package.json b/package.json index f4124b0a7a..8cec8f85db 100644 --- a/package.json +++ b/package.json @@ -6,15 +6,12 @@ "packages/*" ], "scripts": { - "build": "polkadot-dev-build-babel && yarn run build:portal", - "build:portal": "cd packages/portal && react-scripts build", + "build": "polkadot-dev-build-babel && yarn run build:apps", + "build:apps": "cd packages/apps && react-scripts build", "check": "eslint packages && flow check", - "deploy:ghpages": "gh-pages -d packages/portal/build", - "start": "cd packages/portal && react-scripts start", - "test": "echo 'to tests executed'" - }, - "dependencies": { - "@polkadot/portal": "^0.1.1" + "deploy:ghpages": "gh-pages -d packages/apps/build", + "start": "cd packages/apps && react-scripts start", + "test": "echo 'no tests executed'" }, "devDependencies": { "@polkadot/dev": "^0.17.12", diff --git a/packages/app-explorer/package.json b/packages/app-explorer/package.json index d3b9f4c829..b5fa7bddc5 100644 --- a/packages/app-explorer/package.json +++ b/packages/app-explorer/package.json @@ -1,7 +1,7 @@ { "name": "@polkadot/app-explorer", "version": "0.1.3", - "main": "src/index.js", + "main": "index.js", "repository": "https://github.com/polkadot-js/portal.git", "author": "Jaco Greeff ", "license": "ISC", @@ -11,12 +11,12 @@ "test": "jest --coverage" }, "devDependencies": { - "@polkadot/primitives": "^0.10.3", - "@polkadot/primitives-codec": "^0.10.3", - "@polkadot/primitives-json": "^0.10.3", - "@polkadot/rx-react": "^0.4.6", - "@polkadot/util": "^0.19.2", - "@polkadot/util-crypto": "^0.19.2", + "@polkadot/primitives": "^0.10.4", + "@polkadot/primitives-codec": "^0.10.4", + "@polkadot/primitives-json": "^0.10.4", + "@polkadot/rx-react": "^0.4.7", + "@polkadot/util": "^0.19.4", + "@polkadot/util-crypto": "^0.19.4", "react": "^16.3.1", "react-dom": "^16.3.1", "react-i18next": "^7.5.1", diff --git a/packages/app-explorer/src/App/index.js b/packages/app-explorer/src/App/index.js index b0703fc5e0..f48c0c35c0 100644 --- a/packages/app-explorer/src/App/index.js +++ b/packages/app-explorer/src/App/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 './App.css'; diff --git a/packages/app-extrinsics/package.json b/packages/app-extrinsics/package.json index 550979cf03..47dced3dab 100644 --- a/packages/app-extrinsics/package.json +++ b/packages/app-extrinsics/package.json @@ -1,7 +1,7 @@ { "name": "@polkadot/app-extrinsics", "version": "0.1.3", - "main": "src/index.js", + "main": "index.js", "repository": "https://github.com/polkadot-js/portal.git", "author": "Jaco Greeff ", "license": "ISC", @@ -11,10 +11,13 @@ "test": "jest --coverage" }, "devDependencies": { - "@polkadot/rx-react": "^0.4.6", - "@polkadot/ui-react": "^0.9.11", - "@polkadot/util": "^0.19.2", - "@polkadot/util-keyring": "^0.19.2", + "@polkadot/extrinsics": "^0.1.3", + "@polkadot/extrinsics-codec": "^0.1.3", + "@polkadot/extrinsics-polkadot": "^0.1.3", + "@polkadot/rx-react": "^0.4.7", + "@polkadot/ui-react": "^0.9.12", + "@polkadot/util": "^0.19.4", + "@polkadot/util-keyring": "^0.19.4", "react": "^16.3.1", "react-dom": "^16.3.1", "react-i18next": "^7.5.1", diff --git a/packages/app-extrinsics/src/Account.js b/packages/app-extrinsics/src/Account.js index ef8b859a7f..18e0e63a32 100644 --- a/packages/app-extrinsics/src/Account.js +++ b/packages/app-extrinsics/src/Account.js @@ -14,11 +14,12 @@ import translate from './translate'; import InputAddress from './InputAddress'; type Props = BaseProps & { + isError?: boolean, label: string, subject: rxjs$BehaviorSubject }; -function Account ({ className, label, subject, style, t }: Props): React$Node { +function Account ({ className, isError, label, subject, style, t }: Props): React$Node { const AccountBalance = withObservableParams(subject)(Balance); return ( diff --git a/packages/app-extrinsics/src/Extrinsic/index.js b/packages/app-extrinsics/src/Extrinsic/index.js index 5576241cdd..df3fb4b9c4 100644 --- a/packages/app-extrinsics/src/Extrinsic/index.js +++ b/packages/app-extrinsics/src/Extrinsic/index.js @@ -14,12 +14,13 @@ import Params from '../Params'; import createSubjects from './subjects'; type Props = BareProps & { + isError?: boolean, isPrivate?: boolean, label: string, subject: rxjs$BehaviorSubject }; -export default function ExtrinsicMethod ({ className, isPrivate, label, style, subject }: Props): React$Node { +export default function Extrinsic ({ className, isError, isPrivate, label, style, subject }: Props): React$Node { const subjects = createSubjects(subject); const MethodParams = withObservable(subjects.method)(Params); @@ -31,6 +32,7 @@ export default function ExtrinsicMethod ({ className, isPrivate, label, style, s
diff --git a/packages/app-extrinsics/src/Extrinsic/subjects.js b/packages/app-extrinsics/src/Extrinsic/subjects.js index 8272a65434..c25b358206 100644 --- a/packages/app-extrinsics/src/Extrinsic/subjects.js +++ b/packages/app-extrinsics/src/Extrinsic/subjects.js @@ -3,14 +3,13 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Extrinsic } from '../extrinsics/types'; +import type { Extrinsic } from '@polkadot/extrinsics/types'; import type { EncodedParams, RawParam } from '../types'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; +import encodeExtrinsic from '@polkadot/extrinsics-codec/src/encode/extrinsic'; import isUndefined from '@polkadot/util/is/undefined'; -import encodeExtrinsic from '../encode/extrinsic'; - type Subjects = { method: rxjs$BehaviorSubject, params: rxjs$BehaviorSubject> @@ -38,7 +37,6 @@ export default function subjects (subject: rxjs$BehaviorSubject): }); }; - subjects.method.subscribe(onChange); subjects.params.subscribe(onChange); return subjects; diff --git a/packages/app-extrinsics/src/InputAddress/index.js b/packages/app-extrinsics/src/InputAddress/index.js index 1918bf1521..c5dd9b8e61 100644 --- a/packages/app-extrinsics/src/InputAddress/index.js +++ b/packages/app-extrinsics/src/InputAddress/index.js @@ -17,6 +17,7 @@ import keyring from '../keyring'; type Props = { className?: string, + isError?: boolean, onChange?: (event: SyntheticEvent<*>, value: Uint8Array) => void, style?: { [string]: string @@ -44,11 +45,16 @@ export default function InputAddress (props: Props): React$Node { } }; + const _props = {...props}; + + delete _props.isError; + return ( diff --git a/packages/app-extrinsics/src/InputExtrinsic/InputExtrinsic.css b/packages/app-extrinsics/src/InputExtrinsic/InputExtrinsic.css index e48f780182..7f26eb5305 100644 --- a/packages/app-extrinsics/src/InputExtrinsic/InputExtrinsic.css +++ b/packages/app-extrinsics/src/InputExtrinsic/InputExtrinsic.css @@ -4,8 +4,6 @@ .ui--InputExtrinsic {} -.ui--InputExtrinsic-Header {} - .ui--InputExtrinsic .text { box-sizing: border-box; display: flex !important; diff --git a/packages/app-extrinsics/src/InputExtrinsic/index.js b/packages/app-extrinsics/src/InputExtrinsic/index.js index 3c3dff7b51..05b6d3ef87 100644 --- a/packages/app-extrinsics/src/InputExtrinsic/index.js +++ b/packages/app-extrinsics/src/InputExtrinsic/index.js @@ -5,18 +5,19 @@ // TODO: This is a useful, shared component, move out -import type { Extrinsic } from '../extrinsics/types'; +import type { Extrinsic } from '@polkadot/extrinsics/types'; import './InputExtrinsic.css'; import React from 'react'; import Dropdown from 'semantic-ui-react/dist/es/modules/Dropdown'; +import extrinsics from '@polkadot/extrinsics-polkadot/src'; -import extrinsics from '../extrinsics'; import options from './options'; type Props = { className?: string, + isError?: boolean, isPrivate?: boolean, onChange?: (event: SyntheticEvent<*>, value: Extrinsic) => void, style?: { @@ -41,6 +42,7 @@ export default function InputExtrinsic (props: Props): React$Node { const _props = Object.assign({}, props); + delete _props.isError; delete _props.isPrivate; return ( @@ -48,6 +50,7 @@ export default function InputExtrinsic (props: Props): React$Node { selection {..._props} className={['ui--InputExtrinsic', props.className].join(' ')} + error={props.isError} onChange={onChange} options={ // flowlint-next-line sketchy-null-bool:off diff --git a/packages/app-extrinsics/src/InputExtrinsic/options.js b/packages/app-extrinsics/src/InputExtrinsic/options.js index ef764cd9af..9d4f3e68ea 100644 --- a/packages/app-extrinsics/src/InputExtrinsic/options.js +++ b/packages/app-extrinsics/src/InputExtrinsic/options.js @@ -4,33 +4,40 @@ // @flow import React from 'react'; - -import extrinsics from '../extrinsics'; +import Dropdown from 'semantic-ui-react/dist/es/modules/Dropdown'; +import extrinsics from '@polkadot/extrinsics-polkadot/src'; const options = { private: [], public: [] }; -extrinsics.sections.forEach(({ description, hasPrivate, hasPublic, methods, name }) => { - const header = { - className: 'ui--InputExtrinsic-Header', - disabled: true, - text: description, - value: name - }; +const sortByName = (a, b) => + a.name.localeCompare(b.name); - hasPublic && options.public.push(header); - hasPrivate && options.private.push(header); +const addHeader = (shouldAdd, to, description) => { + if (shouldAdd) { + to.push(); + to.push( + + {description} + + ); + } +}; - methods.forEach(({ description, name, params, isPrivate }) => { +extrinsics.sections.sort(sortByName).forEach(({ description, hasPrivate, hasPublic, methods, name }) => { + addHeader(hasPublic, options.public, description); + addHeader(hasPrivate, options.private, description); + + methods.sort(sortByName).forEach(({ description, name, params, isPrivate }) => { const inputs = params.map(({ name }) => name).join(', '); options[isPrivate ? 'private' : 'public'].push({ className: 'ui--InputExtrinsic-Item', text: [
- {description} + {description || name}
,
{name}({inputs}) diff --git a/packages/app-extrinsics/src/Params/Account.js b/packages/app-extrinsics/src/Params/Account.js index 8c309a4f0d..2aaa680a41 100644 --- a/packages/app-extrinsics/src/Params/Account.js +++ b/packages/app-extrinsics/src/Params/Account.js @@ -10,18 +10,19 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject'; import BaseAccount from '../Account'; -export default function Account ({ label, subject }: Props): React$Node { +export default function Account ({ isError, label, subject }: Props): React$Node { const account: rxjs$BehaviorSubject = new BehaviorSubject(new Uint8Array([])); - account.subscribe((value: Uint8Array) => { + account.subscribe((value: Uint8Array) => subject.next({ isValid: !!(value && value.length), value - }); - }); + }) + ); return ( diff --git a/packages/app-extrinsics/src/Params/Amount.js b/packages/app-extrinsics/src/Params/Amount.js index 4160309f98..4bb8199ca9 100644 --- a/packages/app-extrinsics/src/Params/Amount.js +++ b/packages/app-extrinsics/src/Params/Amount.js @@ -11,17 +11,16 @@ import Input from 'semantic-ui-react/dist/es/elements/Input'; import Base from './Base'; -export default function Amount ({ label, subject, t, value: { options: { initValue = 0, maxValue, minValue = 0 } = {} }, type }: Props): React$Node { +export default function Amount ({ isError, label, subject, t, value: { options: { initValue = 0, maxValue, minValue = 0 } = {} } }: Props): React$Node { // flowlint-next-line sketchy-null-mixed:off, sketchy-null-number:off const defaultValue = initValue || minValue; // eslint-disable-next-line no-unused-vars - const onChange = (event: SyntheticEvent<*>, { value }): void => { + const onChange = (event: SyntheticEvent<*>, { value }) => subject.next({ isValid: true, // flowlint-next-line sketchy-null-mixed:off, sketchy-null-number:off value: new BN(value || minValue || 0) }); - }; return ( , { value }) => + subject.next({ + isValid: true, + value + }); + + return ( + + + + ); +} diff --git a/packages/app-extrinsics/src/Params/Hash.js b/packages/app-extrinsics/src/Params/Hash.js new file mode 100644 index 0000000000..bc52a54fd1 --- /dev/null +++ b/packages/app-extrinsics/src/Params/Hash.js @@ -0,0 +1,37 @@ +// 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 { Props } from './types'; + +import React from 'react'; +import Input from 'semantic-ui-react/dist/es/elements/Input'; +import hexToU8a from '@polkadot/util/hex/toU8a'; + +import Base from './Base'; + +export default function Hash ({ isError, label, subject, t }: Props): React$Node { + // eslint-disable-next-line no-unused-vars + const onChange = (event: SyntheticEvent<*>, { value }) => { + const u8a = hexToU8a(value); + + subject.next({ + isValid: u8a.length === 32, + value: u8a + }); + }; + + return ( + + + + ); +} diff --git a/packages/app-extrinsics/src/Params/Param.js b/packages/app-extrinsics/src/Params/Param.js index d4ea2225a5..4bd4d75d46 100644 --- a/packages/app-extrinsics/src/Params/Param.js +++ b/packages/app-extrinsics/src/Params/Param.js @@ -3,33 +3,24 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { BaseProps } from './types'; +import type { Extrinsic$Param } from '@polkadot/extrinsics/types'; +import type { BareProps, RawParam } from '../types'; import React from 'react'; -import Account from './Account'; -import Amount from './Amount'; -import Proposal from './Proposal'; -import Unknown from './Unknown'; +import findComponent from './findComponent'; +import typeToText from './typeToText'; -type Props = BaseProps & { - label?: string; +type Props = BareProps & { + label?: string, + subject: rxjs$BehaviorSubject, + value: Extrinsic$Param } -const Components = { - 'AccountId': Account, - 'Balance': Amount, - 'BlockNumber': Amount, - 'Bytes': Unknown, - 'Proposal': Proposal, - 'u32': Amount, - 'u64': Amount -}; - export default function Param ({ className, label, style, subject, value }: Props): React$Node { // flowlint-next-line sketchy-null-string:off - const defaultLabel = label || `${value.name}: ${value.type}`; - const Component = Components[value.type]; + const defaultLabel = label || `${value.name}: ${typeToText(value.type)}`; + const Component = findComponent(value.type); return ( = new BehaviorSubject(({ isValid: false }: $Shape)); - extrinsic.subscribe(({ data, isValid }: EncodedParams) => { + extrinsic.subscribe(({ data, isValid }: EncodedParams) => subject.next({ isValid, value: data - }); - }); + }) + ); return ( -
+
{t('param.unknown', { - defaultValue: `ERROR: Unknown input of type '{{type}}' found. No renderer exists`, + defaultValue: `ERROR: Unimplemented type '{{type}}' requested. No renderer exists`, replace: { - type + type: typeToText(type) } })}
diff --git a/packages/app-extrinsics/src/Params/VoteThreshold.js b/packages/app-extrinsics/src/Params/VoteThreshold.js new file mode 100644 index 0000000000..70e8c0b82b --- /dev/null +++ b/packages/app-extrinsics/src/Params/VoteThreshold.js @@ -0,0 +1,39 @@ +// 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 { Props } from './types'; + +import React from 'react'; +import Dropdown from 'semantic-ui-react/dist/es/modules/Dropdown'; + +import Base from './Base'; + +const options = [ + { text: 'Super majority approval', value: 0 }, + { text: 'Super majority rejection', value: 1 }, + { text: 'Simple majority', value: 2 } +]; + +export default function VoteThreshold ({ label, subject, t, value: { options: { initValue = 0 } = {} } }: Props): React$Node { + const onChange = (event: SyntheticEvent<*>, { value }) => + subject.next({ + isValid: true, + value + }); + + return ( + + + + ); +} diff --git a/packages/app-extrinsics/src/Params/findComponent.js b/packages/app-extrinsics/src/Params/findComponent.js new file mode 100644 index 0000000000..773a3a0f3c --- /dev/null +++ b/packages/app-extrinsics/src/Params/findComponent.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 { Extrinsic$Type } from '@polkadot/extrinsics/types'; + +import Account from './Account'; +import Amount from './Amount'; +import Bool from './Bool'; +import Hash from './Hash'; +import Proposal from './Proposal'; +import Unknown from './Unknown'; +import VoteThreshold from './VoteThreshold'; + +const Components = { + 'AccountId': Account, + 'Balance': Amount, + 'BlockNumber': Amount, + 'bool': Bool, + 'Bytes': Unknown, + 'Hash': Hash, + 'MisbehaviorReport': Unknown, + 'Proposal': Proposal, + 'SessionKey': Unknown, + 'u32': Amount, + 'u64': Amount, + 'VoteThreshold': VoteThreshold +}; + +export default function findComponent (type: Extrinsic$Type): React$ComponentType<*> { + if (Array.isArray(type)) { + // eslint-disable-next-line no-unused-vars + const [outer, inner] = type; + + return findComponent(inner); + } + + return Components[type]; +} diff --git a/packages/app-extrinsics/src/Params/index.js b/packages/app-extrinsics/src/Params/index.js index a21cebe1c8..12dd1a207e 100644 --- a/packages/app-extrinsics/src/Params/index.js +++ b/packages/app-extrinsics/src/Params/index.js @@ -3,24 +3,30 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Extrinsic } from '../extrinsics/types'; +import type { Extrinsic } from '@polkadot/extrinsics/types'; import type { BaseProps, RawParam } from '../types'; import './Params.css'; import React from 'react'; -import Label from 'semantic-ui-react/dist/es/elements/Label'; +// import Label from 'semantic-ui-react/dist/es/elements/Label'; +// import translate from '../translate'; import Param from './Param'; import createSubscriber from './subscriber'; +import typeToText from './typeToText'; type Props = BaseProps & { subject: rxjs$BehaviorSubject>, value: Extrinsic; }; -function Params ({ className, style, subject, t, value: { name, params } }: Props): React$Node { +function Params ({ className, style, subject, value: { name, params } }: Props): React$Node { if (!params || !params.length) { return null; } @@ -33,18 +39,13 @@ function Params ({ className, style, subject, t, value: { name, params } }: Prop style={style} >
-
- {params.map((param, index) => ( + {params.map((value, index) => ( ))}
diff --git a/packages/app-extrinsics/src/Params/initValue.js b/packages/app-extrinsics/src/Params/initValue.js index 903f3557de..1410c5ac2a 100644 --- a/packages/app-extrinsics/src/Params/initValue.js +++ b/packages/app-extrinsics/src/Params/initValue.js @@ -2,24 +2,27 @@ // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. // @flow +// flowlint sketchy-null-mixed:off -import type { Extrinsic$Param } from '../extrinsics/types'; +import type { Extrinsic$Param } from '@polkadot/extrinsics/types'; import BN from 'bn.js'; export default function getInitValue ({ options: { initValue, minValue } = {}, type }: Extrinsic$Param): mixed { - // flowlint-next-line sketchy-null-mixed:off - const defaultValue = initValue || minValue; - switch (type) { case 'Balance': case 'BlockNumber': case 'u32': case 'u64': - // flowlint-next-line sketchy-null-mixed:off - return new BN(defaultValue || 0); + return new BN(initValue || minValue || 0); + + case 'bool': + return initValue || false; + + case 'VoteThreshold': + return initValue || 0; default: - return defaultValue; + return initValue; } } diff --git a/packages/app-extrinsics/src/Params/subjects.js b/packages/app-extrinsics/src/Params/subjects.js index 53ed8f0900..1c4e7df61a 100644 --- a/packages/app-extrinsics/src/Params/subjects.js +++ b/packages/app-extrinsics/src/Params/subjects.js @@ -3,7 +3,7 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Extrinsic$Params } from '../extrinsics/types'; +import type { Extrinsic$Params } from '@polkadot/extrinsics/types'; import type { RawParam } from '../types'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; diff --git a/packages/app-extrinsics/src/Params/subscriber.js b/packages/app-extrinsics/src/Params/subscriber.js index bb05f5d864..670c73b95a 100644 --- a/packages/app-extrinsics/src/Params/subscriber.js +++ b/packages/app-extrinsics/src/Params/subscriber.js @@ -3,7 +3,7 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Extrinsic$Params } from '../extrinsics/types'; +import type { Extrinsic$Params } from '@polkadot/extrinsics/types'; import type { RawParam } from '../types'; import createSubjects from './subjects'; diff --git a/packages/app-extrinsics/src/Params/typeToText.js b/packages/app-extrinsics/src/Params/typeToText.js new file mode 100644 index 0000000000..4349fbe948 --- /dev/null +++ b/packages/app-extrinsics/src/Params/typeToText.js @@ -0,0 +1,16 @@ +// 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 { Extrinsic$Type } from '@polkadot/extrinsics/types'; + +export default function typeToText (type: Extrinsic$Type): string { + if (Array.isArray(type)) { + const [outer, inner] = type; + + return `${outer}<${inner}>`; + } + + return type; +} diff --git a/packages/app-extrinsics/src/Params/types.js b/packages/app-extrinsics/src/Params/types.js index 9a74727a47..1e6cf4f283 100644 --- a/packages/app-extrinsics/src/Params/types.js +++ b/packages/app-extrinsics/src/Params/types.js @@ -3,7 +3,7 @@ // of the ISC license. See the LICENSE file for details. // @flow -import type { Extrinsic$Param } from '../extrinsics/types'; +import type { Extrinsic$Param } from '@polkadot/extrinsics/types'; import type { BareProps, RawParam } from '../types'; export type BaseProps = BareProps & { @@ -12,5 +12,6 @@ export type BaseProps = BareProps & { }; export type Props = BaseProps & { + isError?: boolean, label: string }; diff --git a/packages/app-extrinsics/src/Signer/sign.js b/packages/app-extrinsics/src/Signer/sign.js deleted file mode 100644 index 0f1fbc5f00..0000000000 --- a/packages/app-extrinsics/src/Signer/sign.js +++ /dev/null @@ -1,21 +0,0 @@ -// 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 - -// TODO: Move to portal - -import type { KeyringPair } from '@polkadot/util-keyring/types'; - -const assert = require('@polkadot/util/assert'); -const u8aConcat = require('@polkadot/util/u8a/concat'); - -module.exports = function sign (sender?: ?KeyringPair, message: Uint8Array): Uint8Array { - assert(sender, 'Expected a valid sender to sign'); - - return u8aConcat( - message, - // $FlowFixMe sender has an actual value - sender.sign(message) - ); -}; diff --git a/packages/app-extrinsics/src/Signer/submit.js b/packages/app-extrinsics/src/Signer/submit.js index d36ff91fde..ee7ef59cb9 100644 --- a/packages/app-extrinsics/src/Signer/submit.js +++ b/packages/app-extrinsics/src/Signer/submit.js @@ -6,19 +6,21 @@ import type { RxApiInterface } from '@polkadot/rx-api/types'; import type { QueueTx } from '../types'; -import encodeCall from '../encode/call'; +import encodeCall from '@polkadot/extrinsics-codec/src/encode/call'; +import u8aConcat from '@polkadot/util/u8a/concat'; +import u8aToHex from '@polkadot/util/u8a/toHex'; + import keyring from '../keyring'; -import sign from './sign'; - export default function submit (api: RxApiInterface, tx: QueueTx, subject: rxjs$BehaviorSubject): Promise { + const message = encodeCall(tx.publicKey, tx.index, tx.data); + const signature = keyring.getPair(tx.publicKey).sign(message); + + console.log('submitExtrinsic: message =', u8aToHex(message)); + console.log('submitExtrinsic: signature =', u8aToHex(signature)); + return api.author - .submitExtrinsic( - sign( - keyring.getPair(tx.publicKey), - encodeCall(tx.publicKey, tx.index, tx.data) - ) - ) + .submitExtrinsic(u8aConcat(message, signature)) .toPromise() .then((result) => { console.log('submitExtrinsic: result=', result); diff --git a/packages/app-extrinsics/src/Submission/index.js b/packages/app-extrinsics/src/Submission/index.js index bbd67f2afa..d787f89b56 100644 --- a/packages/app-extrinsics/src/Submission/index.js +++ b/packages/app-extrinsics/src/Submission/index.js @@ -36,6 +36,12 @@ function Submission ({ className, subject, style, t }: Props): React$Node { })} subject={subjects.sender} /> + -
diff --git a/packages/app-extrinsics/src/Submission/subjects.js b/packages/app-extrinsics/src/Submission/subjects.js index 4f091cffc8..2bd207ee35 100644 --- a/packages/app-extrinsics/src/Submission/subjects.js +++ b/packages/app-extrinsics/src/Submission/subjects.js @@ -18,8 +18,12 @@ type Subjects = { export default function createSubjects (): Subjects { const subjects = { index: new BehaviorSubject(new BN(0)), - call: new BehaviorSubject(({ isValid: false }: $Shape)), - method: new BehaviorSubject(({ isValid: false }: $Shape)), + call: new BehaviorSubject(({ + isValid: false + }: $Shape)), + method: new BehaviorSubject(({ + isValid: false + }: $Shape)), sender: new BehaviorSubject(new Uint8Array([])) }; diff --git a/packages/app-extrinsics/src/encode/param.js b/packages/app-extrinsics/src/encode/param.js deleted file mode 100644 index c321f643c6..0000000000 --- a/packages/app-extrinsics/src/encode/param.js +++ /dev/null @@ -1,34 +0,0 @@ -// 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 { Extrinsic$Param } from '../extrinsics/types'; - -const bnToU8a = require('@polkadot/util/bn/toU8a'); -const u8aToU8a = require('@polkadot/util/u8a/toU8a'); - -// flowlint-next-line unclear-type:off -module.exports = function encodeValue ({ type }: Extrinsic$Param, value: any): Uint8Array { - switch (type) { - case 'AccountId': - return value; - - case 'Balance': - case 'BlockNumber': - case 'u64': - return bnToU8a(value, 64, true); - - case 'Bytes': - return u8aToU8a(value); - - case 'Proposal': - return u8aToU8a(value); - - case 'u32': - return bnToU8a(value, 32, true); - - default: - throw new Error(`Unable to encode value with type '${type}'`); - } -}; diff --git a/packages/app-extrinsics/src/extrinsics/consensus.js b/packages/app-extrinsics/src/extrinsics/consensus.js deleted file mode 100644 index 098796c014..0000000000 --- a/packages/app-extrinsics/src/extrinsics/consensus.js +++ /dev/null @@ -1,14 +0,0 @@ -// 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 { ExtrinsicsBasic } from './types'; - -module.exports = ({ - description: 'Consensus', - methods: { - public: [], - private: [] - } -}: ExtrinsicsBasic); diff --git a/packages/app-extrinsics/src/extrinsics/council.js b/packages/app-extrinsics/src/extrinsics/council.js deleted file mode 100644 index 6ddcff378c..0000000000 --- a/packages/app-extrinsics/src/extrinsics/council.js +++ /dev/null @@ -1,14 +0,0 @@ -// 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 { ExtrinsicsBasic } from './types'; - -module.exports = ({ - description: 'Council', - methods: { - public: [], - private: [] - } -}: ExtrinsicsBasic); diff --git a/packages/app-extrinsics/src/extrinsics/councilVoting.js b/packages/app-extrinsics/src/extrinsics/councilVoting.js deleted file mode 100644 index ef7075dac0..0000000000 --- a/packages/app-extrinsics/src/extrinsics/councilVoting.js +++ /dev/null @@ -1,14 +0,0 @@ -// 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 { ExtrinsicsBasic } from './types'; - -module.exports = ({ - description: 'Council Voting', - methods: { - public: [], - private: [] - } -}: ExtrinsicsBasic); diff --git a/packages/app-extrinsics/src/extrinsics/democracy.js b/packages/app-extrinsics/src/extrinsics/democracy.js deleted file mode 100644 index 8e18561f7b..0000000000 --- a/packages/app-extrinsics/src/extrinsics/democracy.js +++ /dev/null @@ -1,24 +0,0 @@ -// 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 { ExtrinsicsBasic } from './types'; - -module.exports = ({ - description: 'Democracy', - methods: { - public: [ - { - description: 'Propose', - index: 0, - name: 'propose', - params: [ - { name: 'proposal', type: 'Proposal' }, - { name: 'value', type: 'Balance' } - ] - } - ], - private: [] - } -}: ExtrinsicsBasic); diff --git a/packages/app-extrinsics/src/extrinsics/index.js b/packages/app-extrinsics/src/extrinsics/index.js deleted file mode 100644 index fa3ac26a60..0000000000 --- a/packages/app-extrinsics/src/extrinsics/index.js +++ /dev/null @@ -1,82 +0,0 @@ -// 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 - -// TODO: Move to API - -import type { Extrinsic, Extrinsics, ExtrinsicBasic, ExtrinsicsBasic, ExtrinsicsMap, ExtrinsicSection } from './types'; - -const assert = require('@polkadot/util/assert'); -const bnToU8a = require('@polkadot/util/bn/toU8a'); -const u8aConcat = require('@polkadot/util/u8a/concat'); - -const consensus = require('./consensus'); -const council = require('./council'); -const councilVoting = require('./councilVoting'); -const democracy = require('./democracy'); -const session = require('./session'); -const staking = require('./staking'); - -const map: { [string]: ExtrinsicsBasic } = { - consensus, // 0 - session, // 1 - staking, // 2 - democracy, // 3 - council, // 4 - councilVoting // 5 -}; -const extrinsicsMap: ExtrinsicsMap = {}; -const extrinsics: Extrinsics = { - sections: [], - get: (method: string): Extrinsic => { - const extrinsic = extrinsicsMap[method]; - - assert(extrinsic, `Unable to retrieve extrinsic with name '${method}'`); - - return extrinsic; - } -}; - -const sectionNames = Object.keys(map); - -function mapMethods (sectionSource: ExtrinsicsBasic, section: ExtrinsicSection, isPrivate: boolean): void { - const methods = sectionSource.methods[isPrivate ? 'private' : 'public']; - - methods.forEach(({ description, index, name, params }: ExtrinsicBasic) => { - const method: Extrinsic = { - description, - index: u8aConcat(section.index, bnToU8a(index, 8)), - isPrivate, - name: `${section.name}_${name}`, - params - }; - - extrinsicsMap[method.name] = method; - section[isPrivate ? 'hasPrivate' : 'hasPublic'] = true; - - section.methods.push(method); - }); -} - -sectionNames.reduce((sections: Array, sectionName: string, index: number) => { - const sectionSource = map[sectionName]; - - const section: ExtrinsicSection = { - description: sectionSource.description, - hasPrivate: false, - hasPublic: false, - index: bnToU8a(index, 8), - methods: [], - name: sectionName - }; - - mapMethods(sectionSource, section, true); - mapMethods(sectionSource, section, false); - - sections.push(section); - - return sections; -}, extrinsics.sections); - -module.exports = extrinsics; diff --git a/packages/app-extrinsics/src/extrinsics/staking.js b/packages/app-extrinsics/src/extrinsics/staking.js deleted file mode 100644 index 6f0f794ffb..0000000000 --- a/packages/app-extrinsics/src/extrinsics/staking.js +++ /dev/null @@ -1,67 +0,0 @@ -// 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 { ExtrinsicsBasic } from './types'; - -module.exports = ({ - description: 'Staking', - methods: { - public: [ - { - description: 'Transfer', - index: 0, - name: 'transfer', - params: [ - { name: 'recipient', type: 'AccountId' }, - { name: 'value', type: 'Balance', options: { minValue: 1 } } - ] - }, - { - description: 'Stake', - index: 1, - name: 'stake', - params: [] - }, - { - description: 'Unstake', - index: 2, - name: 'unstake', - params: [] - } - ], - private: [ - { - description: 'Set sessions per era', - index: 0, - name: 'setSessionsPerEra', - params: [ - { name: 'sessions', type: 'u64' } - ] - }, - { - description: 'Set bonding duration', - index: 1, - name: 'setBondingDuration', - params: [ - { name: 'duration', type: 'u64' } - ] - }, - { - description: 'Set validator count', - index: 2, - name: 'setValidatorCount', - params: [ - { name: 'count', type: 'u32' } - ] - }, - { - description: 'Force new era', - index: 3, - name: 'forceNewEra', - params: [] - } - ] - } -}: ExtrinsicsBasic); diff --git a/packages/app-extrinsics/src/types.js b/packages/app-extrinsics/src/types.js index efb47e35df..2693c0dc47 100644 --- a/packages/app-extrinsics/src/types.js +++ b/packages/app-extrinsics/src/types.js @@ -4,7 +4,7 @@ // @flow import type BN from 'bn.js'; -import type { Extrinsic } from './extrinsics/types'; +import type { Extrinsic } from '@polkadot/extrinsics/types'; export type BareProps = { className?: string, diff --git a/packages/portal/.env b/packages/apps/.env similarity index 100% rename from packages/portal/.env rename to packages/apps/.env diff --git a/packages/portal/LICENSE b/packages/apps/LICENSE similarity index 100% rename from packages/portal/LICENSE rename to packages/apps/LICENSE diff --git a/packages/portal/README.md b/packages/apps/README.md similarity index 100% rename from packages/portal/README.md rename to packages/apps/README.md diff --git a/packages/portal/package.json b/packages/apps/package.json similarity index 81% rename from packages/portal/package.json rename to packages/apps/package.json index 4c900173c1..68bdd42a6d 100644 --- a/packages/portal/package.json +++ b/packages/apps/package.json @@ -1,8 +1,8 @@ { - "name": "@polkadot/portal", + "name": "@polkadot/apps", "version": "0.1.3", - "description": "A Portal into the Polkadot network", - "main": "src/index.js", + "description": "An Apps portal into the Polkadot network", + "main": "index.js", "homepage": ".", "repository": "https://github.com/polkadot-js/portal.git", "author": "Jaco Greeff ", @@ -16,8 +16,8 @@ "devDependencies": { "@polkadot/app-explorer": "^0.1.3", "@polkadot/app-extrinsics": "^0.1.3", - "@polkadot/rx-react": "^0.4.6", - "@polkadot/ui-react": "^0.9.11", + "@polkadot/rx-react": "^0.4.7", + "@polkadot/ui-react": "^0.9.12", "i18next": "^11.1.1", "i18next-browser-languagedetector": "^2.2.0", "i18next-xhr-backend": "^1.5.1", diff --git a/packages/apps/public/favicon.ico b/packages/apps/public/favicon.ico new file mode 100644 index 0000000000..ec3c167a5b Binary files /dev/null and b/packages/apps/public/favicon.ico differ diff --git a/packages/portal/public/index.html b/packages/apps/public/index.html similarity index 92% rename from packages/portal/public/index.html rename to packages/apps/public/index.html index 57008458f6..701a6f0b20 100644 --- a/packages/portal/public/index.html +++ b/packages/apps/public/index.html @@ -6,7 +6,7 @@ - Polkadot Portal + Polkadot Apps Portal