solui
  • Dapps
  • Getting Started
  • Docs
  • Community

Transformations

Transformations allow you to transform an output value into other formats prior to display. For example, you may wish to treat a returned integer as a timestamp and display it as user-friendly datetime string.

Multiple transformations can be specified for a given value, in which case they are chained together, i.e. the output of a given transformation in the chain becomes the input of the next transformation, and so on.

Structure

{
  ...,
  "panels": [
    {
      ...,
      "outputs": [
        {
          "transform": [
            {
              "type": "...",
              ...
            },
            {
              "type": "...",
              ...
            },
            ...
          ]
        },
        ...
      ]
    }
  ]
}

Reference

The type parameter specifies the transformation type:

  • intToDateString
  • intToScaledIntString
  • intToHexString
  • intToBinaryString
  • stringToSpacedSuffixedString
  • toMappedString

Note: transformations are named in the format <inputType>...<outputType> for ease of use.

Example:

{
  "type": "intToDateString"
}

Additional attributes depend on this parameter.

Transformation: intToDateString

This treats a number value as a blockchain-generated timestamp and converts it to its string representation.

Example:

{
  "type": "intToDateString"
}

The string formatting is performed by the date-fns library and the default format pattern is MMM d, yyyy. For example, the value 1585167477 would be transformed to Mar 25, 2020.

To change the pattern use the format parameter:

{
  "type": "intToDateString",
  "format": "HH:mm"
}

The value 1585167477 would now be transformed to 20:17.

Note: full pattern information is available in the [date-fns/format](date-fns library) docs.

Transformation: intToScaledIntString

This scales a number value by the given scaling amount and returns a base-10 string representation. This means multiplying the input value by 10^scale to obtain the final value.

Example (10 -> "10000"):

{
  "type": "intToScaledIntString",
  "scale": "3"
}

If outputting an ETH value (which gets returned as WEI from a contract call) then the scale should be set to -18.

Transformation: intToHexString

This converts a number value to its hexadecimal string representation.

Example (255 -> "FF"):

{
  "type": "intToHexString"
}

Transformation: intToBinaryString

This converts a number value to its binary string representation.

Example (4 -> "100"):

{
  "type": "intToBinaryString"
}

Transformation: stringToSpacedSuffixedString

This adds a suffix to a string value, leaving a space in between.

Example ("10" -> "10 eth"):

{
  "type": "stringToSpacedSuffixedString",
  "suffix": "eth"
}

Transformation: toMappedString

This maps the value to an output string. The value is first stringified before the map lookup. Thus the map keys must be strings.

Example (mapping ints to strings):

{
  "type": "toMappedString",
  "options": {
    "0": "Created",
    "1": "Initial sale",
    "2": "Active",
    "3": "Matured",
    "4": "Cancelled"
  }
}