buildConnectionUri method

  1. @override
Future<void> buildConnectionUri()
override

This will do nothing if isConnected is true.

Implementation

@override
Future<void> buildConnectionUri() async {
  if (!_isConnected) {
    /// TODO Qs: How do I handle SIWE if non-EVM chains are included?
    /// TODO Qs: How do I handle switch to Solana from EVM chain?
    try {
      if (_siweService.enabled) {
        final walletRedirect = _explorerService.getWalletRedirect(
          selectedWallet,
        );
        final nonce = await _siweService.getNonce();
        final p1 = await _siweService.config!.getMessageParams();
        final methods =
            p1.methods ?? NetworkUtils.defaultNetworkMethods['eip155'];
        //
        final networks = ReownAppKitModalNetworks.getAllSupportedNetworks();
        final chains = networks.map((chain) {
          return ReownAppKitModalNetworks.getCaip2Chain(chain.chainId);
        }).toList();
        final p2 = {'nonce': nonce, 'chains': chains, 'methods': methods};
        final authParams = SessionAuthRequestParams.fromJson({
          ...p1.toJson(),
          ...p2,
        });
        // One-Click Auth
        _appKit.core.logger.d(
          '[$runtimeType] authenticate ${jsonEncode(authParams.toJson())}, ${walletRedirect?.linkMode}',
        );
        final authResponse = await _appKit.authenticate(
          params: authParams,
          walletUniversalLink: walletRedirect?.linkMode,
        );
        _wcUri = authResponse.uri?.toString() ?? '';
        _notify();
        _awaitOCAuthCallback(authResponse);
      } else {
        // Regular Session Proposal
        final connectResponse = await _appKit.connect(
          requiredNamespaces: _requiredNamespaces,
          optionalNamespaces: _optionalNamespaces,
        );
        _wcUri = connectResponse.uri?.toString() ?? '';
        _notify();
        _awaitConnectionCallback(connectResponse);
      }
    } catch (e) {
      _appKit.core.logger.e('[$runtimeType] buildConnectionUri error: $e');
    }
  }
}