How to use the @polkadot/util.isFunction function in @polkadot/util

To help you get started, we’ve selected a few @polkadot/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkadot-js / api / packages / rpc-rx / src / index.ts View on Github external
private createObservable (name: string, section: RpcInterface$Section): RpcRxInterface$Method {
    if (isFunction(section[name].unsubscribe)) {
      const memoized: Memoized = memoize(
        (...params: Array) => this.createReplay(name, params, section, memoized),
        {
          length: false,
          // Normalize args so that different args that should be cached
          // together are cached together.
          // E.g.: `query.my.method('abc') === query.my.method(new AccountId('abc'));`
          normalizer: (args) => {
            // `args` is arguments object as accessible in memoized function
            return JSON.stringify(args);
          }
        }
      );

      return memoized as unknown as RpcRxInterface$Method;
    }
github polkadot-js / api / packages / rpc-rx / src / index.ts View on Github external
private createObservable (subName: string, name: string, section: RpcInterface$Section): RpcRxObervable {
    const isSubscription = isFunction(section[name].unsubscribe);
    const fn = isSubscription
      ? this.createCachedObservable(subName, name, section)
      : (...params: Array): Observable =>
          from(
            section[name]
              .apply(null, params)
              .catch((error: Error) => {
                console.error(error);
              })
          );

    const result = fn as RpcRxObervable;

    result.isSubscription = isSubscription;

    return result;
github polkadot-js / apps / packages / react-signer / src / Modal.tsx View on Github external
const unsubscribe = await extrinsicCall.apply(extrinsic, [...params, async (result: SubmittableResult): Promise => {
        if (!result || !result.status) {
          return;
        }

        const status = result.status.type.toLowerCase() as QueueTxStatus;

        console.log('makeExtrinsicCall: updated status ::', JSON.stringify(result));
        queueSetTxStatus(id, status, result);

        if (isFunction(txUpdateCb)) {
          txUpdateCb(result);
        }

        if (result.status.isFinalized) {
          unsubscribe();

          result.events
            .filter(({ event: { section } }): boolean => section === 'system')
            .forEach(({ event: { method } }): void => {
              if (isFunction(txFailedCb) && method === 'ExtrinsicFailed') {
                txFailedCb(result);
              } else if (isFunction(txSuccessCb) && method === 'ExtrinsicSuccess') {
                txSuccessCb(result);
              }
            });
        } else if (result.isError && isFunction(txFailedCb)) {
github dappforce / dappforce-subsocial-ui / src / components / ui-signer / Modal.tsx View on Github external
private async makeExtrinsicSignature (extrinsic: SubmittableExtrinsic, { id, signerCb, signerOptions }: QueueTx, pair: KeyringPair): Promise {
    console.log('makeExtrinsicSignature: extrinsic ::', extrinsic.toHex());

    extrinsic.sign(pair, signerOptions || {});

    if (isFunction(signerCb)) {
      signerCb(id, true);
    }
  }
}
github polkadot-js / apps / packages / react-hooks / src / useTx.ts View on Github external
function getExtrinsic (api: ApiPromise, txDef: T): SubmittableExtrinsic | null {
  if (!txDef) {
    return null;
  }

  if (Array.isArray(txDef)) {
    const [section, method] = txDef[0].split('.');

    assert(api.tx[section] && api.tx[section][method], `Unable to find api.tx.${section}.${method}`);
    try {
      return api.tx[section][method](...(
        isFunction(txDef[1])
          ? txDef[1]()
          : txDef[1]
      )) as any as SubmittableExtrinsic;
    } catch (e) {
      return null;
    }
  } else {
    if ((txDef as Call).callIndex) {
      const fn = api.findCall(txDef.callIndex);

      return api.tx[fn.section][fn.method](...txDef.args);
    }

    return txDef as any as SubmittableExtrinsic;
  }
}
github polkadot-js / apps / packages / apps / src / SideBar / Item.tsx View on Github external
function hasEndpoint (api: ApiPromise, endpoint: string): boolean {
  const [area, section, method] = endpoint.split('.');

  try {
    return isFunction((api as any)[area][section][method]);
  } catch (error) {
    return false;
  }
}
github polkadot-js / api / packages / api / src / SubmittableExtrinsic.ts View on Github external
value: function (account: IKeyringPair | string | AccountId | Address, optionsOrStatus?: Partial | Callback, statusCb?: Callback): SumbitableResultResult | SumbitableResultSubscription {
          let options: Partial = {};

          if (isFunction(optionsOrStatus)) {
            statusCb = optionsOrStatus;
          } else {
            options = { ...optionsOrStatus };
          }

          const isSubscription = _noStatusCb || !!statusCb;
          const address = isKeyringPair(account) ? account.address : account.toString();
          let updateId: number | undefined;

          return decorateMethod(
            (): Observable => (
              getPrelimState(address, options).pipe(
                first(),
                mergeMap(async ([nonce, header]): Promise => {
                  const eraOptions = expandEraOptions(options, { header, nonce });
github polkadot-js / client / packages / client / src / clientId.ts View on Github external
export async function getNpmVersion (): Promise {
  return isFunction(npmQuery)
    ? npmQuery(pkgJson.name)
      .then((npmJson): string => (npmJson as unknown as PackageJson).version)
      .catch((): string => 'unknown')
    : 'unknown';
}