diff --git a/packages/desktop/views/dashboard/collectibles/components/CollectionsGalleryItem.svelte b/packages/desktop/views/dashboard/collectibles/components/CollectionsGalleryItem.svelte index f3e5fa3cf0..3b7ae4a33a 100644 --- a/packages/desktop/views/dashboard/collectibles/components/CollectionsGalleryItem.svelte +++ b/packages/desktop/views/dashboard/collectibles/components/CollectionsGalleryItem.svelte @@ -33,7 +33,7 @@ {collection.name} - + {localize('general.nfts', { count: collection.nfts.length })} diff --git a/packages/shared/src/lib/core/nfts/stores/selected-account-collections.store.ts b/packages/shared/src/lib/core/nfts/stores/selected-account-collections.store.ts index e45446b556..68105a4dc9 100644 --- a/packages/shared/src/lib/core/nfts/stores/selected-account-collections.store.ts +++ b/packages/shared/src/lib/core/nfts/stores/selected-account-collections.store.ts @@ -3,7 +3,7 @@ import { NftStandard } from '../enums' import { Nft } from '../interfaces' import { Collections } from '../types' import { getCollectionFromNft } from '../utils' -import { selectedAccountNfts } from './selected-account-nfts.store' +import { ownedNfts, selectedAccountNfts } from './selected-account-nfts.store' export const collectionsStore: Writable = writable({}) @@ -50,12 +50,27 @@ async function updateCollections(nfts: Nft[]): Promise { } selectedAccountNfts.subscribe((nfts) => { - void updateCollections(nfts) + void updateCollections(nfts.filter((nft) => nft.isSpendable)) }) export const selectedAccountCollections: Readable = derived( - collectionsStore, - ($collectionsStore) => $collectionsStore + [collectionsStore, ownedNfts], + ([$collectionsStore, $ownedNfts]) => { + const accountCollections: Collections = {} + for (const collectionId in $collectionsStore) { + const collection = $collectionsStore[collectionId] + const nftsForAccount = collection.nfts.filter((nft) => + $ownedNfts.some((ownedNft) => ownedNft.id === nft.id) + ) + if (nftsForAccount.length > 0) { + // @ts-expect-error - ignore type error because we are filtering the existing nfts for the account + accountCollections[collectionId] = { ...collection, nfts: nftsForAccount } + } else { + delete accountCollections[collectionId] + } + } + return accountCollections + } ) export const collectionsSearchTerm: Writable = writable('')