From a5c3a1b462f09febb3935720bacb509e15dd6c9e Mon Sep 17 00:00:00 2001 From: Martin Cayuelas Date: Tue, 19 Nov 2024 16:28:01 +0100 Subject: [PATCH] =?UTF-8?q?bugfix:=20=F0=9F=90=9B=20Spam=20filtering=20err?= =?UTF-8?q?ors=20unhandled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/silly-seals-argue.md | 7 +++++++ .../hooks/nfts/useSyncNFTsWithAccounts.ts | 4 ++-- .../Developer/SimpleHashTools/SpamScore/index.tsx | 2 +- .../src/hooks/nfts/useSyncNFTsWithAccounts.ts | 4 ++-- .../src/hooks/useCheckNftAccount.ts | 15 ++++++++------- 5 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 .changeset/silly-seals-argue.md diff --git a/.changeset/silly-seals-argue.md b/.changeset/silly-seals-argue.md new file mode 100644 index 000000000000..6a4fc5833a23 --- /dev/null +++ b/.changeset/silly-seals-argue.md @@ -0,0 +1,7 @@ +--- +"ledger-live-desktop": minor +"live-mobile": minor +"@ledgerhq/live-nft-react": minor +--- + +Fix undefined join on Spam filter diff --git a/apps/ledger-live-desktop/src/renderer/hooks/nfts/useSyncNFTsWithAccounts.ts b/apps/ledger-live-desktop/src/renderer/hooks/nfts/useSyncNFTsWithAccounts.ts index b795bb62fc0c..10d9d1f138ca 100644 --- a/apps/ledger-live-desktop/src/renderer/hooks/nfts/useSyncNFTsWithAccounts.ts +++ b/apps/ledger-live-desktop/src/renderer/hooks/nfts/useSyncNFTsWithAccounts.ts @@ -66,12 +66,12 @@ export function useSyncNFTsWithAccounts() { const [, setCurrentIndex] = useState(0); const { refetch } = useCheckNftAccount({ - addresses: groupToFetch.join(","), + addresses: groupToFetch?.join(",") || "", nftsOwned, chains: SUPPORTED_NFT_CURRENCIES, threshold, action: hideSpamCollection, - enabled, + enabled: enabled && groupToFetch.length > 0, }); // Refetch with new last group when addressGroups length changes diff --git a/apps/ledger-live-desktop/src/renderer/screens/settings/sections/Developer/SimpleHashTools/SpamScore/index.tsx b/apps/ledger-live-desktop/src/renderer/screens/settings/sections/Developer/SimpleHashTools/SpamScore/index.tsx index 76bc9e4cf834..c5a8b392cb99 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/settings/sections/Developer/SimpleHashTools/SpamScore/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/settings/sections/Developer/SimpleHashTools/SpamScore/index.tsx @@ -72,7 +72,7 @@ export default function SpamScore(props: HookResult) { return (error as Error).message; }; - const getScore = (data?: SimpleHashResponse) => data?.nfts[0].collection.spam_score; + const getScore = (data?: SimpleHashResponse) => data?.nfts[0]?.collection.spam_score || 100; const text = checkSpamScore.isError ? getErrorText(checkSpamScore.error) diff --git a/apps/ledger-live-mobile/src/hooks/nfts/useSyncNFTsWithAccounts.ts b/apps/ledger-live-mobile/src/hooks/nfts/useSyncNFTsWithAccounts.ts index 354731e034f2..92bdda397ede 100644 --- a/apps/ledger-live-mobile/src/hooks/nfts/useSyncNFTsWithAccounts.ts +++ b/apps/ledger-live-mobile/src/hooks/nfts/useSyncNFTsWithAccounts.ts @@ -66,12 +66,12 @@ export function useSyncNFTsWithAccounts() { const [, setCurrentIndex] = useState(0); const { refetch } = useCheckNftAccount({ - addresses: groupToFetch.join(","), + addresses: groupToFetch?.join(",") || "", nftsOwned, chains: SUPPORTED_NFT_CURRENCIES, threshold, action: hideSpamCollection, - enabled, + enabled: enabled && groupToFetch.length > 0, }); // Refetch with new last group when addressGroups length changes diff --git a/libs/live-nft-react/src/hooks/useCheckNftAccount.ts b/libs/live-nft-react/src/hooks/useCheckNftAccount.ts index 6d67b3f56ef4..ef31ce5b196c 100644 --- a/libs/live-nft-react/src/hooks/useCheckNftAccount.ts +++ b/libs/live-nft-react/src/hooks/useCheckNftAccount.ts @@ -65,7 +65,7 @@ export function useCheckNftAccount({ const processingNFTs = queryResult.data?.pages.flatMap(page => page.nfts); - if (!queryResult.hasNextPage && processingNFTs) { + if (!queryResult.hasNextPage && processingNFTs?.length) { for (const nft of processingNFTs) { const hash = hashProtoNFT(nft.contract_address, nft.token_id, nft.chain); const existing = nftsWithProperties.get(hash); @@ -76,14 +76,15 @@ export function useCheckNftAccount({ if (action) { const spams = nftsOwned.filter(nft => !nfts.some(ownedNft => ownedNft.id === nft.id)); - const collections = nftsByCollections(spams); - Object.entries(collections).map(([contract, nfts]: [string, ProtoNFT[]]) => { - const { accountId } = decodeNftId(nfts[0].id); - const collection = `${accountId}|${contract}`; - action(collection); - }); + if (spams.length > 0) { + Object.entries(collections).map(([contract, nfts]: [string, ProtoNFT[]]) => { + const { accountId } = decodeNftId(nfts[0].id); + const collection = `${accountId}|${contract}`; + action(collection); + }); + } } } return { ...queryResult, nfts };