From d0a8abfe841d48cbbcd21e8caec0ec2957cebd2a Mon Sep 17 00:00:00 2001 From: Hadi Amjad <46374292+hadiamjad@users.noreply.github.com> Date: Thu, 6 Jul 2023 15:26:57 -0400 Subject: [PATCH] Adding a check-box to filter NFTs with high spam score (#1102) * check-btn for filtering high spam score NFTs --- src/components/web3/SelectableImageList.tsx | 85 +++++++++++++++------ src/components/web3/api.ts | 7 +- src/components/web3/core.ts | 1 + 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/src/components/web3/SelectableImageList.tsx b/src/components/web3/SelectableImageList.tsx index 2929fe49..3eb14d69 100644 --- a/src/components/web3/SelectableImageList.tsx +++ b/src/components/web3/SelectableImageList.tsx @@ -1,9 +1,16 @@ +import { useEffect, useState } from "react"; import { Dispatch } from "react"; import noNftImage from "../../images/no-nft-image.png"; interface Item { imageUrl: string; name?: string; + collection?: { + collection_id: string; + name: string; + image_url: string; + spam_score: number; + }; } interface Props { @@ -17,30 +24,62 @@ export const SelectableImageList: React.FC = ({ selectedIdxs, onToggleSelection, }) => { + const showCheckbox = items.some( + (item) => item.collection !== undefined && item.collection.spam_score > 80 + ); + + const [showSpamItems, setShowSpamItems] = useState(false); + + const filteredItems = showSpamItems + ? items + : items.filter((item) => { + if (item.collection?.spam_score !== undefined) { + return item.collection.spam_score < 80; + } + return true; + }); + + const onToggleSpamItems = () => { + setShowSpamItems(!showSpamItems); + }; + return ( -
- {items.map((item, idx) => ( -
onToggleSelection(idx)} - css={{ padding: "5px 5px 5px 0" }} - title={item.name} - > - item - {} +
+ {showCheckbox && ( +
+
- ))} + )} +
+ {filteredItems.map((item, idx) => ( +
onToggleSelection(idx)} + css={{ padding: "5px 5px 5px 0" }} + title={item.name} + > + item +
+ ))} +
); -}; +}; \ No newline at end of file diff --git a/src/components/web3/api.ts b/src/components/web3/api.ts index 3b8ef430..12c9807a 100644 --- a/src/components/web3/api.ts +++ b/src/components/web3/api.ts @@ -75,12 +75,6 @@ export const web3NFTs = async (address: string): Promise => { const result: NFT[] = []; nfts.nfts.forEach((nft: any) => { - if ( - "spam_score" in nft.collection && - typeof nft.collection.spam_score === "number" && - nft.collection.spam_score >= 80 - ) - return; result.push({ image_url: nft.previews?.image_small_url ? nft.previews.image_small_url @@ -90,6 +84,7 @@ export const web3NFTs = async (address: string): Promise => { collection_id: nft.collection?.collection_id, name: nft.collection?.name, image_url: nft.collection?.image_url, + spam_score: nft.collection.spam_score, }, }); }); diff --git a/src/components/web3/core.ts b/src/components/web3/core.ts index b2c7c101..2f6c7df9 100644 --- a/src/components/web3/core.ts +++ b/src/components/web3/core.ts @@ -22,6 +22,7 @@ export interface NFT { collection_id: string; name: string; image_url: string; + spam_score: number; }; previews?: { image_small_url: string;