From 8af3bd0321058889ce84aaf89ced91851415ad79 Mon Sep 17 00:00:00 2001 From: Maija Grudule <34912439+MGrudule@users.noreply.github.com> Date: Thu, 4 Jul 2024 16:16:11 +0200 Subject: [PATCH] - Refactored asset page to use ecoLinked instead of verified status (#1506) - Added ecoLinked state to social share cards - Translations Minor bugfix: - fixed asset page/server typescript errors - Sanitized social share image card text to fix Satori text wrap bug with # --- .../src/lib/entities/OgShare/CardBase.svelte | 15 +- .../lib/entities/OgShare/CardLandscape.svelte | 8 +- .../lib/entities/OgShare/CardSquare.svelte | 6 +- .../src/lib/shared/i18n/en/index.ts | 2 +- .../src/lib/shared/i18n/i18n-types.ts | 8 +- .../assets/[assetAddress]/+page.server.ts | 24 +- .../routes/assets/[assetAddress]/+page.svelte | 437 +++++++++--------- .../src/routes/og/+server.ts | 10 +- 8 files changed, 266 insertions(+), 244 deletions(-) diff --git a/apps/verification-portal/src/lib/entities/OgShare/CardBase.svelte b/apps/verification-portal/src/lib/entities/OgShare/CardBase.svelte index 21b5e0b3e..0fd0bb178 100644 --- a/apps/verification-portal/src/lib/entities/OgShare/CardBase.svelte +++ b/apps/verification-portal/src/lib/entities/OgShare/CardBase.svelte @@ -12,6 +12,7 @@ let fontSizeClass = baseFontSize; $: imageUrl = img; + $: sanitizedTitle = sanitizeTitle(title); const mediumTitle = isLongTitle(title); const smallTitle = isLongTitle(title, 9, 3); @@ -29,6 +30,18 @@ } else if (mediumTitle) { fontSizeClass = 'text-62px'; // Medium font size } + + // Function to sanitize title from any hashtags, workaround for Satori generator text wrap bug + function sanitizeTitle(title: string): string { + return title.replace(/#/g, '').trim(); + } - + diff --git a/apps/verification-portal/src/lib/entities/OgShare/CardLandscape.svelte b/apps/verification-portal/src/lib/entities/OgShare/CardLandscape.svelte index 345c3a6ea..0dd9daf0e 100644 --- a/apps/verification-portal/src/lib/entities/OgShare/CardLandscape.svelte +++ b/apps/verification-portal/src/lib/entities/OgShare/CardLandscape.svelte @@ -7,11 +7,13 @@ export let funds = ''; export let source = ''; export let img = ''; + export let ecoLinked = false; - {title} + {sanitizedTitle} {#if source}
{/if}
- {#if funds} + {#if ecoLinked} {fundsText} - {title} + {sanitizedTitle} {#if source}
{/if}
- {#if funds} + {#if ecoLinked} {fundsText} LocalizedString } /** - * Verified: + * Eco-Linked: */ - verified: () => LocalizedString + ecoLinked: () => LocalizedString /** * Share your asset */ diff --git a/apps/verification-portal/src/routes/assets/[assetAddress]/+page.server.ts b/apps/verification-portal/src/routes/assets/[assetAddress]/+page.server.ts index d31581674..2535232fe 100644 --- a/apps/verification-portal/src/routes/assets/[assetAddress]/+page.server.ts +++ b/apps/verification-portal/src/routes/assets/[assetAddress]/+page.server.ts @@ -18,11 +18,11 @@ const config = { const notFoundMessage = 'We’re sorry but that page can’t be found.'; export async function load({ params }) { - let assetData: DeepAsset; - let deepData: DeepData; + let nftData: DeepAsset; + let deepData: DeepData | undefined = undefined; let addressDetails: Address; const assetAddress: string = params.assetAddress; - let verifiedStatus: boolean = false; + let ecoLinked: boolean = false; //TODO: Move to a @sni/clients/assets-client try { @@ -36,7 +36,7 @@ export async function load({ params }) { throw new Error(); } - assetData = fetchedAsset; + nftData = fetchedAsset; addressDetails = parseAddress(assetAddress); } catch (e) { error(404, notFoundMessage); @@ -50,11 +50,11 @@ export async function load({ params }) { config ).then((response) => { if (response.data && response.data.data) { - verifiedStatus = true; + ecoLinked = true; } return response.data.data; }); - if (verifiedStatus) { + if (ecoLinked) { // Fetch deep entity data const { data: entityResponse } = await getEntity( verifiedData.collection_id, @@ -62,6 +62,7 @@ export async function load({ params }) { config ); deepData = entityResponse.data; + if (!deepData) return; deepData.link = verifiedData; const { data: stewardResponse } = await getNewsBySteward( @@ -96,13 +97,18 @@ export async function load({ params }) { return { traces_recorded: tracesRecorded }; } + let extractedProperties: ExtractedProperties; + if (deepData !== undefined) { + extractedProperties = processDeepData(deepData); + } else { + extractedProperties = { traces_recorded: {} }; + } - const extractedProperties: ExtractedProperties = processDeepData(deepData); return { assetAddress, addressDetails, - nftData: assetData, - verifiedStatus, + nftData, + ecoLinked, deepData, baseUrl, properties: extractedProperties, diff --git a/apps/verification-portal/src/routes/assets/[assetAddress]/+page.svelte b/apps/verification-portal/src/routes/assets/[assetAddress]/+page.svelte index 1fed611af..31d692d97 100644 --- a/apps/verification-portal/src/routes/assets/[assetAddress]/+page.svelte +++ b/apps/verification-portal/src/routes/assets/[assetAddress]/+page.svelte @@ -4,6 +4,7 @@ CAMP_PLACEHOLDER, } from '@sni/constants/cdn/placeholders'; import { chainIdToName } from '@sni/address-utils'; + import { onDestroy } from 'svelte'; import Property from '$lib/shared/typography/Property.svelte'; import Info from '$lib/shared/typography/Info.svelte'; import Subheader from '$lib/shared/typography/Subheader.svelte'; @@ -18,7 +19,6 @@ import NewsCarousel from '$lib/components/carousel/NewsCarousel.svelte'; import LL from '$lib/shared/i18n/i18n-svelte.js'; import { subscribeToPage, setTocTitle } from '$lib/features/toc'; - import { onDestroy } from 'svelte'; import { page } from '$app/stores'; @@ -27,34 +27,34 @@ onDestroy(unsubscribe); $: currentPath = $page.url.toString(); - $: pageTitle = `${$LL.assets.title({ assetName: nftData.name })}`; + $: pageTitle = `${$LL.assets.title({ assetName: nftData!.name })}`; export let data; const { nftData, - verifiedStatus, + ecoLinked, deepData, baseUrl, assetAddress, addressDetails, properties, } = data; - const chainReference = addressDetails?.chain?.reference; - setTocTitle(nftData.name); + const chainReference = addressDetails?.chain?.reference ?? ''; + setTocTitle(nftData!.name); // Define specific share card data for a page - $: pageDescription = nftData?.collection?.description || ''; //TODO: Replace with asset description - $: name = nftData.name || ''; + $: pageDescription = nftData?.description || ''; + $: name = nftData!.name; $: funds = deepData?.steward?.funds_raised || 0; $: source = isNaN(parseInt(chainReference)) ? chainReference : chainIdToName(parseInt(chainReference)); - $: image = nftData.image; + $: image = nftData!.image; $: pageImagePath = `/og?title=${encodeURIComponent( name )}&funds=${encodeURIComponent(funds.toString())}&img=${encodeURIComponent( image - )}&source=${encodeURIComponent(source)}`; + )}&source=${encodeURIComponent(source)}&${ecoLinked ? '&ecoLinked' : ''}`; $: pageImage = `${baseUrl}${pageImagePath}`; $: pageImageSquare = `${pageImagePath}&ratio=square`; // styling @@ -70,249 +70,248 @@ /> {/key} - -
+{#if nftData} +
- {#key nftData} - - {/key} -
-
-
-

- {#if verifiedStatus} - {$LL.assets.verified()} - {/if} - - {nftData.name} - -

-
- {#if nftData.description} - - {nftData.description} - {/if} -
+
+ {#key nftData} + + {/key}
-
-
- -

{source}

-
- {#if nftData.tokenId} - -

{nftData.tokenId}

+
+
+

+ {#if ecoLinked} + {$LL.assets.ecoLinked()} + {/if} + + {nftData.name} + +

+
+ {#if nftData.description} + + {nftData.description} + {/if} +
+
+
+
+ +

{source}

- {/if} + {#if nftData.tokenId} + +

{nftData.tokenId}

+
+ {/if} - - {assetAddress} - -
+ + {assetAddress} + +
-
- {$LL.assets.shareText()} - +
+ {$LL.assets.shareText()} + +
-
- + -{#if verifiedStatus} -
- + {#if ecoLinked && deepData}
- {$LL.assets.funds.cardTitle()} +
- -
- - -
-
{$LL.assets.ecEntity.cardTitle()}{$LL.assets.funds.cardTitle()} -

{deepData?.id}

+
-
- {#key deepData} - {#if deepData.sound} - - {/if} - {/key} -
-
- {#key deepData} - {#if deepData.images?.length > 0} - {#each deepData?.images as image, index} - 0 - ? 'border-t-2 dark:border-deep-green ' - : ''} - assetID={image.directus_files_id} - altText={deepData?.id} + + +
+
+ {$LL.assets.ecEntity.cardTitle()} +

{deepData?.id}

+
+
+ {#key deepData} + {#if deepData.sound} + + {/if} + {/key} +
+
+ {#key deepData} + {#if deepData.images?.length > 0} + {#each deepData?.images as image, index} + 0 + ? 'border-t-2 dark:border-deep-green ' + : ''} + assetID={image.directus_files_id} + altText={deepData?.id} + /> + {/each} + {:else} + Not Available - {/each} - {:else} - Not Available - {/if} - {/key} + {/if} + {/key} +
-
- -
-
- {#key deepData.location} - - {/key} + +
+
+ {#key deepData.location} + + {/key} +
-
- -
-
- {$LL.assets.ecEntity.title()} - -

- {deepData.description ? deepData.description : '...'} -

-
- {#key properties} - {#if Object.keys(properties).length > 0 && Object.keys(properties.traces_recorded).length > 0} -
+
+
+ {$LL.assets.ecEntity.title()} - {$LL.assets.ecEntity.propsTitle()} +

+ {deepData.description ? deepData.description : '...'} +

+
+ {#key properties} + {#if Object.keys(properties).length > 0 && Object.keys(properties.traces_recorded).length > 0} +
- - {#if Object.keys(properties.traces_recorded).length > 0} -
- {$LL.assets.ecEntity.traces()} -
-
{$LL.assets.ecEntity.propsTitle()} - {#each Object.keys(properties.traces_recorded) as property} - {#if properties.traces_recorded[property] > 0} -
- From {property}: - {properties.traces_recorded[property]} 0} +
+ {$LL.assets.ecEntity.traces()} +
+
+ {#each Object.keys(properties.traces_recorded) as property} + {#if properties.traces_recorded[property] > 0} +
-
- {/if} - {/each} -
- {/if} -
- {/if} - {/key} -
+ From {property}: + {properties.traces_recorded[property]} +
+ {/if} + {/each} +
+ {/if} +
+ {/if} + {/key} +
- {#key deepData.steward} -
- + {#key deepData.steward} +
+ - {#if deepData.news?.length > 0} + {#if deepData.news?.length > 0} +
+ +
+ {/if} +
- -
- {/if} - -
-
- {$LL.assets.ecSteward.title()} - -

- {deepData.steward?.description} -

-
-
- -
-
- {#if deepData.steward?.images?.length > 0} - {#each deepData.steward?.images as image} - - {/each} - {:else} - Not Available + {$LL.assets.ecSteward.title()} + - {/if} +

+ {deepData.steward?.description} +

+
+
+ +
+
+ {#if deepData.steward?.images?.length > 0} + {#each deepData.steward?.images as image} + + {/each} + {:else} + Not Available + {/if} +
-
- {/key} -
+ {/key} +
+ {/if} {/if}