How to use the @polkadot/types.ClassOf 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 / api / packages / metadata / src / Decorated / consts / fromMetadata / fromMetadata.spec.ts View on Github external
it('should return constants with the correct type and value', (): void => {
    expect(consts.democracy.cooloffPeriod).toBeInstanceOf(ClassOf(registry, 'BlockNumber'));
    // 3 second blocks, 28 days
    expect(consts.democracy.cooloffPeriod.toNumber()).toEqual(28 * 24 * 60 * (60 / 3));
  });
github polkadot-js / apps / packages / react-params / src / Param / Amount.tsx View on Github external
export default function Amount (props: Props): React.ReactElement {
  const { className, defaultValue: { value }, isDisabled, isError, label, onEnter, style, withLabel } = props;
  const defaultValue = isDisabled
    ? (
      value instanceof ClassOf(registry, 'AccountIndex')
        ? value.toString()
        : formatNumber(value)
    )
    : bnToBn((value as number) || 0).toString();

  return (
github polkadot-js / api / packages / api-derive / src / accounts / indexToId.ts View on Github external
return memo((_accountIndex: AccountIndex | string): Observable => {
    const accountIndex = _accountIndex instanceof ClassOf(api.registry, 'AccountIndex')
      ? _accountIndex
      : createType(api.registry, 'AccountIndex', _accountIndex);

    return querySection.enumSet>(accountIndex.div(ENUMSET_SIZE)).pipe(
      startWith([]),
      map((accounts): AccountId | undefined =>
        (accounts || [])[accountIndex.mod(ENUMSET_SIZE).toNumber()]
      )
    );
  });
}
github polkadot-js / apps / packages / react-params / src / Param / VoteThreshold.tsx View on Github external
export default function VoteThresholdParam (props: Props): React.ReactElement {
  const { className, defaultValue: { value }, isDisabled, isError, label, style, withLabel } = props;
  const defaultValue = value instanceof ClassOf(registry, 'VoteThreshold')
    ? value.toNumber()
    : bnToBn(value as number).toNumber();

  return (
github polkadot-js / apps / packages / ui-signer / src / ApiSigner.ts View on Github external
public update (id: number, result: Hash | SubmittableResult): void {
    if (result instanceof ClassOf('Hash')) {
      this._queueSetTxStatus(id, 'sent', result.toHex());
    } else {
      this._queueSetTxStatus(id, result.status.type.toLowerCase() as QueueTxStatus, status);
    }
  }
}
github polkadot-js / apps / packages / react-signer / src / ApiSigner.ts View on Github external
public update (id: number, result: Hash | SubmittableResult): void {
    if (result instanceof ClassOf(registry, 'Hash')) {
      this._queueSetTxStatus(id, 'sent', result.toHex());
    } else {
      this._queueSetTxStatus(id, result.status.type.toLowerCase() as QueueTxStatus, status);
    }
  }
}