@akita-protocol/algomd-rn 0.0.0-stage → 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +137 -2
  2. package/package.json +118 -3
  3. package/src/adapters/index.ts +4 -0
  4. package/src/adapters/txn-graph.ts +138 -0
  5. package/src/components/ASA.tsx +38 -0
  6. package/src/components/ASASearch.tsx +79 -0
  7. package/src/components/Account.tsx +42 -0
  8. package/src/components/AccountSearch.tsx +75 -0
  9. package/src/components/AuctionListing.tsx +40 -0
  10. package/src/components/Collection.tsx +42 -0
  11. package/src/components/DualStakePool.tsx +244 -0
  12. package/src/components/NFDProfile.tsx +45 -0
  13. package/src/components/NFDSearch.tsx +81 -0
  14. package/src/components/NFTListing.tsx +73 -0
  15. package/src/components/NFTSearch.tsx +68 -0
  16. package/src/components/Poll.tsx +39 -0
  17. package/src/components/PollSearch.tsx +79 -0
  18. package/src/components/PrizeBoxBundle.tsx +1 -0
  19. package/src/components/RaffleListing.tsx +40 -0
  20. package/src/components/SelfFetching.tsx +1048 -0
  21. package/src/components/StakingPool.tsx +134 -0
  22. package/src/components/TradeOffer.tsx +47 -0
  23. package/src/components/TradeSearch.tsx +103 -0
  24. package/src/components/TransactionDetails.tsx +37 -0
  25. package/src/components/TransactionSearch.tsx +102 -0
  26. package/src/components/TransactionsGraph.tsx +60 -0
  27. package/src/components/index.ts +41 -0
  28. package/src/fonts/OFL.txt +93 -0
  29. package/src/fonts/SpaceGrotesk_300Light.ttf +0 -0
  30. package/src/fonts/SpaceGrotesk_400Regular.ttf +0 -0
  31. package/src/fonts/SpaceGrotesk_500Medium.ttf +0 -0
  32. package/src/fonts/SpaceGrotesk_600SemiBold.ttf +0 -0
  33. package/src/fonts/SpaceGrotesk_700Bold.ttf +0 -0
  34. package/src/fonts/app.css +5 -0
  35. package/src/graph.ts +3 -0
  36. package/src/hooks/index.ts +17 -0
  37. package/src/hooks/useAlgomdData.ts +1539 -0
  38. package/src/hooks/useAlgorandClient.ts +54 -0
  39. package/src/index.ts +147 -0
  40. package/src/presentation/ASADisplay.tsx +380 -0
  41. package/src/presentation/AccountDisplay.tsx +132 -0
  42. package/src/presentation/AccountMentionInline.tsx +38 -0
  43. package/src/presentation/AccountMentionText.tsx +80 -0
  44. package/src/presentation/AdaptiveImage.tsx +314 -0
  45. package/src/presentation/AssetMention.tsx +87 -0
  46. package/src/presentation/AuctionListingDisplay.tsx +428 -0
  47. package/src/presentation/BundleContents.tsx +228 -0
  48. package/src/presentation/CardContainer.tsx +61 -0
  49. package/src/presentation/CardEntrance.tsx +21 -0
  50. package/src/presentation/CollectionDisplay.tsx +168 -0
  51. package/src/presentation/ContractMenu.tsx +243 -0
  52. package/src/presentation/DualStakePoolDisplay.tsx +335 -0
  53. package/src/presentation/Embeds.tsx +300 -0
  54. package/src/presentation/GateRequirements.tsx +334 -0
  55. package/src/presentation/HEROICONS-LICENSE.txt +21 -0
  56. package/src/presentation/NFDProfileDisplay.tsx +194 -0
  57. package/src/presentation/NFTListingDisplay.tsx +284 -0
  58. package/src/presentation/OnChainActionCard.tsx +557 -0
  59. package/src/presentation/PollDisplay.tsx +222 -0
  60. package/src/presentation/PrizeBoxBundleDisplay.tsx +103 -0
  61. package/src/presentation/PrizeBoxMedia.tsx +46 -0
  62. package/src/presentation/PrizePreview.tsx +296 -0
  63. package/src/presentation/ProgressBar.tsx +50 -0
  64. package/src/presentation/RaffleListingDisplay.tsx +399 -0
  65. package/src/presentation/References.tsx +310 -0
  66. package/src/presentation/ReservedNotice.tsx +73 -0
  67. package/src/presentation/ResultsPanel.tsx +241 -0
  68. package/src/presentation/Sparkline.tsx +70 -0
  69. package/src/presentation/SquishyPressable.tsx +145 -0
  70. package/src/presentation/StakingPoolDisplay.tsx +419 -0
  71. package/src/presentation/StatusBadge.tsx +56 -0
  72. package/src/presentation/TradeOfferDisplay.tsx +275 -0
  73. package/src/presentation/TransactionDisplay.tsx +262 -0
  74. package/src/presentation/WinnerBadge.tsx +58 -0
  75. package/src/presentation/assetHelpers.ts +36 -0
  76. package/src/presentation/assets.ts +7 -0
  77. package/src/presentation/explorer.ts +95 -0
  78. package/src/presentation/format.ts +90 -0
  79. package/src/presentation/gates.ts +100 -0
  80. package/src/presentation/icons.tsx +1178 -0
  81. package/src/presentation/identity.tsx +175 -0
  82. package/src/presentation/index.ts +88 -0
  83. package/src/presentation/media.ts +70 -0
  84. package/src/presentation/pluginColors.ts +8 -0
  85. package/src/presentation/runtime.tsx +268 -0
  86. package/src/presentation/sheets.tsx +7 -0
  87. package/src/presentation/subject.tsx +31 -0
  88. package/src/presentation/textTheme.ts +17 -0
  89. package/src/presentation/themes.json +158 -0
  90. package/src/presentation/variants.ts +14 -0
  91. package/src/provider/AlgomdProvider.tsx +45 -0
  92. package/src/provider/context.ts +18 -0
  93. package/src/provider/imageResolver.ts +12 -0
  94. package/src/provider/index.ts +5 -0
  95. package/src/provider/networks.ts +23 -0
  96. package/src/provider/types.ts +29 -0
  97. package/src/refs/AccountRef.tsx +226 -0
  98. package/src/refs/ApplicationRef.tsx +72 -0
  99. package/src/refs/AssetRef.tsx +142 -0
  100. package/src/refs/AuctionRef.tsx +108 -0
  101. package/src/refs/CollectionRef.tsx +70 -0
  102. package/src/refs/DualStakeRef.tsx +88 -0
  103. package/src/refs/HostRefs.tsx +82 -0
  104. package/src/refs/ListingRef.tsx +90 -0
  105. package/src/refs/NfdRef.tsx +96 -0
  106. package/src/refs/PollRef.tsx +120 -0
  107. package/src/refs/RaffleRef.tsx +101 -0
  108. package/src/refs/RewardRef.tsx +78 -0
  109. package/src/refs/StakingPoolRef.tsx +136 -0
  110. package/src/refs/SubscriptionRef.tsx +200 -0
  111. package/src/refs/TradeRef.tsx +100 -0
  112. package/src/refs/TransactionRef.tsx +156 -0
  113. package/src/refs/assetInfo.ts +49 -0
  114. package/src/refs/contractParts.tsx +159 -0
  115. package/src/refs/index.tsx +137 -0
  116. package/src/refs/primitives.tsx +588 -0
  117. package/src/refs/types.ts +13 -0
  118. package/src/types/algorand.ts +496 -0
  119. package/src/types/index.ts +1 -0
  120. package/src/ui/CopyButton.tsx +44 -0
  121. package/src/ui/DataStates.tsx +45 -0
  122. package/src/ui/ProgressBar.tsx +64 -0
  123. package/src/ui/SearchSheet.tsx +141 -0
  124. package/src/ui/SizeContainer.tsx +25 -0
  125. package/src/ui/StatusBadge.tsx +51 -0
  126. package/src/ui/index.ts +6 -0
  127. package/src/utils/algomdImageUrl.ts +20 -0
  128. package/src/utils/arc19.ts +120 -0
  129. package/src/utils/arc62.ts +246 -0
  130. package/src/utils/capacity.ts +26 -0
  131. package/src/utils/format.ts +181 -0
  132. package/src/utils/ids.ts +31 -0
  133. package/src/utils/index.ts +6 -0
  134. package/src/utils/nfdDisplay.ts +45 -0
  135. package/src/utils/search.ts +87 -0
  136. package/src/utils/stakingPool.ts +174 -0
  137. package/src/utils/stakingSnapshot.ts +132 -0
@@ -0,0 +1,222 @@
1
+ // Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
2
+ import React from "react";
3
+ import { View } from "react-native";
4
+ import * as Haptics from "expo-haptics";
5
+ import { CheckCircleIcon, ClockIcon, LockClosedIcon } from "./icons";
6
+ import { Text } from "./runtime";
7
+ import { SquishyPressable } from "./SquishyPressable";
8
+ import { useAppTheme } from "./runtime";
9
+ import { CardContainer } from "./CardContainer";
10
+ import { ContractMenu } from "./ContractMenu";
11
+ import { OnChainActionCard, OnChainActionHeader } from "./OnChainActionCard";
12
+ import { formatNumber, formatRelativeTime } from "../utils/format";
13
+ import type { Poll as PollType, PollOption } from "../types/algorand";
14
+
15
+ export interface PollDisplayProps {
16
+ data: PollType;
17
+ compact?: boolean;
18
+ onVote?: (pollId: string, optionId: string) => void;
19
+ }
20
+
21
+ function PollOptionRow({
22
+ option,
23
+ totalVotes,
24
+ isActive,
25
+ leading,
26
+ onVote,
27
+ }: {
28
+ option: PollOption;
29
+ totalVotes: number;
30
+ isActive: boolean;
31
+ /** The option with the most votes: highlighted, and marked as the winner once the poll ends. */
32
+ leading: boolean;
33
+ onVote?: () => void;
34
+ }) {
35
+ const { theme } = useAppTheme();
36
+ const percentage = totalVotes > 0 ? option.votes / totalVotes : 0;
37
+ const votable = isActive && !!onVote;
38
+
39
+ return (
40
+ <SquishyPressable
41
+ onPress={() => {
42
+ if (isActive && onVote) {
43
+ Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
44
+ onVote();
45
+ }
46
+ }}
47
+ disabled={!votable}
48
+ pressedScale={0.98}
49
+ accessibilityLabel={`${option.text}, ${Math.round(percentage * 100)} percent${votable ? ", vote for this option" : ""}`}
50
+ containerStyle={{ marginBottom: 8 }}
51
+ >
52
+ <View
53
+ style={{
54
+ borderCurve: "continuous",
55
+ borderRadius: 12,
56
+ backgroundColor: `${theme.colors.textDim}10`,
57
+ minHeight: 44,
58
+ justifyContent: "center",
59
+ overflow: "hidden",
60
+ paddingHorizontal: 12,
61
+ paddingVertical: 10,
62
+ }}
63
+ >
64
+ {/* Background fill bar — uses pure RN inline styles, no NativeWind */}
65
+ <View
66
+ style={{
67
+ position: "absolute",
68
+ top: 0,
69
+ left: 0,
70
+ bottom: 0,
71
+ width: `${percentage * 100}%`,
72
+ backgroundColor: leading
73
+ ? `${theme.colors.primary}2e`
74
+ : `${theme.colors.textDim}14`,
75
+ }}
76
+ />
77
+ <View
78
+ style={{
79
+ flexDirection: "row",
80
+ alignItems: "center",
81
+ justifyContent: "space-between",
82
+ gap: 10,
83
+ }}
84
+ >
85
+ {votable ? (
86
+ <View
87
+ style={{
88
+ borderColor: theme.colors.primary,
89
+ borderRadius: 9,
90
+ borderWidth: 1.5,
91
+ height: 18,
92
+ width: 18,
93
+ }}
94
+ />
95
+ ) : !isActive && leading && totalVotes > 0 ? (
96
+ <CheckCircleIcon size={18} color={theme.colors.primary} />
97
+ ) : null}
98
+ <Text
99
+ size="xs"
100
+ weight={leading ? "semiBold" : "medium"}
101
+ style={{ flex: 1 }}
102
+ numberOfLines={2}
103
+ >
104
+ {option.text}
105
+ </Text>
106
+ <View
107
+ style={{
108
+ flexDirection: "row",
109
+ alignItems: "center",
110
+ gap: 6,
111
+ marginLeft: 8,
112
+ }}
113
+ >
114
+ <Text
115
+ size="xs"
116
+ weight="semiBold"
117
+ style={{
118
+ color: leading ? theme.colors.primary : theme.colors.text,
119
+ }}
120
+ >
121
+ {totalVotes > 0 ? `${Math.round(percentage * 100)}%` : "0%"}
122
+ </Text>
123
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
124
+ {formatNumber(option.votes, 0)}
125
+ </Text>
126
+ </View>
127
+ </View>
128
+ </View>
129
+ </SquishyPressable>
130
+ );
131
+ }
132
+
133
+ export function PollDisplay({ data, compact, onVote }: PollDisplayProps) {
134
+ const { theme } = useAppTheme();
135
+ const isActive = data.status === "active";
136
+
137
+ if (compact) {
138
+ return (
139
+ <CardContainer compact>
140
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 3 }}>
141
+ <Text size="xxs" weight="semiBold" numberOfLines={1}>
142
+ {data.question}
143
+ </Text>
144
+ </View>
145
+ </CardContainer>
146
+ );
147
+ }
148
+
149
+ const leadingVotes = Math.max(
150
+ 0,
151
+ ...data.options.map((option) => option.votes),
152
+ );
153
+ const status = isActive
154
+ ? { label: "Voting open", tone: "success" as const }
155
+ : { label: "Ended", tone: "neutral" as const };
156
+ const facts = [
157
+ `${formatNumber(data.totalVotes, 0)} ${data.totalVotes === 1 ? "vote" : "votes"}`,
158
+ data.expiresAt
159
+ ? isActive
160
+ ? `ends ${formatRelativeTime(data.expiresAt)}`
161
+ : `ended ${formatRelativeTime(data.expiresAt)}`
162
+ : null,
163
+ ].filter(Boolean);
164
+
165
+ return (
166
+ <OnChainActionCard
167
+ accessibilityLabel={`Poll: ${data.question}, ${status.label}`}
168
+ >
169
+ <OnChainActionHeader
170
+ eyebrow="Poll"
171
+ title={data.question}
172
+ status={status}
173
+ menu={<ContractMenu appId={data.id} embedType="Poll" />}
174
+ />
175
+
176
+ <View>
177
+ {data.options.map((option: PollOption) => (
178
+ <PollOptionRow
179
+ key={option.id}
180
+ option={option}
181
+ totalVotes={data.totalVotes}
182
+ isActive={isActive}
183
+ leading={option.votes === leadingVotes && leadingVotes > 0}
184
+ onVote={onVote ? () => onVote(data.id, option.id) : undefined}
185
+ />
186
+ ))}
187
+ </View>
188
+
189
+ <View
190
+ style={{
191
+ flexDirection: "row",
192
+ alignItems: "center",
193
+ justifyContent: "space-between",
194
+ gap: 8,
195
+ }}
196
+ >
197
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 4 }}>
198
+ <ClockIcon size={12} color={theme.colors.textDim} />
199
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
200
+ {facts.join(" · ")}
201
+ </Text>
202
+ </View>
203
+ {isActive && onVote ? (
204
+ <Text
205
+ size="xxs"
206
+ weight="medium"
207
+ style={{ color: theme.colors.primary }}
208
+ >
209
+ Tap an option to vote
210
+ </Text>
211
+ ) : data.gating ? (
212
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 3 }}>
213
+ <LockClosedIcon size={11} color={theme.colors.textDim} />
214
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
215
+ Holders only
216
+ </Text>
217
+ </View>
218
+ ) : null}
219
+ </View>
220
+ </OnChainActionCard>
221
+ );
222
+ }
@@ -0,0 +1,103 @@
1
+ // Shared AlgoMD presentation. Edit this library source.
2
+ import React from "react";
3
+ import { View } from "react-native";
4
+ import type { PrizeBoxBundle } from "../types/algorand";
5
+ import {
6
+ formatBaseUnitAmount,
7
+ formatCompactBaseUnitAmount,
8
+ } from "../utils/format";
9
+ import { Text, useAppTheme } from "./runtime";
10
+ import { GiftIcon } from "./icons";
11
+
12
+ /** What a prize box holds: up to three assets with readable amounts, then a count of the rest. */
13
+ export function PrizeBoxBundleContents({
14
+ bundle,
15
+ }: {
16
+ bundle?: PrizeBoxBundle;
17
+ }) {
18
+ const { theme } = useAppTheme();
19
+ const holdings = bundle?.holdings ?? [];
20
+
21
+ return (
22
+ <View
23
+ accessible
24
+ accessibilityLabel={`Prize box bundle${bundle?.appId ? `, application ${bundle.appId}` : ""}, ${holdings.length} assets`}
25
+ style={{
26
+ backgroundColor: theme.colors.accentBackground,
27
+ borderCurve: "continuous",
28
+ borderRadius: 20,
29
+ gap: 12,
30
+ padding: 16,
31
+ }}
32
+ >
33
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
34
+ <View
35
+ style={{
36
+ alignItems: "center",
37
+ backgroundColor: `${theme.colors.primary}1f`,
38
+ borderRadius: 12,
39
+ height: 40,
40
+ justifyContent: "center",
41
+ width: 40,
42
+ }}
43
+ >
44
+ <GiftIcon size={20} color={theme.colors.primary} />
45
+ </View>
46
+ <View style={{ flex: 1, gap: 1 }}>
47
+ <Text size="sm" weight="semiBold">
48
+ Prize box
49
+ </Text>
50
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
51
+ {holdings.length
52
+ ? `${holdings.length} ${holdings.length === 1 ? "asset" : "assets"} inside`
53
+ : "Empty"}
54
+ {bundle?.appId ? ` · App #${bundle.appId}` : ""}
55
+ </Text>
56
+ </View>
57
+ </View>
58
+
59
+ {holdings.length > 0 ? (
60
+ <View style={{ gap: 10 }}>
61
+ {holdings.slice(0, 3).map((holding, index) => (
62
+ <View
63
+ key={holding.asset.id}
64
+ accessibilityLabel={`${formatBaseUnitAmount(holding.amountRaw, holding.asset.decimals)} ${holding.asset.unitName ?? ""}`}
65
+ style={{
66
+ alignItems: "center",
67
+ flexDirection: "row",
68
+ gap: 12,
69
+ justifyContent: "space-between",
70
+ }}
71
+ >
72
+ <Text
73
+ size="xs"
74
+ numberOfLines={1}
75
+ style={{ flex: 1, minWidth: 0 }}
76
+ >
77
+ {holding.asset.name || `Asset #${holding.asset.id}`}
78
+ </Text>
79
+ <Text size="xs" weight="semiBold">
80
+ {formatCompactBaseUnitAmount(
81
+ holding.amountRaw,
82
+ holding.asset.decimals,
83
+ )}{" "}
84
+ <Text size="xs" style={{ color: theme.colors.textDim }}>
85
+ {holding.asset.unitName}
86
+ </Text>
87
+ </Text>
88
+ </View>
89
+ ))}
90
+ {holdings.length > 3 ? (
91
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
92
+ +{holdings.length - 3} more
93
+ </Text>
94
+ ) : null}
95
+ </View>
96
+ ) : (
97
+ <Text size="xs" style={{ color: theme.colors.textDim }}>
98
+ This box's contents are unavailable or were already withdrawn.
99
+ </Text>
100
+ )}
101
+ </View>
102
+ );
103
+ }
@@ -0,0 +1,46 @@
1
+ // Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
2
+ import React from "react";
3
+ import { View } from "react-native";
4
+ import { OutlineGiftIcon as GiftIcon } from "./icons";
5
+
6
+ import { Text } from "./runtime";
7
+ import { useAppTheme } from "./runtime";
8
+
9
+ export function PrizeBoxMedia({ appId }: { appId?: string }) {
10
+ const { theme } = useAppTheme();
11
+
12
+ return (
13
+ <View
14
+ accessible
15
+ accessibilityLabel={`Prize Box bundle${appId ? `, application ${appId}` : ""}`}
16
+ style={{
17
+ alignItems: "center",
18
+ aspectRatio: 16 / 7,
19
+ backgroundColor: `${theme.colors.primary}12`,
20
+ gap: 7,
21
+ justifyContent: "center",
22
+ padding: 20,
23
+ }}
24
+ >
25
+ <View
26
+ style={{
27
+ alignItems: "center",
28
+ backgroundColor: `${theme.colors.primary}18`,
29
+ borderCurve: "continuous",
30
+ borderRadius: 18,
31
+ height: 58,
32
+ justifyContent: "center",
33
+ width: 58,
34
+ }}
35
+ >
36
+ <GiftIcon size={30} color={theme.colors.primary} />
37
+ </View>
38
+ <Text size="sm" weight="semiBold">
39
+ Prize Box Bundle
40
+ </Text>
41
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
42
+ {appId ? `Bundle app #${appId}` : "Multiple on-chain prizes"}
43
+ </Text>
44
+ </View>
45
+ );
46
+ }
@@ -0,0 +1,296 @@
1
+ // Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
2
+ import React, { useCallback, useRef } from "react";
3
+ import { View, Pressable } from "react-native";
4
+ import { Image } from "expo-image";
5
+ import { PhotoIcon, GiftIcon } from "./icons";
6
+ import BottomSheet, { BottomSheetScrollView } from "./sheets";
7
+ import { Text } from "./runtime";
8
+ import { useAppTheme } from "./runtime";
9
+ import type { ASA as ASAType } from "../types/algorand";
10
+
11
+ export interface PrizePreviewProps {
12
+ /** All prizes (each with optional imageUrl from ARC-19 resolution) */
13
+ prizes: ASAType[];
14
+ /** Resolved image URLs keyed by prize index (fallback for prizes without imageUrl) */
15
+ imageUrls?: (string | undefined)[];
16
+ borderRadiusTop?: number;
17
+ /** Opens the box's contents somewhere else; the built-in sheet is skipped. */
18
+ onPress?: () => void;
19
+ }
20
+
21
+ /** Maximum prizes shown inline before "+N more" overflow */
22
+ const MAX_PREVIEW = 4;
23
+
24
+ function getImageUrl(
25
+ prize: ASAType,
26
+ index: number,
27
+ imageUrls?: (string | undefined)[],
28
+ ): string | undefined {
29
+ return imageUrls?.[index] || prize.imageUrl;
30
+ }
31
+
32
+ /** Fungible tokens get an icon tile; collectibles fill their tile with art. */
33
+ function isCollectible(prize: ASAType): boolean {
34
+ return prize.decimals === 0 && prize.total > 0 && prize.total <= 1000;
35
+ }
36
+
37
+ const GAP = 2;
38
+
39
+ /**
40
+ * Multi-prize (prize box) art: square tiles so art of any shape crops evenly.
41
+ * 2 items sit side by side, 3 use one large tile beside two small ones, and 4+
42
+ * use a 2x2 grid whose last tile counts the rest. Collectibles lead.
43
+ */
44
+ export function PrizePreview({
45
+ prizes,
46
+ imageUrls,
47
+ borderRadiusTop = 16,
48
+ onPress,
49
+ }: PrizePreviewProps) {
50
+ const { theme } = useAppTheme();
51
+ const sheetRef = useRef<BottomSheet>(null);
52
+ const handlePress = useCallback(() => {
53
+ sheetRef.current?.expand();
54
+ }, []);
55
+
56
+ const ordered = prizes
57
+ .map((prize, index) => ({
58
+ prize,
59
+ uri: getImageUrl(prize, index, imageUrls),
60
+ }))
61
+ .sort(
62
+ (a, b) =>
63
+ Number(isCollectible(b.prize) && !!b.uri) -
64
+ Number(isCollectible(a.prize) && !!a.uri),
65
+ );
66
+ const overflow =
67
+ ordered.length > MAX_PREVIEW ? ordered.length - (MAX_PREVIEW - 1) : 0;
68
+ const visible = ordered.slice(0, overflow ? MAX_PREVIEW - 1 : MAX_PREVIEW);
69
+ const layout =
70
+ visible.length + (overflow ? 1 : 0) <= 2
71
+ ? "row"
72
+ : visible.length === 3 && !overflow
73
+ ? "featured"
74
+ : "grid";
75
+ const aspectRatio = layout === "row" ? 2 : layout === "featured" ? 3 / 2 : 1;
76
+ const tile = (index: number) => {
77
+ const item = visible[index];
78
+ if (!item)
79
+ return overflow ? (
80
+ <MoreTile key="more" count={overflow} theme={theme} />
81
+ ) : null;
82
+ return (
83
+ <PrizeTile
84
+ key={`${item.prize.id}-${index}`}
85
+ prize={item.prize}
86
+ uri={item.uri}
87
+ theme={theme}
88
+ />
89
+ );
90
+ };
91
+
92
+ return (
93
+ <>
94
+ <Pressable
95
+ accessibilityRole="button"
96
+ accessibilityLabel={`Prize box with ${prizes.length} items. Show all.`}
97
+ onPress={onPress ?? handlePress}
98
+ >
99
+ <View
100
+ style={{
101
+ width: "100%",
102
+ aspectRatio,
103
+ borderTopLeftRadius: borderRadiusTop,
104
+ borderTopRightRadius: borderRadiusTop,
105
+ overflow: "hidden",
106
+ backgroundColor: theme.colors.accentBackground,
107
+ gap: GAP,
108
+ }}
109
+ >
110
+ {layout === "row" && (
111
+ <View style={{ flex: 1, flexDirection: "row", gap: GAP }}>
112
+ {tile(0)}
113
+ {tile(1)}
114
+ </View>
115
+ )}
116
+ {layout === "featured" && (
117
+ <View style={{ flex: 1, flexDirection: "row", gap: GAP }}>
118
+ <View style={{ flex: 2 }}>{tile(0)}</View>
119
+ <View style={{ flex: 1, gap: GAP }}>
120
+ {tile(1)}
121
+ {tile(2)}
122
+ </View>
123
+ </View>
124
+ )}
125
+ {layout === "grid" && (
126
+ <>
127
+ <View style={{ flex: 1, flexDirection: "row", gap: GAP }}>
128
+ {tile(0)}
129
+ {tile(1)}
130
+ </View>
131
+ <View style={{ flex: 1, flexDirection: "row", gap: GAP }}>
132
+ {tile(2)}
133
+ {tile(3)}
134
+ </View>
135
+ </>
136
+ )}
137
+ </View>
138
+ </Pressable>
139
+
140
+ {/* Full prize list sheet */}
141
+ {onPress ? null : (
142
+ <BottomSheet
143
+ ref={sheetRef}
144
+ index={-1}
145
+ snapPoints={["60%"]}
146
+ enablePanDownToClose
147
+ backgroundStyle={{ backgroundColor: theme.colors.background }}
148
+ handleIndicatorStyle={{ backgroundColor: theme.colors.textDim }}
149
+ >
150
+ <View style={{ paddingHorizontal: 16, paddingBottom: 8 }}>
151
+ <View
152
+ style={{
153
+ flexDirection: "row",
154
+ alignItems: "center",
155
+ gap: 6,
156
+ marginBottom: 12,
157
+ }}
158
+ >
159
+ <GiftIcon size={18} color={theme.colors.primary} />
160
+ <Text size="md" weight="bold">
161
+ Prize Box
162
+ </Text>
163
+ <Text size="xs" style={{ color: theme.colors.textDim }}>
164
+ {prizes.length} items
165
+ </Text>
166
+ </View>
167
+ </View>
168
+ <BottomSheetScrollView
169
+ contentContainerStyle={{ paddingHorizontal: 16, paddingBottom: 32 }}
170
+ >
171
+ {prizes.map((prize, i) => {
172
+ const uri = getImageUrl(prize, i, imageUrls);
173
+ return (
174
+ <View
175
+ key={prize.id}
176
+ style={{
177
+ flexDirection: "row",
178
+ alignItems: "center",
179
+ gap: 12,
180
+ paddingVertical: 8,
181
+ }}
182
+ >
183
+ {uri ? (
184
+ <Image
185
+ source={{ uri }}
186
+ style={{ width: 56, height: 56, borderRadius: 10 }}
187
+ contentFit="cover"
188
+ />
189
+ ) : (
190
+ <View
191
+ style={{
192
+ width: 56,
193
+ height: 56,
194
+ borderRadius: 10,
195
+ backgroundColor: `${theme.colors.textDim}10`,
196
+ alignItems: "center",
197
+ justifyContent: "center",
198
+ }}
199
+ >
200
+ <PhotoIcon size={20} color={theme.colors.textDim} />
201
+ </View>
202
+ )}
203
+ <View style={{ flex: 1 }}>
204
+ <Text size="sm" weight="semiBold" numberOfLines={1}>
205
+ {prize.name}
206
+ </Text>
207
+ {prize.unitName ? (
208
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
209
+ {prize.unitName}
210
+ </Text>
211
+ ) : null}
212
+ </View>
213
+ </View>
214
+ );
215
+ })}
216
+ </BottomSheetScrollView>
217
+ </BottomSheet>
218
+ )}
219
+ </>
220
+ );
221
+ }
222
+
223
+ function PrizeTile({
224
+ prize,
225
+ uri,
226
+ theme,
227
+ }: {
228
+ prize: ASAType;
229
+ uri?: string;
230
+ theme: ReturnType<typeof useAppTheme>["theme"];
231
+ }) {
232
+ if (uri && isCollectible(prize)) {
233
+ return (
234
+ <View style={{ flex: 1, overflow: "hidden" }}>
235
+ <Image
236
+ source={{ uri }}
237
+ accessibilityLabel={prize.name}
238
+ style={{ position: "absolute", top: 0, right: 0, bottom: 0, left: 0 }}
239
+ contentFit="cover"
240
+ />
241
+ </View>
242
+ );
243
+ }
244
+ // Tokens and art-less assets: the icon on a tinted tile, never a stretched logo.
245
+ return (
246
+ <View
247
+ style={{
248
+ flex: 1,
249
+ alignItems: "center",
250
+ justifyContent: "center",
251
+ gap: 6,
252
+ padding: 8,
253
+ backgroundColor: `${theme.colors.primary}14`,
254
+ }}
255
+ >
256
+ {uri ? (
257
+ <Image
258
+ source={{ uri }}
259
+ style={{ width: "34%", aspectRatio: 1, borderRadius: 999 }}
260
+ contentFit="cover"
261
+ />
262
+ ) : (
263
+ <PhotoIcon size={22} color={theme.colors.textDim} />
264
+ )}
265
+ <Text size="xs" weight="semiBold" numberOfLines={1}>
266
+ {prize.unitName || prize.name}
267
+ </Text>
268
+ </View>
269
+ );
270
+ }
271
+
272
+ function MoreTile({
273
+ count,
274
+ theme,
275
+ }: {
276
+ count: number;
277
+ theme: ReturnType<typeof useAppTheme>["theme"];
278
+ }) {
279
+ return (
280
+ <View
281
+ style={{
282
+ flex: 1,
283
+ alignItems: "center",
284
+ justifyContent: "center",
285
+ backgroundColor: `${theme.colors.primary}14`,
286
+ }}
287
+ >
288
+ <Text size="xl" weight="bold" style={{ color: theme.colors.primary }}>
289
+ +{count}
290
+ </Text>
291
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
292
+ more inside
293
+ </Text>
294
+ </View>
295
+ );
296
+ }