From 96f4387678723687cbc4f226c62d7f8dd01a0691 Mon Sep 17 00:00:00 2001 From: 0xIchigo <0xIchigo@protonmail.com> Date: Tue, 23 Jan 2024 02:42:28 -0500 Subject: [PATCH 1/4] Add Burnt Field to JSON Metadata --- src/lib/components/providers/token-provider.svelte | 1 + src/lib/types.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/lib/components/providers/token-provider.svelte b/src/lib/components/providers/token-provider.svelte index b3ed610e..32dadfb1 100644 --- a/src/lib/components/providers/token-provider.svelte +++ b/src/lib/components/providers/token-provider.svelte @@ -92,6 +92,7 @@ metadata.video_uri = data?.content.files?.find((file: any) => file.mime?.startsWith("video/") )?.uri; + metadata.burnt = data?.burnt; } $: if (data?.id && !metadata.image) { diff --git a/src/lib/types.ts b/src/lib/types.ts index 5fe9f713..abd76c52 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -65,6 +65,8 @@ export interface UITokenMetadata { leafId?: number; files?: FileProperties[]; video_uri?: string; + burnt?: boolean; + mintExtensions?: object; } export type Icon = keyof typeof IconPaths; From 0bf37b11f9c332b9b930a30de7b4c85f3579d0d5 Mon Sep 17 00:00:00 2001 From: 0xIchigo <0xIchigo@protonmail.com> Date: Tue, 23 Jan 2024 03:01:07 -0500 Subject: [PATCH 2/4] Add Mint Extensions to JSON Metadata --- src/lib/components/providers/token-provider.svelte | 1 + src/lib/trpc/routes/asset.ts | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/components/providers/token-provider.svelte b/src/lib/components/providers/token-provider.svelte index 32dadfb1..3bc6355d 100644 --- a/src/lib/components/providers/token-provider.svelte +++ b/src/lib/components/providers/token-provider.svelte @@ -93,6 +93,7 @@ file.mime?.startsWith("video/") )?.uri; metadata.burnt = data?.burnt; + metadata.mintExtensions = data?.mint_extensions; } $: if (data?.id && !metadata.image) { diff --git a/src/lib/trpc/routes/asset.ts b/src/lib/trpc/routes/asset.ts index c3b58feb..49de5d2b 100644 --- a/src/lib/trpc/routes/asset.ts +++ b/src/lib/trpc/routes/asset.ts @@ -20,10 +20,10 @@ export const asset = t.procedure jsonrpc: "2.0", method: "getAsset", params: { - displayOptions: { + id: asset, + options: { showFungible: true, }, - id: asset, }, }), headers: { @@ -43,6 +43,7 @@ export const asset = t.procedure address: data?.result?.id || "", assetHash: data?.result?.compression?.asset_hash, attributes: returnAssetData?.attributes || [], + burnt: data?.result?.burnt, collectionKey: data?.result?.grouping[0]?.group_value || "", compressed: true, creatorHash: data?.result?.compression?.creator_hash, @@ -55,6 +56,7 @@ export const asset = t.procedure frozen: data?.result?.ownership?.frozen, image: returnAssetData?.image || "", leafId: data?.result?.compression?.leaf_id, + mintExtensions: data?.result?.mint_extensions || "", mutable: data?.result?.mutable, name: returnAssetData?.name || "", owner: data?.result?.ownership?.owner || "", From 734391c13d4ebf547b6dcee4a24d433962f7e76c Mon Sep 17 00:00:00 2001 From: 0xIchigo <0xIchigo@protonmail.com> Date: Tue, 23 Jan 2024 15:15:13 -0500 Subject: [PATCH 3/4] Add Cool Formatting for Mint Extensions --- src/lib/util/format-object.ts | 28 +++++++++++++++++++++++++++ src/routes/token/[token]/+page.svelte | 19 +++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/lib/util/format-object.ts diff --git a/src/lib/util/format-object.ts b/src/lib/util/format-object.ts new file mode 100644 index 00000000..d6a6d4d5 --- /dev/null +++ b/src/lib/util/format-object.ts @@ -0,0 +1,28 @@ +export const formatKey = (key: string) => + key + .replace(/_/g, " ") + .split(" ") + .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(" "); + +export const formatObject = (obj: any, indentLevel = 0): string => { + const entries = Object.entries(obj).map(([key, value]) => { + const formattedKey = formatKey(key); + // Apply bold style to top-level keys + const boldClass = indentLevel === 0 ? "font-bold" : ""; + const valueClass = indentLevel > 0 ? "text-green-600" : ""; + const formattedValue = + typeof value === "object" && value !== null && !Array.isArray(value) + ? formatObject(value, indentLevel + 1) // Recursively format nested objects + : `${value}`; + + return `
${" ".repeat( + indentLevel * 4 + )}${formattedKey}${ + typeof value === "object" ? "" : ":" + } ${formattedValue}
`; + }); + + // Join all the entries with a new line for top-level properties + return entries.join(indentLevel === 0 ? '
' : ""); +}; diff --git a/src/routes/token/[token]/+page.svelte b/src/routes/token/[token]/+page.svelte index 7fbdecd2..b753d4f6 100644 --- a/src/routes/token/[token]/+page.svelte +++ b/src/routes/token/[token]/+page.svelte @@ -34,7 +34,8 @@ import getMimeType from "$lib/util/get-mime-type"; import { metadataStore } from "$lib/util/stores/metadata"; import type { UITokenMetadata } from "$lib/types"; - import Icon from "$lib/components/icon.svelte"; + + import {formatKey, formatObject } from "$lib/util/format-object" const address = $page.params.token; const params = new URLSearchParams(window.location.search); @@ -75,6 +76,8 @@ $: if (metadata) { metadataStore.set(metadata); } + + $: formattedMintExtensions = metadata?.mintExtensions ? formatObject(metadata.mintExtensions) : ""; + {#if formattedMintExtensions} +
+ +
+ {@html formattedMintExtensions} +
+
+
+ {/if} + {#key metadata.compressed}
Date: Tue, 23 Jan 2024 15:15:30 -0500 Subject: [PATCH 4/4] Formattoooorrr --- src/routes/token/[token]/+page.svelte | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/routes/token/[token]/+page.svelte b/src/routes/token/[token]/+page.svelte index b753d4f6..e5666883 100644 --- a/src/routes/token/[token]/+page.svelte +++ b/src/routes/token/[token]/+page.svelte @@ -35,7 +35,7 @@ import { metadataStore } from "$lib/util/stores/metadata"; import type { UITokenMetadata } from "$lib/types"; - import {formatKey, formatObject } from "$lib/util/format-object" + import { formatKey, formatObject } from "$lib/util/format-object"; const address = $page.params.token; const params = new URLSearchParams(window.location.search); @@ -77,7 +77,9 @@ metadataStore.set(metadata); } - $: formattedMintExtensions = metadata?.mintExtensions ? formatObject(metadata.mintExtensions) : ""; + $: formattedMintExtensions = metadata?.mintExtensions + ? formatObject(metadata.mintExtensions) + : ""; -
+
{@html formattedMintExtensions}