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 nonce = await siweService.instance!.getNonce();
        final p1 = await siweService.instance!.config!.getMessageParams();
        final chains =
            W3MChainPresets.chains.values.map((e) => e.namespace).toList();
        final methods = p1.methods ?? MethodsConstants.allMethods;
        final p2 = {'nonce': nonce, 'chains': chains, 'methods': methods};
        final authParams = SessionAuthRequestParams.fromJson({
          ...p1.toJson(),
          ...p2,
        });
        // One-Click Auth
        final authResponse = await _web3App.authenticate(
          params: authParams,
        );
        _wcUri = authResponse.uri?.toString() ?? '';
        _notify();
        _awaitOCAuthCallback(authResponse);
      } else {
        // Regular Session Proposal
        final connectResponse = await _web3App.connect(
          requiredNamespaces: _requiredNamespaces,
          optionalNamespaces: _optionalNamespaces,
        );
        _wcUri = connectResponse.uri?.toString() ?? '';
        _notify();
        _awaitConnectionCallback(connectResponse);
      }
    } catch (e) {
      _logger.e('[$runtimeType] buildConnectionUri $e');
    }
  }
}