rejectSession method

Future rejectSession({
  1. String? message,
})

Rejects the session requested by the peer (dApp), responding with reason message. https://docs.walletconnect.com/client-api#reject-session-request-disconnect

Implementation

Future rejectSession({String? message}) async {
  if (connected) {
    throw WalletConnectException('Session currently connected');
  }

  message = message ?? 'Session Rejected';

  final response = JsonRpcResponse(
    id: session.handshakeId,
    error: {
      'code': -32000,
      'message': message,
    },
  );

  await _sendResponse(response);
  session.connected = false;

  // Notify listeners
  _eventBus.fire(Event<String>('disconnect', message));
}