Skip to content

Commit

Permalink
bugfix: 🐛 Spam filtering errors unhandled
Browse files Browse the repository at this point in the history
  • Loading branch information
mcayuelas-ledger committed Nov 19, 2024
1 parent 416a171 commit a5c3a1b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .changeset/silly-seals-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"ledger-live-desktop": minor
"live-mobile": minor
"@ledgerhq/live-nft-react": minor
---

Fix undefined join on Spam filter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions libs/live-nft-react/src/hooks/useCheckNftAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 };
Expand Down

0 comments on commit a5c3a1b

Please sign in to comment.