request<T> method

  1. @override
Future<T> request<T>(
  1. SessionRequestParams params
)
override

Implementation

@override
Future<T> request<T>(SessionRequestParams params) async {
  _isInitialized();
  await _isValidRequest(params);
  final id = await _sendRequest<RequestSessionRequest>(
    params.topic,
    JsonRpcMethod.WC_SESSION_REQUEST,
    RequestSessionRequest(
      request: params.request,
      chainId: params.chainId,
    ),
    (v) => v.toJson(),
  );
  final completer = Completer<T>();
  final timer = completer.expirer();
  events.once(
    engineEvent(EngineEvent.SESSION_REQUEST, id),
    (data) {
      timer.cancel();
      if (data is ErrorResponse) {
        completer.completeError(data);
      } else {
        completer.complete(data as T);
      }
    },
  );
  return completer.future;
}