-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨(lld): add detaildrawer for inscriptions
- Loading branch information
1 parent
4cfc118
commit 5b4d288
Showing
8 changed files
with
352 additions
and
14 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,6 @@ | ||
--- | ||
"ledger-live-desktop": patch | ||
"@ledgerhq/live-nft": patch | ||
--- | ||
|
||
Add detail drawers for inscriptions of ordinals protocol |
66 changes: 57 additions & 9 deletions
66
...rc/newArch/features/Collectibles/Ordinals/components/Inscriptions/DetailsDrawer/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,66 @@ | ||
import React from "react"; | ||
import { SideDrawer } from "~/renderer/components/SideDrawer"; | ||
import { SimpleHashNft } from "@ledgerhq/live-nft/api/types"; | ||
import { DetailDrawer } from "LLD/features/Collectibles/components"; | ||
import { CollectibleTypeEnum } from "LLD/features/Collectibles/types/enum/Collectibles"; | ||
import { Flex, Icons, Text } from "@ledgerhq/react-ui"; | ||
import Button from "~/renderer/components/Button"; | ||
import useInscriptionDetailDrawer from "./useInscriptionDetailDrawer"; | ||
import { t } from "i18next"; | ||
|
||
type ViewProps = ReturnType<typeof useInscriptionDetailDrawer> & { | ||
onClose: () => void; | ||
}; | ||
|
||
type Props = { | ||
inscription: SimpleHashNft; | ||
onClose: () => void; | ||
isLoading: boolean; | ||
}; | ||
const InscriptionDetailsDrawer: React.FC<Props> = ({ inscription, onClose }) => { | ||
// will be replaced by DetailsDrawer from collectibles | ||
return ( | ||
<SideDrawer direction={"left"} isOpen={!!inscription} onRequestClose={onClose}> | ||
{inscription.name || inscription.contract.name} | ||
</SideDrawer> | ||
); | ||
|
||
const View: React.FC<ViewProps> = ({ data, onClose }) => ( | ||
<DetailDrawer | ||
collectibleType={CollectibleTypeEnum.NFT} | ||
areFieldsLoading={data.areFieldsLoading} | ||
collectibleName={data.collectibleName} | ||
contentType={data.contentType} | ||
collectionName={data.collectionName} | ||
details={data.details} | ||
previewUri={data.previewUri} | ||
originalUri={data.originalUri} | ||
isPanAndZoomOpen={data.isPanAndZoomOpen} | ||
mediaType={data.mediaType} | ||
tags={data.tags} | ||
useFallback={data.useFallback} | ||
tokenId={data.tokenId} | ||
isOpened={true} | ||
closeCollectiblesPanAndZoom={data.closeCollectiblesPanAndZoom} | ||
handleRequestClose={onClose} | ||
openCollectiblesPanAndZoom={data.openCollectiblesPanAndZoom} | ||
setUseFallback={data.setUseFallback} | ||
> | ||
<DetailDrawer.Actions> | ||
<Flex> | ||
<Button | ||
outlineGrey | ||
style={{ flex: 1, justifyContent: "center" }} | ||
my={4} | ||
onClick={() => console.log("hide " + data.collectibleName + " clicked")} | ||
center | ||
> | ||
<Flex columnGap={1}> | ||
<Icons.Eye color="neutral.c100" /> | ||
<Text variant="bodyLineHeight" fontWeight="600" fontSize={14} color="neutral.c100"> | ||
{t("ordinals.inscriptions.detailsDrawer.hide")} | ||
</Text> | ||
</Flex> | ||
</Button> | ||
</Flex> | ||
</DetailDrawer.Actions> | ||
</DetailDrawer> | ||
); | ||
|
||
const InscriptionDetailDrawer = ({ inscription, isLoading, onClose }: Props) => { | ||
return <View onClose={onClose} {...useInscriptionDetailDrawer({ isLoading, inscription })} />; | ||
}; | ||
|
||
export default InscriptionDetailsDrawer; | ||
export default InscriptionDetailDrawer; |
58 changes: 58 additions & 0 deletions
58
...Collectibles/Ordinals/components/Inscriptions/DetailsDrawer/useInscriptionDetailDrawer.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,58 @@ | ||
import { SimpleHashNft } from "@ledgerhq/live-nft/api/types"; | ||
import useCollectibles from "LLD/features/Collectibles/hooks/useCollectibles"; | ||
import { useState } from "react"; | ||
import { createDetails } from "LLD/features/Collectibles/utils/createInscriptionDetailsArrays"; | ||
import { useCalendarFormatted } from "~/renderer/hooks/useDateFormatter"; | ||
import { Tag } from "LLD/features/Collectibles/types/DetailDrawer"; | ||
|
||
type Props = { | ||
isLoading: boolean; | ||
inscription: SimpleHashNft; | ||
}; | ||
|
||
const useInscriptionDetailDrawer = ({ isLoading, inscription }: Props) => { | ||
const [useFallback, setUseFallback] = useState(false); | ||
const imageUri = | ||
inscription.video_url || inscription.previews?.image_large_url || inscription.image_url; | ||
|
||
const isVideo = !!inscription.video_url; | ||
|
||
const contentType = isVideo ? "video" : imageUri ? "image" : ""; | ||
|
||
const { isPanAndZoomOpen, openCollectiblesPanAndZoom, closeCollectiblesPanAndZoom } = | ||
useCollectibles(); | ||
|
||
const createdDateFromTimestamp = new Date(inscription.first_created?.timestamp || 0); | ||
const formattedCreatedDate = useCalendarFormatted(createdDateFromTimestamp); | ||
const createdDate = createdDateFromTimestamp === new Date(0) ? "" : formattedCreatedDate; | ||
const details = createDetails(inscription, createdDate); | ||
|
||
const tags: Tag[] = | ||
inscription.extra_metadata?.attributes?.map(attr => ({ | ||
key: attr.trait_type, | ||
value: attr.value, | ||
})) || []; | ||
|
||
const data = { | ||
areFieldsLoading: isLoading, | ||
collectibleName: inscription.name || inscription.contract.name || "", | ||
contentType, | ||
collectionName: inscription.collection.name || "", | ||
details: details, | ||
previewUri: imageUri, | ||
originalUri: imageUri, | ||
isPanAndZoomOpen, | ||
mediaType: inscription.video_properties?.mime_type || "image", | ||
tags: tags, | ||
useFallback: useFallback, | ||
tokenId: inscription.nft_id, | ||
isOpened: true, | ||
closeCollectiblesPanAndZoom, | ||
openCollectiblesPanAndZoom, | ||
setUseFallback: setUseFallback, | ||
}; | ||
|
||
return { inscription, data }; | ||
}; | ||
|
||
export default useInscriptionDetailDrawer; |
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
146 changes: 146 additions & 0 deletions
146
...er-live-desktop/src/newArch/features/Collectibles/utils/createInscriptionDetailsArrays.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,146 @@ | ||
import { DetailsArray } from "LLD/features/Collectibles/types/DetailDrawer"; | ||
import { SimpleHashNft } from "@ledgerhq/live-nft/api/types"; | ||
|
||
export function createDetails(inscription: SimpleHashNft, createdDate: string): DetailsArray { | ||
return [ | ||
...(inscription.collection.description | ||
? [ | ||
{ | ||
key: "Description", | ||
title: "ordinals.inscriptions.detailsDrawer.description", | ||
value: inscription.collection.description, | ||
}, | ||
] | ||
: []), | ||
...(inscription.collection.name | ||
? [ | ||
{ | ||
key: "Collection Name", | ||
title: "ordinals.inscriptions.detailsDrawer.collectionName", | ||
value: inscription.collection.name, | ||
}, | ||
] | ||
: []), | ||
...(inscription.extra_metadata?.ordinal_details?.sat_rarity | ||
? [ | ||
{ | ||
key: "Satribute", | ||
title: "ordinals.inscriptions.detailsDrawer.satribute", | ||
value: inscription.extra_metadata.ordinal_details.sat_rarity, | ||
}, | ||
] | ||
: []), | ||
...(inscription.extra_metadata?.ordinal_details?.inscription_id | ||
? [ | ||
{ | ||
key: "InscriptionID", | ||
title: "ordinals.inscriptions.detailsDrawer.inscriptionId", | ||
value: inscription.extra_metadata.ordinal_details.inscription_id, | ||
isCopyable: true, | ||
isHash: | ||
inscription.extra_metadata.ordinal_details.inscription_id.length >= 4 ? true : false, | ||
}, | ||
] | ||
: []), | ||
...(inscription.extra_metadata?.ordinal_details?.inscription_number | ||
? [ | ||
{ | ||
key: "InscriptionNumber", | ||
title: "ordinals.inscriptions.detailsDrawer.inscriptionNumber", | ||
isCopyable: true, | ||
value: String(inscription.extra_metadata.ordinal_details.inscription_number), | ||
}, | ||
] | ||
: []), | ||
...(inscription.first_created?.minted_to | ||
? [ | ||
{ | ||
key: "MintedTo", | ||
title: "ordinals.inscriptions.detailsDrawer.mintedTo", | ||
value: inscription.first_created.minted_to, | ||
isCopyable: true, | ||
isHash: inscription.first_created.minted_to.length >= 4 ? true : false, | ||
}, | ||
] | ||
: []), | ||
...(inscription.first_created?.transaction | ||
? [ | ||
{ | ||
key: "GenesisTx", | ||
title: "ordinals.inscriptions.detailsDrawer.genesisTx", | ||
value: inscription.first_created.transaction, | ||
isCopyable: true, | ||
isHash: inscription.first_created.minted_to.length >= 4 ? true : false, | ||
}, | ||
] | ||
: []), | ||
...(inscription.first_created?.block_number | ||
? [ | ||
{ | ||
key: "BlockNumber", | ||
title: "ordinals.inscriptions.detailsDrawer.blockNumber", | ||
value: String(inscription.first_created.block_number), | ||
isCopyable: true, | ||
}, | ||
] | ||
: []), | ||
...(inscription.extra_metadata?.ordinal_details?.content_type | ||
? [ | ||
{ | ||
key: "ContentType", | ||
title: "ordinals.inscriptions.detailsDrawer.contentType", | ||
value: inscription.extra_metadata?.ordinal_details?.content_type, | ||
}, | ||
] | ||
: []), | ||
...(inscription.first_created?.timestamp | ||
? [ | ||
{ | ||
key: "CreatedDate", | ||
title: "ordinals.inscriptions.detailsDrawer.createdDate", | ||
value: createdDate, | ||
}, | ||
] | ||
: []), | ||
...(inscription.extra_metadata?.ordinal_details?.sat_number | ||
? [ | ||
{ | ||
key: "SatNumber", | ||
title: "ordinals.inscriptions.detailsDrawer.satNumber", | ||
value: String(inscription.extra_metadata.ordinal_details.sat_number), | ||
isCopyable: true, | ||
}, | ||
] | ||
: []), | ||
...(inscription.extra_metadata?.ordinal_details?.sat_name | ||
? [ | ||
{ | ||
key: "SatName", | ||
title: "ordinals.inscriptions.detailsDrawer.satName", | ||
value: inscription.extra_metadata.ordinal_details.sat_name, | ||
isCopyable: true, | ||
}, | ||
] | ||
: []), | ||
...(inscription.extra_metadata?.ordinal_details?.location | ||
? [ | ||
{ | ||
key: "Location", | ||
title: "ordinals.inscriptions.detailsDrawer.location", | ||
value: inscription.extra_metadata.ordinal_details.location, | ||
isCopyable: true, | ||
isHash: inscription.extra_metadata.ordinal_details.location.length >= 4 ? true : false, | ||
}, | ||
] | ||
: []), | ||
...(inscription.extra_metadata?.ordinal_details?.output_value | ||
? [ | ||
{ | ||
key: "OutputValue", | ||
title: "ordinals.inscriptions.detailsDrawer.outputValue", | ||
value: String(inscription.extra_metadata.ordinal_details.output_value), | ||
}, | ||
] | ||
: []), | ||
]; | ||
} |
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.