disconnectSession method

  1. @override
Future<void> disconnectSession({
  1. required String topic,
  2. required WalletConnectError reason,
})
override

Implementation

@override
Future<void> disconnectSession({
  required String topic,
  required WalletConnectError reason,
}) async {
  _checkInitialized();
  _confirmOnlineStateOrThrow();

  try {
    await _isValidDisconnect(topic);

    if (sessions.has(topic)) {
      // Send the request to delete the session, we don't care if it fails
      try {
        final deleteRequest = WcSessionDeleteRequest(
          code: reason.code,
          message: reason.message,
          data: reason.data,
        );
        core.pairing.sendRequest(
          topic,
          MethodConstants.WC_SESSION_DELETE,
          deleteRequest.toJson(),
        );
      } catch (_) {}

      await _deleteSession(topic);
    } else {
      await core.pairing.disconnect(topic: topic);
    }
  } on WalletConnectError catch (error, s) {
    core.logger.e(
      '[$runtimeType] disconnectSession()',
      error: error,
      stackTrace: s,
    );
  }
}