Reformatting
This commit is contained in:
parent
c9ffe7a2de
commit
18e90dbef2
@ -13,7 +13,7 @@
|
||||
"test": "react-scripts test --env=jsdom --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/rx-react": "^0.2.7",
|
||||
"@polkadot/rx-react": "^0.2.8",
|
||||
"@polkadot/util": "^0.18.6",
|
||||
"react": "^16.3.1",
|
||||
"react-dom": "^16.3.1",
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
"test": "react-scripts test --env=jsdom --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/rx-react": "^0.2.7",
|
||||
"@polkadot/rx-react": "^0.2.8",
|
||||
"@polkadot/ui-react": "^0.9.10",
|
||||
"@polkadot/util": "^0.18.6",
|
||||
"@polkadot/util-keyring": "^0.18.6",
|
||||
|
||||
@ -13,9 +13,7 @@ import withObservable from '@polkadot/rx-react/with/observable';
|
||||
|
||||
import StakingTransfer from '../StakingTransfer';
|
||||
import encode from '../encode';
|
||||
import addrSender from '../subject/addrSender';
|
||||
import extrinsicName from '../subject/extrinsicName';
|
||||
import nonceSender from '../subject/nonceSender';
|
||||
import { extrinsicName, senderAddr, senderIndex } from '../subjects';
|
||||
import ErrorComponent from './Error';
|
||||
|
||||
type Props = BaseProps & {
|
||||
@ -33,7 +31,7 @@ function CallDisplay ({ className, style, value }: Props) {
|
||||
|
||||
const Component = COMPONENTS[value] || ErrorComponent;
|
||||
const onSubmit = () => {
|
||||
encode(addrSender.getValue(), nonceSender.getValue(), value, Component.getValues());
|
||||
encode(senderAddr.getValue(), senderIndex.getValue(), value, Component.getValues());
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@ -9,8 +9,8 @@ import React from 'react';
|
||||
import Dropdown from 'semantic-ui-react/dist/es/modules/Dropdown';
|
||||
import Label from 'semantic-ui-react/dist/es/elements/Label';
|
||||
|
||||
import extrinsicName from './subject/extrinsicName';
|
||||
import calls from './calls';
|
||||
import { extrinsicName } from './subjects';
|
||||
import extrinsics from './extrinsics';
|
||||
|
||||
type Props = BaseProps & {};
|
||||
|
||||
@ -18,8 +18,8 @@ const onChange = (event, { value }) => {
|
||||
extrinsicName.next(value);
|
||||
};
|
||||
|
||||
const options = Object.keys(calls).map((value) => ({
|
||||
text: calls[value].description,
|
||||
const options = Object.keys(extrinsics).map((value) => ({
|
||||
text: extrinsics[value].description,
|
||||
value
|
||||
}));
|
||||
|
||||
|
||||
@ -11,12 +11,11 @@ import RxNonce from '@polkadot/rx-react/Nonce';
|
||||
import withObservableParams from '@polkadot/rx-react/with/observableParams';
|
||||
import u8aToBn from '@polkadot/util/u8a/toBn';
|
||||
|
||||
import addrSender from './subject/addrSender';
|
||||
import nonceSender from './subject/nonceSender';
|
||||
import { senderAddr, senderIndex } from './subjects';
|
||||
|
||||
type Props = BaseProps & {};
|
||||
|
||||
const SenderNonce = withObservableParams(RxNonce, addrSender, (pair: KeyringPair) => {
|
||||
const SenderNonce = withObservableParams(RxNonce, senderAddr, (pair: KeyringPair) => {
|
||||
if (!pair) {
|
||||
return new Uint8Array([]);
|
||||
}
|
||||
@ -28,7 +27,9 @@ const onNonceChange = (value: Uint8Array) => {
|
||||
return;
|
||||
}
|
||||
|
||||
nonceSender.next(u8aToBn(value, 64, true));
|
||||
senderIndex.next(
|
||||
u8aToBn(value, 64, true)
|
||||
);
|
||||
};
|
||||
|
||||
export default function Nonce ({ className, style }: Props) {
|
||||
|
||||
@ -8,7 +8,7 @@ import type { BaseProps } from '@polkadot/portal/types';
|
||||
import React from 'react';
|
||||
|
||||
import Account from './Account';
|
||||
import addrRecipient from './subject/addrRecipient';
|
||||
import { recipientAddr } from './subjects';
|
||||
|
||||
type Props = BaseProps & {};
|
||||
|
||||
@ -18,7 +18,7 @@ export default function Recipient (props: Props) {
|
||||
{...props}
|
||||
className={['testing--Recipient', props.className].join(' ')}
|
||||
label='to the recipient'
|
||||
subject={addrRecipient}
|
||||
subject={recipientAddr}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import type { BaseProps } from '@polkadot/portal/types';
|
||||
import React from 'react';
|
||||
|
||||
import Account from './Account';
|
||||
import addrSender from './subject/addrSender';
|
||||
import { senderAddr } from './subjects';
|
||||
|
||||
type Props = BaseProps & {};
|
||||
|
||||
@ -18,7 +18,7 @@ export default function Sender (props: Props) {
|
||||
{...props}
|
||||
className={['testing--Sender', props.className].join(' ')}
|
||||
label='using the selected account'
|
||||
subject={addrSender}
|
||||
subject={senderAddr}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@ -3,12 +3,12 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import amount from './subject/amount';
|
||||
import addrRecipient from '../subject/addrRecipient';
|
||||
import { amount } from './subjects';
|
||||
import { recipientAddr } from '../subjects';
|
||||
|
||||
export default function getValues (): Array<mixed> {
|
||||
return [
|
||||
addrRecipient.getValue().publicKey(),
|
||||
recipientAddr.getValue().publicKey(),
|
||||
amount.getValue()
|
||||
];
|
||||
}
|
||||
|
||||
@ -14,12 +14,14 @@ import Label from 'semantic-ui-react/dist/es/elements/Label';
|
||||
|
||||
import Recipient from '../Recipient';
|
||||
import getValues from './getValues';
|
||||
import amount from './subject/amount';
|
||||
import { amount } from './subjects';
|
||||
|
||||
type Props = BaseProps & {};
|
||||
|
||||
const onChangeAmount = (event, { value }) => {
|
||||
amount.next(new BN(value));
|
||||
amount.next(
|
||||
new BN(value || 0)
|
||||
);
|
||||
};
|
||||
|
||||
function StakingTransfer ({ className, style }: Props) {
|
||||
|
||||
@ -6,6 +6,4 @@
|
||||
import BN from 'bn.js';
|
||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
|
||||
const subject = new BehaviorSubject(new BN(0));
|
||||
|
||||
export default subject;
|
||||
export const amount = new BehaviorSubject(new BN(0));
|
||||
@ -1,18 +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
|
||||
|
||||
export type Call$Type = 'AccountId' | 'Balance' | 'BlockNumber';
|
||||
|
||||
export type Call$Params = Array<Call$Type>;
|
||||
|
||||
export type Call = {
|
||||
description: string,
|
||||
index: Uint8Array,
|
||||
params: Call$Params
|
||||
};
|
||||
|
||||
export type Calls = {
|
||||
[string]: $Shape<Call>
|
||||
}
|
||||
@ -10,12 +10,12 @@ import type BN from 'bn.js';
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
|
||||
const calls = require('../calls');
|
||||
const extrinsics = require('../extrinsics');
|
||||
const encodeParams = require('./params');
|
||||
|
||||
// flowlint-next-line unclear-type:off
|
||||
module.exports = function encode (sender: KeyringPair, nonce: number | BN, method: string, values: Array<mixed>): Uint8Array {
|
||||
const { index, params } = calls[method];
|
||||
const { index, params } = extrinsics[method];
|
||||
const encodedParams = encodeParams(values, params);
|
||||
const message = u8aConcat(
|
||||
sender.publicKey(),
|
||||
|
||||
@ -3,12 +3,12 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Call$Type } from '../../calls/types';
|
||||
import type { Extrinsic$Type } from '../../extrinsics/types';
|
||||
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
|
||||
// flowlint-next-line unclear-type:off
|
||||
module.exports = function encodeValue (value: any, type: Call$Type): Uint8Array {
|
||||
module.exports = function encodeValue (value: any, type: Extrinsic$Type): Uint8Array {
|
||||
switch (type) {
|
||||
case 'AccountId':
|
||||
return value;
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Call$Params } from '../../calls/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: Call$Params): Uint8Array {
|
||||
module.exports = function encodeParams (values: Array<mixed>, params: Extrinsic$Params): Uint8Array {
|
||||
return u8aConcat.apply(null, values.map((value, index) => {
|
||||
return encodeParam(value, params[index]);
|
||||
}));
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Calls } from './types';
|
||||
import type { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
}: Calls);
|
||||
}: ExtrinsicsBasic);
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Calls } from './types';
|
||||
import type { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
}: Calls);
|
||||
}: ExtrinsicsBasic);
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Calls } from './types';
|
||||
import type { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
}: Calls);
|
||||
}: ExtrinsicsBasic);
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Calls } from './types';
|
||||
import type { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
}: Calls);
|
||||
}: ExtrinsicsBasic);
|
||||
@ -5,10 +5,11 @@
|
||||
|
||||
// TODO: Move to API
|
||||
|
||||
import type { Calls } from './types';
|
||||
import type { Extrinsics, ExtrinsicsBasic } from './types';
|
||||
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
const u8aToHex = require('@polkadot/util/u8a/toHex');
|
||||
|
||||
const consensus = require('./consensus');
|
||||
const council = require('./council');
|
||||
@ -17,7 +18,7 @@ const democracy = require('./democracy');
|
||||
const session = require('./session');
|
||||
const staking = require('./staking');
|
||||
|
||||
const calls = {
|
||||
const all: { [string]: ExtrinsicsBasic } = {
|
||||
consensus, // 0
|
||||
session, // 1
|
||||
staking, // 2
|
||||
@ -26,25 +27,31 @@ const calls = {
|
||||
councilVoting // 5
|
||||
};
|
||||
|
||||
const flattenned: Calls = Object
|
||||
.keys(calls)
|
||||
.reduce((flat, sectionName, index) => {
|
||||
const section = calls[sectionName];
|
||||
const sectionIndex = bnToU8a(index, 8);
|
||||
const flattenned: Extrinsics = Object
|
||||
.keys(all)
|
||||
.reduce((flat, sectionName, _index) => {
|
||||
const section = all[sectionName];
|
||||
const sectionIndex = bnToU8a(_index, 8);
|
||||
|
||||
Object
|
||||
.keys(section)
|
||||
.reduce((flat, method, index) => {
|
||||
.reduce((flat, method, _index) => {
|
||||
const name = `${sectionName}_${method}`;
|
||||
const methodIndex = bnToU8a(index, 8);
|
||||
const methodIndex = bnToU8a(_index, 8);
|
||||
const index = u8aConcat(sectionIndex, methodIndex);
|
||||
const indexHex = u8aToHex(index, 16);
|
||||
const expanded = Object.assign(({
|
||||
index,
|
||||
indexHex,
|
||||
name
|
||||
}: $Shape<Extrinsic>), section[method]);
|
||||
|
||||
flat[name] = section[method];
|
||||
flat[name].index = u8aConcat(sectionIndex, methodIndex);
|
||||
flat[name] = expanded;
|
||||
|
||||
return flat;
|
||||
}, flat);
|
||||
|
||||
return flat;
|
||||
}, ({}: $Shape<FlatCalls>));
|
||||
}, ({}: $Shape<Extrinsics>));
|
||||
|
||||
module.exports = flattenned;
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Calls } from './types';
|
||||
import type { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
}: Calls);
|
||||
}: ExtrinsicsBasic);
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Calls } from './types';
|
||||
import type { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
transfer: {
|
||||
@ -18,4 +18,4 @@ module.exports = ({
|
||||
description: 'Unstake',
|
||||
params: []
|
||||
}
|
||||
}: Calls);
|
||||
}: ExtrinsicsBasic);
|
||||
27
packages/app-testing/src/extrinsics/types.js
Normal file
27
packages/app-testing/src/extrinsics/types.js
Normal file
@ -0,0 +1,27 @@
|
||||
// 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
|
||||
|
||||
export type Extrinsic$Type = 'AccountId' | 'Balance' | 'BlockNumber';
|
||||
|
||||
export type Extrinsic$Params = Array<Extrinsic$Type>;
|
||||
|
||||
export type ExtrinsicBasic = {
|
||||
description: string,
|
||||
params: Extrinsic$Params
|
||||
}
|
||||
|
||||
export type Extrinsic = ExtrinsicBasic & {
|
||||
index: Uint8Array,
|
||||
indexHex: string,
|
||||
name: string
|
||||
};
|
||||
|
||||
export type Extrinsics = {
|
||||
[string]: Extrinsic
|
||||
}
|
||||
|
||||
export type ExtrinsicsBasic = {
|
||||
[string]: ExtrinsicBasic
|
||||
}
|
||||
@ -1,10 +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 { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
|
||||
const subject = new BehaviorSubject();
|
||||
|
||||
export default subject;
|
||||
@ -1,10 +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 { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
|
||||
const subject = new BehaviorSubject();
|
||||
|
||||
export default subject;
|
||||
@ -1,10 +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 { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
|
||||
const subject = new BehaviorSubject();
|
||||
|
||||
export default subject;
|
||||
@ -3,9 +3,11 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
|
||||
const subject = new BehaviorSubject(new BN(0));
|
||||
import BN from 'bn.js';
|
||||
|
||||
export default subject;
|
||||
export const extrinsicName = new BehaviorSubject();
|
||||
export const recipientAddr = new BehaviorSubject();
|
||||
export const senderAddr = new BehaviorSubject();
|
||||
export const senderIndex = new BehaviorSubject(new BN(0));
|
||||
@ -16,7 +16,7 @@
|
||||
"devDependencies": {
|
||||
"@polkadot/app-home": "^0.1.0",
|
||||
"@polkadot/app-testing": "^0.1.0",
|
||||
"@polkadot/rx-react": "^0.2.7",
|
||||
"@polkadot/rx-react": "^0.2.8",
|
||||
"@polkadot/ui-react": "^0.9.10",
|
||||
"i18next": "^11.1.1",
|
||||
"i18next-browser-languagedetector": "^2.2.0",
|
||||
|
||||
14
yarn.lock
14
yarn.lock
@ -1299,19 +1299,19 @@
|
||||
"@polkadot/util" "^0.18.4"
|
||||
babel-runtime "^6.26.0"
|
||||
|
||||
"@polkadot/rx-api@^0.2.7":
|
||||
version "0.2.7"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/rx-api/-/rx-api-0.2.7.tgz#aef716e7e8d3740746307331d242043c7694a8fd"
|
||||
"@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"
|
||||
dependencies:
|
||||
"@polkadot/api" "^0.8.14"
|
||||
"@polkadot/api-provider" "^0.8.14"
|
||||
rxjs "^5.5.10"
|
||||
|
||||
"@polkadot/rx-react@^0.2.7":
|
||||
version "0.2.7"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/rx-react/-/rx-react-0.2.7.tgz#5ec876ddf866e1e8ea2a70ddb484c1872102e2ac"
|
||||
"@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"
|
||||
dependencies:
|
||||
"@polkadot/rx-api" "^0.2.7"
|
||||
"@polkadot/rx-api" "^0.2.8"
|
||||
"@polkadot/util" "^0.18.6"
|
||||
|
||||
"@polkadot/ui-identicon@^0.9.10":
|
||||
|
||||
Loading…
Reference in New Issue
Block a user