connectSelectedWallet method

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

Connects the selectedWallet previously selected

Implementation

@override
Future<void> connectSelectedWallet({bool inBrowser = false}) 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();
      await _explorerService.storeConnectedWallet(_selectedWallet);
    } else {
      await buildConnectionUri();
      final linkMode = walletRedirect.linkMode ?? '';
      if (linkMode.isNotEmpty && _wcUri.startsWith(linkMode)) {
        await ReownCoreUtils.openURL(_wcUri);
      } else {
        await _uriService.openRedirect(
          walletRedirect,
          wcURI: _wcUri,
          pType: pType,
        );
      }
    }
  } on LaunchUrlException catch (e) {
    if (e is CanNotLaunchUrl) {
      onModalError.broadcast(WalletNotInstalled());
    } else {
      onModalError.broadcast(ErrorOpeningWallet());
    }
  } 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 {
      _appKit.core.logger.e(
        '[$runtimeType] connectSelectedWallet error: $e',
        stackTrace: s,
      );
      onModalError.broadcast(ErrorOpeningWallet());
    }
  }
}