formatRelayRpcUrl static method

String formatRelayRpcUrl({
  1. required String protocol,
  2. required int version,
  3. required String relayUrl,
  4. required String sdkVersion,
  5. required String auth,
  6. String? projectId,
  7. String? packageName,
})

Implementation

static String formatRelayRpcUrl({
  required String protocol,
  required int version,
  required String relayUrl,
  required String sdkVersion,
  required String auth,
  String? projectId,
  String? packageName,
}) {
  final Uri uri = Uri.parse(relayUrl);
  final Map<String, String> queryParams = Uri.splitQueryString(uri.query);
  final userAgent = formatUA(protocol, version, sdkVersion);

  // Add basic query params
  final Map<String, String> relayParams = {
    'auth': auth,
    'ua': userAgent,
  };

  // Add projectId query param
  if ((projectId ?? '').isNotEmpty) {
    relayParams['projectId'] = projectId!;
  }

  // Add bundleId, packageName or origin query param based on platform
  if ((packageName ?? '').isNotEmpty) {
    final platform = getId();
    if (platform == 'ios') {
      relayParams['bundleId'] = packageName!;
    } else if (platform == 'android') {
      relayParams['packageName'] = packageName!;
    } else {
      relayParams['origin'] = packageName!;
    }
  }

  queryParams.addAll(relayParams);
  return uri.replace(queryParameters: queryParams).toString();
}