launchConnectedWallet method

  1. @override
void launchConnectedWallet()
override

Opens the native wallet selectedWallet after connected

Implementation

@override
void launchConnectedWallet() async {
  _checkInitialized();

  final walletInfo = _explorerService.getConnectedWallet();
  if (walletInfo == null) {
    // if walletInfo is null could mean that either
    // 1. There's no wallet connected (shouldn't happen)
    // 2. Wallet is connected on another device through qr code
    return;
  }

  final isCoinbase = _currentSession!.sessionService.isCoinbase == true;
  if (walletInfo.isCoinbase || isCoinbase) {
    // Coinbase Wallet is getting launched at every request by its service
    // So no need to do it here.
    return;
  }

  final isPhantom = _currentSession!.sessionService.isPhantom == true;
  if (walletInfo.isPhantom || isPhantom) {
    // Phantom Wallet is getting launched at every request by its service
    // So no need to do it here.
    return;
  }

  if (_currentSession!.sessionService.isMagic) {
    // There's no wallet to launch when connected with Email
    return;
  }

  final metadataRedirect = _currentSession!.peer?.metadata.redirect;

  final appLink = (metadataRedirect?.universal ?? '');
  final supportedApps = _appKit.core.getLinkModeSupportedApps();
  final isLinkMode = appLink.isNotEmpty && supportedApps.contains(appLink);
  if (isLinkMode) {
    // Opening peers during Link Mode requests is handled in Sign Engine
    return;
  }

  final walletRedirect = _explorerService.getWalletRedirect(
    walletInfo,
  );

  if (walletRedirect == null) {
    return;
  }

  try {
    final link = metadataRedirect?.native ?? metadataRedirect?.universal;
    final redirect = walletRedirect.copyWith(mobile: link);
    final platform = PlatformUtils.getPlatformType();
    _uriService.openRedirect(redirect, pType: platform);
  } catch (e) {
    onModalError.broadcast(ErrorOpeningWallet());
  }
}