From 7887f5633627be107e71a59d3f23e7dd1071061c Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 15 May 2019 16:11:26 +0200 Subject: [PATCH] Add isMulti param for withCall (#1090) --- packages/app-staking/src/Overview/Address.tsx | 5 +++-- packages/ui-api/src/with/call.tsx | 14 +++++++++----- packages/ui-api/src/with/types.ts | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/app-staking/src/Overview/Address.tsx b/packages/app-staking/src/Overview/Address.tsx index 7ac246f4de..948932a308 100644 --- a/packages/app-staking/src/Overview/Address.tsx +++ b/packages/app-staking/src/Overview/Address.tsx @@ -149,9 +149,10 @@ class Address extends React.PureComponent { private getNominators () { const { staking_stakers } = this.props; + return staking_stakers - ? staking_stakers.others.map(({ who, value }): [AccountId, Balance] => [who, value]) - : []; + ? staking_stakers.others.map(({ who, value }): [AccountId, Balance] => [who, value]) + : []; } private iNominated () { diff --git a/packages/ui-api/src/with/call.tsx b/packages/ui-api/src/with/call.tsx index d867124695..cf2afe575c 100644 --- a/packages/ui-api/src/with/call.tsx +++ b/packages/ui-api/src/with/call.tsx @@ -15,6 +15,7 @@ import withApi from './api'; interface Method { (...params: Array): Promise; at: (hash: Uint8Array | string, ...params: Array) => Promise; + multi: (params: Array, cb: (value?: any) => void) => Promise; } type State = CallState; @@ -23,7 +24,7 @@ const NOOP = () => { // ignore }; -export default function withCall

(endpoint: string, { at, atProp, callOnResult, params = [], paramName, paramValid = false, propName, transform = echoTransform }: Options = {}): (Inner: React.ComponentType) => React.ComponentType { +export default function withCall

(endpoint: string, { at, atProp, callOnResult, isMulti = false, params = [], paramName, paramValid = false, propName, transform = echoTransform }: Options = {}): (Inner: React.ComponentType) => React.ComponentType { return (Inner: React.ComponentType): React.ComponentType> => { class WithPromise extends React.Component { state: State = { @@ -134,7 +135,7 @@ export default function withCall

(endpoint: string, { at, at assert(area.length && section.length && method.length && others.length === 0, `Invalid API format, expected .

., found ${endpoint}`); assert(['rpc', 'query', 'derive'].includes(area), `Unknown api.${area}, expected rpc, query or derive`); - assert(!at || area === 'query', 'Only able todo an at query on the api.query interface'); + assert(!at || area === 'query', `Only able to do an 'at' query on the api.query interface`); const apiSection = (api as any)[area][section]; @@ -172,9 +173,12 @@ export default function withCall

(endpoint: string, { at, at await this.unsubscribe(); if (isSubscription) { - this.destroy = await apiMethod(...params, (value?: any) => - this.triggerUpdate(this.props, value) - ); + const updateCb = (value?: any) => + this.triggerUpdate(this.props, value); + + this.destroy = isMulti + ? await apiMethod.multi(params, updateCb) + : await apiMethod(...params, updateCb); } else { const value: any = at ? await apiMethod.at(at, ...params) diff --git a/packages/ui-api/src/with/types.ts b/packages/ui-api/src/with/types.ts index f66fe8e0e1..07af3c5124 100644 --- a/packages/ui-api/src/with/types.ts +++ b/packages/ui-api/src/with/types.ts @@ -17,6 +17,7 @@ export type Options = { at?: Uint8Array | string, atProp?: string, callOnResult?: OnChangeCb, + isMulti?: boolean, params?: Array, paramName?: string, paramValid?: boolean,