Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When NFT doesn't exist still show collection details #1000

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 72 additions & 42 deletions apps/dashboard/src/pages/search-pages/nft/Nft.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import NftDataRow from './NftDataRow.svelte'
import type { NonFungible } from '@api/utils/nfts'
import type { NonFungibleResource } from '@api/utils/entities/resource/non-fungible'
import { networkConfiguration } from '@stores'

export let nft: Promise<NonFungible | undefined>
export let resource: Promise<NonFungibleResource>
Expand All @@ -28,57 +29,78 @@
: resource.metadata.expected.description?.typed.value
)

let hasNoNft: boolean
$: Promise.all([nft, resource]).then(([nft, resource]) => {
const resourceAddresses = $networkConfiguration?.well_known_addresses
if (
![
resourceAddresses?.ed25519_signature_virtual_badge,
resourceAddresses?.package_of_direct_caller_virtual_badge,
resourceAddresses?.secp256k1_signature_virtual_badge,
resourceAddresses?.global_caller_virtual_badge
].includes(resource.address)
) {
hasNoNft = !nft
}
})

const imageSize = 'large'
</script>

<div class="nft-image">
{#await imageUrl}
<NftImage size={imageSize} />
{:then url}
<NftImage {url} size={imageSize} />
{/await}
</div>
{#if hasNoNft}
<div class="no-nft">
<h2>There is no non-fungible with this local ID</h2>
</div>
{:else}
<div class="nft-image">
{#await imageUrl}
<NftImage size={imageSize} />
{:then url}
<NftImage {url} size={imageSize} />
{/await}
</div>

<div class="card info-card">
<h2>
{#await nft}
<SkeletonLoader />
{:then nft}
{#if nft}
{@const {
nftData: {
expected: { name }
}
} = nft}
{#if name?.value}
{name?.value}
<div class="card info-card">
<h2>
{#await nft}
<SkeletonLoader />
{:then nft}
{#if nft}
{@const {
nftData: {
expected: { name }
}
} = nft}
{#if name?.value}
{name?.value}
{/if}
{/if}
{/if}
{/await}
</h2>
{/await}
</h2>

{#await description}
<SkeletonLoader count={3} />
{:then description}
{#if description}
{description}
{/if}
{/await}
<div>
{#await nft}
<SkeletonLoader />
{:then nft}
{#if nft}
<NftDataRow
value={{ kind: 'String', field_name: 'ID', value: nft.id }}
/>
{#each nft.type === 'generalNft' ? nft.nftData.nonStandard : Object.values(nft.nftData.expected).filter((data) => data.field_name !== 'name') as value}
<NftDataRow {value} />
{/each}
{#await description}
<SkeletonLoader count={3} />
{:then description}
{#if description}
{description}
{/if}
{/await}
<div>
{#await nft}
<SkeletonLoader />
{:then nft}
{#if nft}
<NftDataRow
value={{ kind: 'String', field_name: 'ID', value: nft.id }}
/>
{#each nft.type === 'generalNft' ? nft.nftData.nonStandard : Object.values(nft.nftData.expected).filter((data) => data.field_name !== 'name') as value}
<NftDataRow {value} />
{/each}
{/if}
{/await}
</div>
</div>
</div>
{/if}

<h2 class="resource-card-header">Belongs To:</h2>

Expand All @@ -90,6 +112,14 @@
/>

<style lang="scss">
.no-nft {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
margin: var(--spacing-4xl) 0;
}

.nft-image {
width: fit-content;
margin: var(--spacing-2xl) auto var(--spacing-3xl) auto;
Expand Down
23 changes: 0 additions & 23 deletions apps/dashboard/src/routes/(search-pages)/nft/[nft]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { map, pipe } from 'ramda'
import { transformNft } from '@api/utils/nfts'
import { handleGatewayResult } from '../../../../utils'
import { transformNonFungibleResource } from '@api/utils/entities/resource/non-fungible'
import { errorPage } from '@dashboard/stores'
import type { KnownAddresses } from '@common/ret'

export const load: PageLoad = async ({ params, fetch }) => {
const [resourceAddress, nftId] = decodeURIComponent(params.nft).split(':')
Expand All @@ -21,27 +19,6 @@ export const load: PageLoad = async ({ params, fetch }) => {
handleGatewayResult()
)()

nftData.then((data) => {
if (data.length === 0) {
return fetch('/api/ret/known-addresses')
.then((response) => response.json())
.then(({ resourceAddresses }: KnownAddresses) => {
if (
![
resourceAddresses.ed25519SignatureVirtualBadge,
resourceAddresses.packageOfDirectCallerVirtualBadge,
resourceAddresses.secp256k1SignatureVirtualBadge,
resourceAddresses.globalCallerVirtualBadge
].includes(resourceAddress)
) {
errorPage.set({
message: 'NFT not found'
})
}
})
}
})

const associatedDapps = resourceEntity
.then(getLinkedDappDefinitions)
.then(map(getDappDefinitionData))
Expand Down
Loading