buildConnectionUri method

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

This will do nothing if isConnected is true.

Implementation

@override
Future<void> buildConnectionUri() async {
  if (!_isConnected) {
    try {
      if (siweService.instance!.enabled) {
        final walletRedirect = explorerService.instance.getWalletRedirect(
          selectedWallet,
        );
        final nonce = await siweService.instance!.getNonce();
        final p1 = await siweService.instance!.config!.getMessageParams();
        final methods = p1.methods ?? MethodsConstants.allMethods;
        //
        final supportedNetworks = ReownAppKitModalNetworks.getNetworks(
          CoreConstants.namespace,
        );
        final chains = supportedNetworks
            .map((e) => '${CoreConstants.namespace}:${e.chainId}')
            .toList();
        final p2 = {'nonce': nonce, 'chains': chains, 'methods': methods};
        final authParams = SessionAuthRequestParams.fromJson({
          ...p1.toJson(),
          ...p2,
        });
        // One-Click Auth
        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) {
      _logger.e('[$runtimeType] buildConnectionUri $e');
    }
  }
}