How to use the @polkadot/types.getTypeDef function in @polkadot/types

To help you get started, we’ve selected a few @polkadot/types 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 / Param / findComponent.ts View on Github external
return ['Vec'].includes(type)
          ? 'Vec'
          : 'Vec';

      default:
        return type;
    }
  })(def);

  let Component = findOne(type);

  if (!Component) {
    try {
      const instance = createType(registry, type as any);
      const raw = getTypeDef(instance.toRawType());

      Component = findOne(raw.type);

      if (Component) {
        return Component;
      } else if (instance instanceof BN) {
        return Amount;
      } else if ([TypeDefInfo.Enum, TypeDefInfo.Struct].includes(raw.info)) {
        return findComponent(raw, overrides);
      }
    } catch (error) {
      // console.error(error.message);
    }

    // we only want to want once, not spam
    if (!warnList.includes(type)) {
github polkadot-js / apps / packages / react-params / src / Param / findComponent.ts View on Github external
return ['Vec'].includes(type)
          ? 'Vec'
          : 'Vec';

      default:
        return type;
    }
  })(def);

  let Component = findOne(type);

  if (!Component) {
    try {
      const instance = createType(type as any);
      const raw = getTypeDef(instance.toRawType());

      Component = findOne(raw.type);

      if (Component) {
        return Component;
      } else if (instance instanceof BN) {
        return Amount;
      } else if ([TypeDefInfo.Enum, TypeDefInfo.Struct].includes(raw.info)) {
        return findComponent(raw, overrides);
      }
    } catch (error) {
      // console.error(error.message);
    }

    console.warn(`Cannot find Component for ${type}, defaulting to Unknown`);
  }
github polkadot-js / apps / packages / react-components / src / Extrinsic.tsx View on Github external
return GenericCall.filterOrigin(meta).map((arg): { name: string; type: TypeDef } => ({
    name: arg.name.toString(),
    type: getTypeDef(arg.type.toString())
  }));
}
github polkadot-js / apps / packages / react-components / src / Event.tsx View on Github external
const params = value.typeDef.map(({ type }): { type: TypeDef } => ({
    type: getTypeDef(type)
  }));
  const values = value.data.map((value): { isValid: boolean; value: Codec } => ({
github polkadot-js / apps / packages / app-explorer / src / BlockInfo / Logs.tsx View on Github external
function formatVector (vector: Vec): React.ReactNode {
  const type = getTypeDef(vector.Type);
  const values = vector.toArray().map((value): { isValid: boolean; value: Codec } => ({
    isValid: true,
    value
  }));
  const params = values.map((_, index): { name: string; type: TypeDef } => ({
    name: `${index}`,
    type
  }));

  return (
    
  );
github polkadot-js / apps / packages / react-params / src / Param / Struct.tsx View on Github external
useEffect((): void => {
    let typeDef;
    try {
      const rawType = createType(registry, type.type as any).toRawType();
      typeDef = getTypeDef(rawType);
    } catch (e) {
      typeDef = type;
    }

    setParams((typeDef.sub as TypeDef[]).map((type): ParamDef => ({ name: type.name, type })));
  }, [type]);
github polkadot-js / apps / packages / react-params / src / Param / Tuple.tsx View on Github external
useEffect((): void => {
    try {
      const rawType = createType(registry, type.type as any).toRawType();
      const typeDef = getTypeDef(rawType);

      setParams((typeDef.sub as TypeDef[]).map((type): ParamDef => ({ name: type.name, type })));
    } catch (e) {
      setParams(((Array.isArray(type.sub) ? type.sub : [type.sub]) as TypeDef[]).map((subType): ParamDef => ({ name: subType.name, type: subType })));
    }
  }, [type]);
github polkadot-js / apps / packages / react-params / src / Param / Enum.tsx View on Github external
useEffect((): void => {
    const rawType = createType(registry, type.type as any).toRawType();
    const typeDef = getTypeDef(rawType);
    const subTypes = typeDef.sub as TypeDef[];

    setOptions({
      options: subTypes.map(({ name }): Option => ({
        text: name,
        value: name
      })),
      subTypes
    });
    setCurrent([{ name: subTypes[0].name, type: subTypes[0] }]);
  }, [type]);
github polkadot-js / apps / packages / react-components / src / Call.tsx View on Github external
const params = GenericCall.filterOrigin(value.meta).map(({ name, type }): Param => ({
      name: name.toString(),
      type: getTypeDef(type.toString())
    }));
    const values = value.args.map((value): Value => ({