getIdentity method

  1. @override
Future<BlockchainIdentity> getIdentity(
  1. String address
)
override

Gets the name and avatar of a provided address on the given chain

Implementation

@override
Future<BlockchainIdentity> getIdentity(String address) async {
  try {
    final uri = Uri.parse('$_baseUrl/identity/$address');
    final queryParams = {..._requiredParams};
    final response = await http.get(
      uri.replace(queryParameters: queryParams),
      headers: _requiredHeaders,
    );
    _core.logger.i('[$runtimeType] getIdentity $address => ${response.body}');
    if (response.statusCode == 200 && response.body.isNotEmpty) {
      return BlockchainIdentity.fromJson(jsonDecode(response.body));
    }
    if (response.statusCode == 400) {
      final errorData = jsonDecode(response.body) as Map<String, dynamic>;
      final reasons = errorData['reasons'] as List<dynamic>;
      final reason = reasons.isNotEmpty
          ? reasons.first['description'] ?? ''
          : response.body;
      throw Exception(reason);
    } else {
      throw Exception('Failed to load avatar');
    }
  } catch (e) {
    _core.logger.e('[$runtimeType] getIdentity $address error => $e');
    rethrow;
  }
}