getCredentialNfts function
Future<List<CrossmintCredentialsCollection> >
getCredentialNfts(
- CrossmintVcChain chain,
- String wallet, {
- required CrossmintWalletCredentialNftProvider walletNftsProvider,
- required CrossmintCredentialCollectionProvider collectionProvider,
- CrossmintCredentialFilter filter = const CrossmintCredentialFilter(),
Implementation
Future<List<CrossmintCredentialsCollection>> getCredentialNfts(
CrossmintVcChain chain,
String wallet, {
required CrossmintWalletCredentialNftProvider walletNftsProvider,
required CrossmintCredentialCollectionProvider collectionProvider,
CrossmintCredentialFilter filter = const CrossmintCredentialFilter(),
}) async {
final List<CrossmintVcNft> nfts = await walletNftsProvider(chain, wallet);
final Map<String, List<CrossmintVcNft>> grouped =
<String, List<CrossmintVcNft>>{};
for (final CrossmintVcNft nft in nfts) {
grouped.putIfAbsent(nft.contractAddress, () => <CrossmintVcNft>[]).add(nft);
}
final List<CrossmintCredentialsCollection> collections =
<CrossmintCredentialsCollection>[];
for (final MapEntry<String, List<CrossmintVcNft>> entry in grouped.entries) {
final CrossmintCredentialsCollection? collection = await collectionProvider(
chain,
entry.key,
);
if (collection == null) {
continue;
}
if (!_matchesCredentialFilter(collection, filter)) {
continue;
}
collections.add(
CrossmintCredentialsCollection(
nfts: List<CrossmintVcNft>.unmodifiable(entry.value),
contractAddress: collection.contractAddress,
chain: collection.chain,
metadata: collection.metadata,
raw: collection.raw,
),
);
}
return collections;
}