How to use the @polkadot/util.isUndefined 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 / apps / packages / react-params / src / valueToText.tsx View on Github external
function valueToText (type: string, value: any, swallowError = true, contentShorten = true): React.ReactNode {
  if (isNull(value) || isUndefined(value)) {
    return div({}, '');
  }

  // FIXME dont' even ask, nested ?: ... really?
  return div(
    {},
    ['Bytes', 'Raw', 'Option', 'Keys'].includes(type)
      ? u8aToHex(value.toU8a(true), contentShorten ? 512 : -1)
      : (
        // HACK Handle Keys as hex-only (this should go away once the node value is
        // consistently swapped to `Bytes`)
        type === 'Vec<(ValidatorId,Keys)>'
          ? JSON.stringify(
            (value as ([ValidatorId, Keys])[]).map(([validator, keys]): [string, string] => [
              validator.toString(), keys.toHex()
            ])
github polkadot-js / client / packages / client / src / index.ts View on Github external
private stopInformant (): void {
    if (!isUndefined(this.informantId)) {
      clearInterval(this.informantId);
    }

    this.informantId = undefined;
  }
github polkadot-js / apps / packages / react-params / src / Param / Vector.tsx View on Github external
(defaultValue.value || []).forEach((value: RawParam, index: number): void => {
        values.push(
          isUndefined(value) || isUndefined(value.isValid)
            ? { isValid: !isUndefined(value), value }
            : value
        );
        params.push(generateParam(subType, index));
      });
github polkadot-js / api / packages / types / src / primitive / Generic / Vote.ts View on Github external
private static decodeVote (registry: Registry, value?: InputTypes): Uint8Array {
    if (isUndefined(value)) {
      return Vote.decodeVoteBool(false);
    } else if (value instanceof Boolean || isBoolean(value)) {
      return Vote.decodeVoteBool(new Bool(registry, value).isTrue);
    } else if (isNumber(value)) {
      return Vote.decodeVoteBool(value < 0);
    } else if (isU8a(value)) {
      return Vote.decodeVoteU8a(value);
    }

    const vote = new Bool(registry, value.aye).isTrue ? AYE_BITS : NAY_BITS;
    const conviction = createType(registry, 'Conviction', isUndefined(value.conviction) ? DEF_CONV : value.conviction);

    return new Uint8Array([vote | conviction.index]);
  }
github polkadot-js / apps / packages / app-storage / src / Selection / Modules.tsx View on Github external
(isValid: boolean, value): boolean => (
      isValid &&
      !isUndefined(value) &&
      !isUndefined(value.value) &&
      value.isValid),
    true
github polkadot-js / api / packages / types / src / codec / EnumType.ts View on Github external
private static createValue (def: TypesDef, index: number = 0, value?: any): Decoded {
    const Clazz = Object.values(def)[index];

    assert(!isUndefined(Clazz), `Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);

    return {
      index,
      value: new Clazz(value)
    };
  }
github polkadot-js / apps / packages / ui-api / src / with / call.tsx View on Github external
private getParams (props: any): Array {
        const paramValue = props[paramName];

        if (atProp) {
          at = props[atProp];
        }

        return isUndefined(paramValue)
          ? params
          : params.concat(
            Array.isArray(paramValue)
              ? paramValue
              : [paramValue]
          );
      }
github polkadot-js / api / packages / api-contract / src / inkTypes.ts View on Github external
function getTypeIdPrimitive (_project: InkProject, idPrim: MtTypeIdPrimitive): InterfaceTypes {
  const primitive = PRIMITIVES[idPrim.index];

  assert(!isUndefined(primitive), `getInkPrimitive:: Unable to convert ${idPrim} to primitive`);

  return primitive;
}
github polkadot-js / api / packages / types / src / codec / utils / compareArray.ts View on Github external
export default function compareArray (a: any[], b?: any): boolean {
  if (Array.isArray(b)) {
    return (a.length === b.length) && isUndefined(
      a.find((value, index): boolean =>
        isFunction(value.eq)
          ? !value.eq(b[index])
          : value !== b[index]
      )
    );
  }

  return false;
}
github polkadot-js / api / packages / types / src / ContractAbi.ts View on Github external
private _createEncoded (name: string, method: Partial & ContractABIMethodBase): ContractABIFn {
    const args: Array = method.args.map(({ name, type }) => ({
      name: stringCamelCase(name),
      type: this._convertType(type)
    }));
    const Clazz = this._createClazz(args, isUndefined(method.selector) ? {} : { __selector: 'u32' });
    const baseStruct: { [index: string]: any } = { __selector: method.selector };
    const encoder = (...params: Array): Uint8Array => {
      assert(params.length === args.length, `Expected ${args.length} arguments to contract ${name}, found ${params.length}`);

      const u8a = new Clazz(
        args.reduce((mapped, { name }, index) => {
          mapped[name] = params[index];

          return mapped;
        }, { ...baseStruct })
      ).toU8a();

      return Compact.addLengthPrefix(u8a);
    };

    const fn = (encoder as ContractABIFn);