disconnect method

  1. @override
Future<void> disconnect({
  1. bool disconnectAllSessions = true,
})
override

Disconnects the session and pairing, if any. If there is no session, this does nothing.

Implementation

@override
Future<void> disconnect({bool disconnectAllSessions = true}) async {
  _checkInitialized();

  _status = ReownAppKitModalStatus.initializing;
  _notify();

  if (_currentSession?.sessionService.isCoinbase == true) {
    try {
      await _coinbaseService.resetSession();
    } catch (e) {
      _appKit.core.logger.d('[$runtimeType] disconnect coinbase $e');
      _status = ReownAppKitModalStatus.initialized;
      _notify();
      return;
    }
  }
  if (_currentSession?.sessionService.isMagic == true) {
    try {
      await Future.delayed(Duration(milliseconds: 300));
      await _magicService.disconnect();
    } catch (e) {
      _appKit.core.logger.d('[$runtimeType] disconnect magic $e');
      _status = ReownAppKitModalStatus.initialized;
      _notify();
      return;
    }
  }

  try {
    // If we want to disconnect all sessions, loop through them and disconnect them
    if (disconnectAllSessions) {
      for (final SessionData session in _appKit.sessions.getAll()) {
        await _disconnectSession(session.pairingTopic, session.topic);
      }
    } else {
      // Disconnect the session
      await _disconnectSession(
        _currentSession?.pairingTopic,
        _currentSession?.topic,
      );
    }
    try {
      if (_siweService.signOutOnDisconnect) {
        await _siweService.signOut();
      }
    } catch (_) {}

    _analyticsService.sendEvent(DisconnectSuccessEvent());
    if (!(_currentSession?.sessionService.isWC == true)) {
      // if sessionService.isWC then _cleanSession() is being called on sessionDelete event
      return await _cleanSession();
    }
    return;
  } catch (e) {
    _analyticsService.sendEvent(DisconnectErrorEvent());
    _status = ReownAppKitModalStatus.initialized;
    _notify();
  }
}