sendResult method

  1. @override
Future sendResult(
  1. int id,
  2. String topic,
  3. String method,
  4. dynamic result, {
  5. EncodeOptions? encodeOptions,
  6. String? appLink,
})
override

Implementation

@override
Future<dynamic> sendResult(
  int id,
  String topic,
  String method,
  dynamic result, {
  EncodeOptions? encodeOptions,
  String? appLink,
}) async {
  final payload = JsonRpcUtils.formatJsonRpcResponse<dynamic>(
    id,
    result,
  );

  final String? message = await core.crypto.encode(
    topic,
    payload,
    options: encodeOptions,
  );

  if (message == null) {
    return;
  }

  if ((appLink ?? '').isNotEmpty) {
    final redirectURL = ReownCoreUtils.getLinkModeURL(
      appLink!,
      topic,
      message,
    );
    core.logger.t(
      'pairing sendResult LinkMode, '
      'id: $id topic: $topic, method: $method, result: $result',
    );
    await ReownCoreUtils.openURL(redirectURL);
  } else {
    final RpcOptions opts = MethodConstants.RPC_OPTS[method]!['res']!;
    core.logger.t(
      'pairing sendResult Relay, '
      'id: $id topic: $topic, method: $method, result: $result',
    );
    await core.relayClient.publish(
      topic: topic,
      message: message,
      ttl: opts.ttl,
      tag: opts.tag,
    );
  }
}