getInitial static method
Implementation
static String getInitial(String pubkey, Metadata? metadata) {
final displayName = metadata?.displayName;
if (displayName != null && displayName.trim().isNotEmpty) {
return displayName.trim()[0].toUpperCase();
}
final name = metadata?.name;
if (name != null && name.trim().isNotEmpty) {
return name.trim()[0].toUpperCase();
}
final nip05 = metadata?.nip05;
if (nip05 != null && nip05.trim().isNotEmpty) {
final cleanNip05 = nip05.trim();
if (cleanNip05.startsWith('_@') && cleanNip05.length > 2) {
return cleanNip05[2].toUpperCase();
}
if (cleanNip05.startsWith('@') && cleanNip05.length > 1) {
return cleanNip05[1].toUpperCase();
}
return cleanNip05[0].toUpperCase();
}
if (pubkey.length >= 64) {
final char = pubkey[28].toLowerCase();
final hexValue = int.tryParse(char, radix: 16);
if (hexValue != null && hexValue >= 0 && hexValue <= 15) {
return String.fromCharCode('A'.codeUnitAt(0) + hexValue);
}
}
return '';
}