@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.
- package/README.md +137 -2
- package/package.json +118 -3
- package/src/adapters/index.ts +4 -0
- package/src/adapters/txn-graph.ts +138 -0
- package/src/components/ASA.tsx +38 -0
- package/src/components/ASASearch.tsx +79 -0
- package/src/components/Account.tsx +42 -0
- package/src/components/AccountSearch.tsx +75 -0
- package/src/components/AuctionListing.tsx +40 -0
- package/src/components/Collection.tsx +42 -0
- package/src/components/DualStakePool.tsx +244 -0
- package/src/components/NFDProfile.tsx +45 -0
- package/src/components/NFDSearch.tsx +81 -0
- package/src/components/NFTListing.tsx +73 -0
- package/src/components/NFTSearch.tsx +68 -0
- package/src/components/Poll.tsx +39 -0
- package/src/components/PollSearch.tsx +79 -0
- package/src/components/PrizeBoxBundle.tsx +1 -0
- package/src/components/RaffleListing.tsx +40 -0
- package/src/components/SelfFetching.tsx +1048 -0
- package/src/components/StakingPool.tsx +134 -0
- package/src/components/TradeOffer.tsx +47 -0
- package/src/components/TradeSearch.tsx +103 -0
- package/src/components/TransactionDetails.tsx +37 -0
- package/src/components/TransactionSearch.tsx +102 -0
- package/src/components/TransactionsGraph.tsx +60 -0
- package/src/components/index.ts +41 -0
- package/src/fonts/OFL.txt +93 -0
- package/src/fonts/SpaceGrotesk_300Light.ttf +0 -0
- package/src/fonts/SpaceGrotesk_400Regular.ttf +0 -0
- package/src/fonts/SpaceGrotesk_500Medium.ttf +0 -0
- package/src/fonts/SpaceGrotesk_600SemiBold.ttf +0 -0
- package/src/fonts/SpaceGrotesk_700Bold.ttf +0 -0
- package/src/fonts/app.css +5 -0
- package/src/graph.ts +3 -0
- package/src/hooks/index.ts +17 -0
- package/src/hooks/useAlgomdData.ts +1539 -0
- package/src/hooks/useAlgorandClient.ts +54 -0
- package/src/index.ts +147 -0
- package/src/presentation/ASADisplay.tsx +380 -0
- package/src/presentation/AccountDisplay.tsx +132 -0
- package/src/presentation/AccountMentionInline.tsx +38 -0
- package/src/presentation/AccountMentionText.tsx +80 -0
- package/src/presentation/AdaptiveImage.tsx +314 -0
- package/src/presentation/AssetMention.tsx +87 -0
- package/src/presentation/AuctionListingDisplay.tsx +428 -0
- package/src/presentation/BundleContents.tsx +228 -0
- package/src/presentation/CardContainer.tsx +61 -0
- package/src/presentation/CardEntrance.tsx +21 -0
- package/src/presentation/CollectionDisplay.tsx +168 -0
- package/src/presentation/ContractMenu.tsx +243 -0
- package/src/presentation/DualStakePoolDisplay.tsx +335 -0
- package/src/presentation/Embeds.tsx +300 -0
- package/src/presentation/GateRequirements.tsx +334 -0
- package/src/presentation/HEROICONS-LICENSE.txt +21 -0
- package/src/presentation/NFDProfileDisplay.tsx +194 -0
- package/src/presentation/NFTListingDisplay.tsx +284 -0
- package/src/presentation/OnChainActionCard.tsx +557 -0
- package/src/presentation/PollDisplay.tsx +222 -0
- package/src/presentation/PrizeBoxBundleDisplay.tsx +103 -0
- package/src/presentation/PrizeBoxMedia.tsx +46 -0
- package/src/presentation/PrizePreview.tsx +296 -0
- package/src/presentation/ProgressBar.tsx +50 -0
- package/src/presentation/RaffleListingDisplay.tsx +399 -0
- package/src/presentation/References.tsx +310 -0
- package/src/presentation/ReservedNotice.tsx +73 -0
- package/src/presentation/ResultsPanel.tsx +241 -0
- package/src/presentation/Sparkline.tsx +70 -0
- package/src/presentation/SquishyPressable.tsx +145 -0
- package/src/presentation/StakingPoolDisplay.tsx +419 -0
- package/src/presentation/StatusBadge.tsx +56 -0
- package/src/presentation/TradeOfferDisplay.tsx +275 -0
- package/src/presentation/TransactionDisplay.tsx +262 -0
- package/src/presentation/WinnerBadge.tsx +58 -0
- package/src/presentation/assetHelpers.ts +36 -0
- package/src/presentation/assets.ts +7 -0
- package/src/presentation/explorer.ts +95 -0
- package/src/presentation/format.ts +90 -0
- package/src/presentation/gates.ts +100 -0
- package/src/presentation/icons.tsx +1178 -0
- package/src/presentation/identity.tsx +175 -0
- package/src/presentation/index.ts +88 -0
- package/src/presentation/media.ts +70 -0
- package/src/presentation/pluginColors.ts +8 -0
- package/src/presentation/runtime.tsx +280 -0
- package/src/presentation/sheets.tsx +7 -0
- package/src/presentation/subject.tsx +31 -0
- package/src/presentation/textTheme.ts +17 -0
- package/src/presentation/themes.json +158 -0
- package/src/presentation/variants.ts +14 -0
- package/src/provider/AlgomdProvider.tsx +45 -0
- package/src/provider/context.ts +18 -0
- package/src/provider/imageResolver.ts +12 -0
- package/src/provider/index.ts +5 -0
- package/src/provider/networks.ts +23 -0
- package/src/provider/types.ts +29 -0
- package/src/refs/AccountRef.tsx +226 -0
- package/src/refs/ApplicationRef.tsx +72 -0
- package/src/refs/AssetRef.tsx +142 -0
- package/src/refs/AuctionRef.tsx +108 -0
- package/src/refs/CollectionRef.tsx +70 -0
- package/src/refs/DualStakeRef.tsx +88 -0
- package/src/refs/GuildProposalRef.tsx +285 -0
- package/src/refs/HostRefs.tsx +82 -0
- package/src/refs/ListingRef.tsx +90 -0
- package/src/refs/NfdRef.tsx +96 -0
- package/src/refs/PollRef.tsx +120 -0
- package/src/refs/RaffleRef.tsx +101 -0
- package/src/refs/RewardRef.tsx +78 -0
- package/src/refs/StakingPoolRef.tsx +136 -0
- package/src/refs/SubscriptionRef.tsx +200 -0
- package/src/refs/TradeRef.tsx +100 -0
- package/src/refs/TransactionRef.tsx +156 -0
- package/src/refs/assetInfo.ts +49 -0
- package/src/refs/contractParts.tsx +159 -0
- package/src/refs/index.tsx +140 -0
- package/src/refs/primitives.tsx +588 -0
- package/src/refs/types.ts +13 -0
- package/src/types/algorand.ts +496 -0
- package/src/types/index.ts +1 -0
- package/src/ui/CopyButton.tsx +44 -0
- package/src/ui/DataStates.tsx +45 -0
- package/src/ui/ProgressBar.tsx +64 -0
- package/src/ui/SearchSheet.tsx +141 -0
- package/src/ui/SizeContainer.tsx +25 -0
- package/src/ui/StatusBadge.tsx +51 -0
- package/src/ui/index.ts +6 -0
- package/src/utils/algomdImageUrl.ts +20 -0
- package/src/utils/arc19.ts +120 -0
- package/src/utils/arc62.ts +246 -0
- package/src/utils/capacity.ts +26 -0
- package/src/utils/format.ts +181 -0
- package/src/utils/ids.ts +31 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/nfdDisplay.ts +45 -0
- package/src/utils/search.ts +87 -0
- package/src/utils/stakingPool.ts +174 -0
- package/src/utils/stakingSnapshot.ts +132 -0
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
Pressable,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
View,
|
|
6
|
+
type StyleProp,
|
|
7
|
+
type ViewStyle,
|
|
8
|
+
} from "react-native";
|
|
9
|
+
import { Image } from "expo-image";
|
|
10
|
+
import { CheckBadgeIcon, CheckCircleIcon, ChevronRightIcon, ClockIcon, ExclamationCircleIcon } from "../presentation/icons";
|
|
11
|
+
import { LinearGradient, Text, useAppTheme, usePresentation, type PresentationTheme } from "../presentation/runtime";
|
|
12
|
+
import { SquishyPressable } from "../presentation/SquishyPressable";
|
|
13
|
+
import { defaultResolveImageUrl } from "../provider/imageResolver";
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* Shared building blocks for references at every size. Each size has one
|
|
17
|
+
* shape, so every kind looks consistent:
|
|
18
|
+
* inline a pill that sits in a line of text (22 px, same as text runs)
|
|
19
|
+
* small a full-width row (56 px)
|
|
20
|
+
* large a card
|
|
21
|
+
* full a full-detail layout that fills its container
|
|
22
|
+
* Loading and error states keep the same shape and size.
|
|
23
|
+
*
|
|
24
|
+
* The parts follow the Akita app: fills instead of borders, nested surfaces
|
|
25
|
+
* in the page background, uppercase role labels, an icon status badge and the
|
|
26
|
+
* interactive gradient for the one action a card offers.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export const INLINE_HEIGHT = 22;
|
|
30
|
+
export const ROW_HEIGHT = 56;
|
|
31
|
+
|
|
32
|
+
export type IconComponent = React.ComponentType<{ size?: number; color?: string }>;
|
|
33
|
+
|
|
34
|
+
export function useImageUrl(src: string | undefined, width: number): string | undefined {
|
|
35
|
+
const resolve = usePresentation().resolveImageUrl ?? defaultResolveImageUrl;
|
|
36
|
+
if (!src) return undefined;
|
|
37
|
+
if (src.startsWith("data:") || src.startsWith("file://")) return src;
|
|
38
|
+
return resolve(src, Math.round(width * 3));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ---------------------------------------------------------------- color
|
|
42
|
+
|
|
43
|
+
export type Tone = "neutral" | "good" | "warn" | "bad";
|
|
44
|
+
|
|
45
|
+
function isLight(hex: string): boolean {
|
|
46
|
+
const n = parseInt(hex.replace("#", "").slice(0, 6), 16);
|
|
47
|
+
if (Number.isNaN(n)) return false;
|
|
48
|
+
return 0.299 * ((n >> 16) & 255) + 0.587 * ((n >> 8) & 255) + 0.114 * (n & 255) > 150;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Status text must stay readable on the card and on its own tint. The theme's
|
|
52
|
+
// success and warning fills are too light for text on a light card.
|
|
53
|
+
const TONE_TEXT: Record<"light" | "dark", Record<Exclude<Tone, "neutral">, string>> = {
|
|
54
|
+
light: { good: "#15803d", warn: "#b45309", bad: "#b91c1c" },
|
|
55
|
+
dark: { good: "#4ade80", warn: "#fcd34d", bad: "#f87171" },
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** Text-safe colors for status tones and the nested-surface fill, per theme. */
|
|
59
|
+
export function usePalette(): { theme: PresentationTheme; tone: (t: Tone) => string; inset: string; tint: string } {
|
|
60
|
+
const { theme } = useAppTheme();
|
|
61
|
+
const scheme = isLight(theme.colors.background) ? "light" : "dark";
|
|
62
|
+
return {
|
|
63
|
+
theme,
|
|
64
|
+
tone: (t) => (t === "neutral" ? theme.colors.textDim : TONE_TEXT[scheme][t]),
|
|
65
|
+
// Akita sets nested blocks in the page background, over the card.
|
|
66
|
+
inset: `${theme.colors.background}${scheme === "light" ? "CC" : "88"}`,
|
|
67
|
+
tint: `${theme.colors.primary}24`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ---------------------------------------------------------------- avatar
|
|
72
|
+
|
|
73
|
+
export interface AvatarProps {
|
|
74
|
+
uri?: string;
|
|
75
|
+
size: number;
|
|
76
|
+
shape?: "circle" | "rounded";
|
|
77
|
+
/** Shown when there is no image: usually the first letter of the name. */
|
|
78
|
+
initial?: string;
|
|
79
|
+
icon?: React.ReactNode;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function Avatar({ uri, size, shape = "circle", initial, icon }: AvatarProps) {
|
|
83
|
+
const { theme } = useAppTheme();
|
|
84
|
+
const resolved = useImageUrl(uri, size);
|
|
85
|
+
const radius = shape === "circle" ? size / 2 : Math.max(4, size / 4);
|
|
86
|
+
const frame = { width: size, height: size, borderRadius: radius };
|
|
87
|
+
if (resolved) {
|
|
88
|
+
return (
|
|
89
|
+
<Image
|
|
90
|
+
source={{ uri: resolved }}
|
|
91
|
+
contentFit="cover"
|
|
92
|
+
cachePolicy="memory-disk"
|
|
93
|
+
recyclingKey={resolved}
|
|
94
|
+
style={[frame, { backgroundColor: theme.colors.border }]}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return (
|
|
99
|
+
<View style={[frame, styles.center, { backgroundColor: theme.colors.border }]}>
|
|
100
|
+
{icon ?? (
|
|
101
|
+
<Text
|
|
102
|
+
weight="bold"
|
|
103
|
+
style={{ color: theme.colors.textDim, fontSize: Math.max(9, Math.round(size * 0.45)), lineHeight: size }}
|
|
104
|
+
>
|
|
105
|
+
{(initial ?? "?").slice(0, 1).toUpperCase()}
|
|
106
|
+
</Text>
|
|
107
|
+
)}
|
|
108
|
+
</View>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The tile for kinds without their own image: the kind's icon on a primary tint. */
|
|
113
|
+
export function KindTile({ Icon, size, dim }: { Icon: IconComponent; size: number; dim?: boolean }) {
|
|
114
|
+
const { theme, tint } = usePalette();
|
|
115
|
+
return (
|
|
116
|
+
<View style={[styles.center, { width: size, height: size, borderRadius: Math.max(4, size / 4), backgroundColor: dim ? theme.colors.border : tint }]}>
|
|
117
|
+
<Icon size={Math.round(size * 0.48)} color={dim ? theme.colors.textDim : theme.colors.primary} />
|
|
118
|
+
</View>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function VerifiedMark({ size = 12 }: { size?: number }) {
|
|
123
|
+
return <CheckBadgeIcon size={size} color="#60a5fa" />;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// ---------------------------------------------------------------- inline
|
|
127
|
+
|
|
128
|
+
export interface InlinePillProps {
|
|
129
|
+
label: string;
|
|
130
|
+
leading?: React.ReactNode;
|
|
131
|
+
trailing?: React.ReactNode;
|
|
132
|
+
dim?: boolean;
|
|
133
|
+
onPress?: () => void;
|
|
134
|
+
onLongPress?: () => void;
|
|
135
|
+
accessibilityLabel?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The inline shape. It is a View, so it can sit inside a Text run. */
|
|
139
|
+
export function InlinePill({ label, leading, trailing, dim, onPress, onLongPress, accessibilityLabel }: InlinePillProps) {
|
|
140
|
+
const { theme } = useAppTheme();
|
|
141
|
+
const pill = (
|
|
142
|
+
<View style={[styles.pill, { backgroundColor: theme.colors.accentBackground, opacity: dim ? 0.6 : 1 }]}>
|
|
143
|
+
{leading}
|
|
144
|
+
<Text weight="medium" numberOfLines={1} style={[styles.pillText, { color: theme.colors.text }]}>
|
|
145
|
+
{label}
|
|
146
|
+
</Text>
|
|
147
|
+
{trailing}
|
|
148
|
+
</View>
|
|
149
|
+
);
|
|
150
|
+
if (!onPress && !onLongPress) return pill;
|
|
151
|
+
return (
|
|
152
|
+
<Pressable
|
|
153
|
+
accessibilityRole="button"
|
|
154
|
+
accessibilityLabel={accessibilityLabel ?? label}
|
|
155
|
+
onPress={onPress}
|
|
156
|
+
onLongPress={onLongPress}
|
|
157
|
+
style={styles.pillPress}
|
|
158
|
+
>
|
|
159
|
+
{pill}
|
|
160
|
+
</Pressable>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ---------------------------------------------------------------- small
|
|
165
|
+
|
|
166
|
+
export interface RowProps {
|
|
167
|
+
leading: React.ReactNode;
|
|
168
|
+
title: React.ReactNode;
|
|
169
|
+
subtitle?: React.ReactNode;
|
|
170
|
+
trailing?: React.ReactNode;
|
|
171
|
+
onPress?: () => void;
|
|
172
|
+
accessibilityLabel?: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** The small shape: full width, one short row. */
|
|
176
|
+
export function Row({ leading, title, subtitle, trailing, onPress, accessibilityLabel }: RowProps) {
|
|
177
|
+
const { theme } = useAppTheme();
|
|
178
|
+
const body = (
|
|
179
|
+
<View style={[styles.row, { backgroundColor: theme.colors.accentBackground }]}>
|
|
180
|
+
{leading}
|
|
181
|
+
<View style={styles.rowText}>
|
|
182
|
+
<View style={styles.inlineRow}>{title}</View>
|
|
183
|
+
{subtitle ? (
|
|
184
|
+
typeof subtitle === "string" ? (
|
|
185
|
+
<Text size="xxs" numberOfLines={1} style={{ color: theme.colors.textDim }}>
|
|
186
|
+
{subtitle}
|
|
187
|
+
</Text>
|
|
188
|
+
) : (
|
|
189
|
+
subtitle
|
|
190
|
+
)
|
|
191
|
+
) : null}
|
|
192
|
+
</View>
|
|
193
|
+
{trailing}
|
|
194
|
+
{onPress ? <ChevronRightIcon size={16} color={theme.colors.textDim} /> : null}
|
|
195
|
+
</View>
|
|
196
|
+
);
|
|
197
|
+
if (!onPress) return body;
|
|
198
|
+
return (
|
|
199
|
+
<Pressable accessibilityRole="button" accessibilityLabel={accessibilityLabel} onPress={onPress}>
|
|
200
|
+
{body}
|
|
201
|
+
</Pressable>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function Title({ children, verified }: { children: React.ReactNode; verified?: boolean }) {
|
|
206
|
+
return (
|
|
207
|
+
<>
|
|
208
|
+
<Text size="xs" weight="semiBold" numberOfLines={1} style={{ flexShrink: 1 }}>
|
|
209
|
+
{children}
|
|
210
|
+
</Text>
|
|
211
|
+
{verified ? <VerifiedMark /> : null}
|
|
212
|
+
</>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ---------------------------------------------------------------- large and full
|
|
217
|
+
|
|
218
|
+
export function Card({ children, style }: { children: React.ReactNode; style?: StyleProp<ViewStyle> }) {
|
|
219
|
+
const { theme } = useAppTheme();
|
|
220
|
+
return (
|
|
221
|
+
<View style={[styles.card, { backgroundColor: theme.colors.accentBackground }, style]}>
|
|
222
|
+
{children}
|
|
223
|
+
</View>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface CardHeaderProps {
|
|
228
|
+
media: React.ReactNode;
|
|
229
|
+
title: React.ReactNode;
|
|
230
|
+
verified?: boolean;
|
|
231
|
+
/** A status badge, shown before the meta line. */
|
|
232
|
+
status?: React.ReactNode;
|
|
233
|
+
/** One short line of context: a countdown, an id, a ticker. */
|
|
234
|
+
meta?: React.ReactNode;
|
|
235
|
+
/** The overflow menu. */
|
|
236
|
+
menu?: React.ReactNode;
|
|
237
|
+
full?: boolean;
|
|
238
|
+
/** Lines the title may use. Default 2. */
|
|
239
|
+
titleLines?: number;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The top of every card: image or kind tile, title, then the status and one
|
|
244
|
+
* line of context under it. Status sits under the title so a long name keeps
|
|
245
|
+
* the full width on a phone.
|
|
246
|
+
*/
|
|
247
|
+
export function CardHeader({ media, title, verified, status, meta, menu, full, titleLines = 2 }: CardHeaderProps) {
|
|
248
|
+
const { theme } = useAppTheme();
|
|
249
|
+
return (
|
|
250
|
+
<View style={styles.header}>
|
|
251
|
+
{media}
|
|
252
|
+
<View style={styles.headerText}>
|
|
253
|
+
<View style={styles.inlineRow}>
|
|
254
|
+
{typeof title === "string" ? (
|
|
255
|
+
<Text size={full ? "lg" : "md"} weight="bold" numberOfLines={titleLines} style={{ flexShrink: 1 }}>
|
|
256
|
+
{title}
|
|
257
|
+
</Text>
|
|
258
|
+
) : (
|
|
259
|
+
title
|
|
260
|
+
)}
|
|
261
|
+
{verified ? <VerifiedMark size={full ? 16 : 14} /> : null}
|
|
262
|
+
</View>
|
|
263
|
+
{status || meta ? (
|
|
264
|
+
<View style={styles.metaRow}>
|
|
265
|
+
{status}
|
|
266
|
+
{typeof meta === "string" ? (
|
|
267
|
+
<Text size="xxs" numberOfLines={1} style={{ color: theme.colors.textDim, flexShrink: 1 }}>
|
|
268
|
+
{meta}
|
|
269
|
+
</Text>
|
|
270
|
+
) : (
|
|
271
|
+
meta
|
|
272
|
+
)}
|
|
273
|
+
</View>
|
|
274
|
+
) : null}
|
|
275
|
+
</View>
|
|
276
|
+
{menu}
|
|
277
|
+
</View>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** The media size for card headers. */
|
|
282
|
+
export const headerMedia = (full: boolean) => (full ? 64 : 52);
|
|
283
|
+
|
|
284
|
+
/** An uppercase role label, as the Akita app writes "FOR SALE" or "CREATOR". */
|
|
285
|
+
export function SectionLabel({ children, color }: { children: string; color?: string }) {
|
|
286
|
+
const { theme } = useAppTheme();
|
|
287
|
+
return (
|
|
288
|
+
<Text size="xxs" weight="bold" numberOfLines={1} style={{ color: color ?? theme.colors.textDim, textTransform: "uppercase", letterSpacing: 0.6 }}>
|
|
289
|
+
{children}
|
|
290
|
+
</Text>
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** A labelled block: role label, then its content. */
|
|
295
|
+
export function Section({ label, color, children }: { label: string; color?: string; children: React.ReactNode }) {
|
|
296
|
+
return (
|
|
297
|
+
<View style={{ gap: 8 }}>
|
|
298
|
+
<SectionLabel color={color}>{label}</SectionLabel>
|
|
299
|
+
{children}
|
|
300
|
+
</View>
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** One labelled value. `grow` gives a long value (a balance) more of the row. */
|
|
305
|
+
export function Stat({ label, children, align = "left", grow = 1 }: { label: string; children: React.ReactNode; align?: "left" | "right"; grow?: number }) {
|
|
306
|
+
return (
|
|
307
|
+
<View style={{ flex: grow, minWidth: 0, alignItems: align === "right" ? "flex-end" : "flex-start", gap: 4 }}>
|
|
308
|
+
<SectionLabel>{label}</SectionLabel>
|
|
309
|
+
{typeof children === "string" || typeof children === "number" ? (
|
|
310
|
+
<Text size="sm" weight="bold" numberOfLines={1}>
|
|
311
|
+
{children}
|
|
312
|
+
</Text>
|
|
313
|
+
) : (
|
|
314
|
+
children
|
|
315
|
+
)}
|
|
316
|
+
</View>
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** Two or three stats on a nested surface. */
|
|
321
|
+
export function StatRow({ children }: { children: React.ReactNode }) {
|
|
322
|
+
const { inset } = usePalette();
|
|
323
|
+
return <View style={[styles.statRow, { backgroundColor: inset }]}>{children}</View>;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** A nested surface for grouped rows. */
|
|
327
|
+
export function Inset({ children, style }: { children: React.ReactNode; style?: StyleProp<ViewStyle> }) {
|
|
328
|
+
const { inset } = usePalette();
|
|
329
|
+
return <View style={[styles.inset, { backgroundColor: inset }, style]}>{children}</View>;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** One label-value line in a full-size detail list. The label never wraps; the value does. */
|
|
333
|
+
export function DetailLine({ label, children }: { label: string; children: React.ReactNode }) {
|
|
334
|
+
const { theme } = useAppTheme();
|
|
335
|
+
return (
|
|
336
|
+
<View style={styles.detail}>
|
|
337
|
+
<Text size="xs" numberOfLines={1} style={{ color: theme.colors.textDim, flexShrink: 0 }}>
|
|
338
|
+
{label}
|
|
339
|
+
</Text>
|
|
340
|
+
<View style={styles.detailValue}>
|
|
341
|
+
{typeof children === "string" ? (
|
|
342
|
+
<Text size="xs" weight="medium" numberOfLines={2} style={{ textAlign: "right" }}>
|
|
343
|
+
{children}
|
|
344
|
+
</Text>
|
|
345
|
+
) : (
|
|
346
|
+
children
|
|
347
|
+
)}
|
|
348
|
+
</View>
|
|
349
|
+
</View>
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** A tag such as "NFT" or "Explicit". Status uses StatusBadge instead. */
|
|
354
|
+
export function Chip({ label, tone = "neutral" }: { label: string; tone?: Tone }) {
|
|
355
|
+
const { tone: color } = usePalette();
|
|
356
|
+
const c = color(tone);
|
|
357
|
+
return (
|
|
358
|
+
<View style={[styles.chip, { backgroundColor: `${c}1F` }]}>
|
|
359
|
+
<Text size="xxs" weight="semiBold" numberOfLines={1} style={{ color: c }}>
|
|
360
|
+
{label}
|
|
361
|
+
</Text>
|
|
362
|
+
</View>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const TONE_ICON: Record<Tone, IconComponent | undefined> = {
|
|
367
|
+
good: CheckCircleIcon,
|
|
368
|
+
warn: ClockIcon,
|
|
369
|
+
bad: ExclamationCircleIcon,
|
|
370
|
+
neutral: undefined,
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
/** Icon and uppercase label, as on the Akita subscriptions screen. */
|
|
374
|
+
export function StatusBadge({ label, tone = "neutral" }: { label: string; tone?: Tone }) {
|
|
375
|
+
const { tone: color } = usePalette();
|
|
376
|
+
const c = color(tone);
|
|
377
|
+
const Icon = TONE_ICON[tone];
|
|
378
|
+
return (
|
|
379
|
+
<View style={styles.badge} accessibilityLabel={`Status: ${label}`}>
|
|
380
|
+
{Icon ? <Icon size={13} color={c} /> : <View style={[styles.dot, { backgroundColor: c }]} />}
|
|
381
|
+
<Text size="xxs" weight="bold" numberOfLines={1} style={{ color: c, textTransform: "uppercase", letterSpacing: 0.6 }}>
|
|
382
|
+
{label}
|
|
383
|
+
</Text>
|
|
384
|
+
</View>
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export interface ActionButtonProps {
|
|
389
|
+
label: string;
|
|
390
|
+
onPress: () => void;
|
|
391
|
+
/** `secondary` is a quiet fill for the second of two actions. */
|
|
392
|
+
variant?: "primary" | "secondary";
|
|
393
|
+
accessibilityLabel?: string;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** The card's action, drawn like the Akita app's confirm buttons. */
|
|
397
|
+
export function ActionButton({ label, onPress, variant = "primary", accessibilityLabel }: ActionButtonProps) {
|
|
398
|
+
const { theme, inset } = usePalette();
|
|
399
|
+
return (
|
|
400
|
+
<SquishyPressable pressedScale={0.97} onPress={onPress} accessibilityRole="button" accessibilityLabel={accessibilityLabel ?? label}>
|
|
401
|
+
{variant === "primary" ? (
|
|
402
|
+
<LinearGradient
|
|
403
|
+
colors={[...theme.gradients.interactive]}
|
|
404
|
+
locations={theme.gradients.interactiveLocations ? [...theme.gradients.interactiveLocations] : undefined}
|
|
405
|
+
start={{ x: 0, y: 0 }}
|
|
406
|
+
end={{ x: 1, y: 0 }}
|
|
407
|
+
style={styles.button}
|
|
408
|
+
>
|
|
409
|
+
<Text size="sm" weight="bold" numberOfLines={1} style={{ color: theme.gradients.interactiveText }}>
|
|
410
|
+
{label}
|
|
411
|
+
</Text>
|
|
412
|
+
</LinearGradient>
|
|
413
|
+
) : (
|
|
414
|
+
<View style={[styles.button, { backgroundColor: inset }]}>
|
|
415
|
+
<Text size="sm" weight="bold" numberOfLines={1}>
|
|
416
|
+
{label}
|
|
417
|
+
</Text>
|
|
418
|
+
</View>
|
|
419
|
+
)}
|
|
420
|
+
</SquishyPressable>
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** A quiet line of supporting copy at the end of a card. */
|
|
425
|
+
export function Note({ children, tone }: { children: React.ReactNode; tone?: Tone }) {
|
|
426
|
+
const { tone: color } = usePalette();
|
|
427
|
+
return (
|
|
428
|
+
<Text size="xxs" style={{ color: color(tone ?? "neutral") }}>
|
|
429
|
+
{children}
|
|
430
|
+
</Text>
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// ---------------------------------------------------------------- loading and errors
|
|
435
|
+
|
|
436
|
+
export function Bone({ width, height = 12, radius = 6 }: { width: number | `${number}%`; height?: number; radius?: number }) {
|
|
437
|
+
const { theme } = useAppTheme();
|
|
438
|
+
return <View style={{ width, height, borderRadius: radius, backgroundColor: theme.colors.border }} />;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export function RowSkeleton({ shape = "circle" }: { shape?: "circle" | "rounded" }) {
|
|
442
|
+
return (
|
|
443
|
+
<View accessibilityLabel="Loading">
|
|
444
|
+
<Row
|
|
445
|
+
leading={<Bone width={36} height={36} radius={shape === "circle" ? 18 : 9} />}
|
|
446
|
+
title={<Bone width={140} />}
|
|
447
|
+
subtitle={
|
|
448
|
+
<View style={{ marginTop: 6 }}>
|
|
449
|
+
<Bone width={90} height={9} />
|
|
450
|
+
</View>
|
|
451
|
+
}
|
|
452
|
+
/>
|
|
453
|
+
</View>
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export interface CardSkeletonProps {
|
|
458
|
+
/** The header media's shape. `banner` is a full-width image above the body. */
|
|
459
|
+
media?: "circle" | "rounded" | "banner";
|
|
460
|
+
/** A role label and a large value under the header. */
|
|
461
|
+
value?: boolean;
|
|
462
|
+
/** Nested blocks under the header: stat rows, person rows, option bars. */
|
|
463
|
+
blocks?: number;
|
|
464
|
+
/** A closing action button. */
|
|
465
|
+
action?: boolean;
|
|
466
|
+
full?: boolean;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** A loading card with the loaded card's outline, so the feed does not jump. */
|
|
470
|
+
export function CardSkeleton({ media = "circle", value, blocks = 1, action, full }: CardSkeletonProps) {
|
|
471
|
+
const { inset } = usePalette();
|
|
472
|
+
const size = headerMedia(Boolean(full));
|
|
473
|
+
const block = (key: number) => <View key={key} style={{ height: 56, borderRadius: 14, backgroundColor: inset }} />;
|
|
474
|
+
if (media === "banner") {
|
|
475
|
+
return (
|
|
476
|
+
<View accessibilityLabel="Loading">
|
|
477
|
+
<Card style={{ padding: 0, gap: 0 }}>
|
|
478
|
+
<Bone width="100%" height={full ? 160 : 112} radius={0} />
|
|
479
|
+
<View style={{ gap: 14, padding: 18, paddingTop: 10 }}>
|
|
480
|
+
<Bone width="55%" height={18} />
|
|
481
|
+
<Bone width="35%" height={22} />
|
|
482
|
+
{action ? <Bone width="100%" height={48} radius={14} /> : null}
|
|
483
|
+
<Bone width="90%" height={10} />
|
|
484
|
+
<Bone width="70%" height={10} />
|
|
485
|
+
</View>
|
|
486
|
+
</Card>
|
|
487
|
+
</View>
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
return (
|
|
491
|
+
<View accessibilityLabel="Loading">
|
|
492
|
+
<Card>
|
|
493
|
+
<View style={styles.header}>
|
|
494
|
+
<Bone width={size} height={size} radius={media === "circle" ? size / 2 : size / 4} />
|
|
495
|
+
<View style={{ gap: 8, flex: 1 }}>
|
|
496
|
+
<Bone width="60%" height={16} />
|
|
497
|
+
<Bone width="35%" height={10} />
|
|
498
|
+
</View>
|
|
499
|
+
</View>
|
|
500
|
+
{value ? (
|
|
501
|
+
<View style={{ gap: 8 }}>
|
|
502
|
+
<Bone width={70} height={10} />
|
|
503
|
+
<Bone width={150} height={26} />
|
|
504
|
+
</View>
|
|
505
|
+
) : null}
|
|
506
|
+
{Array.from({ length: blocks }, (_, i) => block(i))}
|
|
507
|
+
{action ? <Bone width="100%" height={48} radius={14} /> : null}
|
|
508
|
+
</Card>
|
|
509
|
+
</View>
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export interface UnavailableProps {
|
|
514
|
+
size: "small" | "large" | "full";
|
|
515
|
+
label: string;
|
|
516
|
+
detail?: string;
|
|
517
|
+
/** The kind's icon, so a failed reference still says what it was. */
|
|
518
|
+
Icon?: IconComponent;
|
|
519
|
+
/** Set when loading failed (as opposed to the id not existing). Shows "Try again". */
|
|
520
|
+
onRetry?: () => void;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** A reference that could not be loaded keeps its shape and says what it was. */
|
|
524
|
+
export function Unavailable({ size, label, detail, Icon, onRetry }: UnavailableProps) {
|
|
525
|
+
const { theme } = useAppTheme();
|
|
526
|
+
const text = onRetry ? "Couldn't load this right now." : detail ?? "Not found on this network.";
|
|
527
|
+
const tile = (px: number) => (Icon ? <KindTile Icon={Icon} size={px} dim /> : <Avatar size={px} initial="?" />);
|
|
528
|
+
const retry = onRetry ? (
|
|
529
|
+
<Pressable accessibilityRole="button" onPress={onRetry} hitSlop={8}>
|
|
530
|
+
<Text size="xs" weight="bold" style={{ color: theme.colors.primary }}>
|
|
531
|
+
Try again
|
|
532
|
+
</Text>
|
|
533
|
+
</Pressable>
|
|
534
|
+
) : null;
|
|
535
|
+
if (size === "small") {
|
|
536
|
+
return <Row leading={tile(36)} title={<Title>{label}</Title>} subtitle={text} trailing={retry} />;
|
|
537
|
+
}
|
|
538
|
+
return (
|
|
539
|
+
<Card>
|
|
540
|
+
<CardHeader media={tile(headerMedia(size === "full"))} title={label} meta={text} full={size === "full"} menu={retry} />
|
|
541
|
+
</Card>
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const styles = StyleSheet.create({
|
|
546
|
+
center: { alignItems: "center", justifyContent: "center" },
|
|
547
|
+
pill: {
|
|
548
|
+
alignItems: "center",
|
|
549
|
+
borderRadius: 999,
|
|
550
|
+
flexDirection: "row",
|
|
551
|
+
gap: 4,
|
|
552
|
+
height: INLINE_HEIGHT,
|
|
553
|
+
marginRight: 2,
|
|
554
|
+
maxWidth: 240,
|
|
555
|
+
paddingHorizontal: 7,
|
|
556
|
+
},
|
|
557
|
+
pillPress: {},
|
|
558
|
+
pillText: { fontSize: 13, lineHeight: 16, flexShrink: 1 },
|
|
559
|
+
row: {
|
|
560
|
+
alignItems: "center",
|
|
561
|
+
borderRadius: 14,
|
|
562
|
+
flexDirection: "row",
|
|
563
|
+
gap: 10,
|
|
564
|
+
minHeight: ROW_HEIGHT,
|
|
565
|
+
paddingHorizontal: 12,
|
|
566
|
+
paddingVertical: 8,
|
|
567
|
+
},
|
|
568
|
+
rowText: { flex: 1, minWidth: 0, gap: 1 },
|
|
569
|
+
inlineRow: { alignItems: "center", flexDirection: "row", gap: 4 },
|
|
570
|
+
card: { borderRadius: 16, gap: 16, overflow: "hidden", padding: 16 },
|
|
571
|
+
header: { alignItems: "center", flexDirection: "row", gap: 12 },
|
|
572
|
+
headerText: { flex: 1, minWidth: 0, gap: 4 },
|
|
573
|
+
metaRow: { alignItems: "center", flexDirection: "row", flexWrap: "wrap", columnGap: 8, rowGap: 2 },
|
|
574
|
+
statRow: { borderRadius: 14, flexDirection: "row", gap: 12, paddingHorizontal: 14, paddingVertical: 12 },
|
|
575
|
+
inset: { borderRadius: 14, paddingHorizontal: 14, paddingVertical: 4 },
|
|
576
|
+
detail: {
|
|
577
|
+
alignItems: "center",
|
|
578
|
+
flexDirection: "row",
|
|
579
|
+
gap: 16,
|
|
580
|
+
justifyContent: "space-between",
|
|
581
|
+
paddingVertical: 8,
|
|
582
|
+
},
|
|
583
|
+
detailValue: { alignItems: "flex-end", flex: 1, minWidth: 0 },
|
|
584
|
+
chip: { borderRadius: 999, paddingHorizontal: 8, paddingVertical: 2 },
|
|
585
|
+
badge: { alignItems: "center", flexDirection: "row", gap: 5 },
|
|
586
|
+
dot: { borderRadius: 3, height: 6, marginHorizontal: 3, width: 6 },
|
|
587
|
+
button: { alignItems: "center", borderRadius: 14, height: 48, justifyContent: "center", paddingHorizontal: 16 },
|
|
588
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Size } from "@akita-protocol/algomd-core";
|
|
2
|
+
|
|
3
|
+
export interface RefViewProps {
|
|
4
|
+
/** The kind's id: address, asset id, app id. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Default `large`. */
|
|
7
|
+
size?: Size;
|
|
8
|
+
params?: Record<string, string>;
|
|
9
|
+
/** Overrides the host's default open handler for this kind. */
|
|
10
|
+
onPress?: () => void;
|
|
11
|
+
/** Live data refetches only while visible. Lists pass their viewability here. */
|
|
12
|
+
visible?: boolean;
|
|
13
|
+
}
|