toString method

  1. @override
String toString()
override

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Implementation

@override
String toString() {
  final m = 'method:"$method"';
  final t = 'type:"${super.type}"';

  if (params is Map) {
    List<String> ps =
        (params as Map).entries.map((e) => '${e.key}:"${e.value}"').toList();
    final pString = ps.join(',');
    return '{$t,payload:{$m,params:{$pString}}}';
  }

  final p = params.map((i) => '$i').toList();

  if (method == 'personal_sign') {
    final data = p.first;
    final address = p.last;
    return '{$t,payload:{$m,params:["$data","$address"]}}';
  }
  if (method == 'eth_sign') {
    final address = p.first;
    final data = p.last;
    return '{$t,payload:{$m,params:["$address","$data"]}}';
  }
  if (method == 'eth_signTypedData_v4' ||
      method == 'eth_signTypedData_v3' ||
      method == 'eth_signTypedData') {
    final data = p.first;
    final address = p.last;
    return '{$t,payload:{$m,params:["$address","$data"]}}';
  }
  if (method == 'eth_sendTransaction' || method == 'eth_signTransaction') {
    final jp = jsonEncode(params.first);
    return '{$t,payload:{$m,params:[$jp]}}';
  }

  final ps = p.join(',');
  return '{$t,payload:{$m,params:[$ps]}}';
}