@akita-protocol/algomd-rn 0.0.0-stage → 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +268 -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/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 +137 -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,200 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StyleSheet, View } from "react-native";
|
|
3
|
+
import { Image } from "expo-image";
|
|
4
|
+
import { formatAmount, splitSubscriptionId, type SubscriptionData } from "@akita-protocol/algomd-core";
|
|
5
|
+
import { useSubscription } from "@akita-protocol/algomd-core/react";
|
|
6
|
+
import { UserGroupIcon } from "../presentation/icons";
|
|
7
|
+
import { LinearGradient, Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
8
|
+
import { SquishyPressable } from "../presentation/SquishyPressable";
|
|
9
|
+
import { CreatorIdentity } from "./AccountRef";
|
|
10
|
+
import { useAssetInfo } from "./assetInfo";
|
|
11
|
+
import { AmountLockup, plural } from "./contractParts";
|
|
12
|
+
import { Avatar, Card, CardSkeleton, InlinePill, KindTile, Note, Row, RowSkeleton, StatusBadge, Title, Unavailable, useImageUrl, type Tone } from "./primitives";
|
|
13
|
+
import type { RefViewProps } from "./types";
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* A subscription service, drawn like the Akita app's service offering card
|
|
17
|
+
* (highlight band, banner, price, Subscribe) with the creator block from its
|
|
18
|
+
* subscriptions screen. The id is `<owner>/<serviceId>`; tags written without
|
|
19
|
+
* an owner resolve only through a resolver.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const STATUS: Record<string, [string, Tone]> = {
|
|
23
|
+
active: ["Active", "good"],
|
|
24
|
+
paused: ["Paused", "warn"],
|
|
25
|
+
shutdown: ["Closed", "bad"],
|
|
26
|
+
draft: ["Draft", "neutral"],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const HIGHLIGHT_LABELS: Record<number, string> = {
|
|
30
|
+
1: "Best Value",
|
|
31
|
+
2: "Popular",
|
|
32
|
+
3: "New",
|
|
33
|
+
4: "Limited Offer",
|
|
34
|
+
5: "Recommended",
|
|
35
|
+
6: "Trending",
|
|
36
|
+
7: "Staff Pick",
|
|
37
|
+
8: "Top Rated",
|
|
38
|
+
9: "Editor's Choice",
|
|
39
|
+
10: "Hot Deal",
|
|
40
|
+
11: "Seasonal",
|
|
41
|
+
12: "Flash Sale",
|
|
42
|
+
13: "Exclusive",
|
|
43
|
+
14: "Limited Edition",
|
|
44
|
+
15: "Early Access",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// The Akita app's service gradients, picked by service id.
|
|
48
|
+
const SERVICE_GRADIENTS: [string, string][] = [
|
|
49
|
+
["#3EE1A1", "#1CB5E0"],
|
|
50
|
+
["#90E0FF", "#4BC9FF"],
|
|
51
|
+
["#D16BA5", "#C777B9"],
|
|
52
|
+
["#F7971E", "#FFD200"],
|
|
53
|
+
["#7F7FD5", "#86A8E7"],
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
const DAY = 86_400;
|
|
57
|
+
|
|
58
|
+
/** "Month", "Week", "Year" or "N Days", as the app labels billing periods. */
|
|
59
|
+
function intervalLabel(seconds: number): string {
|
|
60
|
+
if (seconds >= DAY * 28 && seconds <= DAY * 31) return "Month";
|
|
61
|
+
if (seconds >= DAY * 6 && seconds <= DAY * 8) return "Week";
|
|
62
|
+
if (seconds >= DAY * 364 && seconds <= DAY * 366) return "Year";
|
|
63
|
+
if (seconds >= DAY) return `${Math.round(seconds / DAY)} Days`;
|
|
64
|
+
if (seconds >= 3600) return `${Math.round(seconds / 3600)} Hours`;
|
|
65
|
+
return `${seconds} Seconds`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Dark text on light fills, white on dark ones. */
|
|
69
|
+
function textOn(hex: string): string {
|
|
70
|
+
const n = parseInt(hex.replace("#", "").slice(0, 6), 16);
|
|
71
|
+
if (Number.isNaN(n)) return "#FFFFFF";
|
|
72
|
+
const [r, g, b] = [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
73
|
+
return 0.299 * r + 0.587 * g + 0.114 * b > 150 ? "#09090b" : "#FFFFFF";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface ServicePrice {
|
|
77
|
+
period?: string;
|
|
78
|
+
line: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function useServicePrice(data: SubscriptionData | undefined): ServicePrice {
|
|
82
|
+
const info = useAssetInfo(data?.asset);
|
|
83
|
+
const amount = data && info.data ? formatAmount(data.amount, info.data.decimals, { maxFraction: 4 }) : undefined;
|
|
84
|
+
const period = data && Number(data.interval) ? intervalLabel(Number(data.interval)) : undefined;
|
|
85
|
+
return { period, line: amount ? `${amount} ${info.label}${period ? ` / ${period}` : ""}` : "" };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The description's markdown list markers, as bullets. Other markdown stays as text. */
|
|
89
|
+
const plainDescription = (md: string) => md.replace(/^\s*[-*]\s+/gm, "• ").trim();
|
|
90
|
+
|
|
91
|
+
export function SubscriptionRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
92
|
+
const { theme } = useAppTheme();
|
|
93
|
+
const presentation = usePresentation();
|
|
94
|
+
const sub = useSubscription(id, { visible });
|
|
95
|
+
const press = onPress ?? (presentation.onOpenContract ? () => presentation.onOpenContract!("subscription", id) : undefined);
|
|
96
|
+
const retry = sub.isError ? () => void sub.refetch() : undefined;
|
|
97
|
+
const data = sub.data?.data ?? undefined;
|
|
98
|
+
const price = useServicePrice(data);
|
|
99
|
+
const title = data?.title || `Subscription ${splitSubscriptionId(id).serviceId}`;
|
|
100
|
+
if (size === "inline") return <InlinePill label={title} dim={sub.isPending} leading={<UserGroupIcon size={12} color={theme.colors.primary} />} onPress={press} />;
|
|
101
|
+
|
|
102
|
+
if (size === "small") {
|
|
103
|
+
if (sub.isPending) return <RowSkeleton shape="rounded" />;
|
|
104
|
+
if (!data) return <Unavailable size="small" label={title} Icon={UserGroupIcon} onRetry={retry} />;
|
|
105
|
+
const [label, tone] = STATUS[data.status] ?? [data.status, "neutral"];
|
|
106
|
+
return (
|
|
107
|
+
<Row
|
|
108
|
+
leading={data.banner ? <Avatar uri={data.banner} size={40} shape="rounded" /> : <KindTile Icon={UserGroupIcon} size={40} />}
|
|
109
|
+
title={<Title>{title}</Title>}
|
|
110
|
+
subtitle={price.line}
|
|
111
|
+
trailing={data.status === "active" ? undefined : <StatusBadge label={label} tone={tone} />}
|
|
112
|
+
onPress={press}
|
|
113
|
+
accessibilityLabel={`Open subscription ${title}`}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (sub.isPending) return <CardSkeleton media="banner" action full={size === "full"} />;
|
|
119
|
+
if (!data) return <Unavailable size={size} label={title} Icon={UserGroupIcon} onRetry={retry} />;
|
|
120
|
+
return <ServiceCard data={data} title={title} price={price} full={size === "full"} visible={visible} />;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function ServiceCard({ data, title, price, full, visible }: { data: SubscriptionData; title: string; price: ServicePrice; full: boolean; visible?: boolean }) {
|
|
124
|
+
const { theme } = useAppTheme();
|
|
125
|
+
const subscribe = usePresentation().actions?.subscribe;
|
|
126
|
+
const banner = useImageUrl(data.banner, 600);
|
|
127
|
+
const accent = SERVICE_GRADIENTS[Number(data.serviceId) % SERVICE_GRADIENTS.length] ?? SERVICE_GRADIENTS[0]!;
|
|
128
|
+
const highlight = data.highlightMessage ? HIGHLIGHT_LABELS[data.highlightMessage] : undefined;
|
|
129
|
+
const highlightColor = data.highlightColor && data.highlightColor !== "#000000" ? data.highlightColor : theme.colors.primary;
|
|
130
|
+
const [statusLabel, statusTone] = STATUS[data.status] ?? [data.status, "neutral"];
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<Card style={styles.card}>
|
|
134
|
+
{highlight ? (
|
|
135
|
+
<View style={[styles.highlight, { backgroundColor: highlightColor }]}>
|
|
136
|
+
<Text size="xs" weight="bold" style={{ color: textOn(highlightColor) }}>
|
|
137
|
+
{highlight}
|
|
138
|
+
</Text>
|
|
139
|
+
</View>
|
|
140
|
+
) : null}
|
|
141
|
+
|
|
142
|
+
<View style={{ height: full ? 160 : 112 }}>
|
|
143
|
+
{banner ? (
|
|
144
|
+
<>
|
|
145
|
+
<Image source={{ uri: banner }} contentFit="cover" cachePolicy="memory-disk" style={StyleSheet.absoluteFill} />
|
|
146
|
+
<LinearGradient
|
|
147
|
+
colors={["rgba(0,0,0,0)", "rgba(0,0,0,0.2)", theme.colors.accentBackground]}
|
|
148
|
+
locations={[0, 0.6, 1]}
|
|
149
|
+
start={{ x: 0, y: 0 }}
|
|
150
|
+
end={{ x: 0, y: 1 }}
|
|
151
|
+
style={StyleSheet.absoluteFill}
|
|
152
|
+
/>
|
|
153
|
+
</>
|
|
154
|
+
) : (
|
|
155
|
+
<LinearGradient colors={accent} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={StyleSheet.absoluteFill} />
|
|
156
|
+
)}
|
|
157
|
+
</View>
|
|
158
|
+
|
|
159
|
+
<View style={styles.body}>
|
|
160
|
+
<View style={{ gap: 4 }}>
|
|
161
|
+
<View style={styles.titleRow}>
|
|
162
|
+
<Text size={full ? "xl" : "md"} weight="bold" numberOfLines={2} style={{ flex: 1 }}>
|
|
163
|
+
{title}
|
|
164
|
+
</Text>
|
|
165
|
+
<StatusBadge label={statusLabel} tone={statusTone} />
|
|
166
|
+
</View>
|
|
167
|
+
<AmountLockup amount={data.amount} assetId={data.asset} size="lg" suffix={price.period ? `/ ${price.period}` : undefined} />
|
|
168
|
+
</View>
|
|
169
|
+
|
|
170
|
+
{data.status === "active" && subscribe ? (
|
|
171
|
+
<SquishyPressable pressedScale={0.97} accessibilityRole="button" accessibilityLabel={`Subscribe to ${title}`} onPress={() => subscribe(data.owner, data.serviceId)}>
|
|
172
|
+
<LinearGradient colors={accent} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={styles.subscribe}>
|
|
173
|
+
<Text weight="bold" style={{ color: textOn(accent[0]) }}>
|
|
174
|
+
Subscribe
|
|
175
|
+
</Text>
|
|
176
|
+
</LinearGradient>
|
|
177
|
+
</SquishyPressable>
|
|
178
|
+
) : null}
|
|
179
|
+
|
|
180
|
+
{data.description ? (
|
|
181
|
+
<Text size="sm" numberOfLines={full ? undefined : 5} style={{ color: theme.colors.textDim }}>
|
|
182
|
+
{plainDescription(data.description)}
|
|
183
|
+
</Text>
|
|
184
|
+
) : null}
|
|
185
|
+
|
|
186
|
+
<CreatorIdentity address={data.owner} visible={visible} />
|
|
187
|
+
|
|
188
|
+
{data.subscriberCount !== undefined ? <Note>{plural(data.subscriberCount, "subscriber")}</Note> : null}
|
|
189
|
+
</View>
|
|
190
|
+
</Card>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const styles = StyleSheet.create({
|
|
195
|
+
card: { gap: 0, padding: 0 },
|
|
196
|
+
highlight: { alignItems: "center", justifyContent: "center", paddingHorizontal: 12, paddingVertical: 8 },
|
|
197
|
+
body: { gap: 14, paddingBottom: 18, paddingHorizontal: 18, paddingTop: 6 },
|
|
198
|
+
titleRow: { alignItems: "center", flexDirection: "row", gap: 12 },
|
|
199
|
+
subscribe: { alignItems: "center", borderRadius: 14, height: 48, justifyContent: "center" },
|
|
200
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { formatRelativeTime } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { useTrade } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { ArrowsRightLeftIcon, ChevronRightIcon } from "../presentation/icons";
|
|
7
|
+
import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
8
|
+
import { AccountRef, PersonRow } from "./AccountRef";
|
|
9
|
+
import { ActionButton, Amount, ProvenanceNote, StatusChip } from "./contractParts";
|
|
10
|
+
import { Card, CardHeader, CardSkeleton, headerMedia, InlinePill, Inset, KindTile, Row, RowSkeleton, Section, Stat, StatRow, Title, Unavailable } from "./primitives";
|
|
11
|
+
import type { RefViewProps } from "./types";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A HyperSwap trade offer. The chain keeps only Merkle roots of the transfers,
|
|
15
|
+
* so the transfers themselves show only when a resolver or host supplies them.
|
|
16
|
+
*/
|
|
17
|
+
export function TradeRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
18
|
+
const { theme } = useAppTheme();
|
|
19
|
+
const presentation = usePresentation();
|
|
20
|
+
const trade = useTrade(id, { visible });
|
|
21
|
+
const data = trade.data?.data ?? undefined;
|
|
22
|
+
const accept = presentation.actions?.acceptTrade;
|
|
23
|
+
const title = `Trade offer #${id}`;
|
|
24
|
+
const expiry = data && Number(data.expiration) ? formatRelativeTime(Number(data.expiration)) : undefined;
|
|
25
|
+
const retry = trade.isError ? () => void trade.refetch() : undefined;
|
|
26
|
+
|
|
27
|
+
if (size === "inline") {
|
|
28
|
+
return <InlinePill label={title} dim={trade.isPending} leading={<ArrowsRightLeftIcon size={12} color={theme.colors.primary} />} onPress={onPress} />;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (size === "small") {
|
|
32
|
+
if (trade.isPending) return <RowSkeleton shape="rounded" />;
|
|
33
|
+
if (!data) return <Unavailable size="small" label={title} Icon={ArrowsRightLeftIcon} onRetry={retry} />;
|
|
34
|
+
return (
|
|
35
|
+
<Row
|
|
36
|
+
leading={<KindTile Icon={ArrowsRightLeftIcon} size={40} />}
|
|
37
|
+
title={<Title>{title}</Title>}
|
|
38
|
+
subtitle={`${data.legCount} transfers · ${data.participantCount} parties${expiry ? ` · expires ${expiry}` : ""}`}
|
|
39
|
+
trailing={<StatusChip status={data.state} />}
|
|
40
|
+
onPress={onPress}
|
|
41
|
+
accessibilityLabel={`Open ${title}`}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const full = size === "full";
|
|
47
|
+
if (trade.isPending) return <CardSkeleton media="rounded" blocks={2} full={full} />;
|
|
48
|
+
if (!data) return <Unavailable size={size} label={title} Icon={ArrowsRightLeftIcon} onRetry={retry} />;
|
|
49
|
+
const others = (data.participants ?? []).filter((p) => p !== data.creator);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Card>
|
|
53
|
+
<CardHeader
|
|
54
|
+
media={<KindTile Icon={ArrowsRightLeftIcon} size={headerMedia(full)} />}
|
|
55
|
+
title={title}
|
|
56
|
+
full={full}
|
|
57
|
+
status={<StatusChip status={data.state} />}
|
|
58
|
+
meta={expiry ? `Expires ${expiry}` : undefined}
|
|
59
|
+
menu={<ContractMenu appId={data.hyperSwapAppId} type="application" embedType="TradeOffer" embedProp="offerId" embedValue={id} />}
|
|
60
|
+
/>
|
|
61
|
+
<StatRow>
|
|
62
|
+
<Stat label="Accepted">{`${data.acceptances} of ${data.participantCount}`}</Stat>
|
|
63
|
+
<Stat label="In escrow" align="right">{`${data.escrowed} of ${data.legCount}`}</Stat>
|
|
64
|
+
</StatRow>
|
|
65
|
+
|
|
66
|
+
<View style={{ gap: 8 }}>
|
|
67
|
+
{data.creator ? <PersonRow address={data.creator} role="Offered by" visible={visible} /> : null}
|
|
68
|
+
{others.map((p) => (
|
|
69
|
+
<PersonRow key={p} address={p} role="With" visible={visible} />
|
|
70
|
+
))}
|
|
71
|
+
</View>
|
|
72
|
+
|
|
73
|
+
{data.legs?.length ? (
|
|
74
|
+
<Section label="Transfers">
|
|
75
|
+
<View style={{ gap: 8 }}>
|
|
76
|
+
{data.legs.map((leg, i) => (
|
|
77
|
+
<Inset key={i} style={{ paddingVertical: 10, gap: 6 }}>
|
|
78
|
+
<View style={{ flexDirection: "row", alignItems: "center", flexWrap: "wrap", gap: 4 }}>
|
|
79
|
+
<AccountRef id={leg.from} size="inline" />
|
|
80
|
+
<ChevronRightIcon size={14} color={theme.colors.textDim} />
|
|
81
|
+
<AccountRef id={leg.to} size="inline" />
|
|
82
|
+
</View>
|
|
83
|
+
<Amount amount={leg.amount} assetId={leg.asset} />
|
|
84
|
+
</Inset>
|
|
85
|
+
))}
|
|
86
|
+
</View>
|
|
87
|
+
</Section>
|
|
88
|
+
) : null}
|
|
89
|
+
|
|
90
|
+
{!data.legs?.length && full ? (
|
|
91
|
+
<Text size="xxs" style={{ color: theme.colors.textDim }}>
|
|
92
|
+
The chain keeps only a fingerprint of the transfers, so they can't be listed here.
|
|
93
|
+
</Text>
|
|
94
|
+
) : null}
|
|
95
|
+
|
|
96
|
+
<ProvenanceNote entity={trade.data} />
|
|
97
|
+
{data.state === "offered" && accept ? <ActionButton label="Review and accept" onPress={() => accept(id)} /> : null}
|
|
98
|
+
</Card>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { formatAlgo, formatRelativeTime, fromBase64, shortAddress, utf8, type IndexerTransaction } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { useTransaction } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { HashtagIcon } from "../presentation/icons";
|
|
7
|
+
import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
8
|
+
import { PersonRow } from "./AccountRef";
|
|
9
|
+
import { ApplicationRef } from "./ApplicationRef";
|
|
10
|
+
import { AssetRef } from "./AssetRef";
|
|
11
|
+
import { useFormattedAmount } from "./assetInfo";
|
|
12
|
+
import { PriceBlock } from "./contractParts";
|
|
13
|
+
import { Card, CardHeader, CardSkeleton, DetailLine, headerMedia, InlinePill, Inset, KindTile, Row, RowSkeleton, Section, Title, Unavailable } from "./primitives";
|
|
14
|
+
import type { RefViewProps } from "./types";
|
|
15
|
+
|
|
16
|
+
export interface TxSummary {
|
|
17
|
+
type: string;
|
|
18
|
+
amount?: string;
|
|
19
|
+
assetId?: string;
|
|
20
|
+
to?: string;
|
|
21
|
+
appId?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** What a transaction did, in one line. */
|
|
25
|
+
export function summarizeTransaction(t: IndexerTransaction): TxSummary {
|
|
26
|
+
const pay = t["payment-transaction"];
|
|
27
|
+
const ax = t["asset-transfer-transaction"];
|
|
28
|
+
const appl = t["application-transaction"];
|
|
29
|
+
switch (t["tx-type"]) {
|
|
30
|
+
case "pay":
|
|
31
|
+
return { type: "Payment", amount: String(pay?.amount ?? 0), assetId: "0", to: pay?.receiver };
|
|
32
|
+
case "axfer":
|
|
33
|
+
if (ax && ax.amount === 0 && ax.receiver === t.sender) return { type: "Asset opt-in", assetId: String(ax["asset-id"]) };
|
|
34
|
+
return { type: "Asset transfer", amount: String(ax?.amount ?? 0), assetId: String(ax?.["asset-id"] ?? ""), to: ax?.receiver };
|
|
35
|
+
case "appl": {
|
|
36
|
+
const appId = String(appl?.["application-id"] || t["created-application-index"] || "");
|
|
37
|
+
const onc = appl?.["on-completion"];
|
|
38
|
+
return { type: !appl?.["application-id"] ? "App created" : onc === "delete" ? "App deleted" : onc === "optin" ? "App opt-in" : "App call", appId };
|
|
39
|
+
}
|
|
40
|
+
case "acfg":
|
|
41
|
+
return { type: t["created-asset-index"] ? "Asset created" : "Asset config", assetId: String(t["created-asset-index"] ?? t["asset-config-transaction"]?.["asset-id"] ?? "") };
|
|
42
|
+
case "afrz":
|
|
43
|
+
return { type: t["asset-freeze-transaction"]?.["new-freeze-status"] ? "Asset frozen" : "Asset unfrozen", assetId: String(t["asset-freeze-transaction"]?.["asset-id"] ?? ""), to: t["asset-freeze-transaction"]?.address };
|
|
44
|
+
case "keyreg":
|
|
45
|
+
return { type: "Key registration" };
|
|
46
|
+
default:
|
|
47
|
+
return { type: t["tx-type"] };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function decodeNote(note?: string): string | undefined {
|
|
52
|
+
if (!note) return undefined;
|
|
53
|
+
const text = utf8(fromBase64(note));
|
|
54
|
+
// Binary notes (msgpack, hashes) are not shown.
|
|
55
|
+
return text.includes("\uFFFD") || /[\u0000-\u0008\u000E-\u001F]/.test(text) ? undefined : text;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function countInner(t: IndexerTransaction): number {
|
|
59
|
+
return (t["inner-txns"] ?? []).reduce((n, i) => n + 1 + countInner(i), 0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A confirmed transaction. Transactions never change, so they are cached for good. */
|
|
63
|
+
export function TransactionRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
64
|
+
const { theme } = useAppTheme();
|
|
65
|
+
const presentation = usePresentation();
|
|
66
|
+
const tx = useTransaction(id, { visible });
|
|
67
|
+
const t = tx.data?.data as IndexerTransaction | undefined;
|
|
68
|
+
const sum = t ? summarizeTransaction(t) : undefined;
|
|
69
|
+
const amount = useFormattedAmount(sum?.amount, sum?.amount !== undefined ? sum.assetId : undefined);
|
|
70
|
+
const press = onPress ?? (presentation.onOpenTransaction ? () => presentation.onOpenTransaction!(id) : undefined);
|
|
71
|
+
const retry = tx.isError ? () => void tx.refetch() : undefined;
|
|
72
|
+
|
|
73
|
+
if (size === "inline") {
|
|
74
|
+
return <InlinePill label={sum ? `${sum.type} ${shortAddress(id)}` : `TX ${shortAddress(id)}`} dim={tx.isPending} leading={<HashtagIcon size={12} color={theme.colors.primary} />} onPress={press} />;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (size === "small") {
|
|
78
|
+
if (tx.isPending) return <RowSkeleton shape="rounded" />;
|
|
79
|
+
if (!t || !sum) return <Unavailable size="small" label={`TX ${shortAddress(id)}`} Icon={HashtagIcon} onRetry={retry} />;
|
|
80
|
+
return (
|
|
81
|
+
<Row
|
|
82
|
+
leading={<KindTile Icon={HashtagIcon} size={40} />}
|
|
83
|
+
title={<Title>{sum.amount !== undefined ? `${sum.type} · ${amount}` : sum.type}</Title>}
|
|
84
|
+
subtitle={t["round-time"] ? `Confirmed ${formatRelativeTime(t["round-time"])}` : `Round ${t["confirmed-round"]}`}
|
|
85
|
+
onPress={press}
|
|
86
|
+
accessibilityLabel={`Open transaction ${id}`}
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const full = size === "full";
|
|
92
|
+
if (tx.isPending) return <CardSkeleton media="rounded" value blocks={2} full={full} />;
|
|
93
|
+
if (!t || !sum) return <Unavailable size={size} label={`TX ${shortAddress(id)}`} Icon={HashtagIcon} onRetry={retry} />;
|
|
94
|
+
const note = decodeNote(t.note);
|
|
95
|
+
const inner = countInner(t);
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Card>
|
|
99
|
+
<CardHeader
|
|
100
|
+
media={<KindTile Icon={HashtagIcon} size={headerMedia(full)} />}
|
|
101
|
+
title={sum.type}
|
|
102
|
+
full={full}
|
|
103
|
+
meta={
|
|
104
|
+
<Text size="xxs" selectable numberOfLines={1} style={{ color: theme.colors.textDim, flexShrink: 1 }}>
|
|
105
|
+
{`${t["round-time"] ? `${formatRelativeTime(t["round-time"])} · ` : ""}${full ? id : shortAddress(id, 8, 8)}`}
|
|
106
|
+
</Text>
|
|
107
|
+
}
|
|
108
|
+
menu={<ContractMenu appId={id} type="tx" embedType="Transaction" embedProp="id" />}
|
|
109
|
+
/>
|
|
110
|
+
|
|
111
|
+
{sum.amount !== undefined ? <PriceBlock label="Amount" amount={sum.amount} assetId={sum.assetId} /> : null}
|
|
112
|
+
|
|
113
|
+
<View style={{ gap: 8 }}>
|
|
114
|
+
<PersonRow address={t.sender} role="Sender" visible={visible} />
|
|
115
|
+
{sum.to && sum.to !== t.sender ? <PersonRow address={sum.to} role="Receiver" visible={visible} /> : null}
|
|
116
|
+
</View>
|
|
117
|
+
|
|
118
|
+
{sum.appId || (sum.assetId && sum.assetId !== "0" && sum.amount === undefined) || (note && !full) ? (
|
|
119
|
+
<View>
|
|
120
|
+
{sum.appId ? (
|
|
121
|
+
<DetailLine label="Application">
|
|
122
|
+
<ApplicationRef id={sum.appId} size="inline" />
|
|
123
|
+
</DetailLine>
|
|
124
|
+
) : null}
|
|
125
|
+
{sum.assetId && sum.assetId !== "0" && sum.amount === undefined ? (
|
|
126
|
+
<DetailLine label="Asset">
|
|
127
|
+
<AssetRef id={sum.assetId} size="inline" />
|
|
128
|
+
</DetailLine>
|
|
129
|
+
) : null}
|
|
130
|
+
{note && !full ? (
|
|
131
|
+
<DetailLine label="Note">{note}</DetailLine>
|
|
132
|
+
) : null}
|
|
133
|
+
</View>
|
|
134
|
+
) : null}
|
|
135
|
+
|
|
136
|
+
{full ? (
|
|
137
|
+
<View>
|
|
138
|
+
<DetailLine label="Round">{Number(t["confirmed-round"] ?? 0).toLocaleString()}</DetailLine>
|
|
139
|
+
{t.fee !== undefined ? <DetailLine label="Fee">{`${formatAlgo(t.fee)} ALGO`}</DetailLine> : null}
|
|
140
|
+
{t.group ? <DetailLine label="Part of a group">{`${t.group.slice(0, 10)}…`}</DetailLine> : null}
|
|
141
|
+
{inner ? <DetailLine label="Inner transactions">{String(inner)}</DetailLine> : null}
|
|
142
|
+
</View>
|
|
143
|
+
) : null}
|
|
144
|
+
|
|
145
|
+
{full && note ? (
|
|
146
|
+
<Section label="Note">
|
|
147
|
+
<Inset style={{ paddingVertical: 12 }}>
|
|
148
|
+
<Text size="sm" selectable>
|
|
149
|
+
{note}
|
|
150
|
+
</Text>
|
|
151
|
+
</Inset>
|
|
152
|
+
</Section>
|
|
153
|
+
) : null}
|
|
154
|
+
</Card>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { formatAmount, type AssetData, type AssetMediaData } from "@akita-protocol/algomd-core";
|
|
2
|
+
import { useAsset, useAssetMedia } from "@akita-protocol/algomd-core/react";
|
|
3
|
+
import { algoIcon } from "../presentation/assets";
|
|
4
|
+
|
|
5
|
+
/** ALGO is asset 0 by convention. It has no on-chain asset record. */
|
|
6
|
+
export const ALGO_ASSET: AssetData = {
|
|
7
|
+
id: "0",
|
|
8
|
+
name: "Algorand",
|
|
9
|
+
unitName: "ALGO",
|
|
10
|
+
decimals: 6,
|
|
11
|
+
total: "10000000000000000",
|
|
12
|
+
creator: "",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export interface AssetInfo {
|
|
16
|
+
data?: AssetData;
|
|
17
|
+
media?: AssetMediaData;
|
|
18
|
+
image?: string;
|
|
19
|
+
/** Ticker, else name, else `ASA <id>`. */
|
|
20
|
+
label: string;
|
|
21
|
+
pending: boolean;
|
|
22
|
+
archived: boolean;
|
|
23
|
+
error: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** An asset and its media through the shared cache. Handles ALGO (id 0). */
|
|
27
|
+
export function useAssetInfo(id: string | undefined, visible?: boolean): AssetInfo {
|
|
28
|
+
const isAlgo = id === "0";
|
|
29
|
+
const asset = useAsset(isAlgo ? undefined : id, { visible });
|
|
30
|
+
const media = useAssetMedia(isAlgo ? undefined : id, { visible });
|
|
31
|
+
const data = isAlgo ? ALGO_ASSET : asset.data?.data ?? undefined;
|
|
32
|
+
return {
|
|
33
|
+
data,
|
|
34
|
+
media: media.data?.data ?? undefined,
|
|
35
|
+
image: isAlgo ? algoIcon.uri : media.data?.data?.image,
|
|
36
|
+
label: data?.unitName || data?.name || (id ? `ASA ${id}` : "Asset"),
|
|
37
|
+
pending: !isAlgo && Boolean(id) && asset.isPending,
|
|
38
|
+
archived: asset.data?.status === "archived",
|
|
39
|
+
error: asset.error,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** `100 ALGO`, `2.5 USDC`: a base-unit amount in its asset's decimals and ticker. */
|
|
44
|
+
export function useFormattedAmount(amount: string | undefined, assetId: string | undefined): string {
|
|
45
|
+
const info = useAssetInfo(assetId);
|
|
46
|
+
if (amount === undefined || amount === "") return "—";
|
|
47
|
+
if (!info.data) return info.pending ? "…" : `${amount} units`;
|
|
48
|
+
return `${formatAmount(amount, info.data.decimals, { maxFraction: 4 })} ${info.data.unitName || info.data.name || ""}`.trim();
|
|
49
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { formatAmount, formatRelativeTime, type Entity } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { GiftIcon } from "../presentation/icons";
|
|
5
|
+
import { Text, useAppTheme } from "../presentation/runtime";
|
|
6
|
+
import { useAssetInfo, useFormattedAmount } from "./assetInfo";
|
|
7
|
+
import { ActionButton, Avatar, KindTile, Note, SectionLabel, StatusBadge, type Tone } from "./primitives";
|
|
8
|
+
|
|
9
|
+
export { ActionButton };
|
|
10
|
+
|
|
11
|
+
/** Unix seconds, ticking while mounted. Countdown views use it; idle views do not. */
|
|
12
|
+
export function useNow(intervalMs = 1000, enabled = true): number {
|
|
13
|
+
const [now, setNow] = useState(() => Math.floor(Date.now() / 1000));
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!enabled) return;
|
|
16
|
+
const t = setInterval(() => setNow(Math.floor(Date.now() / 1000)), intervalMs);
|
|
17
|
+
return () => clearInterval(t);
|
|
18
|
+
}, [intervalMs, enabled]);
|
|
19
|
+
return now;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function Amount({ amount, assetId, size = "sm" }: { amount?: string; assetId?: string; size?: "xs" | "sm" | "md" | "lg" }) {
|
|
23
|
+
const text = useFormattedAmount(amount, assetId);
|
|
24
|
+
return (
|
|
25
|
+
<Text size={size} weight="semiBold" numberOfLines={1}>
|
|
26
|
+
{text}
|
|
27
|
+
</Text>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A price as the Akita app sets it: the token's icon, the amount large and
|
|
33
|
+
* bold, then the ticker and an optional period ("/ Month").
|
|
34
|
+
*/
|
|
35
|
+
export function AmountLockup({ amount, assetId, size = "xl", suffix }: { amount?: string; assetId?: string; size?: "lg" | "xl"; suffix?: string }) {
|
|
36
|
+
const { theme } = useAppTheme();
|
|
37
|
+
const info = useAssetInfo(assetId);
|
|
38
|
+
const value = amount !== undefined && info.data ? formatAmount(amount, info.data.decimals, { maxFraction: 4 }) : info.pending ? "…" : amount ?? "—";
|
|
39
|
+
const icon = size === "xl" ? 24 : 20;
|
|
40
|
+
return (
|
|
41
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 8, flexWrap: "wrap" }}>
|
|
42
|
+
<Avatar uri={info.image} size={icon} initial={info.label} />
|
|
43
|
+
<Text size={size} weight="bold" numberOfLines={1}>
|
|
44
|
+
{value}
|
|
45
|
+
</Text>
|
|
46
|
+
<Text size="sm" numberOfLines={1} style={{ color: theme.colors.textDim }}>
|
|
47
|
+
{`${info.label}${suffix ? ` ${suffix}` : ""}`}
|
|
48
|
+
</Text>
|
|
49
|
+
</View>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** A role label over a price, as the Akita marketplace card leads with "FOR SALE". */
|
|
54
|
+
export function PriceBlock({ label, amount, assetId, caption, live }: { label: string; amount?: string; assetId?: string; caption?: string; live?: boolean }) {
|
|
55
|
+
const { theme } = useAppTheme();
|
|
56
|
+
return (
|
|
57
|
+
<View style={{ gap: 6 }}>
|
|
58
|
+
<SectionLabel color={live ? theme.colors.primary : undefined}>{label}</SectionLabel>
|
|
59
|
+
<AmountLockup amount={amount} assetId={assetId} />
|
|
60
|
+
{caption ? (
|
|
61
|
+
<Text size="xxs" style={{ color: theme.colors.textDim }}>
|
|
62
|
+
{caption}
|
|
63
|
+
</Text>
|
|
64
|
+
) : null}
|
|
65
|
+
</View>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const STATUS: Record<string, [string, Tone]> = {
|
|
70
|
+
active: ["Active", "good"],
|
|
71
|
+
live: ["Live", "good"],
|
|
72
|
+
claimable: ["Claimable", "good"],
|
|
73
|
+
claimed: ["Fully claimed", "neutral"],
|
|
74
|
+
online: ["Online", "good"],
|
|
75
|
+
offered: ["Open", "good"],
|
|
76
|
+
upcoming: ["Upcoming", "warn"],
|
|
77
|
+
signups: ["Signups open", "good"],
|
|
78
|
+
locked: ["Locked", "warn"],
|
|
79
|
+
drawing: ["Drawing", "warn"],
|
|
80
|
+
escrowing: ["Escrowing", "warn"],
|
|
81
|
+
disbursing: ["Paying out", "warn"],
|
|
82
|
+
paused: ["Paused", "warn"],
|
|
83
|
+
offline: ["Offline", "warn"],
|
|
84
|
+
draft: ["Draft", "neutral"],
|
|
85
|
+
ended: ["Ended", "neutral"],
|
|
86
|
+
expired: ["Expired", "neutral"],
|
|
87
|
+
sold: ["Sold", "neutral"],
|
|
88
|
+
settled: ["Settled", "neutral"],
|
|
89
|
+
complete: ["Complete", "neutral"],
|
|
90
|
+
completed: ["Complete", "neutral"],
|
|
91
|
+
delisted: ["Delisted", "neutral"],
|
|
92
|
+
cancelled: ["Cancelled", "neutral"],
|
|
93
|
+
closed: ["Closed", "neutral"],
|
|
94
|
+
shutdown: ["Closed", "bad"],
|
|
95
|
+
deleted: ["Deleted", "bad"],
|
|
96
|
+
failed: ["Failed", "bad"],
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** A status in the one vocabulary every kind shares. */
|
|
100
|
+
export function StatusChip({ status }: { status: string }) {
|
|
101
|
+
const [label, tone] = STATUS[status] ?? [status.charAt(0).toUpperCase() + status.slice(1), "neutral"];
|
|
102
|
+
return <StatusBadge label={label} tone={tone} />;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* How far an archived entity can be trusted: rebuilt from chain history,
|
|
107
|
+
* checked against it, or not matching it.
|
|
108
|
+
*/
|
|
109
|
+
export function ProvenanceNote({ entity }: { entity?: Entity }) {
|
|
110
|
+
if (!entity || entity.status !== "archived") return null;
|
|
111
|
+
const chainDerived = entity.provenance.source === "indexer" || entity.provenance.source === "algod";
|
|
112
|
+
const v = entity.verification ?? (chainDerived ? { state: "verified" as const, checkedAt: entity.provenance.fetchedAt } : undefined);
|
|
113
|
+
const [text, tone]: [string, Tone] =
|
|
114
|
+
v?.state === "mismatch"
|
|
115
|
+
? [`The record differs from chain history (${v.mismatches?.join(", ") ?? "unknown"}). Showing the chain's values.`, "bad"]
|
|
116
|
+
: v?.state === "verified"
|
|
117
|
+
? [chainDerived ? "Final state rebuilt from chain history." : "Final state verified against chain history.", "neutral"]
|
|
118
|
+
: ["Final state from an off-chain record. Checking chain history…", "warn"];
|
|
119
|
+
return <Note tone={tone}>{text}</Note>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The prize of a listing, auction or raffle: an asset's image, or a prize box. */
|
|
123
|
+
export function PrizeThumb({ prize, isPrizeBox, size }: { prize: string; isPrizeBox: boolean; size: number }) {
|
|
124
|
+
const info = useAssetInfo(isPrizeBox ? undefined : prize);
|
|
125
|
+
if (isPrizeBox) return <KindTile Icon={GiftIcon} size={size} />;
|
|
126
|
+
return <Avatar uri={info.image} size={size} shape="rounded" initial={info.label} />;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function usePrizeLabel(prize: string | undefined, isPrizeBox: boolean | undefined): string {
|
|
130
|
+
const info = useAssetInfo(isPrizeBox || !prize ? undefined : prize);
|
|
131
|
+
if (!prize) return "Prize";
|
|
132
|
+
if (isPrizeBox) return `Prize box ${prize}`;
|
|
133
|
+
return info.data?.name || info.label;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** "Starts in 2h", "Ends in 5h 19m", "Ended 3d ago". */
|
|
137
|
+
export function timeLeft(end: number, start: number | undefined, now: number): string {
|
|
138
|
+
return start && now < start ? `Starts ${formatRelativeTime(start, now)}` : now < end ? `Ends ${formatRelativeTime(end, now)}` : `Ended ${formatRelativeTime(end, now)}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function TimeLeft({ end, start, now }: { end: number; start?: number; now: number }) {
|
|
142
|
+
const { theme } = useAppTheme();
|
|
143
|
+
return (
|
|
144
|
+
<Text size="xxs" style={{ color: theme.colors.textDim }}>
|
|
145
|
+
{timeLeft(end, start, now)}
|
|
146
|
+
</Text>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function percent(basis: string | undefined): string {
|
|
151
|
+
const n = Number(basis || 0) / 1000;
|
|
152
|
+
return `${Number.isInteger(n) ? n : n.toFixed(2)}%`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** "1 bid", "7 bids". */
|
|
156
|
+
export function plural(n: number | string, one: string, many = `${one}s`): string {
|
|
157
|
+
const v = Number(n) || 0;
|
|
158
|
+
return `${v.toLocaleString()} ${v === 1 ? one : many}`;
|
|
159
|
+
}
|