Skip to content

Commit

Permalink
fix duplicated nft generation (#2394)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkNerdi authored Apr 30, 2024
1 parent 0c12d2a commit 781747b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { getActiveProfile } from '@core/profile/stores'
import { NftStandard } from '../enums'
import { IPersistedErc721Nft } from '../interfaces'
import { persistedNfts } from '../stores'
import { NetworkId } from '@core/network'

export function getPersistedErc721Nfts(): IPersistedErc721Nft[] {
export function getPersistedErc721NftsForNetwork(networkId: NetworkId): IPersistedErc721Nft[] {
const activeProfileId = getActiveProfile()?.id
if (activeProfileId) {
const profileNfts = Object.values(get(persistedNfts)[activeProfileId] ?? {})
return profileNfts.filter(({ standard }) => standard === NftStandard.Erc721) as IPersistedErc721Nft[]
return profileNfts.filter(
({ standard, networkId: _networkId }) => standard === NftStandard.Erc721 && networkId === networkId
) as IPersistedErc721Nft[]
} else {
throw new Error('Unable to get active profile')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/lib/core/nfts/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export * from './buildNftFromNftOutput'
export * from './checkForUntrackedNfts'
export * from './downloadNextNftInQueue'
export * from './getNftByIdFromAllAccountNfts'
export * from './getPersistedErc721Nfts'
export * from './getPersistedErc721NftsForNetwork'
export * from './interruptNftDownloadAfterTimeout'
export * from './isNftPersisted'
export * from './loadNftsForActiveProfile'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Nft } from '../interfaces'
import { buildNftFromPersistedErc721Nft, getNftsFromNftIds } from '../utils'
import { addNftsToDownloadQueue } from './addNftsToDownloadQueue'
import { buildNftFromNftOutput } from './buildNftFromNftOutput'
import { getPersistedErc721Nfts } from './getPersistedErc721Nfts'
import { getPersistedErc721NftsForNetwork } from './getPersistedErc721NftsForNetwork'
import { setAccountNftsInAllAccountNfts } from './setAccountNftsInAllAccountNfts'

export async function loadNftsForActiveProfile(): Promise<void> {
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function loadNftsForAccount(profileId: string, account: IAccountSta
if (!evmAddress) {
continue
}
const erc721Nfts = getPersistedErc721Nfts()
const erc721Nfts = getPersistedErc721NftsForNetwork(evmNetwork.id)
const convertedNfts: Nft[] = erc721Nfts.map((persistedErc721Nft) =>
buildNftFromPersistedErc721Nft(persistedErc721Nft, evmAddress)
)
Expand Down

0 comments on commit 781747b

Please sign in to comment.