Submission ... working...
This commit is contained in:
parent
c550c88a06
commit
e7fa6e8e1f
@ -17,6 +17,7 @@
|
||||
"@polkadot/ui-react": "^0.9.10",
|
||||
"@polkadot/util": "^0.19.1",
|
||||
"@polkadot/util-keyring": "^0.19.1",
|
||||
"prop-types": "^15.6.1",
|
||||
"react": "^16.3.1",
|
||||
"react-dom": "^16.3.1",
|
||||
"semantic-ui-css": "^2.3.1",
|
||||
|
||||
@ -3,20 +3,19 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { BaseProps } from '@polkadot/portal/types';
|
||||
import type { BaseProps, BaseContext } from '@polkadot/portal/types';
|
||||
|
||||
import './CallDisplay.css';
|
||||
|
||||
import PropTypes from 'prop-types';
|
||||
import React from 'react';
|
||||
import Button from 'semantic-ui-react/dist/es/elements/Button';
|
||||
import withObservable from '@polkadot/rx-react/with/observable';
|
||||
|
||||
import StakingTransfer from '../StakingTransfer';
|
||||
import encode from '../encode';
|
||||
import extrinsics from '../extrinsics';
|
||||
import keyring from '../keyring';
|
||||
import { extrinsicName, senderAddr, senderIndex } from '../subjects';
|
||||
import { extrinsicName } from '../subjects';
|
||||
import ErrorComponent from './Error';
|
||||
import submitExtrinsic from './submit';
|
||||
|
||||
type Props = BaseProps & {
|
||||
value?: string;
|
||||
@ -26,17 +25,14 @@ const COMPONENTS = {
|
||||
'staking_transfer': StakingTransfer
|
||||
};
|
||||
|
||||
function CallDisplay ({ className, style, value }: Props) {
|
||||
function CallDisplay ({ className, style, value }: Props, { api }: BaseContext) {
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const Component = COMPONENTS[value] || ErrorComponent;
|
||||
const onSubmit = () => {
|
||||
const extrinsic = extrinsics[value];
|
||||
const sender = keyring.getPair(senderAddr.getValue());
|
||||
|
||||
encode(extrinsic, sender, senderIndex.getValue(), Component.getValues());
|
||||
submitExtrinsic(api, value, Component.getValues());
|
||||
};
|
||||
|
||||
return (
|
||||
@ -56,4 +52,8 @@ function CallDisplay ({ className, style, value }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
CallDisplay.contextTypes = {
|
||||
api: PropTypes.object
|
||||
};
|
||||
|
||||
export default withObservable(CallDisplay, extrinsicName);
|
||||
|
||||
32
packages/app-testing/src/CallDisplay/submit.js
Normal file
32
packages/app-testing/src/CallDisplay/submit.js
Normal file
@ -0,0 +1,32 @@
|
||||
// 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';
|
||||
|
||||
import encode from '../encode';
|
||||
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
|
||||
api.author
|
||||
.submitExtrinsic(
|
||||
encode(
|
||||
extrinsics[method],
|
||||
keyring.getPair(senderAddr.getValue()),
|
||||
senderIndex.getValue(),
|
||||
values
|
||||
)
|
||||
)
|
||||
.toPromise()
|
||||
.then((result) => {
|
||||
console.error('submitExtrinsic', result);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('submitExtrinsic', error);
|
||||
});
|
||||
}
|
||||
@ -3,6 +3,8 @@
|
||||
// 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?: {
|
||||
@ -11,6 +13,10 @@ export type BaseProps = {
|
||||
t: I18Next$Translate
|
||||
};
|
||||
|
||||
export type BaseContext = {
|
||||
api: RxApiInterface
|
||||
};
|
||||
|
||||
export type Route = {
|
||||
component: React$StatelessFunctionalComponent<*>,
|
||||
i18n: I18Nex$tTranslate$Config,
|
||||
|
||||
@ -8503,7 +8503,7 @@ promise@^7.1.1:
|
||||
dependencies:
|
||||
asap "~2.0.3"
|
||||
|
||||
prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.6.0:
|
||||
prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.6.0, prop-types@^15.6.1:
|
||||
version "15.6.1"
|
||||
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.1.tgz#36644453564255ddda391191fb3a125cbdf654ca"
|
||||
dependencies:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user