connectSelectedWallet method

  1. @override
Future<void> connectSelectedWallet({
  1. bool inBrowser = false,
  2. AppKitSocialOption? socialOption,
})
override

Connects the selectedWallet previously selected

Implementation

@override
Future<void> connectSelectedWallet({
  bool inBrowser = false,
  AppKitSocialOption? socialOption,
}) async {
  _checkInitialized();

  final walletRedirect = _explorerService.getWalletRedirect(_selectedWallet);

  if (walletRedirect == null) {
    throw ReownAppKitModalException(
      'You didn\'t select a wallet or walletInfo argument is null',
    );
  }
  _trackSelectedWallet(walletRedirect, inBrowser: inBrowser);

  var pType = PlatformUtils.getPlatformType();
  if (inBrowser) {
    pType = PlatformType.web;
  }
  try {
    if (_selectedWallet!.isCoinbase) {
      await _coinbaseService.getAccount();
    } else if (_selectedWallet!.isPhantom) {
      await _phantomService.connect(chainId: _selectedChainID);
    } else if (_selectedWallet!.isSolflare) {
      await _solflareService.connect(chainId: _selectedChainID);
    } else {
      await _connect(walletRedirect, pType, socialOption);
    }
  } on LaunchUrlException catch (e) {
    if (e is CanNotLaunchUrl) {
      onModalError.broadcast(WalletNotInstalled());
    } else {
      onModalError.broadcast(ErrorOpeningWallet());
    }
  } on ThirdPartyWalletException catch (e) {
    if (e is ThirdPartyWalletNotInstalled) {
      onModalError.broadcast(WalletNotInstalled());
    } else {
      onModalError.broadcast(ErrorOpeningWallet(description: e.message));
    }
  } catch (e, s) {
    if (e is PlatformException) {
      final installed = _selectedWallet?.installed ?? false;
      if (!installed) {
        onModalError.broadcast(WalletNotInstalled());
      } else {
        onModalError.broadcast(ErrorOpeningWallet());
      }
    } else if (e is CoinbaseServiceException) {
      if (e is CoinbaseWalletNotInstalledException) {
        onModalError.broadcast(WalletNotInstalled());
      } else {
        if (_isUserRejectedError(e)) {
          onModalError.broadcast(UserRejectedConnection());
          _analyticsService.sendEvent(
            ConnectErrorEvent(message: 'User declined connection'),
          );
        } else {
          onModalError.broadcast(ErrorOpeningWallet());
          _analyticsService.sendEvent(ConnectErrorEvent(message: e.message));
        }
      }
    } else {
      if (_isUserRejectedError(e)) {
        onModalError.broadcast(UserRejectedConnection());
        _analyticsService.sendEvent(
          ConnectErrorEvent(message: 'User declined connection'),
        );
      } else if (e is ReownCoreError) {
        onModalError.broadcast(ErrorOpeningWallet(description: e.message));
        _appKit.core.logger.e(
          '[$runtimeType] connectSelectedWallet error: $e',
          stackTrace: s,
        );
      } else {
        onModalError.broadcast(ErrorOpeningWallet());
        _appKit.core.logger.e(
          '[$runtimeType] connectSelectedWallet error: $e',
          stackTrace: s,
        );
      }
    }
  }
}