diff --git a/packages/app-testing/package.json b/packages/app-testing/package.json index 12d9df3a3c..a39b614ead 100644 --- a/packages/app-testing/package.json +++ b/packages/app-testing/package.json @@ -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", diff --git a/packages/app-testing/src/CallDisplay/index.js b/packages/app-testing/src/CallDisplay/index.js index 06ac81015d..7dc82fd14b 100644 --- a/packages/app-testing/src/CallDisplay/index.js +++ b/packages/app-testing/src/CallDisplay/index.js @@ -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); diff --git a/packages/app-testing/src/CallDisplay/submit.js b/packages/app-testing/src/CallDisplay/submit.js new file mode 100644 index 0000000000..8c7281547e --- /dev/null +++ b/packages/app-testing/src/CallDisplay/submit.js @@ -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): Promise { + // 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); + }); +} diff --git a/packages/portal/src/types.js b/packages/portal/src/types.js index 5aec01f66c..2d5a7273d6 100644 --- a/packages/portal/src/types.js +++ b/packages/portal/src/types.js @@ -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, diff --git a/yarn.lock b/yarn.lock index c0e2674c1d..73edddaef2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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: