-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨feat(ui): add simplehash calls for ordis
- Loading branch information
1 parent
7f53095
commit 6d95b40
Showing
14 changed files
with
235 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"ledger-live-desktop": patch | ||
"@ledgerhq/live-nft-react": patch | ||
"@ledgerhq/live-nft": patch | ||
--- | ||
|
||
Plug the front with simplehash api for the rare sats table and inscriptions table |
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
4 changes: 2 additions & 2 deletions
4
...esktop/src/newArch/features/Collectibles/Ordinals/components/RareSats/useRareSatsModel.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
7 changes: 5 additions & 2 deletions
7
.../ledger-live-desktop/src/newArch/features/Collectibles/Ordinals/screens/Account/index.tsx
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
18 changes: 18 additions & 0 deletions
18
apps/ledger-live-desktop/src/newArch/features/Collectibles/hooks/useFetchOrdinals.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,18 @@ | ||
import { useFetchOrdinals as fetchOrdinalsFromSimpleHash } from "@ledgerhq/live-nft-react"; | ||
import { BitcoinAccount } from "@ledgerhq/coin-bitcoin/lib/types"; | ||
|
||
type Props = { | ||
account: BitcoinAccount; | ||
}; | ||
|
||
const useFetchOrdinals = ({ account }: Props) => { | ||
const utxosAddresses = account.bitcoinResources?.utxos?.map(utxo => utxo.address).join(",") || ""; | ||
const { rareSats, inscriptions, status } = fetchOrdinalsFromSimpleHash({ | ||
addresses: utxosAddresses, | ||
threshold: 0, | ||
}); | ||
|
||
return { rareSats, inscriptions, status }; | ||
}; | ||
|
||
export default useFetchOrdinals; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { SimpleHashNft } from "@ledgerhq/live-nft/api/types"; | ||
import { OrdinalsChainsEnum, RareSatRarity } from "../types"; | ||
|
||
/** | ||
* Categorizes an array of NFTs into two categories: rareSats and inscriptions. | ||
* @param nfts - The array of NFTs to categorize. | ||
* @returns An object containing two arrays: rareSats and inscriptions. | ||
*/ | ||
export function categorizeNftsByChain(nfts: SimpleHashNft[]): { | ||
rareSats: SimpleHashNft[]; | ||
inscriptions: SimpleHashNft[]; | ||
} { | ||
const initialAccumulator = { | ||
rareSats: [] as SimpleHashNft[], | ||
inscriptions: [] as SimpleHashNft[], | ||
}; | ||
|
||
return nfts.reduce((accumulator, nft) => { | ||
if (nft.chain === OrdinalsChainsEnum.INSCRIPTIONS) accumulator.inscriptions.push(nft); | ||
else accumulator.rareSats.push(nft); | ||
|
||
return accumulator; | ||
}, initialAccumulator); | ||
} | ||
|
||
/** | ||
* Processes an array of rareSats by removing the common rarity. | ||
* @param rareSats - An array of rareSats to process. | ||
* @returns An array of rareSats with the common rarity removed. | ||
*/ | ||
export function removeCommonRareSats(rareSats: SimpleHashNft[]): SimpleHashNft[] { | ||
return rareSats.filter(rareSat => rareSat.name !== RareSatRarity.COMMON); | ||
} | ||
|
||
/** | ||
* Processes an array of rareSats by regrouping them by Contract Address. | ||
* @param rareSats - An array of rareSats to process. | ||
* @returns An array of rareSats with the common rarity removed. | ||
*/ | ||
export function regroupRareSatsByContractAddress( | ||
rareSats: SimpleHashNft[], | ||
): Record<string, SimpleHashNft[]> { | ||
return rareSats.reduce<Record<string, SimpleHashNft[]>>((acc, sat) => { | ||
const { contract_address } = sat; | ||
acc[contract_address] = acc[contract_address] || []; | ||
acc[contract_address].push(sat); | ||
return acc; | ||
}, {}); | ||
} | ||
|
||
/** | ||
* Processes the NFTs by restructuring them. | ||
* @param nfts - The array of NFTs to process. | ||
* @returns An object containing two arrays: rareSats and inscriptions. | ||
*/ | ||
export function processOrdinals(nfts: SimpleHashNft[]): { | ||
rareSats: Record<string, SimpleHashNft[]>; | ||
inscriptions: SimpleHashNft[]; | ||
} { | ||
const { rareSats, inscriptions } = categorizeNftsByChain(nfts); | ||
const rareSatsWithoutCommonSats = removeCommonRareSats(rareSats); | ||
const regroupedRareSats = regroupRareSatsByContractAddress(rareSatsWithoutCommonSats); | ||
|
||
return { | ||
rareSats: regroupedRareSats, | ||
inscriptions, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { fetchNftsFromSimpleHash } from "@ledgerhq/live-nft/api/simplehash"; | ||
import { InfiniteData, useInfiniteQuery, UseInfiniteQueryResult } from "@tanstack/react-query"; | ||
import { SimpleHashResponse, SimpleHashNft } from "@ledgerhq/live-nft/api/types"; | ||
import { FetchNftsProps, OrdinalsChainsEnum } from "./types"; | ||
import { NFTS_QUERY_KEY } from "../queryKeys"; | ||
import { processOrdinals } from "./helpers/ordinals"; | ||
|
||
type Result = UseInfiniteQueryResult<InfiniteData<SimpleHashResponse, unknown>, Error> & { | ||
rareSats: Record<string, SimpleHashNft[]>; | ||
inscriptions: SimpleHashNft[]; | ||
}; | ||
|
||
export function useFetchOrdinals({ addresses, threshold }: FetchNftsProps): Result { | ||
const chains = [OrdinalsChainsEnum.INSCRIPTIONS, OrdinalsChainsEnum.RARESATS]; | ||
const addressesString = Array.isArray(addresses) ? addresses.join(",") : addresses; | ||
const queryResult = useInfiniteQuery({ | ||
queryKey: [NFTS_QUERY_KEY.FetchOrdinals, addresses, chains], | ||
queryFn: ({ pageParam }: { pageParam: string | undefined }) => | ||
fetchNftsFromSimpleHash({ | ||
addresses: addressesString, | ||
chains, | ||
cursor: pageParam, | ||
threshold, | ||
}), | ||
initialPageParam: undefined, | ||
getNextPageParam: lastPage => lastPage.next_cursor, | ||
enabled: addresses.length > 0, | ||
}); | ||
|
||
const nfts = queryResult.data?.pages.flatMap(page => page.nfts) ?? []; | ||
|
||
const { rareSats, inscriptions } = processOrdinals(nfts); | ||
|
||
return { | ||
...queryResult, | ||
rareSats, | ||
inscriptions, | ||
}; | ||
} |
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