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

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 (138) 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 +280 -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/GuildProposalRef.tsx +285 -0
  104. package/src/refs/HostRefs.tsx +82 -0
  105. package/src/refs/ListingRef.tsx +90 -0
  106. package/src/refs/NfdRef.tsx +96 -0
  107. package/src/refs/PollRef.tsx +120 -0
  108. package/src/refs/RaffleRef.tsx +101 -0
  109. package/src/refs/RewardRef.tsx +78 -0
  110. package/src/refs/StakingPoolRef.tsx +136 -0
  111. package/src/refs/SubscriptionRef.tsx +200 -0
  112. package/src/refs/TradeRef.tsx +100 -0
  113. package/src/refs/TransactionRef.tsx +156 -0
  114. package/src/refs/assetInfo.ts +49 -0
  115. package/src/refs/contractParts.tsx +159 -0
  116. package/src/refs/index.tsx +140 -0
  117. package/src/refs/primitives.tsx +588 -0
  118. package/src/refs/types.ts +13 -0
  119. package/src/types/algorand.ts +496 -0
  120. package/src/types/index.ts +1 -0
  121. package/src/ui/CopyButton.tsx +44 -0
  122. package/src/ui/DataStates.tsx +45 -0
  123. package/src/ui/ProgressBar.tsx +64 -0
  124. package/src/ui/SearchSheet.tsx +141 -0
  125. package/src/ui/SizeContainer.tsx +25 -0
  126. package/src/ui/StatusBadge.tsx +51 -0
  127. package/src/ui/index.ts +6 -0
  128. package/src/utils/algomdImageUrl.ts +20 -0
  129. package/src/utils/arc19.ts +120 -0
  130. package/src/utils/arc62.ts +246 -0
  131. package/src/utils/capacity.ts +26 -0
  132. package/src/utils/format.ts +181 -0
  133. package/src/utils/ids.ts +31 -0
  134. package/src/utils/index.ts +6 -0
  135. package/src/utils/nfdDisplay.ts +45 -0
  136. package/src/utils/search.ts +87 -0
  137. package/src/utils/stakingPool.ts +174 -0
  138. package/src/utils/stakingSnapshot.ts +132 -0
@@ -0,0 +1,285 @@
1
+ import React, { useState } from "react";
2
+ import { StyleSheet, View } from "react-native";
3
+ import {
4
+ GUILD_ZERO_ADDRESS,
5
+ formatRelativeTime,
6
+ guildBallotOutcome,
7
+ guildProposalStatusLabel,
8
+ guildRequirementsText,
9
+ splitGuildProposalId,
10
+ type GuildBallotData,
11
+ type GuildProposalData,
12
+ type GuildProposalStatus,
13
+ } from "@akita-protocol/algomd-core";
14
+ import { useGuildProposal } from "@akita-protocol/algomd-core/react";
15
+ import { UserGroupIcon } from "../presentation/icons";
16
+ import { Text, useAppTheme, usePresentation, type GuildVoteChoice } from "../presentation/runtime";
17
+ import { PersonRow } from "./AccountRef";
18
+ import { ActionButton, plural, useNow } from "./contractParts";
19
+ import {
20
+ Card,
21
+ CardHeader,
22
+ CardSkeleton,
23
+ headerMedia,
24
+ InlinePill,
25
+ KindTile,
26
+ Note,
27
+ Row,
28
+ RowSkeleton,
29
+ Section,
30
+ StatusBadge,
31
+ Title,
32
+ Unavailable,
33
+ usePalette,
34
+ type Tone,
35
+ } from "./primitives";
36
+ import type { RefViewProps } from "./types";
37
+
38
+ type CardAction = GuildVoteChoice | "submit" | "finalize" | "execute";
39
+
40
+ const PROGRESS: Record<CardAction, string> = {
41
+ approve: "Voting yes…",
42
+ reject: "Voting no…",
43
+ abstain: "Abstaining…",
44
+ submit: "Opening the vote…",
45
+ finalize: "Closing the vote…",
46
+ execute: "Carrying it out…",
47
+ };
48
+
49
+ const VOTED: Record<GuildVoteChoice, string> = {
50
+ approve: "You voted yes",
51
+ reject: "You voted no",
52
+ abstain: "You abstained",
53
+ };
54
+
55
+ const STATUS_TONE: Record<GuildProposalStatus, Tone> = {
56
+ draft: "neutral",
57
+ invalid: "bad",
58
+ voting: "warn",
59
+ rejected: "bad",
60
+ approved: "good",
61
+ executed: "good",
62
+ };
63
+
64
+ function timeLeft(votingEnd: string, now: number): string {
65
+ const remaining = Number(votingEnd) - now;
66
+ if (remaining <= 0) return "Voting closed";
67
+ const minutes = Math.ceil(remaining / 60);
68
+ if (minutes < 60) return `${minutes}m left`;
69
+ const hours = Math.floor(minutes / 60);
70
+ return hours < 48 ? `${hours}h left` : `${Math.floor(hours / 24)}d left`;
71
+ }
72
+
73
+ /**
74
+ * A Guild proposal: its status, what it does if it passes, and the tally against
75
+ * the Guild's requirements, all from chain. `params.title` and `params.summary`
76
+ * are the proposer's own words, shown as such. Members vote with the host's wallet.
77
+ */
78
+ export function GuildProposalRef({ id, size = "large", params, onPress, visible }: RefViewProps) {
79
+ const { theme } = useAppTheme();
80
+ const presentation = usePresentation();
81
+ const proposal = useGuildProposal(id, { visible });
82
+ const data = proposal.data?.data;
83
+ const parts = splitGuildProposalId(id);
84
+ const label = params?.title || `Proposal #${parts?.proposalId ?? id}`;
85
+ const press = onPress ?? (presentation.onOpenContract ? () => presentation.onOpenContract!("guild-proposal", id) : undefined);
86
+ const retry = proposal.isError ? () => void proposal.refetch() : undefined;
87
+
88
+ if (size === "inline") {
89
+ return <InlinePill label={label} dim={proposal.isPending} leading={<UserGroupIcon size={12} color={theme.colors.primary} />} onPress={press} />;
90
+ }
91
+
92
+ if (size === "small") {
93
+ if (proposal.isPending) return <RowSkeleton shape="rounded" />;
94
+ if (!data) return <Unavailable size="small" label={label} Icon={UserGroupIcon} onRetry={retry} />;
95
+ return (
96
+ <Row
97
+ leading={<KindTile Icon={UserGroupIcon} size={40} />}
98
+ title={<Title>{label}</Title>}
99
+ subtitle={`Guild proposal #${data.proposalId} · ${plural(data.actions.length, "action")}`}
100
+ trailing={<StatusBadge label={guildProposalStatusLabel(data.status)} tone={STATUS_TONE[data.status]} />}
101
+ onPress={press}
102
+ accessibilityLabel={`Open guild proposal: ${label}`}
103
+ />
104
+ );
105
+ }
106
+
107
+ if (proposal.isPending) return <CardSkeleton media="rounded" blocks={3} action full={size === "full"} />;
108
+ if (!data) return <Unavailable size={size} label={label} Icon={UserGroupIcon} onRetry={retry} />;
109
+ return (
110
+ <GuildProposalCard
111
+ data={data}
112
+ title={label}
113
+ summary={params?.summary}
114
+ full={size === "full"}
115
+ visible={visible}
116
+ refresh={() => void proposal.refetch()}
117
+ />
118
+ );
119
+ }
120
+
121
+ function TallyBar({ ballot }: { ballot: GuildBallotData }) {
122
+ const { theme, tone, inset } = usePalette();
123
+ const approvals = Number(ballot.votes.approvals);
124
+ const rejections = Number(ballot.votes.rejections);
125
+ const abstains = Number(ballot.votes.abstains);
126
+ const total = approvals + rejections + abstains;
127
+ const share = (n: number) => (total ? `${(n / total) * 100}%` : "0%") as `${number}%`;
128
+ return (
129
+ <View style={[styles.track, { backgroundColor: inset }]} accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
130
+ <View style={{ width: share(approvals), backgroundColor: tone("good") }} />
131
+ <View style={{ width: share(rejections), backgroundColor: tone("bad") }} />
132
+ <View style={{ width: share(abstains), backgroundColor: theme.colors.textDim }} />
133
+ </View>
134
+ );
135
+ }
136
+
137
+ function GuildProposalCard({
138
+ data,
139
+ title,
140
+ summary,
141
+ full,
142
+ visible,
143
+ refresh,
144
+ }: {
145
+ data: GuildProposalData;
146
+ title: string;
147
+ summary?: string;
148
+ full: boolean;
149
+ visible?: boolean;
150
+ refresh: () => void;
151
+ }) {
152
+ const { theme, tone } = usePalette();
153
+ const presentation = usePresentation();
154
+ const actions = presentation.actions;
155
+ const now = useNow(60_000, data.status === "voting");
156
+ const [busy, setBusy] = useState<CardAction>();
157
+ const [error, setError] = useState<string>();
158
+ const [voted, setVoted] = useState<GuildVoteChoice>();
159
+ const ballot = data.ballot;
160
+ const outcome = ballot ? guildBallotOutcome(ballot, now) : undefined;
161
+ const blocked = presentation.guildActionBlock?.(data.guildAppId);
162
+ const open = data.status === "voting" && !!ballot && !ballot.resolved;
163
+ const canVote = open && outcome === undefined && now <= Number(ballot!.votingEnd) && !!actions?.guildVote;
164
+ const canFinalize = open && outcome !== undefined && !!actions?.guildFinalize;
165
+ const canExecute = data.status === "approved" && !!actions?.guildExecute;
166
+ const canSubmit =
167
+ data.status === "draft" && !!data.creator && data.creator === presentation.viewerAddress && !!actions?.guildSubmit;
168
+ const statusLabel = canFinalize ? (outcome === "approved" ? "Passing" : "Failing") : guildProposalStatusLabel(data.status);
169
+ const statusTone: Tone = canFinalize ? (outcome === "approved" ? "good" : "bad") : STATUS_TONE[data.status];
170
+
171
+ const run = async (action: CardAction) => {
172
+ if (busy || blocked) return;
173
+ setBusy(action);
174
+ setError(undefined);
175
+ try {
176
+ const { guildAppId, proposalId } = data;
177
+ if (action === "approve" || action === "reject" || action === "abstain") {
178
+ await actions?.guildVote?.(guildAppId, proposalId, action);
179
+ setVoted(action);
180
+ } else if (action === "submit") await actions?.guildSubmit?.(guildAppId, proposalId);
181
+ else if (action === "finalize") await actions?.guildFinalize?.(guildAppId, proposalId);
182
+ else await actions?.guildExecute?.(guildAppId, proposalId);
183
+ refresh();
184
+ } catch (cause) {
185
+ setError(cause instanceof Error ? cause.message : "The guild transaction failed.");
186
+ } finally {
187
+ setBusy(undefined);
188
+ }
189
+ };
190
+
191
+ return (
192
+ <Card>
193
+ <CardHeader
194
+ media={<KindTile Icon={UserGroupIcon} size={headerMedia(full)} />}
195
+ title={title}
196
+ titleLines={3}
197
+ full={full}
198
+ status={<StatusBadge label={statusLabel} tone={statusTone} />}
199
+ meta={`Guild proposal #${data.proposalId}${data.created && data.created !== "0" ? ` · ${formatRelativeTime(Number(data.created))}` : ""}`}
200
+ />
201
+
202
+ {summary ? (
203
+ <Text size="xs" numberOfLines={full ? undefined : 6} style={{ color: theme.colors.textDim }}>
204
+ {summary}
205
+ </Text>
206
+ ) : null}
207
+
208
+ {data.actions.length ? (
209
+ <Section label={data.actions.length === 1 ? "If it passes" : `If it passes · ${data.actions.length} actions`}>
210
+ <View style={{ gap: 6 }}>
211
+ {data.actions.map((action, i) => (
212
+ <View key={`${action.type}:${i}`} style={{ gap: 6 }}>
213
+ <View style={styles.actionRow}>
214
+ <View style={[styles.dot, { backgroundColor: theme.colors.primary }]} />
215
+ <Text size="xs" style={{ flex: 1 }}>
216
+ {action.label}
217
+ {action.pluginAppId ? ` #${action.pluginAppId}` : ""}
218
+ {action.caller === GUILD_ZERO_ADDRESS ? " for members by vote" : ""}
219
+ </Text>
220
+ </View>
221
+ {action.caller && action.caller !== GUILD_ZERO_ADDRESS ? (
222
+ <PersonRow address={action.caller} role={action.type === 40 ? "Loses the plugin" : "Gets the plugin"} visible={visible} />
223
+ ) : null}
224
+ </View>
225
+ ))}
226
+ </View>
227
+ </Section>
228
+ ) : null}
229
+
230
+ {ballot ? (
231
+ <View style={{ gap: 6 }}>
232
+ <TallyBar ballot={ballot} />
233
+ <View style={styles.legend}>
234
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
235
+ {`${ballot.votes.approvals} yes · ${ballot.votes.rejections} no · ${ballot.votes.abstains} abstain`}
236
+ </Text>
237
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
238
+ {ballot.resolved ? "Closed" : timeLeft(ballot.votingEnd, now)}
239
+ </Text>
240
+ </View>
241
+ {guildRequirementsText(ballot) ? <Note>{guildRequirementsText(ballot)}</Note> : null}
242
+ </View>
243
+ ) : null}
244
+
245
+ {blocked ? (
246
+ <Note tone="warn">{blocked}</Note>
247
+ ) : busy ? (
248
+ <Note>{PROGRESS[busy]}</Note>
249
+ ) : voted && canVote ? (
250
+ <Text size="xs" weight="semiBold" style={{ color: tone("good") }}>
251
+ {VOTED[voted]}
252
+ </Text>
253
+ ) : canVote ? (
254
+ <View style={styles.buttons}>
255
+ <View style={styles.flex}>
256
+ <ActionButton label="Yes" onPress={() => void run("approve")} accessibilityLabel="Vote yes" />
257
+ </View>
258
+ <View style={styles.flex}>
259
+ <ActionButton label="No" variant="secondary" onPress={() => void run("reject")} accessibilityLabel="Vote no" />
260
+ </View>
261
+ <View style={styles.flex}>
262
+ <ActionButton label="Abstain" variant="secondary" onPress={() => void run("abstain")} />
263
+ </View>
264
+ </View>
265
+ ) : canFinalize ? (
266
+ <ActionButton label="Close the vote" onPress={() => void run("finalize")} />
267
+ ) : canExecute ? (
268
+ <ActionButton label="Carry it out" onPress={() => void run("execute")} />
269
+ ) : canSubmit ? (
270
+ <ActionButton label="Open voting" onPress={() => void run("submit")} />
271
+ ) : null}
272
+
273
+ {error ? <Note tone="bad">{error}</Note> : null}
274
+ </Card>
275
+ );
276
+ }
277
+
278
+ const styles = StyleSheet.create({
279
+ track: { borderRadius: 3, flexDirection: "row", height: 6, overflow: "hidden" },
280
+ legend: { flexDirection: "row", justifyContent: "space-between", gap: 12 },
281
+ actionRow: { alignItems: "flex-start", flexDirection: "row", gap: 8 },
282
+ dot: { borderRadius: 3, height: 6, marginTop: 6, width: 6 },
283
+ buttons: { flexDirection: "row", gap: 8 },
284
+ flex: { flex: 1 },
285
+ });
@@ -0,0 +1,82 @@
1
+ import React, { createContext, useContext } from "react";
2
+ import { Pressable } from "react-native";
3
+ import { formatRelativeTime } from "@akita-protocol/algomd-core";
4
+ import { usePrivateContent } from "@akita-protocol/algomd-core/react";
5
+ import { ChevronRightIcon, OutlineDocumentTextIcon, OutlineLockClosedIcon } from "../presentation/icons";
6
+ import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
7
+ import { CreatorIdentity } from "./AccountRef";
8
+ import { Card, CardHeader, headerMedia, InlinePill, KindTile, Note, Row, Title } from "./primitives";
9
+ import type { RefViewProps } from "./types";
10
+
11
+ // ---------------------------------------------------------------- page cards
12
+
13
+ /** Pages of the post being rendered. Page cards link to them. */
14
+ export interface PageLinks {
15
+ preview?: (path: string) => string | undefined;
16
+ open?: (path: string) => void;
17
+ }
18
+
19
+ const PageContext = createContext<PageLinks>({});
20
+ export const PageLinksProvider = PageContext.Provider;
21
+
22
+ /** A link to another page of the same post. Title is the author's label. */
23
+ export function PageCardRef({ id: path, size = "large", params, onPress }: RefViewProps) {
24
+ const { theme } = useAppTheme();
25
+ const pages = useContext(PageContext);
26
+ const title = params?.title || "Linked page";
27
+ const preview = pages.preview?.(path);
28
+ const press = onPress ?? (pages.open ? () => pages.open!(path) : undefined);
29
+ if (size === "inline") return <InlinePill label={title} leading={<OutlineDocumentTextIcon size={12} color={theme.colors.primary} />} onPress={press} />;
30
+ if (size === "small") {
31
+ return <Row leading={<KindTile Icon={OutlineDocumentTextIcon} size={36} />} title={<Title>{title}</Title>} subtitle={preview} onPress={press} />;
32
+ }
33
+ const full = size === "full";
34
+ return (
35
+ <Pressable disabled={!press} onPress={press} accessibilityRole={press ? "link" : undefined}>
36
+ <Card>
37
+ <CardHeader
38
+ media={<KindTile Icon={OutlineDocumentTextIcon} size={headerMedia(full)} />}
39
+ title={title}
40
+ full={full}
41
+ meta="Page in this post"
42
+ menu={press ? <ChevronRightIcon size={16} color={theme.colors.textDim} /> : null}
43
+ />
44
+ {preview ? (
45
+ <Text size="sm" numberOfLines={full ? 6 : 2} style={{ color: theme.colors.textDim }}>
46
+ {preview}
47
+ </Text>
48
+ ) : null}
49
+ </Card>
50
+ </Pressable>
51
+ );
52
+ }
53
+
54
+ // ---------------------------------------------------------------- private content
55
+
56
+ /**
57
+ * Encrypted content. Unlocking needs the viewer's keys, so the host renders it
58
+ * through `renderPrivateContent`. Without that, the public metadata shows.
59
+ */
60
+ export function PrivateContentRef({ id, size = "large", params, visible }: RefViewProps) {
61
+ const { theme } = useAppTheme();
62
+ const presentation = usePresentation();
63
+ const title = params?.title;
64
+ const meta = usePrivateContent(presentation.renderPrivateContent ? undefined : id, { visible });
65
+ if (presentation.renderPrivateContent) return <>{presentation.renderPrivateContent(id, title, size)}</>;
66
+
67
+ const label = title || "Private content";
68
+ if (size === "inline") return <InlinePill label={label} leading={<OutlineLockClosedIcon size={12} color={theme.colors.primary} />} />;
69
+ const data = meta.data?.data ?? undefined;
70
+ const detail = [data?.ciphertextSize ? `${Math.max(1, Math.round(data.ciphertextSize / 1024))} KB` : undefined, data?.createdAt ? formatRelativeTime(Math.floor(data.createdAt / (data.createdAt > 1e12 ? 1000 : 1))) : undefined]
71
+ .filter(Boolean)
72
+ .join(" · ");
73
+ if (size === "small") return <Row leading={<KindTile Icon={OutlineLockClosedIcon} size={36} />} title={<Title>{label}</Title>} subtitle={detail || "Locked"} />;
74
+ const full = size === "full";
75
+ return (
76
+ <Card>
77
+ <CardHeader media={<KindTile Icon={OutlineLockClosedIcon} size={headerMedia(full)} />} title={label} full={full} meta={detail ? `Locked · ${detail}` : "Locked"} />
78
+ {data?.authorAddress ? <CreatorIdentity address={data.authorAddress} label="Author" visible={visible} /> : null}
79
+ <Note>Only viewers the author granted access can unlock this.</Note>
80
+ </Card>
81
+ );
82
+ }
@@ -0,0 +1,90 @@
1
+ import React from "react";
2
+ import { View } from "react-native";
3
+ import { formatRelativeTime, type ListingData } from "@akita-protocol/algomd-core";
4
+ import { useListing } from "@akita-protocol/algomd-core/react";
5
+ import { ContractMenu } from "../presentation/ContractMenu";
6
+ import { TagIcon } from "../presentation/icons";
7
+ import { usePresentation } from "../presentation/runtime";
8
+ import { PersonRow } from "./AccountRef";
9
+ import { useFormattedAmount } from "./assetInfo";
10
+ import { ActionButton, percent, PriceBlock, PrizeThumb, ProvenanceNote, StatusChip, usePrizeLabel } from "./contractParts";
11
+ import { Card, CardHeader, CardSkeleton, DetailLine, headerMedia, InlinePill, Row, RowSkeleton, Title, Unavailable } from "./primitives";
12
+ import type { RefViewProps } from "./types";
13
+
14
+ /** A marketplace listing: live from algod, or its final state after the app was deleted. */
15
+ export function ListingRef({ id, size = "large", onPress, visible }: RefViewProps) {
16
+ const presentation = usePresentation();
17
+ const listing = useListing(id, { visible });
18
+ const data = listing.data?.data as ListingData | undefined;
19
+ const prizeName = usePrizeLabel(data?.prize, data?.isPrizeBox);
20
+ const price = useFormattedAmount(data?.price, data?.paymentAsset);
21
+ const press = onPress ?? (presentation.onOpenContract ? () => presentation.onOpenContract!("listing", id) : undefined);
22
+ const buy = presentation.actions?.buyListing;
23
+ const sold = data?.status === "sold";
24
+ const retry = listing.isError ? () => void listing.refetch() : undefined;
25
+
26
+ if (size === "inline") {
27
+ return (
28
+ <InlinePill
29
+ label={data ? `${prizeName} · ${sold ? "sold" : price}` : `Listing ${id}`}
30
+ dim={listing.isPending}
31
+ leading={data ? <PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={16} /> : null}
32
+ onPress={press}
33
+ />
34
+ );
35
+ }
36
+
37
+ if (size === "small") {
38
+ if (listing.isPending) return <RowSkeleton shape="rounded" />;
39
+ if (!data) return <Unavailable size="small" label={`Listing ${id}`} Icon={TagIcon} onRetry={retry} />;
40
+ return (
41
+ <Row
42
+ leading={<PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={40} />}
43
+ title={<Title>{prizeName}</Title>}
44
+ subtitle={sold ? `Sold for ${price}` : price}
45
+ trailing={<StatusChip status={data.status} />}
46
+ onPress={press}
47
+ accessibilityLabel={`Open listing for ${prizeName}`}
48
+ />
49
+ );
50
+ }
51
+
52
+ const full = size === "full";
53
+ if (listing.isPending) return <CardSkeleton media="rounded" value blocks={full ? 2 : 1} action full={full} />;
54
+ if (!data) return <Unavailable size={size} label={`Listing ${id}`} Icon={TagIcon} onRetry={retry} />;
55
+ const active = data.status === "active";
56
+
57
+ return (
58
+ <Card>
59
+ <CardHeader
60
+ media={<PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={headerMedia(full)} />}
61
+ title={prizeName}
62
+ full={full}
63
+ status={<StatusChip status={data.status} />}
64
+ meta={sold && data.closedAt ? `Sold ${formatRelativeTime(data.closedAt)}` : `Listing #${id}`}
65
+ menu={<ContractMenu appId={id} type="application" embedType="NFTListing" />}
66
+ />
67
+
68
+ <PriceBlock label={sold ? "Sold for" : active ? "For sale" : "Price"} amount={data.price} assetId={data.paymentAsset} live={active} />
69
+
70
+ <View style={{ gap: 8 }}>
71
+ {full && data.reservedFor ? <PersonRow address={data.reservedFor} role="Reserved for" roleTone="warn" visible={visible} /> : null}
72
+ {sold && data.buyer ? <PersonRow address={data.buyer} role="Buyer" visible={visible} /> : null}
73
+ <PersonRow address={data.seller} role="Seller" visible={visible} />
74
+ </View>
75
+
76
+ {full ? (
77
+ <View>
78
+ {data.expiration !== "0" ? <DetailLine label={active ? "Expires" : "Expired"}>{formatRelativeTime(Number(data.expiration))}</DetailLine> : null}
79
+ <DetailLine label="Creator royalty">{percent(data.creatorRoyalty)}</DetailLine>
80
+ <DetailLine label="Marketplace fee">{percent(data.marketplaceRoyalties)}</DetailLine>
81
+ {data.gateId !== "0" ? <DetailLine label="Buyers need">{`Gate ${data.gateId}`}</DetailLine> : null}
82
+ {data.closeTxId ? <DetailLine label="Closing transaction">{`${data.closeTxId.slice(0, 8)}…`}</DetailLine> : null}
83
+ </View>
84
+ ) : null}
85
+
86
+ <ProvenanceNote entity={listing.data} />
87
+ {active && buy ? <ActionButton label={data.isPrizeBox ? "Buy bundle" : "Buy collectible"} onPress={() => buy(id)} /> : null}
88
+ </Card>
89
+ );
90
+ }
@@ -0,0 +1,96 @@
1
+ import React from "react";
2
+ import { formatAlgo, formatRelativeTime, shortAddress } from "@akita-protocol/algomd-core";
3
+ import { useNfd } from "@akita-protocol/algomd-core/react";
4
+ import { ContractMenu } from "../presentation/ContractMenu";
5
+ import { AtSymbolIcon } from "../presentation/icons";
6
+ import { Text, usePresentation } from "../presentation/runtime";
7
+ import { PersonRow } from "./AccountRef";
8
+ import { PriceBlock } from "./contractParts";
9
+ import {
10
+ Avatar,
11
+ Card,
12
+ CardHeader,
13
+ CardSkeleton,
14
+ DetailLine,
15
+ headerMedia,
16
+ InlinePill,
17
+ Inset,
18
+ Row,
19
+ RowSkeleton,
20
+ Section,
21
+ StatusBadge,
22
+ Title,
23
+ Unavailable,
24
+ } from "./primitives";
25
+ import type { RefViewProps } from "./types";
26
+
27
+ const title = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
28
+
29
+ /** An NFD by name, at any size. */
30
+ export function NfdRef({ id, size = "large", onPress, visible }: RefViewProps) {
31
+ const presentation = usePresentation();
32
+ const nfd = useNfd(id, { visible });
33
+ const data = nfd.data?.data;
34
+ const name = data?.name ?? id;
35
+ const press = onPress ?? (presentation.onOpenNfd ? () => presentation.onOpenNfd!(name) : undefined);
36
+ const forSale = data?.state === "forSale" && data.sellAmount;
37
+ const retry = nfd.isError ? () => void nfd.refetch() : undefined;
38
+ const category = data?.category && data.category !== "common" ? title(data.category) : undefined;
39
+
40
+ if (size === "inline") {
41
+ return <InlinePill label={name} dim={nfd.isPending} leading={<Avatar uri={data?.avatar} size={16} initial={name} />} onPress={press} />;
42
+ }
43
+
44
+ if (size === "small") {
45
+ if (nfd.isPending) return <RowSkeleton />;
46
+ if (!data) return <Unavailable size="small" label={name} Icon={AtSymbolIcon} detail="No NFD has this name." onRetry={retry} />;
47
+ return (
48
+ <Row
49
+ leading={<Avatar uri={data.avatar} size={36} initial={name} />}
50
+ title={<Title>{name}</Title>}
51
+ subtitle={forSale ? `For sale · ${formatAlgo(data.sellAmount!, { maxFraction: 2 })} ALGO` : data.owner ? `Owned by ${shortAddress(data.owner)}` : title(data.state ?? "")}
52
+ trailing={category ? <StatusBadge label={category} /> : undefined}
53
+ onPress={press}
54
+ accessibilityLabel={`Open ${name}`}
55
+ />
56
+ );
57
+ }
58
+
59
+ const full = size === "full";
60
+ if (nfd.isPending) return <CardSkeleton blocks={1} full={full} />;
61
+ if (!data) return <Unavailable size={size} label={name} Icon={AtSymbolIcon} detail="No NFD has this name." onRetry={retry} />;
62
+
63
+ return (
64
+ <Card>
65
+ <CardHeader
66
+ media={<Avatar uri={data.avatar} size={headerMedia(full)} initial={name} />}
67
+ title={name}
68
+ titleLines={1}
69
+ full={full}
70
+ status={forSale ? <StatusBadge label="For sale" tone="good" /> : category ? <StatusBadge label={category} /> : undefined}
71
+ meta={data.expires ? `Expires ${formatRelativeTime(data.expires)}` : undefined}
72
+ menu={<ContractMenu appId={data.appId ?? name} type="application" embedType="NFDProfile" embedProp="name" embedValue={name} />}
73
+ />
74
+ {forSale ? <PriceBlock label="For sale" amount={data.sellAmount!} assetId="0" live /> : null}
75
+ {data.owner ? <PersonRow address={data.owner} role="Owner" visible={visible} /> : null}
76
+ {full ? (
77
+ <>
78
+ {data.depositAccount && data.depositAccount !== data.owner ? <PersonRow address={data.depositAccount} role="Receives payments" visible={visible} /> : null}
79
+ {data.verifiedAddresses.length ? (
80
+ <Section label={`Verified addresses · ${data.verifiedAddresses.length}`}>
81
+ <Inset>
82
+ {data.verifiedAddresses.map((a) => (
83
+ <DetailLine key={a} label={a === data.owner ? "Owner" : a === data.depositAccount ? "Payments" : "Linked"}>
84
+ <Text size="xs" weight="medium" selectable numberOfLines={1}>
85
+ {shortAddress(a, 6, 6)}
86
+ </Text>
87
+ </DetailLine>
88
+ ))}
89
+ </Inset>
90
+ </Section>
91
+ ) : null}
92
+ </>
93
+ ) : null}
94
+ </Card>
95
+ );
96
+ }
@@ -0,0 +1,120 @@
1
+ import React, { useState } from "react";
2
+ import { Pressable, StyleSheet, View } from "react-native";
3
+ import { formatRelativeTime, type PollData } from "@akita-protocol/algomd-core";
4
+ import { usePoll } from "@akita-protocol/algomd-core/react";
5
+ import { ContractMenu } from "../presentation/ContractMenu";
6
+ import { ChartBarIcon } from "../presentation/icons";
7
+ import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
8
+ import { ActionButton, plural, ProvenanceNote, StatusChip } from "./contractParts";
9
+ import { Card, CardHeader, CardSkeleton, DetailLine, headerMedia, InlinePill, KindTile, Note, Row, RowSkeleton, Title, Unavailable, usePalette } from "./primitives";
10
+ import type { RefViewProps } from "./types";
11
+
12
+ /** A poll: live tallies, or the final tallies after the app was deleted. */
13
+ export function PollRef({ id, size = "large", onPress, visible }: RefViewProps) {
14
+ const { theme } = useAppTheme();
15
+ const presentation = usePresentation();
16
+ const poll = usePoll(id, { visible });
17
+ const data = poll.data?.data as PollData | undefined;
18
+ const press = onPress ?? (presentation.onOpenContract ? () => presentation.onOpenContract!("poll", id) : undefined);
19
+ const retry = poll.isError ? () => void poll.refetch() : undefined;
20
+
21
+ if (size === "inline") {
22
+ return <InlinePill label={data?.question || `Poll ${id}`} dim={poll.isPending} leading={<ChartBarIcon size={12} color={theme.colors.primary} />} onPress={press} />;
23
+ }
24
+
25
+ if (size === "small") {
26
+ if (poll.isPending) return <RowSkeleton shape="rounded" />;
27
+ if (!data) return <Unavailable size="small" label={`Poll ${id}`} Icon={ChartBarIcon} onRetry={retry} />;
28
+ const end = Number(data.endTime);
29
+ return (
30
+ <Row
31
+ leading={<KindTile Icon={ChartBarIcon} size={40} />}
32
+ title={<Title>{data.question}</Title>}
33
+ subtitle={`${plural(data.totalVotes, "vote")} · ${data.status === "active" ? `ends ${formatRelativeTime(end)}` : `ended ${formatRelativeTime(end)}`}`}
34
+ trailing={<StatusChip status={data.status} />}
35
+ onPress={press}
36
+ accessibilityLabel={`Open poll: ${data.question}`}
37
+ />
38
+ );
39
+ }
40
+
41
+ if (poll.isPending) return <CardSkeleton media="rounded" blocks={3} full={size === "full"} />;
42
+ if (!data) return <Unavailable size={size} label={`Poll ${id}`} Icon={ChartBarIcon} onRetry={retry} />;
43
+ return <PollCard id={id} data={data} full={size === "full"} entity={poll.data} />;
44
+ }
45
+
46
+ function PollCard({ id, data, full, entity }: { id: string; data: PollData; full: boolean; entity: Parameters<typeof ProvenanceNote>[0]["entity"] }) {
47
+ const { theme, inset, tone } = usePalette();
48
+ const vote = usePresentation().actions?.vote;
49
+ const [picked, setPicked] = useState<number[]>([]);
50
+ const total = Number(data.totalVotes) || 0;
51
+ const max = Math.max(1, Number(data.maxSelected) || 1);
52
+ const canVote = data.status === "active" && Boolean(vote);
53
+ const leader = Math.max(0, ...data.options.map((o) => Number(o.votes)));
54
+
55
+ const toggle = (i: number) =>
56
+ setPicked((p) => (p.includes(i) ? p.filter((x) => x !== i) : max === 1 ? [i] : p.length < max ? [...p, i] : p));
57
+
58
+ return (
59
+ <Card>
60
+ <CardHeader
61
+ media={<KindTile Icon={ChartBarIcon} size={headerMedia(full)} />}
62
+ title={data.question}
63
+ titleLines={4}
64
+ full={full}
65
+ status={<StatusChip status={data.status} />}
66
+ meta={`${data.status === "active" ? "Ends" : "Ended"} ${formatRelativeTime(Number(data.endTime))}`}
67
+ menu={<ContractMenu appId={id} type="application" embedType="Poll" />}
68
+ />
69
+
70
+ <View style={{ gap: 8 }}>
71
+ {data.options.map((o, i) => {
72
+ const votes = Number(o.votes);
73
+ const share = total ? votes / total : 0;
74
+ const selected = picked.includes(i);
75
+ const winning = data.status !== "active" && votes === leader && votes > 0;
76
+ return (
77
+ <Pressable
78
+ key={i}
79
+ disabled={!canVote}
80
+ onPress={() => toggle(i)}
81
+ accessibilityRole={canVote ? "checkbox" : undefined}
82
+ accessibilityState={canVote ? { checked: selected } : undefined}
83
+ style={[styles.option, { backgroundColor: selected ? `${theme.colors.primary}2E` : inset }]}
84
+ >
85
+ <View style={[styles.bar, { width: `${share * 100}%`, backgroundColor: winning ? `${tone("good")}2E` : selected ? `${theme.colors.primary}26` : `${theme.colors.textDim}1F` }]} />
86
+ <Text size="xs" weight={winning || selected ? "bold" : "medium"} numberOfLines={2} style={{ flex: 1 }}>
87
+ {o.label}
88
+ </Text>
89
+ <Text size="xs" weight="bold" style={{ color: winning ? tone("good") : theme.colors.textDim }}>
90
+ {total ? `${Math.round(share * 100)}%` : "0%"}
91
+ </Text>
92
+ </Pressable>
93
+ );
94
+ })}
95
+ </View>
96
+
97
+ <Note>
98
+ {`${plural(data.totalVotes, "vote")}${data.voters !== undefined ? ` from ${plural(data.voters, "voter")}` : ""}${max > 1 ? ` · pick up to ${max}` : ""}${canVote && !picked.length ? " · tap an option to vote" : ""}`}
99
+ </Note>
100
+
101
+ {full && data.gateId !== "0" ? <DetailLine label="Voters need">{`Gate ${data.gateId}`}</DetailLine> : null}
102
+
103
+ <ProvenanceNote entity={entity} />
104
+ {canVote && picked.length ? <ActionButton label={picked.length > 1 ? `Vote for ${picked.length} options` : "Vote"} onPress={() => vote!(id, picked)} /> : null}
105
+ </Card>
106
+ );
107
+ }
108
+
109
+ const styles = StyleSheet.create({
110
+ option: {
111
+ alignItems: "center",
112
+ borderRadius: 10,
113
+ flexDirection: "row",
114
+ gap: 8,
115
+ overflow: "hidden",
116
+ paddingHorizontal: 12,
117
+ paddingVertical: 10,
118
+ },
119
+ bar: { bottom: 0, left: 0, position: "absolute", top: 0 },
120
+ });