-
Notifications
You must be signed in to change notification settings - Fork 333
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 1bb85d6
Showing
26 changed files
with
485 additions
and
182 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 |
21 changes: 21 additions & 0 deletions
21
apps/ledger-live-desktop/src/newArch/features/Collectibles/Ordinals/components/Error.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react"; | ||
import { Flex, Icons, Text } from "@ledgerhq/react-ui"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
type Props = { | ||
hasError: boolean; | ||
}; | ||
|
||
const Error: React.FC<Props> = ({ hasError }) => { | ||
const { t } = useTranslation(); | ||
if (!hasError) return null; | ||
|
||
return ( | ||
<Flex justifyContent="center" my={4} columnGap={2}> | ||
<Icons.Warning size={"S"} color="palette.error.c60" /> | ||
<Text color="palette.error.c60">{t("crash.title")}</Text> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default Error; |
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
18 changes: 18 additions & 0 deletions
18
apps/ledger-live-desktop/src/newArch/features/Collectibles/Ordinals/components/Loader.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Flex, InfiniteLoader } from "@ledgerhq/react-ui"; | ||
import React from "react"; | ||
|
||
type Props = { | ||
isLoading: boolean; | ||
}; | ||
|
||
const Loader: React.FC<Props> = ({ isLoading }) => { | ||
if (!isLoading) return null; | ||
|
||
return ( | ||
<Flex justifyContent="center" my={4}> | ||
<InfiniteLoader /> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default Loader; |
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; | ||
} |
Oops, something went wrong.