@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,310 @@
1
+ import React, { Component, type ReactNode, type ErrorInfo } from "react";
2
+ import {
3
+ View,
4
+ Text as RNText,
5
+ Pressable,
6
+ Image,
7
+ ActivityIndicator,
8
+ useWindowDimensions,
9
+ type ViewStyle,
10
+ } from "react-native";
11
+ import { Text, useAppTheme } from "./runtime";
12
+ import { ContractMenu } from "./ContractMenu";
13
+ import { OnChainStateCard } from "./OnChainActionCard";
14
+ const LOADING_FALLBACK_HEIGHTS: Partial<Record<string, number>> = {
15
+ Account: 148,
16
+ ASA: 148,
17
+ "NFD Profile": 148,
18
+ Poll: 236,
19
+ Collection: 108,
20
+ "Collectible Listing": 380,
21
+ Raffle: 430,
22
+ Auction: 440,
23
+ "Trade Offer": 240,
24
+ };
25
+
26
+ const FULLSCREEN_LOADING_FOOTPRINT = 0.56;
27
+
28
+ export function LoadingFallback({
29
+ name,
30
+ fullscreen = false,
31
+ }: {
32
+ name: string;
33
+ fullscreen?: boolean;
34
+ }) {
35
+ const { theme } = useAppTheme();
36
+ const { height: windowHeight } = useWindowDimensions();
37
+ const baseMinHeight = LOADING_FALLBACK_HEIGHTS[name] ?? 160;
38
+ const minHeight = fullscreen
39
+ ? Math.max(
40
+ baseMinHeight,
41
+ Math.round(windowHeight * FULLSCREEN_LOADING_FOOTPRINT),
42
+ )
43
+ : baseMinHeight;
44
+
45
+ return (
46
+ <View
47
+ style={{
48
+ backgroundColor: theme.colors.accentBackground,
49
+ borderRadius: 16,
50
+ padding: 16,
51
+ alignItems: "center",
52
+ justifyContent: "center",
53
+ alignSelf: "stretch",
54
+ width: "100%",
55
+ minHeight,
56
+ }}
57
+ >
58
+ <ActivityIndicator size="small" color={theme.colors.textDim} />
59
+ <Text size="xxs" style={{ color: theme.colors.textDim, marginTop: 8 }}>
60
+ Loading {name}...
61
+ </Text>
62
+ </View>
63
+ );
64
+ }
65
+
66
+ export function ErrorFallback({
67
+ name,
68
+ message,
69
+ appId,
70
+ embedType,
71
+ onRetry,
72
+ snapshotTitle,
73
+ }: {
74
+ name: string;
75
+ message?: string;
76
+ appId?: string | number;
77
+ embedType?: React.ComponentProps<typeof ContractMenu>["embedType"];
78
+ onRetry?: () => void;
79
+ snapshotTitle?: string;
80
+ }) {
81
+ return (
82
+ <OnChainStateCard
83
+ appId={appId}
84
+ title={snapshotTitle || name}
85
+ stateLabel={snapshotTitle ? `${name} snapshot` : `${name} unavailable`}
86
+ detail={
87
+ snapshotTitle
88
+ ? `Live state is unavailable. This saved snapshot may be out of date.${
89
+ message ? ` ${message}` : ""
90
+ }`
91
+ : message
92
+ }
93
+ onRetry={onRetry}
94
+ menu={
95
+ appId ? <ContractMenu appId={appId} embedType={embedType} /> : undefined
96
+ }
97
+ />
98
+ );
99
+ }
100
+
101
+ export function ClosedListingFallback({ appId }: { appId?: number }) {
102
+ const { theme } = useAppTheme();
103
+ return (
104
+ <View
105
+ style={{
106
+ backgroundColor: theme.colors.accentBackground,
107
+ borderRadius: 16,
108
+ padding: 16,
109
+ borderWidth: 1,
110
+ borderColor: `${theme.colors.textDim}30`,
111
+ minHeight: 96,
112
+ justifyContent: "center",
113
+ }}
114
+ >
115
+ <Text size="xs" weight="semiBold" style={{ color: theme.colors.text }}>
116
+ Collectible Listing Closed
117
+ </Text>
118
+ <Text size="xxs" style={{ color: theme.colors.textDim, marginTop: 4 }}>
119
+ This listing is no longer active{appId ? ` (#${appId})` : ""}.
120
+ </Text>
121
+ </View>
122
+ );
123
+ }
124
+
125
+ /**
126
+ * A pill nested in text is laid out as an inline view. Centre it on the line, as
127
+ * the web renderer does, instead of letting it sit on the text baseline.
128
+ */
129
+ const INLINE_PILL_STYLE = { verticalAlign: "middle" } as unknown as ViewStyle;
130
+
131
+ export function CompactPill({
132
+ label,
133
+ inline,
134
+ onPress,
135
+ }: {
136
+ label: string;
137
+ inline?: boolean;
138
+ onPress?: () => void;
139
+ }) {
140
+ const { theme } = useAppTheme();
141
+ const content = (
142
+ <View
143
+ style={{
144
+ backgroundColor: theme.colors.accentBackground,
145
+ borderRadius: 9999,
146
+ paddingHorizontal: 8,
147
+ height: 22,
148
+ justifyContent: "center",
149
+ ...(inline ? INLINE_PILL_STYLE : { alignSelf: "flex-start" }),
150
+ }}
151
+ >
152
+ <RNText
153
+ style={{ color: theme.colors.text, fontSize: 11, fontWeight: "500" }}
154
+ numberOfLines={1}
155
+ >
156
+ {label}
157
+ </RNText>
158
+ </View>
159
+ );
160
+
161
+ if (!onPress) return content;
162
+
163
+ return (
164
+ <Pressable
165
+ accessibilityRole="link"
166
+ accessibilityLabel={`Open ${label}`}
167
+ onPress={onPress}
168
+ style={({ pressed }) => [
169
+ inline ? INLINE_PILL_STYLE : { alignSelf: "flex-start" },
170
+ pressed && { opacity: 0.82 },
171
+ ]}
172
+ >
173
+ {content}
174
+ </Pressable>
175
+ );
176
+ }
177
+
178
+ export function CompactPillWithImage({
179
+ label,
180
+ imageUrl,
181
+ inline,
182
+ onPress,
183
+ }: {
184
+ label: string;
185
+ imageUrl?: string;
186
+ inline?: boolean;
187
+ onPress?: () => void;
188
+ }) {
189
+ const { theme } = useAppTheme();
190
+ const content = (
191
+ <View
192
+ style={{
193
+ backgroundColor: theme.colors.accentBackground,
194
+ borderRadius: 9999,
195
+ paddingHorizontal: 6,
196
+ height: 22,
197
+ flexDirection: "row",
198
+ alignItems: "center",
199
+ gap: 3,
200
+ ...(inline ? INLINE_PILL_STYLE : { alignSelf: "flex-start" }),
201
+ }}
202
+ >
203
+ {imageUrl && (
204
+ <Image
205
+ source={{ uri: imageUrl }}
206
+ style={{ width: 14, height: 14, borderRadius: 7 }}
207
+ />
208
+ )}
209
+ <RNText
210
+ style={{ color: theme.colors.text, fontSize: 11, fontWeight: "500" }}
211
+ numberOfLines={1}
212
+ >
213
+ {label}
214
+ </RNText>
215
+ </View>
216
+ );
217
+
218
+ if (!onPress) return content;
219
+
220
+ return (
221
+ <Pressable
222
+ accessibilityRole="link"
223
+ accessibilityLabel={`Open ${label}`}
224
+ onPress={onPress}
225
+ style={({ pressed }) => [
226
+ inline ? INLINE_PILL_STYLE : { alignSelf: "flex-start" },
227
+ pressed && { opacity: 0.82 },
228
+ ]}
229
+ >
230
+ {content}
231
+ </Pressable>
232
+ );
233
+ }
234
+
235
+ /** Inline references render the same pill as small ones; inside text it flows as an inline view. */
236
+ export function CompactLoadingPill(_props: { inline?: boolean }) {
237
+ const { theme } = useAppTheme();
238
+ return (
239
+ <View
240
+ style={{
241
+ backgroundColor: theme.colors.accentBackground,
242
+ borderRadius: 4,
243
+ paddingHorizontal: 8,
244
+ height: 20,
245
+ justifyContent: "center",
246
+ }}
247
+ >
248
+ <ActivityIndicator size={10} color={theme.colors.textDim} />
249
+ </View>
250
+ );
251
+ }
252
+
253
+ export function NavigableBlock({
254
+ accessibilityLabel,
255
+ children,
256
+ onPress,
257
+ }: {
258
+ accessibilityLabel: string;
259
+ children: ReactNode;
260
+ onPress?: () => void;
261
+ }) {
262
+ if (!onPress) return <>{children}</>;
263
+
264
+ return (
265
+ <Pressable
266
+ accessibilityRole="link"
267
+ accessibilityLabel={accessibilityLabel}
268
+ onPress={onPress}
269
+ style={({ pressed }) => pressed && { opacity: 0.92 }}
270
+ >
271
+ {children}
272
+ </Pressable>
273
+ );
274
+ }
275
+
276
+ interface ErrorBoundaryState {
277
+ hasError: boolean;
278
+ error: Error | null;
279
+ }
280
+
281
+ export class ComponentErrorBoundary extends Component<
282
+ { name: string; children: ReactNode },
283
+ ErrorBoundaryState
284
+ > {
285
+ state: ErrorBoundaryState = { hasError: false, error: null };
286
+
287
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState {
288
+ return { hasError: true, error };
289
+ }
290
+
291
+ componentDidCatch(error: Error, info: ErrorInfo) {
292
+ console.error(
293
+ `[AlgoMD] ${this.props.name} crashed:`,
294
+ error,
295
+ info.componentStack,
296
+ );
297
+ }
298
+
299
+ render() {
300
+ if (this.state.hasError) {
301
+ return (
302
+ <ErrorFallback
303
+ name={this.props.name}
304
+ message={this.state.error?.message}
305
+ />
306
+ );
307
+ }
308
+ return this.props.children;
309
+ }
310
+ }
@@ -0,0 +1,73 @@
1
+ // Shared AlgoMD presentation. Edit this library source.
2
+ import React from "react";
3
+ import { Image, View } from "react-native";
4
+ import { LockClosedIcon } from "./icons";
5
+ import { IdentityResolver, Text, useAppTheme } from "./runtime";
6
+ import { fallbackAvatar as FALLBACK_AVATAR } from "./assets";
7
+
8
+ /** The button-sized, warning-coloured frame shared by reserved and gate notices. */
9
+ export function noticeFrame(theme: ReturnType<typeof useAppTheme>["theme"]) {
10
+ return {
11
+ alignItems: "center" as const,
12
+ backgroundColor: `${theme.colors.warning}14`,
13
+ borderColor: `${theme.colors.warning}66`,
14
+ borderCurve: "continuous" as const,
15
+ borderRadius: 14,
16
+ borderWidth: 1,
17
+ flexDirection: "row" as const,
18
+ gap: 8,
19
+ justifyContent: "center" as const,
20
+ minHeight: 48,
21
+ paddingHorizontal: 14,
22
+ width: "100%" as const,
23
+ };
24
+ }
25
+
26
+ /**
27
+ * A reserved listing's notice in the warning colour: a button-sized notice naming
28
+ * who it is held for, or a small line above the buy button when it is the viewer.
29
+ */
30
+ export function ReservedNotice({
31
+ address,
32
+ forViewer,
33
+ }: {
34
+ address: string;
35
+ forViewer?: boolean;
36
+ }) {
37
+ const { theme } = useAppTheme();
38
+ const color = theme.colors.warningText;
39
+ const frame = noticeFrame(theme);
40
+
41
+ if (forViewer) {
42
+ return (
43
+ <Text size="xs" weight="semiBold" style={{ color }}>
44
+ Reserved for you
45
+ </Text>
46
+ );
47
+ }
48
+
49
+ return (
50
+ <IdentityResolver address={address}>
51
+ {({ avatarUrl, name }) => (
52
+ <View accessibilityLabel={`Reserved for ${name}`} style={frame}>
53
+ <LockClosedIcon size={14} color={color} />
54
+ <Text size="sm" weight="medium" style={{ color }}>
55
+ Reserved for
56
+ </Text>
57
+ <Image
58
+ source={avatarUrl ? { uri: avatarUrl } : FALLBACK_AVATAR}
59
+ style={{ width: 20, height: 20, borderRadius: 10 }}
60
+ />
61
+ <Text
62
+ size="sm"
63
+ weight="semiBold"
64
+ numberOfLines={1}
65
+ style={{ color, flexShrink: 1 }}
66
+ >
67
+ {name}
68
+ </Text>
69
+ </View>
70
+ )}
71
+ </IdentityResolver>
72
+ );
73
+ }
@@ -0,0 +1,241 @@
1
+ // Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
2
+ import React, { type ReactNode } from "react";
3
+ import { Image, View } from "react-native";
4
+ import { IdentityResolver, Text, useAppTheme } from "./runtime";
5
+ import { fallbackAvatar as FALLBACK_AVATAR } from "./assets";
6
+ import Svg, { Path } from "react-native-svg";
7
+ import { TICKET_PATH, TROPHY_PATH } from "./icons";
8
+
9
+ const GLYPHS = { trophy: TROPHY_PATH, ticket: TICKET_PATH } as const;
10
+
11
+ /** The panel's fill. Opaque, so the trophy's backing matches it exactly. */
12
+ const PANEL_SURFACE = (theme: { colors: { background: string } }) =>
13
+ theme.colors.background;
14
+
15
+ const AVATAR = 36;
16
+ const GLYPH = 18;
17
+ const RING = 2.5;
18
+
19
+ /**
20
+ * A glyph pinned to the avatar's bottom-right like a notification's action
21
+ * glyph: no disc, just the glyph in the kind's colour on a backing of its own
22
+ * outline grown by the ring, in the surface colour, so the avatar never shows
23
+ * through.
24
+ */
25
+ function GlyphMark({
26
+ glyph,
27
+ color,
28
+ ringColor,
29
+ }: {
30
+ glyph: keyof typeof GLYPHS;
31
+ color: string;
32
+ ringColor: string;
33
+ }) {
34
+ const d = GLYPHS[glyph];
35
+ // The glyph draws a 20-unit box at GLYPH px; the ring in those units.
36
+ const ringUnits = (RING * 20) / GLYPH;
37
+ const box = GLYPH + RING * 2;
38
+ const pad = ringUnits;
39
+ return (
40
+ <View
41
+ pointerEvents="none"
42
+ style={{
43
+ position: "absolute",
44
+ right: -3,
45
+ bottom: -3,
46
+ width: box,
47
+ height: box,
48
+ }}
49
+ >
50
+ {/* One drawing, so the backing and the glyph share a coordinate system and the ring is even. */}
51
+ <Svg
52
+ width={box}
53
+ height={box}
54
+ viewBox={`${-pad} ${-pad} ${20 + pad * 2} ${20 + pad * 2}`}
55
+ >
56
+ <Path
57
+ d={d}
58
+ fill={ringColor}
59
+ stroke={ringColor}
60
+ strokeWidth={ringUnits * 2}
61
+ strokeLinejoin="round"
62
+ strokeLinecap="round"
63
+ />
64
+ <Path d={d} fill={color} fillRule="evenodd" clipRule="evenodd" />
65
+ </Svg>
66
+ </View>
67
+ );
68
+ }
69
+
70
+ /** Who won what once a block is over, set apart from the live figures above it. */
71
+ export function ResultsPanel({ children }: { children: ReactNode }) {
72
+ const { theme } = useAppTheme();
73
+ return (
74
+ <View
75
+ style={{
76
+ backgroundColor: PANEL_SURFACE(theme),
77
+ borderRadius: 14,
78
+ paddingHorizontal: 12,
79
+ paddingVertical: 12,
80
+ gap: 12,
81
+ }}
82
+ >
83
+ {children}
84
+ </View>
85
+ );
86
+ }
87
+
88
+ function Amount({
89
+ amount,
90
+ icon,
91
+ caption,
92
+ }: {
93
+ amount?: string;
94
+ icon?: ReactNode;
95
+ caption?: string;
96
+ }) {
97
+ const { theme } = useAppTheme();
98
+ if (!amount && !caption) return null;
99
+ return (
100
+ <View style={{ alignItems: "flex-end", gap: 1, flexShrink: 0 }}>
101
+ {amount ? (
102
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 4 }}>
103
+ {icon}
104
+ <Text size="sm" weight="semiBold" numberOfLines={1}>
105
+ {amount}
106
+ </Text>
107
+ </View>
108
+ ) : null}
109
+ {caption ? (
110
+ <Text size="xxs" style={{ color: theme.colors.textDim }}>
111
+ {caption}
112
+ </Text>
113
+ ) : null}
114
+ </View>
115
+ );
116
+ }
117
+
118
+ export interface ResultWinnerProps {
119
+ address: string;
120
+ /** What they won, e.g. "Won the auction". */
121
+ label: string;
122
+ /** The kind's plugin colour, used for the trophy on the avatar. */
123
+ accent: string;
124
+ /** The glyph pinned to the avatar: a trophy for a sale's winner, a ticket for a raffle's. */
125
+ glyph?: keyof typeof GLYPHS;
126
+ amount?: string;
127
+ amountIcon?: ReactNode;
128
+ amountCaption?: string;
129
+ }
130
+
131
+ export function ResultWinner({
132
+ address,
133
+ label,
134
+ accent,
135
+ glyph = "trophy",
136
+ amount,
137
+ amountIcon,
138
+ amountCaption,
139
+ }: ResultWinnerProps) {
140
+ const { theme } = useAppTheme();
141
+ return (
142
+ <IdentityResolver address={address}>
143
+ {({ avatarUrl, name }) => (
144
+ <View
145
+ accessible
146
+ accessibilityLabel={`${label}: ${name}${amount ? `, ${amount}` : ""}`}
147
+ style={{ flexDirection: "row", alignItems: "center", gap: 10 }}
148
+ >
149
+ <View style={{ width: AVATAR, height: AVATAR }}>
150
+ <Image
151
+ source={avatarUrl ? { uri: avatarUrl } : FALLBACK_AVATAR}
152
+ style={{
153
+ width: AVATAR,
154
+ height: AVATAR,
155
+ borderRadius: AVATAR / 2,
156
+ }}
157
+ />
158
+ <GlyphMark
159
+ glyph={glyph}
160
+ color={accent}
161
+ ringColor={PANEL_SURFACE(theme)}
162
+ />
163
+ </View>
164
+ <View style={{ flex: 1, minWidth: 0, gap: 1 }}>
165
+ <Text size="sm" weight="semiBold" numberOfLines={1}>
166
+ {name}
167
+ </Text>
168
+ <Text
169
+ size="xxs"
170
+ numberOfLines={1}
171
+ style={{ color: theme.colors.textDim }}
172
+ >
173
+ {label}
174
+ </Text>
175
+ </View>
176
+ <Amount amount={amount} icon={amountIcon} caption={amountCaption} />
177
+ </View>
178
+ )}
179
+ </IdentityResolver>
180
+ );
181
+ }
182
+
183
+ export interface ResultPendingProps {
184
+ title: string;
185
+ detail: string;
186
+ accent: string;
187
+ /** The glyph inside the empty seat, in the accent colour. */
188
+ icon: ReactNode;
189
+ amount?: string;
190
+ amountIcon?: ReactNode;
191
+ amountCaption?: string;
192
+ }
193
+
194
+ /** A result still being settled: an empty seat where the winner will go. */
195
+ export function ResultPending({
196
+ title,
197
+ detail,
198
+ accent,
199
+ icon,
200
+ amount,
201
+ amountIcon,
202
+ amountCaption,
203
+ }: ResultPendingProps) {
204
+ const { theme } = useAppTheme();
205
+ return (
206
+ <View
207
+ accessible
208
+ accessibilityLabel={`${title}. ${detail}${amount ? `. ${amount}` : ""}`}
209
+ style={{ flexDirection: "row", alignItems: "center", gap: 10 }}
210
+ >
211
+ <View
212
+ style={{
213
+ width: AVATAR,
214
+ height: AVATAR,
215
+ borderRadius: AVATAR / 2,
216
+ borderWidth: 1.5,
217
+ borderStyle: "dashed",
218
+ borderColor: accent,
219
+ backgroundColor: `${accent}1A`,
220
+ alignItems: "center",
221
+ justifyContent: "center",
222
+ }}
223
+ >
224
+ {icon}
225
+ </View>
226
+ <View style={{ flex: 1, minWidth: 0, gap: 1 }}>
227
+ <Text size="sm" weight="semiBold" numberOfLines={1}>
228
+ {title}
229
+ </Text>
230
+ <Text
231
+ size="xxs"
232
+ numberOfLines={2}
233
+ style={{ color: theme.colors.textDim }}
234
+ >
235
+ {detail}
236
+ </Text>
237
+ </View>
238
+ <Amount amount={amount} icon={amountIcon} caption={amountCaption} />
239
+ </View>
240
+ );
241
+ }
@@ -0,0 +1,70 @@
1
+ // Shared AlgoMD presentation. Edit this library source.
2
+ import React, { useState } from "react";
3
+ import { View, type LayoutChangeEvent } from "react-native";
4
+ import Svg, { Defs, LinearGradient, Path, Stop } from "react-native-svg";
5
+
6
+ export interface SparklineProps {
7
+ /** Values oldest first. Fewer than two draws nothing. */
8
+ values: readonly number[];
9
+ color: string;
10
+ height?: number;
11
+ /** A gradient id unique on the page, so two sparklines never share a fill. */
12
+ id: string;
13
+ }
14
+
15
+ /** A small price line with a soft fill under it, sized to its parent's width. */
16
+ export function Sparkline({ values, color, height = 40, id }: SparklineProps) {
17
+ const [width, setWidth] = useState(0);
18
+ const stroke = 1.75;
19
+ let line = "";
20
+ let area = "";
21
+ if (width > 0 && values.length >= 2) {
22
+ const min = Math.min(...values);
23
+ const max = Math.max(...values);
24
+ // Moves under 1% of the price stay near flat, so a stablecoin's noise is not blown up.
25
+ const mean = values.reduce((sum, value) => sum + value, 0) / values.length;
26
+ const floor = Math.abs(mean) * 0.01;
27
+ const pad = Math.max(0, floor - (max - min)) / 2;
28
+ const low = min - pad;
29
+ const span = max - min + pad * 2 || 1;
30
+ // Keep the stroke inside the box at the extremes.
31
+ const top = stroke;
32
+ const usable = height - stroke * 2;
33
+ const points = values.map((value, index) => [
34
+ (index / (values.length - 1)) * width,
35
+ max === min ? height / 2 : top + (1 - (value - low) / span) * usable,
36
+ ]);
37
+ line = points
38
+ .map(([x, y], index) => `${index ? "L" : "M"}${x.toFixed(1)} ${y.toFixed(1)}`)
39
+ .join(" ");
40
+ area = `${line} L${width} ${height} L0 ${height} Z`;
41
+ }
42
+ const fillId = `algomd-spark-${id}`;
43
+ return (
44
+ <View
45
+ pointerEvents="none"
46
+ style={{ height, width: "100%" }}
47
+ onLayout={(event: LayoutChangeEvent) => setWidth(Math.round(event.nativeEvent.layout.width))}
48
+ >
49
+ {line ? (
50
+ <Svg width={width} height={height}>
51
+ <Defs>
52
+ <LinearGradient id={fillId} x1="0" y1="0" x2="0" y2="1">
53
+ <Stop offset="0" stopColor={color} stopOpacity={0.22} />
54
+ <Stop offset="1" stopColor={color} stopOpacity={0} />
55
+ </LinearGradient>
56
+ </Defs>
57
+ <Path d={area} fill={`url(#${fillId})`} />
58
+ <Path
59
+ d={line}
60
+ fill="none"
61
+ stroke={color}
62
+ strokeWidth={stroke}
63
+ strokeLinejoin="round"
64
+ strokeLinecap="round"
65
+ />
66
+ </Svg>
67
+ ) : null}
68
+ </View>
69
+ );
70
+ }