Relaycode

Moment Input

Date-time picker with quick presets for timestamp parameters

Timezone: UTC
import { Moment } from "@/components/params/inputs/moment";

<Moment
  name="when"
  label="Schedule Time"
  description="The time at which to execute"
  client={client}
  typeId={4}
  isRequired
  onChange={(timestamp) => console.log("Timestamp:", timestamp)}
/>

Moment Input

The Moment input provides a date-time picker for Substrate Moment parameters. It uses the browser's native datetime-local input and offers quick preset buttons for common time offsets. The selected date-time is converted to a Unix timestamp in milliseconds.

Supported Type Names

The Moment component matches the following type names at priority 65:

  • Moment
  • Any type name matching /Moment/

Props

The component accepts the standard ParamInputProps interface:

PropTypeRequiredDescription
namestringYesField identifier used for the HTML id and form state
labelstringNoDisplay label shown above the input
descriptionstringNoHelp text shown below the input
typeNamestringNoThe SCALE type name ("Moment")
isDisabledbooleanNoDisables the input and preset buttons when true
isRequiredbooleanNoShows a red asterisk next to the label
errorstringNoValidation error message to display
clientDedotClient<PolkadotApi>YesConnected Dedot client
typeIdnumberNoMetadata type ID for this parameter
valueanyNoExternally controlled timestamp in milliseconds (e.g. from hex decode)
onChange(value: unknown) => voidNoCallback fired with the timestamp as a string

Features

  • Native date-time picker: Uses the browser's datetime-local input type for a familiar date and time selection interface.
  • Quick preset buttons: Five preset buttons for common time values -- "Now", "+1h", "+6h", "+24h", and "+7d" -- that calculate timestamps relative to the current time.
  • Timezone display: Shows the user's local timezone (e.g. "America/New_York") beneath the input so there is no ambiguity about the time reference.
  • External value sync: When an external timestamp is set (e.g. from hex decoding), it is converted to a datetime-local string and displayed in the picker.

Type Resolution

import { findComponent } from "@/lib/input-map";

// Resolves to the Moment component
findComponent("Moment", typeId, client);

Usage

The Moment component is rendered by the extrinsic builder when a parameter resolves to a Moment type. Direct usage:

import { Moment } from "@/components/params/inputs/moment";

<Moment
  name="when"
  label="Schedule Time"
  description="The time at which to execute"
  client={client}
  typeId={4}
  isRequired
  onChange={(timestamp) => console.log("Timestamp:", timestamp)}
/>

Validation

The component uses a Zod schema that checks for a non-negative integer:

const schema = z.number().int().min(0);

Value Format

The onChange callback receives a string representing the Unix timestamp in milliseconds (e.g. "1700000000000"). This format is compatible with BigInt conversion for SCALE encoding. If the input is cleared, undefined is emitted.