Skip to content

Commit 885abae

Browse files
committed
feat: display ipfs media
1 parent 8665596 commit 885abae

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

Diff for: packages/shared/components/MediaDisplay.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</script>
3232

3333
<div class="h-full w-full object-cover">
34-
{#if htmlTag === ParentMimeType.Image}
34+
{#if htmlTag === ParentMimeType.Image || htmlTag === ParentMimeType.Text}
3535
<img {src} {alt} loading="lazy" class="w-full h-full object-cover" />
3636
{:else if htmlTag === ParentMimeType.Video}
3737
<video

Diff for: packages/shared/components/NftImageOrIconBox.svelte

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<script lang="ts">
2-
import { INft } from '@core/nfts'
3-
import { NftSize } from 'shared/components/enums'
2+
import { INft, ParentMimeType } from '@core/nfts'
43
import { MediaPlaceholder, NftMedia } from 'shared/components'
5-
import { ParentMimeType } from '@core/nfts'
4+
import { NftSize } from 'shared/components/enums'
65
76
export let nft: INft | null = null
87
export let size: NftSize = NftSize.Medium
@@ -18,7 +17,7 @@
1817
class:medium={size === NftSize.Medium}
1918
class:large={size === NftSize.Large}
2019
>
21-
{#if parentType === ParentMimeType.Image && nft}
20+
{#if (parentType === ParentMimeType.Image && nft) || (parentType === ParentMimeType.Text && nft)}
2221
<NftMedia {nft} {useCaching}>
2322
<placeholder-wrapper
2423
slot="placeholder"

Diff for: packages/shared/lib/core/nfts/actions/downloadNextNftInQueue.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Platform } from '@core/app'
22
import { get } from 'svelte/store'
33
import { downloadingNftId, nftDownloadQueue, removeNftFromDownloadQueue } from '../stores'
4+
import { getIpfsUri } from '../utils'
45

56
export async function downloadNextNftInQueue(): Promise<void> {
67
const nextDownload = get(nftDownloadQueue)?.[0]
@@ -9,8 +10,15 @@ export async function downloadNextNftInQueue(): Promise<void> {
910
}
1011

1112
try {
12-
const { downloadUrl, path, nft, accountIndex } = nextDownload
13+
// eslint-disable-next-line prefer-const
14+
let { downloadUrl, path, nft, accountIndex } = nextDownload
1315
downloadingNftId.set(nft.id)
16+
const ipfsUri = await getIpfsUri({ hash: downloadUrl })
17+
18+
if (ipfsUri) {
19+
downloadUrl = ipfsUri
20+
}
21+
1422
await Platform.downloadNft(downloadUrl, path, nft.id, accountIndex)
1523
} catch (error) {
1624
downloadingNftId.set(undefined)

Diff for: packages/shared/lib/core/nfts/actions/updateNftInAllAccountNfts.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { allAccountNfts } from '../stores'
2-
import { INft } from '../interfaces'
2+
import { getIpfsUri } from '../utils'
33

4-
export function updateNftInAllAccountNfts(accountIndex: number, nftId: string, partialNft: Partial<INft>): void {
4+
export function updateNftInAllAccountNfts(accountIndex: number, nftId: string): void {
55
allAccountNfts.update((state) => {
66
if (!state[accountIndex]) {
77
state[accountIndex] = []
88
}
99
const nft = state[accountIndex].find((_nft) => _nft.id === nftId)
1010
if (nft) {
11-
Object.assign(nft, { ...nft, ...partialNft })
11+
const downloadUrl = nft.downloadUrl
12+
void getIpfsUri({ hash: downloadUrl }).then((ipfsUri) => {
13+
if (ipfsUri) {
14+
nft.downloadUrl = ipfsUri
15+
nft.composedUrl = ipfsUri
16+
}
17+
})
1218
}
1319
return state
1420
})

0 commit comments

Comments
 (0)