Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] : simpleHash usage for NFTs Gallery in LL #6029

Merged
merged 19 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nasty-icons-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

Use SimpleHash APi to filter Spam in NFT Gallery
6 changes: 6 additions & 0 deletions .changeset/poor-kings-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ledgerhq/live-nft-react": minor
"@ledgerhq/live-nft": minor
---

Hook using SimpleHash Api to filter Spam NFTs from Accounts
5 changes: 5 additions & 0 deletions .changeset/smooth-feet-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

Use SimpleHash APi to filter Spam in NFT Gallery
1 change: 1 addition & 0 deletions apps/ledger-live-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@sentry/electron": "^4.15.1",
"@sentry/node": "7.84.0",
"@sentry/tracing": "7.84.0",
"@tanstack/react-query": "^5.17.19",
"@tippyjs/react": "^4.2.6",
"@trust/keyto": "^1.0.1",
"@types/qrcode": "^1.5.0",
Expand Down
8 changes: 7 additions & 1 deletion apps/ledger-live-desktop/src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import PostOnboardingProviderWrapped from "~/renderer/components/PostOnboardingH
import { useBraze } from "./hooks/useBraze";
import { StorylyProvider } from "~/storyly/StorylyProvider";
import { CounterValuesStateRaw } from "@ledgerhq/live-countervalues/types";
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";

const reloadApp = (event: KeyboardEvent) => {
if ((event.ctrlKey || event.metaKey) && event.key === "r") {
window.api?.reloadRenderer();
Expand All @@ -40,6 +42,8 @@ type Props = {
initialCountervalues: CounterValuesStateRaw;
};

const queryClient = new QueryClient();

const InnerApp = ({ initialCountervalues }: { initialCountervalues: CounterValuesStateRaw }) => {
const [reloadEnabled, setReloadEnabled] = useState(true);

Expand Down Expand Up @@ -80,7 +84,9 @@ const InnerApp = ({ initialCountervalues }: { initialCountervalues: CounterValue
<NftMetadataProvider getCurrencyBridge={getCurrencyBridge}>
<MarketDataProvider>
<StorylyProvider>
<Default />
<QueryClientProvider client={queryClient}>
<Default />
</QueryClientProvider>
</StorylyProvider>
</MarketDataProvider>
</NftMetadataProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useCallback, useState, useEffect, memo } from "react";
import { useNftMetadata, useNftCollectionMetadata } from "@ledgerhq/live-nft-react";
import { getFloorPrice } from "@ledgerhq/live-nft/api";
import { getFloorPrice } from "@ledgerhq/live-nft/api/metadataservice";
import styled from "styled-components";
import { useTranslation } from "react-i18next";
import { useSelector, useDispatch } from "react-redux";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import Text from "~/renderer/components/Text";
import { openURL } from "~/renderer/linking";
import Box from "~/renderer/components/Box";
import Row from "./Row";
import { useNftGalleryFilter } from "@ledgerhq/live-nft-react";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";

const INCREMENT = 5;
const EmptyState = styled.div`
padding: 15px 20px;
Expand All @@ -42,6 +45,8 @@ type Props = {
account: Account;
};
const Collections = ({ account }: Props) => {
const nftsFromSimplehashFeature = useFeature("nftsFromSimplehash");

const dispatch = useDispatch();
const { t } = useTranslation();
const history = useHistory();
Expand All @@ -64,13 +69,25 @@ const Collections = ({ account }: Props) => {
history.push(`/account/${account.id}/nft-collection/${collectionAddress}`),
[account.id, history],
);
const collections = useMemo(() => nftsByCollections(account.nfts), [account.nfts]);

const { nfts, fetchNextPage, hasNextPage } = useNftGalleryFilter({
nftsOwned: account.nfts || [],
addresses: account.freshAddress,
chains: [account.currency.id],
});
const collections = useMemo(
() => nftsByCollections(nftsFromSimplehashFeature?.enabled ? nfts : account.nfts),
[account.nfts, nfts, nftsFromSimplehashFeature],
);
const collectionsLength = Object.keys(collections).length;
const onShowMore = useCallback(() => {
setNumberOfVisibleCollections(numberOfVisibleCollections =>
Math.min(numberOfVisibleCollections + INCREMENT, collectionsLength),
);
}, [collectionsLength]);
if (hasNextPage) {
fetchNextPage();
}
}, [collectionsLength, fetchNextPage, hasNextPage]);
const hiddenNftCollections = useSelector(hiddenNftCollectionsSelector);
const filteredCollections = useMemo(
() =>
Expand All @@ -94,6 +111,7 @@ const Collections = ({ account }: Props) => {
)),
[account, filteredCollections, numberOfVisibleCollections, onOpenCollection],
);

useEffect(() => {
track("View NFT Collections (Account Page)");
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { State } from "~/renderer/reducers";
import { ProtoNFT } from "@ledgerhq/types-live";
import theme from "@ledgerhq/react-ui/styles/theme";
import { useOnScreen } from "../useOnScreen";
import { useNftGalleryFilter } from "@ledgerhq/live-nft-react";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";

const SpinnerContainer = styled.div`
display: flex;
Expand Down Expand Up @@ -50,6 +52,8 @@ const Footer = styled.footer`
`;

const Gallery = () => {
const nftsFromSimplehashFeature = useFeature("nftsFromSimplehash");

const { t } = useTranslation();
const dispatch = useDispatch();
const { id } = useParams<{ id: string }>();
Expand All @@ -60,12 +64,19 @@ const Gallery = () => {
);
const history = useHistory();
const hiddenNftCollections = useSelector(hiddenNftCollectionsSelector);

const { nfts, fetchNextPage, hasNextPage } = useNftGalleryFilter({
nftsOwned: account?.nfts || [],
addresses: account?.freshAddress || "",
chains: [account?.currency.id ?? "ethereum"],
});

const collections = useMemo(
() =>
Object.entries(nftsByCollections(account?.nfts)).filter(
([contract]) => !hiddenNftCollections.includes(`${account?.id}|${contract}`),
),
[account?.id, account?.nfts, hiddenNftCollections],
Object.entries(
nftsByCollections(nftsFromSimplehashFeature?.enabled ? nfts : account?.nfts),
).filter(([contract]) => !hiddenNftCollections.includes(`${account?.id}|${contract}`)),
[account?.id, account?.nfts, hiddenNftCollections, nfts, nftsFromSimplehashFeature?.enabled],
);

// Should redirect to the account page if there is not NFT anymore in the page.
Expand All @@ -92,7 +103,12 @@ const Gallery = () => {
);
const listFooterRef = useRef<HTMLDivElement>(null);
const [maxVisibleNFTs, setMaxVisibleNFTs] = useState(1);
const updateMaxVisibleNtfs = () => setMaxVisibleNFTs(maxVisibleNFTs => maxVisibleNFTs + 5);
const updateMaxVisibleNtfs = () => {
setMaxVisibleNFTs(maxVisibleNFTs => maxVisibleNFTs + 5);
if (hasNextPage) {
fetchNextPage();
}
};

useOnScreen({
enabled: maxVisibleNFTs < (account?.nfts?.length ?? 0),
Expand Down
Loading
Loading