Open History to see the last commit
1import type { AssetResource, EnvironmentId } from "@t3tools/contracts";
2import type { ImageSource } from "expo-image";
3
4/**
5 * Every mint signs a new URL, and a reconnect mints again, so a URL-keyed cache
6 * misses each time. Attachments never change once stored, so they cache under
7 * their id instead.
8 */
9export function assetImageSource(
10 environmentId: EnvironmentId,
11 resource: AssetResource,
12 uri: string,
13): ImageSource {
14 return resource._tag === "attachment"
15 ? {
16 uri,
17 cacheKey: `t3-attachment:${JSON.stringify([environmentId, resource.attachmentId])}`,
18 }
19 : { uri };
20}