-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a96bcd1
commit 0cf8861
Showing
18 changed files
with
344 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
apps/ledger-live-mobile/src/hooks/nfts/useHideSpamCollection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useCallback } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { useFeature } from "@ledgerhq/live-common/featureFlags/index"; | ||
import { hideNftCollection } from "~/actions/settings"; | ||
import { whitelistedNftCollectionsSelector } from "~/reducers/settings"; | ||
|
||
export function useHideSpamCollection() { | ||
const spamFilteringTxFeature = useFeature("spamFilteringTx"); | ||
const whitelistedNftCollections = useSelector(whitelistedNftCollectionsSelector); | ||
|
||
const dispatch = useDispatch(); | ||
const hideSpamCollection = useCallback( | ||
(collection: string) => { | ||
if (!whitelistedNftCollections.includes(collection)) { | ||
dispatch(hideNftCollection(collection)); | ||
} | ||
}, | ||
[dispatch, whitelistedNftCollections], | ||
); | ||
|
||
return { | ||
hideSpamCollection, | ||
enabled: spamFilteringTxFeature?.enabled, | ||
}; | ||
} |
76 changes: 76 additions & 0 deletions
76
apps/ledger-live-mobile/src/hooks/nfts/useNftCollections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { useFeature } from "@ledgerhq/live-common/featureFlags/index"; | ||
import { decodeCollectionId, getThreshold, useNftGalleryFilter } from "@ledgerhq/live-nft-react"; | ||
import { nftsByCollections } from "@ledgerhq/live-nft/index"; | ||
import { BlockchainEVM } from "@ledgerhq/live-nft/supported"; | ||
import { Account, ProtoNFT } from "@ledgerhq/types-live"; | ||
import { useMemo } from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { | ||
hiddenNftCollectionsSelector, | ||
whitelistedNftCollectionsSelector, | ||
} from "~/reducers/settings"; | ||
|
||
export function useNftCollections({ | ||
account, | ||
nftsOwned, | ||
addresses, | ||
chains, | ||
}: { | ||
account?: Account; | ||
nftsOwned?: ProtoNFT[]; | ||
addresses?: string; | ||
chains?: string[]; | ||
}) { | ||
const nftsFromSimplehashFeature = useFeature("nftsFromSimplehash"); | ||
const threshold = nftsFromSimplehashFeature?.params?.threshold; | ||
const simplehashEnabled = nftsFromSimplehashFeature?.enabled; | ||
|
||
const whitelistNft = useSelector(whitelistedNftCollectionsSelector); | ||
const hiddenNftCollections = useSelector(hiddenNftCollectionsSelector); | ||
|
||
const nftsOwnedToCheck = useMemo(() => account?.nfts ?? nftsOwned, [account?.nfts, nftsOwned]); | ||
|
||
const whitelistedNfts = useMemo( | ||
() => | ||
nftsOwnedToCheck?.filter(nft => | ||
whitelistNft | ||
.map(collection => decodeCollectionId(collection).contractAddress) | ||
.includes(nft.contract), | ||
) ?? [], | ||
[nftsOwnedToCheck, whitelistNft], | ||
); | ||
|
||
const { nfts, fetchNextPage, hasNextPage, ...rest } = useNftGalleryFilter({ | ||
nftsOwned: account?.nfts ?? nftsOwned ?? [], | ||
addresses: account?.freshAddress ?? addresses ?? "", | ||
chains: account | ||
? [account.currency.id || BlockchainEVM.Ethereum] | ||
: chains ?? [BlockchainEVM.Ethereum], | ||
threshold: getThreshold(threshold), | ||
}); | ||
|
||
const allNfts = useMemo( | ||
() => (simplehashEnabled ? [...nfts, ...whitelistedNfts] : account?.nfts || nftsOwned || []), | ||
[simplehashEnabled, nfts, whitelistedNfts, account, nftsOwned], | ||
); | ||
|
||
const collections = useMemo( | ||
() => | ||
Object.entries(nftsByCollections(allNfts)).filter( | ||
([contract]) => !hiddenNftCollections.includes(`${account?.id}|${contract}`), | ||
), | ||
[account?.id, allNfts, hiddenNftCollections], | ||
); | ||
|
||
const collectionsLength = Object.keys(collections).length; | ||
|
||
return { | ||
collections, | ||
collectionsLength, | ||
fetchNextPage, | ||
hasNextPage, | ||
nfts, | ||
allNfts, | ||
...rest, | ||
}; | ||
} |
Oops, something went wrong.