diff --git a/packages/ui-api/src/types.ts b/packages/ui-api/src/types.ts index 647bc898b2..c13d39f0ce 100644 --- a/packages/ui-api/src/types.ts +++ b/packages/ui-api/src/types.ts @@ -5,6 +5,10 @@ import { SubmittableExtrinsicFunction } from '@polkadot/api/promise/types'; import ApiPromise from '@polkadot/api/promise'; +// helpers for HOC props +export type Omit = Pick>; +export type Subtract = Omit; + export type BareProps = { className?: string, style?: { [index: string]: any } diff --git a/packages/ui-api/src/with/api.tsx b/packages/ui-api/src/with/api.tsx index b14a8df72e..d465e53a44 100644 --- a/packages/ui-api/src/with/api.tsx +++ b/packages/ui-api/src/with/api.tsx @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { ApiProps } from '../types'; +import { ApiProps, Subtract } from '../types'; import { DefaultProps } from './types'; import React from 'react'; @@ -11,7 +11,7 @@ import { assert } from '@polkadot/util'; import { ApiConsumer } from '../ApiContext'; export default function withApi (Inner: React.ComponentType

, defaultProps: DefaultProps = {}): React.ComponentType { - return class WithApi extends React.PureComponent { + return class WithApi extends React.PureComponent> { constructor (props: any) { super(props); diff --git a/packages/ui-api/src/with/call.tsx b/packages/ui-api/src/with/call.tsx index fffb008bec..ad255eb860 100644 --- a/packages/ui-api/src/with/call.tsx +++ b/packages/ui-api/src/with/call.tsx @@ -2,8 +2,6 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -// TODO: Lots of duplicated code between this and withObservable, surely there is a better way of doing this? - import { ApiProps, RxProps } from '../types'; import { HOC, Options } from './types'; @@ -26,20 +24,16 @@ type State = RxProps & { timerId: number }; -type Props = ApiProps & {}; - const NOOP = () => { // ignore }; -// FIXME proper types for attributes - -export default function withCall (endpoint: string, { at, atProp, rxChange, params = [], paramProp = 'params', propName, transform = echoTransform }: Options = {}): HOC { +export default function withCall (endpoint: string, { at, atProp, rxChange, params = [], paramProp = 'params', propName, transform = echoTransform }: Options = {}): HOC { return (Inner: React.ComponentType): React.ComponentType => { - class WithPromise extends React.Component> { + class WithPromise extends React.Component> { state: State; - constructor (props: Props) { + constructor (props: P) { super(props); const [area, section, method] = endpoint.split('.');