crossmintNftAttributes function

List<Map<String, String>> crossmintNftAttributes(
  1. CrossmintNftRecord nft
)

Extracts NFT attributes (trait_type / value pairs) for display.

Implementation

List<Map<String, String>> crossmintNftAttributes(CrossmintNftRecord nft) {
  final Object? attrs = _tryValue(nft.raw, const [
    ['metadata', 'attributes'],
    ['onChain', 'metadata', 'attributes'],
    ['attributes'],
  ]);

  if (attrs is! List) return const [];

  return attrs
      .whereType<Map<String, Object?>>()
      .where((a) => a['trait_type'] != null)
      .map(
        (a) => {
          'trait_type': a['trait_type'].toString(),
          'value': (a['value'] ?? '').toString(),
        },
      )
      .toList();
}