@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,284 @@
1
+ // Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
2
+ import { useRef } from "react";
3
+ import { Image, Pressable, View } from "react-native";
4
+ import * as Haptics from "expo-haptics";
5
+ import { CheckBadgeIcon, MarketplaceIcon } from "./icons";
6
+ import {
7
+ BundleContentsButton,
8
+ PrizeBoxHoldingsMedia,
9
+ type BundleSheetHandle,
10
+ } from "./BundleContents";
11
+ import { Text, usePresentation } from "./runtime";
12
+ import { useAppTheme } from "./runtime";
13
+ import {
14
+ OnChainActionButton,
15
+ OnChainActionCard,
16
+ OnChainActionHeader,
17
+ } from "./OnChainActionCard";
18
+ import { ContractMenu } from "./ContractMenu";
19
+ import { WinnerBadge } from "./WinnerBadge";
20
+ import { PLUGIN_COLORS } from "./pluginColors";
21
+ import { ReservedNotice } from "./ReservedNotice";
22
+ import { GateNotice } from "./GateRequirements";
23
+ import { useIsAssetSubject } from "./subject";
24
+ import {
25
+ AdaptiveImage,
26
+ ImagePlaceholder,
27
+ useImageBudget,
28
+ } from "./AdaptiveImage";
29
+ import { getAssetUnitName, getAssetIconSource } from "./assetHelpers";
30
+ import { formatNumber } from "../utils/format";
31
+ import { formatPrice } from "./format";
32
+ import type {
33
+ NFTListing as NFTListingType,
34
+ PrizeBoxHolding,
35
+ } from "../types/algorand";
36
+
37
+ export interface NFTListingDisplayProps {
38
+ data: NFTListingType;
39
+ imageUrl?: string;
40
+ priceAssetImageUrl?: string;
41
+ onPressCollectible?: () => void;
42
+ onPurchase?: (listing: NFTListingType) => void;
43
+ purchased?: boolean;
44
+ buyer?: string;
45
+ /** The signed-in account; defaults to the presentation provider's viewerAddress. */
46
+ viewerAddress?: string;
47
+ /** Whether the viewer passes the listing's gate; leave undefined when unchecked. */
48
+ gateEligible?: boolean;
49
+ /** Pass (true) or fail (false) for each gate rule, in the gate's rule order. */
50
+ gateResults?: boolean[];
51
+ }
52
+
53
+ // Approximate non-image content height:
54
+ // padding(12) + title(20) + collection badges(24) + price box(52) + CTA(44) + gaps(~18)
55
+ const NON_IMAGE_HEIGHT = 170;
56
+ const PRICE_ICON_SIZE = 22;
57
+
58
+ export function NFTListingDisplay({
59
+ data,
60
+ imageUrl,
61
+ priceAssetImageUrl,
62
+ onPressCollectible,
63
+ onPurchase,
64
+ purchased,
65
+ buyer,
66
+ viewerAddress: viewerAddressProp,
67
+ gateEligible,
68
+ gateResults,
69
+ }: NFTListingDisplayProps) {
70
+ const { theme } = useAppTheme();
71
+ const viewerAddress = viewerAddressProp ?? usePresentation().viewerAddress;
72
+ const reservedForViewer =
73
+ !!data.reservedFor && !!viewerAddress && data.reservedFor === viewerAddress;
74
+ // Per-rule results settle eligibility when the host didn't pass it directly.
75
+ const gatePassed =
76
+ gateEligible ??
77
+ (gateResults?.length && gateResults.length === data.gating?.rules?.length
78
+ ? gateResults.every(Boolean)
79
+ : undefined);
80
+ const currency = data.currency || getAssetUnitName(data.priceAsset);
81
+ const priceIconSource = getAssetIconSource(
82
+ data.priceAsset,
83
+ priceAssetImageUrl,
84
+ );
85
+ const maxImageHeight = useImageBudget(NON_IMAGE_HEIGHT);
86
+ // On the collectible's own page its art, name and collection are already shown above.
87
+ const onSubjectPage = useIsAssetSubject(
88
+ data.isPrizeBox ? undefined : data.nft.id,
89
+ );
90
+ const status = purchased
91
+ ? { label: "Purchased", tone: "neutral" as const }
92
+ : data.reservedFor
93
+ ? { label: "Reserved", tone: "warning" as const }
94
+ : { label: "For sale", tone: "success" as const };
95
+ const priceLabel =
96
+ `${formatPrice(data.price, data.priceAsset.decimals)} ${currency}`.trim();
97
+ const holdings = data.isPrizeBox ? (data.prizeBox?.holdings ?? []) : [];
98
+ const boxSheet = useRef<BundleSheetHandle>(null);
99
+ const title = data.isPrizeBox
100
+ ? `Prize box · ${holdings.length || "multiple"} ${holdings.length === 1 ? "item" : "items"}`
101
+ : data.nft.name;
102
+ // The price sits right above the button, so the label just names the purchase.
103
+ const buyLabel = data.isPrizeBox ? "Buy bundle" : "Buy collectible";
104
+ const available =
105
+ data.quantity > 1 ? `${formatNumber(data.quantity, 0)} available` : null;
106
+
107
+ const card = (
108
+ <OnChainActionCard
109
+ accessibilityLabel={`${title}, ${status.label}, ${priceLabel}`}
110
+ media={
111
+ onSubjectPage ? undefined : data.isPrizeBox ? (
112
+ <PrizeBoxHoldingsMedia
113
+ holdings={holdings}
114
+ onPress={() => boxSheet.current?.present()}
115
+ appId={data.prizeBoxAppId}
116
+ maxHeight={maxImageHeight}
117
+ />
118
+ ) : imageUrl ? (
119
+ <AdaptiveImage
120
+ uri={imageUrl}
121
+ assetId={data.nft.id}
122
+ maxHeight={maxImageHeight}
123
+ borderRadiusTop={0}
124
+ fill
125
+ />
126
+ ) : (
127
+ <ImagePlaceholder
128
+ assetId={data.nft.id}
129
+ maxHeight={maxImageHeight}
130
+ borderRadiusTop={0}
131
+ fill
132
+ />
133
+ )
134
+ }
135
+ testID={`nft-listing-card-${data.id}`}
136
+ >
137
+ <OnChainActionHeader
138
+ eyebrow={onSubjectPage ? undefined : "Listing"}
139
+ eyebrowColor={PLUGIN_COLORS.Marketplace}
140
+ eyebrowIcon={
141
+ <MarketplaceIcon size={13} color={PLUGIN_COLORS.Marketplace} />
142
+ }
143
+ title={onSubjectPage ? "Listing" : title}
144
+ titleColor={onSubjectPage ? PLUGIN_COLORS.Marketplace : undefined}
145
+ titleIcon={
146
+ onSubjectPage ? (
147
+ <MarketplaceIcon size={18} color={PLUGIN_COLORS.Marketplace} />
148
+ ) : undefined
149
+ }
150
+ titleAccessory={
151
+ !onSubjectPage &&
152
+ !data.isPrizeBox &&
153
+ (data.authenticityBadge || data.nft.verified) ? (
154
+ <CheckBadgeIcon size={18} color={theme.colors.primary} />
155
+ ) : null
156
+ }
157
+ subtitle={
158
+ !onSubjectPage && !data.isPrizeBox && data.collection ? (
159
+ <Text
160
+ size="xs"
161
+ numberOfLines={1}
162
+ style={{ color: theme.colors.textDim }}
163
+ >
164
+ {data.collection}
165
+ </Text>
166
+ ) : undefined
167
+ }
168
+ menu={<ContractMenu appId={data.id} embedType="NFTListing" />}
169
+ />
170
+
171
+ {holdings.length ? <BundleContentsButton holdings={holdings} sheetRef={boxSheet} /> : null}
172
+
173
+ {/* Price is the headline. */}
174
+ <View style={{ gap: 2 }}>
175
+ <Text
176
+ size="xxs"
177
+ weight="medium"
178
+ style={{ color: theme.colors.textDim }}
179
+ >
180
+ Price
181
+ </Text>
182
+ <View
183
+ style={{
184
+ flexDirection: "row",
185
+ alignItems: "flex-end",
186
+ justifyContent: "space-between",
187
+ gap: 12,
188
+ minHeight: 30,
189
+ }}
190
+ >
191
+ <View
192
+ style={{
193
+ flexDirection: "row",
194
+ alignItems: "center",
195
+ gap: 6,
196
+ flexShrink: 1,
197
+ }}
198
+ >
199
+ {priceIconSource ? (
200
+ <Image
201
+ source={priceIconSource}
202
+ style={{
203
+ width: PRICE_ICON_SIZE,
204
+ height: PRICE_ICON_SIZE,
205
+ borderRadius: PRICE_ICON_SIZE / 2,
206
+ }}
207
+ />
208
+ ) : null}
209
+ <Text size="lg" weight="bold" numberOfLines={1}>
210
+ {priceLabel}
211
+ </Text>
212
+ </View>
213
+ {available ? (
214
+ <Text
215
+ size="sm"
216
+ style={{ color: theme.colors.textDim, marginBottom: 2 }}
217
+ >
218
+ {available}
219
+ </Text>
220
+ ) : null}
221
+ </View>
222
+ </View>
223
+
224
+ {purchased ? (
225
+ buyer ? (
226
+ <WinnerBadge address={buyer} label="Purchased by" />
227
+ ) : (
228
+ <Text size="xs" style={{ color: theme.colors.textDim }}>
229
+ Purchased
230
+ </Text>
231
+ )
232
+ ) : data.reservedFor && !reservedForViewer ? (
233
+ // Reserved for someone else: say who instead of offering a buy that would fail.
234
+ <ReservedNotice address={data.reservedFor} />
235
+ ) : data.gating && gatePassed === false ? (
236
+ <GateNotice
237
+ gating={data.gating}
238
+ action="buy"
239
+ eligible={false}
240
+ results={gateResults}
241
+ />
242
+ ) : (
243
+ <>
244
+ {data.gating ? (
245
+ <GateNotice
246
+ gating={data.gating}
247
+ action="buy"
248
+ eligible={gatePassed}
249
+ results={gateResults}
250
+ />
251
+ ) : null}
252
+ {reservedForViewer ? (
253
+ <ReservedNotice address={data.reservedFor!} forViewer />
254
+ ) : null}
255
+ {onPurchase ? (
256
+ <View style={{ flexDirection: "row" }}>
257
+ <OnChainActionButton
258
+ accessibilityLabel={`Buy ${title} for ${priceLabel}`}
259
+ label={buyLabel}
260
+ onPress={() => {
261
+ Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
262
+ onPurchase(data);
263
+ }}
264
+ />
265
+ </View>
266
+ ) : null}
267
+ </>
268
+ )}
269
+ </OnChainActionCard>
270
+ );
271
+
272
+ if (!onPressCollectible) return card;
273
+
274
+ return (
275
+ <Pressable
276
+ accessibilityRole="link"
277
+ accessibilityLabel={`Open ${title}`}
278
+ onPress={onPressCollectible}
279
+ style={({ pressed }) => pressed && { opacity: 0.92 }}
280
+ >
281
+ {card}
282
+ </Pressable>
283
+ );
284
+ }