-
Notifications
You must be signed in to change notification settings - Fork 345
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 2d0c38b
Showing
20 changed files
with
369 additions
and
157 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
150 changes: 51 additions & 99 deletions
150
...er-live-desktop/src/newArch/features/Collectibles/Ordinals/components/RareSats/helpers.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 |
---|---|---|
@@ -1,107 +1,59 @@ | ||
import { mappingKeysWithIconAndName } from "../Icons"; | ||
import { MappingKeys } from "LLD/features/Collectibles/types/Ordinals"; | ||
import { IconProps } from "LLD/features/Collectibles/types/Collection"; | ||
import { RareSat } from "LLD/features/Collectibles/types/Ordinals"; | ||
import { | ||
Satributes, | ||
Subrange, | ||
SatRange, | ||
MockedRareSat, | ||
Sat, | ||
Icons, | ||
} from "LLD/features/Collectibles/types/RareSats"; | ||
|
||
export const processSatType = ( | ||
type: string, | ||
satributes: Satributes, | ||
icons: Icons, | ||
displayNames: string[], | ||
totalCount: number, | ||
) => { | ||
const attribute = satributes[type as MappingKeys]; | ||
if (attribute && attribute.count) { | ||
displayNames.push(type); | ||
if (mappingKeysWithIconAndName[type as MappingKeys]) { | ||
icons[type] = mappingKeysWithIconAndName[type as MappingKeys].icon; | ||
import { SimpleHashNft } from "@ledgerhq/live-nft/api/types"; | ||
import { SimpleHashNftWithIcons, RareSat } from "../../../types/Ordinals"; | ||
|
||
export function matchCorrespondingIcon(rareSats: SimpleHashNft[]): SimpleHashNftWithIcons[] { | ||
return rareSats.map(rareSat => { | ||
const iconKeys: string[] = []; | ||
if (rareSat.name) { | ||
iconKeys.push(rareSat.name.toLowerCase().replace(" ", "_")); | ||
} | ||
totalCount = attribute.count; | ||
} | ||
return { displayNames, totalCount }; | ||
}; | ||
|
||
export const processSatTypes = (satTypes: string[], satributes: Satributes) => { | ||
let displayNames: string[] = []; | ||
let totalCount = 0; | ||
const icons: { [key: string]: ({ size, color, style }: IconProps) => JSX.Element } = {}; | ||
|
||
satTypes.forEach(type => { | ||
const result = processSatType(type, satributes, icons, displayNames, totalCount); | ||
displayNames = result.displayNames; | ||
totalCount = result.totalCount; | ||
}); | ||
|
||
return { displayNames, totalCount, icons }; | ||
}; | ||
|
||
export const processSubrange = ( | ||
subrange: Subrange, | ||
satributes: Satributes, | ||
year: string, | ||
value: number, | ||
) => { | ||
const { sat_types } = subrange; | ||
const { displayNames, totalCount, icons } = processSatTypes(sat_types, satributes); | ||
|
||
const name = displayNames | ||
.map(dn => mappingKeysWithIconAndName[dn.toLowerCase().replace(" ", "_") as MappingKeys]?.name) | ||
.filter(Boolean) | ||
.join(" / "); | ||
if (rareSat.extra_metadata?.utxo_details?.satributes) { | ||
iconKeys.push(...Object.keys(rareSat.extra_metadata.utxo_details.satributes)); | ||
} | ||
|
||
return { | ||
count: totalCount.toString() + (totalCount === 1 ? " sat" : " sats"), | ||
display_name: displayNames.join(" / "), | ||
year, | ||
utxo_size: value.toString(), | ||
icons, | ||
name, | ||
}; | ||
}; | ||
const icons = iconKeys | ||
.map( | ||
iconKey => | ||
mappingKeysWithIconAndName[iconKey as keyof typeof mappingKeysWithIconAndName]?.icon, | ||
) | ||
.filter(Boolean) as (({ size, color, style }: IconProps) => JSX.Element)[]; | ||
|
||
export const processSatRanges = (satRanges: SatRange[], satributes: Satributes) => { | ||
return satRanges.flatMap(range => { | ||
const { year, value, subranges } = range; | ||
return subranges.flatMap(subrange => processSubrange(subrange, satributes, year, value)); | ||
return { ...rareSat, icons }; | ||
}); | ||
}; | ||
|
||
export const processRareSat = (sat: Sat) => { | ||
const { extra_metadata } = sat; | ||
const satributes = extra_metadata.utxo_details.satributes as Satributes; | ||
const satRanges = extra_metadata.utxo_details.sat_ranges; | ||
return processSatRanges(satRanges, satributes); | ||
}; | ||
|
||
export const processRareSats = (rareSats: MockedRareSat[]) => { | ||
return rareSats.flatMap(item => item.nfts.flatMap(processRareSat)); | ||
}; | ||
|
||
export const groupRareSats = (processedRareSats: RareSat[]) => { | ||
return processedRareSats.reduce( | ||
(acc, sat) => { | ||
if (!acc[sat.utxo_size]) { | ||
acc[sat.utxo_size] = []; | ||
} | ||
acc[sat.utxo_size].push(sat); | ||
return acc; | ||
}, | ||
{} as Record<string, RareSat[]>, | ||
); | ||
}; | ||
} | ||
|
||
export function createRareSatObject( | ||
rareSats: Record<string, SimpleHashNftWithIcons[]>, | ||
): Record<string, RareSat[]> { | ||
const result: Record<string, RareSat[]> = {}; | ||
|
||
for (const [key, value] of Object.entries(rareSats)) { | ||
result[key] = value.map(rareSat => { | ||
const { icons, extra_metadata } = rareSat; | ||
const year = extra_metadata?.utxo_details?.sat_ranges?.[0]?.year || ""; | ||
const displayed_names = | ||
Object.values(extra_metadata?.utxo_details?.satributes || {}) | ||
.map(attr => attr.display_name) | ||
.join(" / ") || ""; | ||
const utxo_size = extra_metadata?.utxo_details?.sat_ranges?.[0]?.value || ""; | ||
const name = rareSat.name || ""; | ||
const count = extra_metadata?.utxo_details?.value || 0; | ||
const isMultipleRow = value.length > 1; | ||
|
||
return { | ||
year, | ||
displayed_names, | ||
utxo_size, | ||
name, | ||
count: `${count} ${count > 1 ? "sats" : "sat"}`, | ||
isMultipleRow, | ||
icons, | ||
}; | ||
}); | ||
} | ||
|
||
export const finalizeRareSats = (groupedRareSats: Record<string, RareSat[]>) => { | ||
return Object.entries(groupedRareSats).map(([utxo_size, sats]) => ({ | ||
utxo_size, | ||
sats, | ||
isMultipleRow: sats.length > 1, | ||
})); | ||
}; | ||
return result; | ||
} |
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
20 changes: 11 additions & 9 deletions
20
...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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { mockedRareSats } from "LLD/features/Collectibles/__integration__/mockedRareSats"; | ||
import { processRareSats, groupRareSats, finalizeRareSats } from "./helpers"; | ||
import { matchCorrespondingIcon, createRareSatObject } from "./helpers"; | ||
import { SimpleHashNft } from "@ledgerhq/live-nft/api/types"; | ||
import { regroupRareSatsByContractAddress } from "@ledgerhq/live-nft-react"; | ||
|
||
type RareSatsProps = {}; | ||
|
||
export const useRareSatsModel = (_props: RareSatsProps) => { | ||
const processedRareSats = processRareSats(mockedRareSats); | ||
const groupedRareSats = groupRareSats(processedRareSats); | ||
const finalRareSats = finalizeRareSats(groupedRareSats); | ||
type Props = { | ||
rareSats: SimpleHashNft[]; | ||
}; | ||
|
||
return { rareSats: finalRareSats }; | ||
export const useRareSatsModel = ({ rareSats }: Props) => { | ||
const matchedRareSats = matchCorrespondingIcon(rareSats); | ||
const regroupedRareSats = regroupRareSatsByContractAddress(matchedRareSats); | ||
const rareSatsCreated = createRareSatObject(regroupedRareSats); | ||
return { rareSats: rareSatsCreated }; | ||
}; |
8 changes: 5 additions & 3 deletions
8
.../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
19 changes: 11 additions & 8 deletions
19
apps/ledger-live-desktop/src/newArch/features/Collectibles/types/Ordinals.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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { SimpleHashNft } from "@ledgerhq/live-nft/api/types"; | ||
import { mappingKeysWithIconAndName } from "../Ordinals/components/Icons"; | ||
import { IconProps } from "./Collection"; | ||
|
||
export type MappingKeys = keyof typeof mappingKeysWithIconAndName; | ||
|
||
export type RareSat = { | ||
count: string; | ||
display_name: string | string[]; | ||
export interface RareSat { | ||
displayed_names: string; | ||
icons?: (({ size, color, style }: IconProps) => JSX.Element)[]; | ||
year: string; | ||
utxo_size: string; | ||
icons?: { [key: string]: ({ size, color, style }: IconProps) => JSX.Element }; | ||
name: string; | ||
isDoubleRow?: boolean; | ||
}; | ||
count: string; | ||
utxo_size: string | number; | ||
isMultipleRow: boolean; | ||
} | ||
export interface SimpleHashNftWithIcons extends SimpleHashNft { | ||
icons?: (({ size, color, style }: IconProps) => JSX.Element)[]; | ||
} |
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
Oops, something went wrong.