@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,428 @@
|
|
|
1
|
+
// Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
|
|
2
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { Image, View } from "react-native";
|
|
4
|
+
import * as Haptics from "expo-haptics";
|
|
5
|
+
import { AuctionIcon, CheckBadgeIcon, FireIcon, TicketIcon } from "./icons";
|
|
6
|
+
import { ResultPending, ResultWinner, ResultsPanel } from "./ResultsPanel";
|
|
7
|
+
import {
|
|
8
|
+
BundleContentsButton,
|
|
9
|
+
PrizeBoxHoldingsMedia,
|
|
10
|
+
type BundleSheetHandle,
|
|
11
|
+
} from "./BundleContents";
|
|
12
|
+
import { GateNotice } from "./GateRequirements";
|
|
13
|
+
|
|
14
|
+
import type { AuctionListing as AuctionListingType } from "../types/algorand";
|
|
15
|
+
import { formatNumber } from "../utils/format";
|
|
16
|
+
import { Text, useAppTheme } from "./runtime";
|
|
17
|
+
import {
|
|
18
|
+
AdaptiveImage,
|
|
19
|
+
ImagePlaceholder,
|
|
20
|
+
useImageBudget,
|
|
21
|
+
} from "./AdaptiveImage";
|
|
22
|
+
import { ContractMenu } from "./ContractMenu";
|
|
23
|
+
import {
|
|
24
|
+
OnChainActionButton,
|
|
25
|
+
OnChainActionCard,
|
|
26
|
+
OnChainActionHeader,
|
|
27
|
+
OnChainActionNotice,
|
|
28
|
+
OnChainMetric,
|
|
29
|
+
OnChainMetricGrid,
|
|
30
|
+
} from "./OnChainActionCard";
|
|
31
|
+
import { useIsAssetSubject } from "./subject";
|
|
32
|
+
import { PrizePreview } from "./PrizePreview";
|
|
33
|
+
import { getAssetIconSource, getAssetUnitName } from "./assetHelpers";
|
|
34
|
+
import {
|
|
35
|
+
formatAtomicAmount,
|
|
36
|
+
formatPrice,
|
|
37
|
+
formatShortDistance,
|
|
38
|
+
isShortDistanceDate,
|
|
39
|
+
} from "./format";
|
|
40
|
+
import { PLUGIN_COLORS } from "./pluginColors";
|
|
41
|
+
|
|
42
|
+
export interface AuctionListingDisplayProps {
|
|
43
|
+
data: AuctionListingType;
|
|
44
|
+
imageUrl?: string;
|
|
45
|
+
prizeImageUrls?: (string | undefined)[];
|
|
46
|
+
bidAssetImageUrl?: string;
|
|
47
|
+
notice?: string;
|
|
48
|
+
onRetry?: () => void;
|
|
49
|
+
onBid?: (auction: AuctionListingType) => void;
|
|
50
|
+
/** Whether the viewer passes the auction's gate; leave undefined when unchecked. */
|
|
51
|
+
gateEligible?: boolean;
|
|
52
|
+
/** Pass (true) or fail (false) for each gate rule, in the gate's rule order. */
|
|
53
|
+
gateResults?: boolean[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type AuctionWithPrizeBox = AuctionListingType & {
|
|
57
|
+
authenticityBadge?: boolean;
|
|
58
|
+
isPrizeBox?: boolean;
|
|
59
|
+
prizeBoxAppId?: string;
|
|
60
|
+
currentHighestBidRaw?: string;
|
|
61
|
+
minimumNextBidRaw?: string;
|
|
62
|
+
isSnapshot?: boolean;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const NON_IMAGE_HEIGHT = 244;
|
|
66
|
+
|
|
67
|
+
function amountLabel(
|
|
68
|
+
amount: number,
|
|
69
|
+
decimals: number,
|
|
70
|
+
unit: string,
|
|
71
|
+
rawAmount?: string,
|
|
72
|
+
): string {
|
|
73
|
+
const formatted = rawAmount
|
|
74
|
+
? formatAtomicAmount(rawAmount, decimals)
|
|
75
|
+
: undefined;
|
|
76
|
+
return `${formatted ?? formatPrice(amount, decimals)} ${unit}`.trim();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** "Starts in 3h", "Ends in 2d", "Ended 5m": the shorthand a post's timestamp uses. */
|
|
80
|
+
export function auctionTimerLabel(
|
|
81
|
+
data: Pick<AuctionListingType, "status" | "startTime" | "endTime">,
|
|
82
|
+
nowMs = Date.now(),
|
|
83
|
+
): string {
|
|
84
|
+
if (data.status === "upcoming") {
|
|
85
|
+
const at = formatShortDistance(data.startTime, nowMs);
|
|
86
|
+
if (at === "now") return "Starts now";
|
|
87
|
+
return isShortDistanceDate(data.startTime, nowMs)
|
|
88
|
+
? `Starts ${at}`
|
|
89
|
+
: `Starts in ${at}`;
|
|
90
|
+
}
|
|
91
|
+
if (data.status === "active") {
|
|
92
|
+
const at = formatShortDistance(data.endTime, nowMs);
|
|
93
|
+
if (at === "now") return "Ends now";
|
|
94
|
+
return isShortDistanceDate(data.endTime, nowMs)
|
|
95
|
+
? `Ends ${at}`
|
|
96
|
+
: `Ends in ${at}`;
|
|
97
|
+
}
|
|
98
|
+
const at = formatShortDistance(data.endTime, nowMs);
|
|
99
|
+
return at === "now" ? "Ended now" : `Ended ${at}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Re-renders on a timer so a countdown stays current; stops once nothing changes. */
|
|
103
|
+
function useNow(live: boolean): number {
|
|
104
|
+
const [now, setNow] = useState(() => Date.now());
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!live) return;
|
|
107
|
+
const id = setInterval(() => setNow(Date.now()), 30_000);
|
|
108
|
+
return () => clearInterval(id);
|
|
109
|
+
}, [live]);
|
|
110
|
+
return now;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function AuctionListingDisplay({
|
|
114
|
+
data,
|
|
115
|
+
imageUrl,
|
|
116
|
+
prizeImageUrls,
|
|
117
|
+
bidAssetImageUrl,
|
|
118
|
+
notice,
|
|
119
|
+
onRetry,
|
|
120
|
+
onBid,
|
|
121
|
+
gateEligible,
|
|
122
|
+
gateResults,
|
|
123
|
+
}: AuctionListingDisplayProps) {
|
|
124
|
+
const { theme } = useAppTheme();
|
|
125
|
+
const listing = data as AuctionWithPrizeBox;
|
|
126
|
+
const prize = data.prizes.length === 1 ? data.prizes[0] : undefined;
|
|
127
|
+
// On the prize's own page its art is already shown above, so the card starts at its header.
|
|
128
|
+
const onSubjectPage = useIsAssetSubject(
|
|
129
|
+
!listing.isPrizeBox && prize ? prize.id : undefined,
|
|
130
|
+
);
|
|
131
|
+
const isActive = data.status === "active";
|
|
132
|
+
const isOver = data.status === "ended" || data.status === "claimed";
|
|
133
|
+
const now = useNow(!isOver);
|
|
134
|
+
const endingSoon = isActive && data.endTime.getTime() - now < 60 * 60 * 1000;
|
|
135
|
+
const timerLabel = auctionTimerLabel(data, now);
|
|
136
|
+
const bidUnit = getAssetUnitName(data.bidAsset);
|
|
137
|
+
const bidIcon = getAssetIconSource(data.bidAsset, bidAssetImageUrl);
|
|
138
|
+
const maxImageHeight = useImageBudget(NON_IMAGE_HEIGHT);
|
|
139
|
+
const winner = data.winner;
|
|
140
|
+
const raffle = data.raffle;
|
|
141
|
+
const holdings = listing.isPrizeBox ? (data.prizeBox?.holdings ?? []) : [];
|
|
142
|
+
const boxSheet = useRef<BundleSheetHandle>(null);
|
|
143
|
+
const itemCount = holdings.length || data.prizes.length;
|
|
144
|
+
// Auctions have no title of their own: name the prize, like a listing does.
|
|
145
|
+
const title = listing.isPrizeBox
|
|
146
|
+
? `Prize box · ${itemCount || "multiple"} ${itemCount === 1 ? "item" : "items"}`
|
|
147
|
+
: prize
|
|
148
|
+
? prize.name
|
|
149
|
+
: data.prizes.length > 1
|
|
150
|
+
? `${data.prizes.length} prizes`
|
|
151
|
+
: data.title;
|
|
152
|
+
const verified =
|
|
153
|
+
!listing.isPrizeBox &&
|
|
154
|
+
!!prize &&
|
|
155
|
+
(listing.authenticityBadge || prize.verified);
|
|
156
|
+
// Per-rule results settle eligibility when the host didn't pass it directly.
|
|
157
|
+
const gatePassed =
|
|
158
|
+
gateEligible ??
|
|
159
|
+
(gateResults?.length && gateResults.length === data.gating?.rules?.length
|
|
160
|
+
? gateResults.every(Boolean)
|
|
161
|
+
: undefined);
|
|
162
|
+
const canBid = !!onBid && (isActive || data.status === "upcoming");
|
|
163
|
+
const noBidsYet = listing.isSnapshot || data.bidCount === 0;
|
|
164
|
+
const auctionColor = PLUGIN_COLORS.Auction;
|
|
165
|
+
const hasBidFee = (data.bidFeePercentage ?? 0) > 0;
|
|
166
|
+
const bidCountLabel = listing.isSnapshot
|
|
167
|
+
? "Not indexed"
|
|
168
|
+
: `${formatNumber(data.bidCount, 0)} ${data.bidCount === 1 ? "bid" : "bids"}`;
|
|
169
|
+
|
|
170
|
+
const media = listing.isPrizeBox ? (
|
|
171
|
+
<PrizeBoxHoldingsMedia
|
|
172
|
+
holdings={holdings}
|
|
173
|
+
onPress={() => boxSheet.current?.present()}
|
|
174
|
+
appId={listing.prizeBoxAppId}
|
|
175
|
+
maxHeight={maxImageHeight}
|
|
176
|
+
/>
|
|
177
|
+
) : data.prizes.length > 1 ? (
|
|
178
|
+
<PrizePreview prizes={data.prizes} imageUrls={prizeImageUrls} />
|
|
179
|
+
) : imageUrl ? (
|
|
180
|
+
<AdaptiveImage
|
|
181
|
+
uri={imageUrl}
|
|
182
|
+
assetId={prize?.id}
|
|
183
|
+
maxHeight={maxImageHeight}
|
|
184
|
+
borderRadiusTop={0}
|
|
185
|
+
fill
|
|
186
|
+
/>
|
|
187
|
+
) : (
|
|
188
|
+
<ImagePlaceholder
|
|
189
|
+
assetId={prize?.id}
|
|
190
|
+
maxHeight={maxImageHeight}
|
|
191
|
+
borderRadiusTop={0}
|
|
192
|
+
fill
|
|
193
|
+
/>
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
const bidAssetIcon = bidIcon ? (
|
|
197
|
+
<Image
|
|
198
|
+
source={bidIcon}
|
|
199
|
+
style={{ width: 16, height: 16, borderRadius: 8 }}
|
|
200
|
+
/>
|
|
201
|
+
) : null;
|
|
202
|
+
|
|
203
|
+
const smallBidAssetIcon = bidIcon ? (
|
|
204
|
+
<Image
|
|
205
|
+
source={bidIcon}
|
|
206
|
+
style={{ width: 14, height: 14, borderRadius: 7 }}
|
|
207
|
+
/>
|
|
208
|
+
) : null;
|
|
209
|
+
const winningBid = amountLabel(
|
|
210
|
+
data.currentHighestBid,
|
|
211
|
+
data.bidAsset.decimals,
|
|
212
|
+
bidUnit,
|
|
213
|
+
listing.currentHighestBidRaw,
|
|
214
|
+
);
|
|
215
|
+
const raffleColor = PLUGIN_COLORS.Raffle;
|
|
216
|
+
|
|
217
|
+
const raffleAmount = raffle
|
|
218
|
+
? amountLabel(
|
|
219
|
+
raffle.amount,
|
|
220
|
+
data.bidAsset.decimals,
|
|
221
|
+
bidUnit,
|
|
222
|
+
raffle.amountRaw,
|
|
223
|
+
)
|
|
224
|
+
: "";
|
|
225
|
+
|
|
226
|
+
const timer = (
|
|
227
|
+
<Text
|
|
228
|
+
size="xs"
|
|
229
|
+
weight="semiBold"
|
|
230
|
+
accessibilityLiveRegion="polite"
|
|
231
|
+
style={{
|
|
232
|
+
color: endingSoon
|
|
233
|
+
? (theme.colors.secondary ?? theme.colors.primary)
|
|
234
|
+
: theme.colors.textDim,
|
|
235
|
+
}}
|
|
236
|
+
>
|
|
237
|
+
{timerLabel}
|
|
238
|
+
</Text>
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
return (
|
|
242
|
+
<OnChainActionCard
|
|
243
|
+
accessibilityLabel={`Auction of ${title}, ${timerLabel}`}
|
|
244
|
+
media={onSubjectPage ? undefined : media}
|
|
245
|
+
testID={`auction-card-${data.id}`}
|
|
246
|
+
>
|
|
247
|
+
{onSubjectPage ? (
|
|
248
|
+
// On the prize's own page the name and art are already shown above.
|
|
249
|
+
<OnChainActionHeader
|
|
250
|
+
title="Auction"
|
|
251
|
+
titleColor={auctionColor}
|
|
252
|
+
titleIcon={<AuctionIcon size={18} color={auctionColor} />}
|
|
253
|
+
menu={<ContractMenu appId={data.id} embedType="AuctionListing" />}
|
|
254
|
+
/>
|
|
255
|
+
) : (
|
|
256
|
+
<OnChainActionHeader
|
|
257
|
+
eyebrow="Auction"
|
|
258
|
+
eyebrowColor={auctionColor}
|
|
259
|
+
eyebrowIcon={<AuctionIcon size={13} color={auctionColor} />}
|
|
260
|
+
title={title}
|
|
261
|
+
titleAccessory={
|
|
262
|
+
verified ? (
|
|
263
|
+
<CheckBadgeIcon size={18} color={theme.colors.primary} />
|
|
264
|
+
) : null
|
|
265
|
+
}
|
|
266
|
+
menu={<ContractMenu appId={data.id} embedType="AuctionListing" />}
|
|
267
|
+
/>
|
|
268
|
+
)}
|
|
269
|
+
|
|
270
|
+
{holdings.length ? <BundleContentsButton holdings={holdings} sheetRef={boxSheet} /> : null}
|
|
271
|
+
|
|
272
|
+
{isOver && winner ? null : (
|
|
273
|
+
<OnChainMetricGrid>
|
|
274
|
+
<OnChainMetric
|
|
275
|
+
valueIcon={bidAssetIcon}
|
|
276
|
+
label={
|
|
277
|
+
noBidsYet
|
|
278
|
+
? "Starting bid"
|
|
279
|
+
: isOver
|
|
280
|
+
? "Winning bid"
|
|
281
|
+
: "Current bid"
|
|
282
|
+
}
|
|
283
|
+
value={
|
|
284
|
+
noBidsYet
|
|
285
|
+
? amountLabel(
|
|
286
|
+
data.minimumNextBid,
|
|
287
|
+
data.bidAsset.decimals,
|
|
288
|
+
bidUnit,
|
|
289
|
+
listing.minimumNextBidRaw,
|
|
290
|
+
)
|
|
291
|
+
: amountLabel(
|
|
292
|
+
data.currentHighestBid,
|
|
293
|
+
data.bidAsset.decimals,
|
|
294
|
+
bidUnit,
|
|
295
|
+
listing.currentHighestBidRaw,
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
secondary={hasBidFee ? bidCountLabel : undefined}
|
|
299
|
+
/>
|
|
300
|
+
{hasBidFee ? (
|
|
301
|
+
// The fee on every bid builds a raffle pool for the bidders who don't win.
|
|
302
|
+
<OnChainMetric
|
|
303
|
+
icon={<TicketIcon size={13} color={PLUGIN_COLORS.Raffle} />}
|
|
304
|
+
valueIcon={bidAssetIcon}
|
|
305
|
+
label="Raffle pool"
|
|
306
|
+
value={
|
|
307
|
+
listing.isSnapshot
|
|
308
|
+
? "Not indexed"
|
|
309
|
+
: amountLabel(
|
|
310
|
+
raffle?.amount ?? data.currentBidFeePool ?? 0,
|
|
311
|
+
data.bidAsset.decimals,
|
|
312
|
+
bidUnit,
|
|
313
|
+
raffle?.amountRaw ?? data.currentBidFeePoolRaw,
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
secondary={`${formatTrimmedPercent(data.bidFeePercentage ?? 0)} bid fee`}
|
|
317
|
+
/>
|
|
318
|
+
) : (
|
|
319
|
+
<OnChainMetric
|
|
320
|
+
icon={<FireIcon size={13} color={theme.colors.textDim} />}
|
|
321
|
+
label="Activity"
|
|
322
|
+
value={bidCountLabel}
|
|
323
|
+
/>
|
|
324
|
+
)}
|
|
325
|
+
</OnChainMetricGrid>
|
|
326
|
+
)}
|
|
327
|
+
|
|
328
|
+
{notice ? (
|
|
329
|
+
<OnChainActionNotice detail={notice} onRetry={onRetry} />
|
|
330
|
+
) : null}
|
|
331
|
+
|
|
332
|
+
{isOver ? (
|
|
333
|
+
<>
|
|
334
|
+
{timer}
|
|
335
|
+
{winner ? (
|
|
336
|
+
<View style={{ gap: 8 }}>
|
|
337
|
+
<ResultsPanel>
|
|
338
|
+
<ResultWinner
|
|
339
|
+
address={winner}
|
|
340
|
+
label="Won the auction"
|
|
341
|
+
accent={auctionColor}
|
|
342
|
+
amount={winningBid}
|
|
343
|
+
amountIcon={smallBidAssetIcon}
|
|
344
|
+
amountCaption={
|
|
345
|
+
data.status === "claimed" ? "Claimed" : undefined
|
|
346
|
+
}
|
|
347
|
+
/>
|
|
348
|
+
</ResultsPanel>
|
|
349
|
+
{raffle ? (
|
|
350
|
+
<ResultsPanel>
|
|
351
|
+
{raffle.winner &&
|
|
352
|
+
(raffle.status === "won" || raffle.status === "claimed") ? (
|
|
353
|
+
<ResultWinner
|
|
354
|
+
address={raffle.winner}
|
|
355
|
+
label="Won the raffle"
|
|
356
|
+
glyph="ticket"
|
|
357
|
+
accent={raffleColor}
|
|
358
|
+
amount={raffleAmount}
|
|
359
|
+
amountIcon={smallBidAssetIcon}
|
|
360
|
+
amountCaption={
|
|
361
|
+
raffle.status === "claimed" ? "Claimed" : undefined
|
|
362
|
+
}
|
|
363
|
+
/>
|
|
364
|
+
) : (
|
|
365
|
+
<ResultPending
|
|
366
|
+
title={
|
|
367
|
+
raffle.status === "waiting"
|
|
368
|
+
? "Raffle not drawn yet"
|
|
369
|
+
: "Drawing the raffle"
|
|
370
|
+
}
|
|
371
|
+
detail="Takes a few rounds"
|
|
372
|
+
accent={raffleColor}
|
|
373
|
+
icon={<TicketIcon size={16} color={raffleColor} />}
|
|
374
|
+
amount={raffleAmount}
|
|
375
|
+
amountIcon={smallBidAssetIcon}
|
|
376
|
+
amountCaption="Pot"
|
|
377
|
+
/>
|
|
378
|
+
)}
|
|
379
|
+
</ResultsPanel>
|
|
380
|
+
) : null}
|
|
381
|
+
</View>
|
|
382
|
+
) : null}
|
|
383
|
+
</>
|
|
384
|
+
) : canBid && data.gating && gatePassed === false ? (
|
|
385
|
+
<>
|
|
386
|
+
{timer}
|
|
387
|
+
<GateNotice
|
|
388
|
+
gating={data.gating}
|
|
389
|
+
action="bid"
|
|
390
|
+
eligible={false}
|
|
391
|
+
results={gateResults}
|
|
392
|
+
/>
|
|
393
|
+
</>
|
|
394
|
+
) : canBid ? (
|
|
395
|
+
<>
|
|
396
|
+
{data.gating ? (
|
|
397
|
+
<GateNotice
|
|
398
|
+
gating={data.gating}
|
|
399
|
+
action="bid"
|
|
400
|
+
eligible={gatePassed}
|
|
401
|
+
results={gateResults}
|
|
402
|
+
/>
|
|
403
|
+
) : null}
|
|
404
|
+
<View style={{ gap: 8 }}>
|
|
405
|
+
{timer}
|
|
406
|
+
<View style={{ flexDirection: "row" }}>
|
|
407
|
+
<OnChainActionButton
|
|
408
|
+
accessibilityLabel={`Place a bid on ${title}`}
|
|
409
|
+
label="Place bid"
|
|
410
|
+
disabled={!isActive}
|
|
411
|
+
onPress={() => {
|
|
412
|
+
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
|
|
413
|
+
onBid?.(data);
|
|
414
|
+
}}
|
|
415
|
+
/>
|
|
416
|
+
</View>
|
|
417
|
+
</View>
|
|
418
|
+
</>
|
|
419
|
+
) : (
|
|
420
|
+
timer
|
|
421
|
+
)}
|
|
422
|
+
</OnChainActionCard>
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function formatTrimmedPercent(value: number): string {
|
|
427
|
+
return `${formatNumber(value, 3)}%`;
|
|
428
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// Shared AlgoMD presentation. Edit this library source.
|
|
2
|
+
import React, {
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useImperativeHandle,
|
|
6
|
+
useRef,
|
|
7
|
+
type Ref,
|
|
8
|
+
} from "react";
|
|
9
|
+
import { Image, Pressable, View } from "react-native";
|
|
10
|
+
import * as Haptics from "expo-haptics";
|
|
11
|
+
import {
|
|
12
|
+
BottomSheetModal,
|
|
13
|
+
BottomSheetBackdrop,
|
|
14
|
+
BottomSheetScrollView,
|
|
15
|
+
} from "./sheets";
|
|
16
|
+
import { ChevronRightIcon, PhotoIcon } from "./icons";
|
|
17
|
+
import {
|
|
18
|
+
AppPresentationProvider,
|
|
19
|
+
Text,
|
|
20
|
+
useAppTheme,
|
|
21
|
+
usePresentation,
|
|
22
|
+
} from "./runtime";
|
|
23
|
+
import { AdaptiveImage } from "./AdaptiveImage";
|
|
24
|
+
import { PrizePreview } from "./PrizePreview";
|
|
25
|
+
import { PrizeBoxMedia } from "./PrizeBoxMedia";
|
|
26
|
+
import { formatSupply } from "./ASADisplay";
|
|
27
|
+
import type { PrizeBoxHolding } from "../types/algorand";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A prize box's art: a grid of its items when it holds several, the one item's
|
|
31
|
+
* art when it holds one, or the box's own media when its contents are unknown.
|
|
32
|
+
*/
|
|
33
|
+
export function PrizeBoxHoldingsMedia({
|
|
34
|
+
holdings,
|
|
35
|
+
appId,
|
|
36
|
+
maxHeight,
|
|
37
|
+
onPress,
|
|
38
|
+
}: {
|
|
39
|
+
holdings: PrizeBoxHolding[];
|
|
40
|
+
appId?: string;
|
|
41
|
+
maxHeight: number;
|
|
42
|
+
/** Opens the contents sheet when the grid is tapped. */
|
|
43
|
+
onPress?: () => void;
|
|
44
|
+
}) {
|
|
45
|
+
if (holdings.length > 1) {
|
|
46
|
+
return (
|
|
47
|
+
<PrizePreview
|
|
48
|
+
prizes={holdings.map((holding) => holding.asset)}
|
|
49
|
+
borderRadiusTop={0}
|
|
50
|
+
onPress={onPress}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
if (holdings[0]?.asset.imageUrl) {
|
|
55
|
+
return (
|
|
56
|
+
<AdaptiveImage
|
|
57
|
+
uri={holdings[0].asset.imageUrl}
|
|
58
|
+
assetId={holdings[0].asset.id}
|
|
59
|
+
maxHeight={maxHeight}
|
|
60
|
+
borderRadiusTop={0}
|
|
61
|
+
fill
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return <PrizeBoxMedia appId={appId} />;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const THUMB = 40;
|
|
69
|
+
const SHEET_SPRING = {
|
|
70
|
+
damping: 70,
|
|
71
|
+
stiffness: 900,
|
|
72
|
+
mass: 2,
|
|
73
|
+
overshootClamping: false,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** What's inside a prize box: art or token icon, name and amount. */
|
|
77
|
+
export function BundleContents({
|
|
78
|
+
holdings,
|
|
79
|
+
limit = holdings.length,
|
|
80
|
+
}: {
|
|
81
|
+
holdings: PrizeBoxHolding[];
|
|
82
|
+
/** Rows to show before "and N more"; all of them by default. */
|
|
83
|
+
limit?: number;
|
|
84
|
+
}) {
|
|
85
|
+
const { theme } = useAppTheme();
|
|
86
|
+
const shown = holdings.slice(0, limit);
|
|
87
|
+
const rest = holdings.length - shown.length;
|
|
88
|
+
return (
|
|
89
|
+
<View style={{ gap: 12 }}>
|
|
90
|
+
{shown.map(({ asset, amountRaw }, index) => (
|
|
91
|
+
<View
|
|
92
|
+
key={`${asset.id}-${index}`}
|
|
93
|
+
style={{ flexDirection: "row", alignItems: "center", gap: 12 }}
|
|
94
|
+
>
|
|
95
|
+
{asset.imageUrl ? (
|
|
96
|
+
<Image
|
|
97
|
+
source={{ uri: asset.imageUrl }}
|
|
98
|
+
style={{
|
|
99
|
+
width: THUMB,
|
|
100
|
+
height: THUMB,
|
|
101
|
+
borderRadius: asset.decimals > 0 ? THUMB / 2 : 10,
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
) : (
|
|
105
|
+
<View
|
|
106
|
+
style={{
|
|
107
|
+
width: THUMB,
|
|
108
|
+
height: THUMB,
|
|
109
|
+
borderRadius: 10,
|
|
110
|
+
alignItems: "center",
|
|
111
|
+
justifyContent: "center",
|
|
112
|
+
backgroundColor: `${theme.colors.primary}14`,
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
<PhotoIcon size={18} color={theme.colors.textDim} />
|
|
116
|
+
</View>
|
|
117
|
+
)}
|
|
118
|
+
<Text size="sm" weight="semiBold" numberOfLines={1} style={{ flex: 1 }}>
|
|
119
|
+
{asset.name || `Asset #${asset.id}`}
|
|
120
|
+
</Text>
|
|
121
|
+
{/* A single collectible needs no "1 UNIT"; tokens and editions show their amount. */}
|
|
122
|
+
{asset.decimals === 0 && amountRaw === "1" ? null : (
|
|
123
|
+
<Text size="sm" weight="semiBold">
|
|
124
|
+
{formatSupply(amountRaw, asset.decimals)}
|
|
125
|
+
{asset.unitName ? ` ${asset.unitName}` : ""}
|
|
126
|
+
</Text>
|
|
127
|
+
)}
|
|
128
|
+
</View>
|
|
129
|
+
))}
|
|
130
|
+
{rest > 0 ? (
|
|
131
|
+
<Text size="xxs" style={{ color: theme.colors.textDim }}>
|
|
132
|
+
and {rest} more
|
|
133
|
+
</Text>
|
|
134
|
+
) : null}
|
|
135
|
+
</View>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* A text button that opens a prize box's contents in a bottom sheet, so the card
|
|
141
|
+
* keeps to the art, the price and the action.
|
|
142
|
+
*/
|
|
143
|
+
export interface BundleSheetHandle {
|
|
144
|
+
present: () => void;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function BundleContentsButton({
|
|
148
|
+
holdings,
|
|
149
|
+
sheetRef: handleRef,
|
|
150
|
+
}: {
|
|
151
|
+
holdings: PrizeBoxHolding[];
|
|
152
|
+
/** Lets the box's art open the same sheet. */
|
|
153
|
+
sheetRef?: Ref<BundleSheetHandle>;
|
|
154
|
+
}) {
|
|
155
|
+
const { theme } = useAppTheme();
|
|
156
|
+
const presentation = usePresentation();
|
|
157
|
+
const PortalProvider =
|
|
158
|
+
presentation.components?.PortalProvider ?? React.Fragment;
|
|
159
|
+
const sheetRef = useRef<BottomSheetModal>(null);
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
const sheet = sheetRef.current;
|
|
162
|
+
return () => sheet?.dismiss();
|
|
163
|
+
}, []);
|
|
164
|
+
const open = useCallback(() => {
|
|
165
|
+
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
|
|
166
|
+
sheetRef.current?.present();
|
|
167
|
+
}, []);
|
|
168
|
+
useImperativeHandle(handleRef, () => ({ present: open }), [open]);
|
|
169
|
+
const count = `${holdings.length} ${holdings.length === 1 ? "item" : "items"}`;
|
|
170
|
+
return (
|
|
171
|
+
<>
|
|
172
|
+
<Pressable
|
|
173
|
+
accessibilityRole="button"
|
|
174
|
+
accessibilityLabel={`View the ${count} in this prize box`}
|
|
175
|
+
onPress={open}
|
|
176
|
+
style={({ pressed }) => [
|
|
177
|
+
{
|
|
178
|
+
flexDirection: "row",
|
|
179
|
+
alignItems: "center",
|
|
180
|
+
alignSelf: "flex-start",
|
|
181
|
+
gap: 4,
|
|
182
|
+
},
|
|
183
|
+
pressed && { opacity: 0.7 },
|
|
184
|
+
]}
|
|
185
|
+
>
|
|
186
|
+
<Text size="xs" weight="semiBold" style={{ color: theme.colors.primary }}>
|
|
187
|
+
View items
|
|
188
|
+
</Text>
|
|
189
|
+
<ChevronRightIcon size={14} color={theme.colors.primary} />
|
|
190
|
+
</Pressable>
|
|
191
|
+
<BottomSheetModal
|
|
192
|
+
ref={sheetRef}
|
|
193
|
+
enableDynamicSizing
|
|
194
|
+
backgroundStyle={{ backgroundColor: theme.colors.background }}
|
|
195
|
+
handleIndicatorStyle={{ backgroundColor: theme.colors.border }}
|
|
196
|
+
animationConfigs={SHEET_SPRING}
|
|
197
|
+
backdropComponent={(
|
|
198
|
+
props: React.ComponentProps<typeof BottomSheetBackdrop>,
|
|
199
|
+
) => (
|
|
200
|
+
<BottomSheetBackdrop
|
|
201
|
+
{...props}
|
|
202
|
+
appearsOnIndex={0}
|
|
203
|
+
disappearsOnIndex={-1}
|
|
204
|
+
pressBehavior="close"
|
|
205
|
+
/>
|
|
206
|
+
)}
|
|
207
|
+
>
|
|
208
|
+
<PortalProvider>
|
|
209
|
+
<AppPresentationProvider {...presentation}>
|
|
210
|
+
<BottomSheetScrollView
|
|
211
|
+
contentContainerStyle={{
|
|
212
|
+
paddingHorizontal: 20,
|
|
213
|
+
paddingTop: 4,
|
|
214
|
+
paddingBottom: 40,
|
|
215
|
+
gap: 16,
|
|
216
|
+
}}
|
|
217
|
+
>
|
|
218
|
+
<Text size="md" weight="bold">
|
|
219
|
+
{`In this prize box · ${count}`}
|
|
220
|
+
</Text>
|
|
221
|
+
<BundleContents holdings={holdings} />
|
|
222
|
+
</BottomSheetScrollView>
|
|
223
|
+
</AppPresentationProvider>
|
|
224
|
+
</PortalProvider>
|
|
225
|
+
</BottomSheetModal>
|
|
226
|
+
</>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { StyleProp, View, ViewStyle } from "react-native";
|
|
4
|
+
import { useAppTheme } from "./runtime";
|
|
5
|
+
|
|
6
|
+
export interface CardContainerProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
compact?: boolean;
|
|
9
|
+
style?: StyleProp<ViewStyle>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Inline compact pill height matches the default AlgoMDContent line height (22px).
|
|
14
|
+
* This ensures pills sit flush with surrounding text in flex-wrap rows.
|
|
15
|
+
*/
|
|
16
|
+
const COMPACT_HEIGHT = 22;
|
|
17
|
+
|
|
18
|
+
export function CardContainer({
|
|
19
|
+
children,
|
|
20
|
+
compact,
|
|
21
|
+
style,
|
|
22
|
+
}: CardContainerProps) {
|
|
23
|
+
const { theme } = useAppTheme();
|
|
24
|
+
|
|
25
|
+
if (compact) {
|
|
26
|
+
return (
|
|
27
|
+
<View
|
|
28
|
+
style={[
|
|
29
|
+
{
|
|
30
|
+
backgroundColor: theme.colors.accentBackground,
|
|
31
|
+
borderRadius: 9999,
|
|
32
|
+
paddingHorizontal: 6,
|
|
33
|
+
height: COMPACT_HEIGHT,
|
|
34
|
+
justifyContent: "center",
|
|
35
|
+
},
|
|
36
|
+
style,
|
|
37
|
+
]}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</View>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<View
|
|
46
|
+
style={[
|
|
47
|
+
{
|
|
48
|
+
backgroundColor: theme.colors.accentBackground,
|
|
49
|
+
borderRadius: 16,
|
|
50
|
+
padding: 16,
|
|
51
|
+
borderWidth: 1,
|
|
52
|
+
borderColor: theme.colors.border,
|
|
53
|
+
overflow: "hidden",
|
|
54
|
+
},
|
|
55
|
+
style,
|
|
56
|
+
]}
|
|
57
|
+
>
|
|
58
|
+
{children}
|
|
59
|
+
</View>
|
|
60
|
+
);
|
|
61
|
+
}
|