@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,142 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { formatAmount, type AssetData } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { AdaptiveImage } from "../presentation/AdaptiveImage";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
7
|
+
import { CircleStackIcon } from "../presentation/icons";
|
|
8
|
+
import { useAssetInfo } from "./assetInfo";
|
|
9
|
+
import { AccountRef, PersonRow } from "./AccountRef";
|
|
10
|
+
import {
|
|
11
|
+
Avatar,
|
|
12
|
+
Card,
|
|
13
|
+
CardHeader,
|
|
14
|
+
CardSkeleton,
|
|
15
|
+
DetailLine,
|
|
16
|
+
headerMedia,
|
|
17
|
+
InlinePill,
|
|
18
|
+
Note,
|
|
19
|
+
Row,
|
|
20
|
+
RowSkeleton,
|
|
21
|
+
Stat,
|
|
22
|
+
StatRow,
|
|
23
|
+
StatusBadge,
|
|
24
|
+
Title,
|
|
25
|
+
Unavailable,
|
|
26
|
+
useImageUrl,
|
|
27
|
+
} from "./primitives";
|
|
28
|
+
import type { RefViewProps } from "./types";
|
|
29
|
+
|
|
30
|
+
const label = (a: AssetData | undefined, id: string) => a?.unitName || a?.name || `ASA ${id}`;
|
|
31
|
+
const isCollectible = (a: AssetData) => a.decimals === 0 && a.total === "1";
|
|
32
|
+
|
|
33
|
+
/** An asset (ASA) at any size. */
|
|
34
|
+
export function AssetRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
35
|
+
const presentation = usePresentation();
|
|
36
|
+
const { data, image, pending, error } = useAssetInfo(id, visible);
|
|
37
|
+
const press = onPress ?? (presentation.onOpenAsset ? () => presentation.onOpenAsset!(id) : undefined);
|
|
38
|
+
const name = label(data, id);
|
|
39
|
+
|
|
40
|
+
if (size === "inline") {
|
|
41
|
+
return (
|
|
42
|
+
<InlinePill
|
|
43
|
+
label={name}
|
|
44
|
+
dim={pending}
|
|
45
|
+
leading={<Avatar uri={image} size={16} shape="rounded" initial={name} />}
|
|
46
|
+
onPress={press}
|
|
47
|
+
accessibilityLabel={`Open ${name}`}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (size === "small") {
|
|
53
|
+
if (pending) return <RowSkeleton shape="rounded" />;
|
|
54
|
+
if (!data) return <Unavailable size="small" label={`ASA ${id}`} Icon={CircleStackIcon} detail={error ? "Couldn't load this asset." : undefined} />;
|
|
55
|
+
return (
|
|
56
|
+
<Row
|
|
57
|
+
leading={<Avatar uri={image} size={36} shape="rounded" initial={name} />}
|
|
58
|
+
title={<Title>{data.name || name}</Title>}
|
|
59
|
+
subtitle={[data.unitName, id === "0" ? undefined : `ASA ${id}`].filter(Boolean).join(" · ")}
|
|
60
|
+
trailing={isCollectible(data) ? <StatusBadge label="NFT" /> : undefined}
|
|
61
|
+
onPress={press}
|
|
62
|
+
accessibilityLabel={`Open ${name}`}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return <AssetCard id={id} full={size === "full"} visible={visible} />;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function AssetCard({ id, full, visible }: { id: string; full: boolean; visible?: boolean }) {
|
|
71
|
+
const { theme } = useAppTheme();
|
|
72
|
+
const { data, image, media, pending, archived, error } = useAssetInfo(id, visible);
|
|
73
|
+
const hero = useImageUrl(image, 600);
|
|
74
|
+
|
|
75
|
+
if (pending) return <CardSkeleton media="rounded" blocks={1} full={full} />;
|
|
76
|
+
if (!data) return <Unavailable size={full ? "full" : "large"} label={`ASA ${id}`} Icon={CircleStackIcon} detail={error ? "Couldn't load this asset." : undefined} />;
|
|
77
|
+
|
|
78
|
+
const name = data.name || label(data, id);
|
|
79
|
+
const supply = formatAmount(data.total, data.decimals, { maxFraction: 2 });
|
|
80
|
+
const collectible = isCollectible(data);
|
|
81
|
+
const showHero = full && hero;
|
|
82
|
+
const url = data.url && /^https?:\/\//.test(data.url) ? data.url : undefined;
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<Card style={showHero ? { padding: 0, gap: 0 } : undefined}>
|
|
86
|
+
{showHero ? <AdaptiveImage uri={hero} assetId={id} maxHeight={360} /> : null}
|
|
87
|
+
<View style={{ gap: 16, padding: showHero ? 16 : 0 }}>
|
|
88
|
+
<CardHeader
|
|
89
|
+
media={showHero ? null : <Avatar uri={image} size={headerMedia(full)} shape="rounded" initial={name} />}
|
|
90
|
+
title={name}
|
|
91
|
+
full={full}
|
|
92
|
+
status={archived ? <StatusBadge label="Destroyed" tone="bad" /> : collectible ? <StatusBadge label="NFT" /> : undefined}
|
|
93
|
+
meta={[data.unitName, id === "0" ? "Native asset" : `ASA ${id}`].filter(Boolean).join(" · ")}
|
|
94
|
+
menu={id === "0" ? null : <ContractMenu appId={id} type="asset" embedType="ASA" />}
|
|
95
|
+
/>
|
|
96
|
+
|
|
97
|
+
{collectible ? null : (
|
|
98
|
+
<StatRow>
|
|
99
|
+
<Stat label="Supply">{`${supply} ${data.unitName ?? ""}`.trim()}</Stat>
|
|
100
|
+
<Stat label="Decimals" align="right">{String(data.decimals)}</Stat>
|
|
101
|
+
</StatRow>
|
|
102
|
+
)}
|
|
103
|
+
|
|
104
|
+
{data.creator ? <PersonRow address={data.creator} role="Creator" visible={visible} /> : null}
|
|
105
|
+
|
|
106
|
+
{media?.metadataVerified === false ? <Note tone="bad">Its metadata does not match the hash stored on chain.</Note> : null}
|
|
107
|
+
|
|
108
|
+
{full && media?.description ? (
|
|
109
|
+
<Text size="sm" style={{ color: theme.colors.textDim }}>
|
|
110
|
+
{media.description}
|
|
111
|
+
</Text>
|
|
112
|
+
) : null}
|
|
113
|
+
|
|
114
|
+
{full ? (
|
|
115
|
+
<View>
|
|
116
|
+
<Role label="Manager" address={data.manager} />
|
|
117
|
+
<Role label="Reserve" address={data.reserve} />
|
|
118
|
+
<Role label="Freeze" address={data.freeze} />
|
|
119
|
+
<Role label="Clawback" address={data.clawback} />
|
|
120
|
+
{collectible ? <DetailLine label="Supply">{supply}</DetailLine> : null}
|
|
121
|
+
{url ? <DetailLine label="Website">{url.replace(/^https?:\/\//, "")}</DetailLine> : null}
|
|
122
|
+
{media && media.standard !== "none" ? (
|
|
123
|
+
<DetailLine label="Metadata">
|
|
124
|
+
{media.standard === "arc3" || media.standard === "arc19"
|
|
125
|
+
? `${media.standard.toUpperCase()}${media.metadataVerified ? " · verified" : ""}`
|
|
126
|
+
: media.standard.toUpperCase()}
|
|
127
|
+
</DetailLine>
|
|
128
|
+
) : null}
|
|
129
|
+
</View>
|
|
130
|
+
) : null}
|
|
131
|
+
</View>
|
|
132
|
+
</Card>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function Role({ label: roleLabel, address }: { label: string; address?: string }) {
|
|
137
|
+
return (
|
|
138
|
+
<DetailLine label={roleLabel}>
|
|
139
|
+
{address ? <AccountRef id={address} size="inline" /> : "None"}
|
|
140
|
+
</DetailLine>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { formatRelativeTime, type AuctionData } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { useAuction } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { HandRaisedIcon } from "../presentation/icons";
|
|
7
|
+
import { usePresentation } from "../presentation/runtime";
|
|
8
|
+
import { AccountRef, PersonRow } from "./AccountRef";
|
|
9
|
+
import { useFormattedAmount } from "./assetInfo";
|
|
10
|
+
import { ActionButton, Amount, plural, PriceBlock, PrizeThumb, ProvenanceNote, StatusChip, timeLeft, useNow, usePrizeLabel } from "./contractParts";
|
|
11
|
+
import { Card, CardHeader, CardSkeleton, DetailLine, headerMedia, InlinePill, Inset, Note, Row, RowSkeleton, Section, Title, Unavailable } from "./primitives";
|
|
12
|
+
import type { RefViewProps } from "./types";
|
|
13
|
+
|
|
14
|
+
/** An auction: live state, or its final state and full bid history after deletion. */
|
|
15
|
+
export function AuctionRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
16
|
+
const presentation = usePresentation();
|
|
17
|
+
const auction = useAuction(id, { visible });
|
|
18
|
+
const data = auction.data?.data as AuctionData | undefined;
|
|
19
|
+
const live = data?.status === "live" || data?.status === "upcoming";
|
|
20
|
+
const now = useNow(1000, live && size !== "inline");
|
|
21
|
+
const prizeName = usePrizeLabel(data?.prize, data?.isPrizeBox);
|
|
22
|
+
const hasBids = Number(data?.bidCount ?? 0) > 0;
|
|
23
|
+
const shown = useFormattedAmount(hasBids ? data?.highestBid : data?.startingBid, data?.bidAsset);
|
|
24
|
+
const press = onPress ?? (presentation.onOpenContract ? () => presentation.onOpenContract!("auction", id) : undefined);
|
|
25
|
+
const bid = presentation.actions?.bid;
|
|
26
|
+
const retry = auction.isError ? () => void auction.refetch() : undefined;
|
|
27
|
+
|
|
28
|
+
if (size === "inline") {
|
|
29
|
+
return (
|
|
30
|
+
<InlinePill
|
|
31
|
+
label={data ? `${prizeName} · ${shown}` : `Auction ${id}`}
|
|
32
|
+
dim={auction.isPending}
|
|
33
|
+
leading={data ? <PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={16} /> : null}
|
|
34
|
+
onPress={press}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (size === "small") {
|
|
40
|
+
if (auction.isPending) return <RowSkeleton shape="rounded" />;
|
|
41
|
+
if (!data) return <Unavailable size="small" label={`Auction ${id}`} Icon={HandRaisedIcon} onRetry={retry} />;
|
|
42
|
+
const end = Number(data.endTimestamp);
|
|
43
|
+
return (
|
|
44
|
+
<Row
|
|
45
|
+
leading={<PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={40} />}
|
|
46
|
+
title={<Title>{prizeName}</Title>}
|
|
47
|
+
subtitle={`${hasBids ? (live ? "Highest bid" : "Won for") : "Starts at"} ${shown}${live ? ` · ends ${formatRelativeTime(end, now)}` : ""}`}
|
|
48
|
+
trailing={<StatusChip status={data.status} />}
|
|
49
|
+
onPress={press}
|
|
50
|
+
accessibilityLabel={`Open auction for ${prizeName}`}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const full = size === "full";
|
|
56
|
+
if (auction.isPending) return <CardSkeleton media="rounded" value blocks={1} action full={full} />;
|
|
57
|
+
if (!data) return <Unavailable size={size} label={`Auction ${id}`} Icon={HandRaisedIcon} onRetry={retry} />;
|
|
58
|
+
const allBids = data.bids ?? [];
|
|
59
|
+
const bids = allBids.slice(-10).reverse();
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Card>
|
|
63
|
+
<CardHeader
|
|
64
|
+
media={<PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={headerMedia(full)} />}
|
|
65
|
+
title={prizeName}
|
|
66
|
+
full={full}
|
|
67
|
+
status={<StatusChip status={data.status} />}
|
|
68
|
+
meta={timeLeft(Number(data.endTimestamp), Number(data.startTimestamp), now)}
|
|
69
|
+
menu={<ContractMenu appId={id} type="application" embedType="AuctionListing" />}
|
|
70
|
+
/>
|
|
71
|
+
|
|
72
|
+
<PriceBlock
|
|
73
|
+
label={hasBids ? (live ? "Highest bid" : "Winning bid") : "Starting bid"}
|
|
74
|
+
amount={hasBids ? data.highestBid : data.startingBid}
|
|
75
|
+
assetId={data.bidAsset}
|
|
76
|
+
caption={hasBids ? `${plural(data.bidCount, "bid")} from ${plural(data.uniqueBidders || 1, "bidder")}` : "No bids yet"}
|
|
77
|
+
live={data.status === "live"}
|
|
78
|
+
/>
|
|
79
|
+
|
|
80
|
+
<View style={{ gap: 8 }}>
|
|
81
|
+
{data.highestBidder ? (
|
|
82
|
+
<PersonRow address={data.highestBidder} role={live ? "Leading" : "Winner"} roleTone={live ? undefined : "good"} visible={visible} />
|
|
83
|
+
) : null}
|
|
84
|
+
{full || !data.highestBidder ? <PersonRow address={data.seller} role="Seller" visible={visible} /> : null}
|
|
85
|
+
{full && data.raffleWinner ? <PersonRow address={data.raffleWinner} role="Won the bid-fee raffle" visible={visible} /> : null}
|
|
86
|
+
</View>
|
|
87
|
+
|
|
88
|
+
{full && bids.length ? (
|
|
89
|
+
<Section label="Latest bids">
|
|
90
|
+
<Inset>
|
|
91
|
+
{bids.map((b, i) => (
|
|
92
|
+
<DetailLine key={`${b.round}-${i}`} label={i === 0 && live ? "Top" : `#${allBids.length - i}`}>
|
|
93
|
+
<View style={{ flexDirection: "row", alignItems: "center", flexWrap: "wrap", justifyContent: "flex-end", gap: 6 }}>
|
|
94
|
+
<AccountRef id={b.bidder} size="inline" />
|
|
95
|
+
<Amount amount={b.amount} assetId={data.bidAsset} size="xs" />
|
|
96
|
+
</View>
|
|
97
|
+
</DetailLine>
|
|
98
|
+
))}
|
|
99
|
+
</Inset>
|
|
100
|
+
</Section>
|
|
101
|
+
) : null}
|
|
102
|
+
|
|
103
|
+
<ProvenanceNote entity={auction.data} />
|
|
104
|
+
{data.status === "live" && bid ? <ActionButton label="Place a bid" onPress={() => bid(id)} /> : null}
|
|
105
|
+
{data.bidFee !== "0" && live ? <Note>Losing bids share a bid-fee raffle.</Note> : null}
|
|
106
|
+
</Card>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { useCollection } from "@akita-protocol/algomd-core/react";
|
|
4
|
+
import { AdaptiveImage } from "../presentation/AdaptiveImage";
|
|
5
|
+
import { Squares2X2Icon } from "../presentation/icons";
|
|
6
|
+
import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
7
|
+
import { useAssetInfo } from "./assetInfo";
|
|
8
|
+
import { Avatar, Card, CardHeader, CardSkeleton, headerMedia, InlinePill, Row, RowSkeleton, StatusBadge, Title, Unavailable, useImageUrl } from "./primitives";
|
|
9
|
+
import type { RefViewProps } from "./types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An NFT collection. The record comes from a resolver; its avatar and banner
|
|
13
|
+
* are assets, so their images resolve and verify like any asset's.
|
|
14
|
+
*/
|
|
15
|
+
export function CollectionRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
16
|
+
const { theme } = useAppTheme();
|
|
17
|
+
const presentation = usePresentation();
|
|
18
|
+
const collection = useCollection(id, { visible });
|
|
19
|
+
const data = collection.data?.data;
|
|
20
|
+
const avatar = useAssetInfo(data?.avatarAssetId, visible);
|
|
21
|
+
const banner = useAssetInfo(size === "full" ? data?.bannerAssetId : undefined, visible);
|
|
22
|
+
const bannerUrl = useImageUrl(banner.image, 600);
|
|
23
|
+
const name = data?.name ?? "Collection";
|
|
24
|
+
const press = onPress ?? (presentation.onOpenCollection ? () => presentation.onOpenCollection!(id) : undefined);
|
|
25
|
+
const retry = collection.isError ? () => void collection.refetch() : undefined;
|
|
26
|
+
|
|
27
|
+
if (size === "inline") {
|
|
28
|
+
return <InlinePill label={name} dim={collection.isPending} leading={<Avatar uri={avatar.image} size={16} shape="rounded" initial={name} />} onPress={press} />;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (size === "small") {
|
|
32
|
+
if (collection.isPending) return <RowSkeleton shape="rounded" />;
|
|
33
|
+
if (!data) return <Unavailable size="small" label="Collection" Icon={Squares2X2Icon} onRetry={retry} />;
|
|
34
|
+
return (
|
|
35
|
+
<Row
|
|
36
|
+
leading={<Avatar uri={avatar.image} size={36} shape="rounded" initial={name} />}
|
|
37
|
+
title={<Title>{name}</Title>}
|
|
38
|
+
subtitle={data.description}
|
|
39
|
+
trailing={data.explicit ? <StatusBadge label="Explicit" tone="warn" /> : undefined}
|
|
40
|
+
onPress={press}
|
|
41
|
+
accessibilityLabel={`Open ${name}`}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const full = size === "full";
|
|
47
|
+
if (collection.isPending) return <CardSkeleton media="rounded" full={full} blocks={0} />;
|
|
48
|
+
if (!data) return <Unavailable size={size} label="Collection" Icon={Squares2X2Icon} onRetry={retry} />;
|
|
49
|
+
const showBanner = full && bannerUrl;
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Card style={showBanner ? { padding: 0, gap: 0 } : undefined}>
|
|
53
|
+
{showBanner ? <AdaptiveImage uri={bannerUrl} assetId={data.bannerAssetId} maxHeight={220} /> : null}
|
|
54
|
+
<View style={{ gap: 12, padding: showBanner ? 16 : 0 }}>
|
|
55
|
+
<CardHeader
|
|
56
|
+
media={<Avatar uri={avatar.image} size={headerMedia(full)} shape="rounded" initial={name} />}
|
|
57
|
+
title={name}
|
|
58
|
+
full={full}
|
|
59
|
+
status={data.explicit ? <StatusBadge label="Explicit" tone="warn" /> : undefined}
|
|
60
|
+
meta="Collection"
|
|
61
|
+
/>
|
|
62
|
+
{data.description ? (
|
|
63
|
+
<Text size="sm" numberOfLines={full ? undefined : 3} style={{ color: theme.colors.textDim }}>
|
|
64
|
+
{data.description}
|
|
65
|
+
</Text>
|
|
66
|
+
) : null}
|
|
67
|
+
</View>
|
|
68
|
+
</Card>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { formatAlgo } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { useDualStake } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { BanknotesIcon } from "../presentation/icons";
|
|
7
|
+
import { useAppTheme, usePresentation } from "../presentation/runtime";
|
|
8
|
+
import { AssetRef } from "./AssetRef";
|
|
9
|
+
import { useAssetInfo, useFormattedAmount } from "./assetInfo";
|
|
10
|
+
import { ActionButton, PriceBlock, StatusChip } from "./contractParts";
|
|
11
|
+
import { Card, CardHeader, CardSkeleton, DetailLine, headerMedia, InlinePill, KindTile, Row, RowSkeleton, Stat, StatRow, Title, Unavailable } from "./primitives";
|
|
12
|
+
import type { RefViewProps } from "./types";
|
|
13
|
+
|
|
14
|
+
/** A dualSTAKE pool (an external contract): stake ALGO, earn ALGO and a paired asset. */
|
|
15
|
+
export function DualStakeRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
16
|
+
const { theme } = useAppTheme();
|
|
17
|
+
const presentation = usePresentation();
|
|
18
|
+
const pool = useDualStake(id, { visible });
|
|
19
|
+
const data = pool.data?.data ?? undefined;
|
|
20
|
+
const paired = useFormattedAmount(data?.asaBalance, data?.pairedAssetId);
|
|
21
|
+
const pairedInfo = useAssetInfo(data?.pairedAssetId);
|
|
22
|
+
const mint = presentation.actions?.dualStakeMint;
|
|
23
|
+
const redeem = presentation.actions?.dualStakeRedeem;
|
|
24
|
+
const title = data?.name || `dualSTAKE ${id}`;
|
|
25
|
+
const retry = pool.isError ? () => void pool.refetch() : undefined;
|
|
26
|
+
const status = data?.isOnline === false ? "offline" : "online";
|
|
27
|
+
|
|
28
|
+
if (size === "inline") return <InlinePill label={title} dim={pool.isPending} leading={<BanknotesIcon size={12} color={theme.colors.primary} />} onPress={onPress} />;
|
|
29
|
+
|
|
30
|
+
if (size === "small") {
|
|
31
|
+
if (pool.isPending) return <RowSkeleton shape="rounded" />;
|
|
32
|
+
if (!data) return <Unavailable size="small" label={title} Icon={BanknotesIcon} onRetry={retry} />;
|
|
33
|
+
return (
|
|
34
|
+
<Row
|
|
35
|
+
leading={<KindTile Icon={BanknotesIcon} size={40} />}
|
|
36
|
+
title={<Title>{title}</Title>}
|
|
37
|
+
subtitle={data.staked ? `${formatAlgo(data.staked, { maxFraction: 0 })} ALGO staked` : undefined}
|
|
38
|
+
trailing={data.isOnline === false ? <StatusChip status="offline" /> : undefined}
|
|
39
|
+
onPress={onPress}
|
|
40
|
+
accessibilityLabel={`Open ${title}`}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const full = size === "full";
|
|
46
|
+
if (pool.isPending) return <CardSkeleton media="rounded" value blocks={1} action full={full} />;
|
|
47
|
+
if (!data) return <Unavailable size={size} label={title} Icon={BanknotesIcon} onRetry={retry} />;
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Card>
|
|
51
|
+
<CardHeader
|
|
52
|
+
media={<KindTile Icon={BanknotesIcon} size={headerMedia(full)} />}
|
|
53
|
+
title={title}
|
|
54
|
+
full={full}
|
|
55
|
+
status={<StatusChip status={status} />}
|
|
56
|
+
meta={`Pool #${id}`}
|
|
57
|
+
menu={<ContractMenu appId={id} type="application" embedType="DualStakePool" />}
|
|
58
|
+
/>
|
|
59
|
+
{data.staked ? <PriceBlock label="Total staked" amount={data.staked} assetId="0" /> : null}
|
|
60
|
+
<StatRow>
|
|
61
|
+
<Stat label="ALGO liquidity">{data.algoBalance ? formatAlgo(data.algoBalance, { maxFraction: 0 }) : "—"}</Stat>
|
|
62
|
+
<Stat label={`${pairedInfo.label} liquidity`} align="right">{data.asaBalance ? paired : "—"}</Stat>
|
|
63
|
+
</StatRow>
|
|
64
|
+
<View>
|
|
65
|
+
<DetailLine label="Also earns">
|
|
66
|
+
<AssetRef id={data.pairedAssetId} size="inline" />
|
|
67
|
+
</DetailLine>
|
|
68
|
+
<DetailLine label="You receive">
|
|
69
|
+
<AssetRef id={data.lstAssetId} size="inline" />
|
|
70
|
+
</DetailLine>
|
|
71
|
+
</View>
|
|
72
|
+
{mint || redeem ? (
|
|
73
|
+
<View style={{ flexDirection: "row", gap: 8 }}>
|
|
74
|
+
{mint ? (
|
|
75
|
+
<View style={{ flex: 1 }}>
|
|
76
|
+
<ActionButton label="Stake" onPress={() => mint(id)} />
|
|
77
|
+
</View>
|
|
78
|
+
) : null}
|
|
79
|
+
{redeem ? (
|
|
80
|
+
<View style={{ flex: 1 }}>
|
|
81
|
+
<ActionButton label="Redeem" variant={mint ? "secondary" : "primary"} onPress={() => redeem(id)} />
|
|
82
|
+
</View>
|
|
83
|
+
) : null}
|
|
84
|
+
</View>
|
|
85
|
+
) : null}
|
|
86
|
+
</Card>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React, { createContext, useContext } from "react";
|
|
2
|
+
import { Pressable } from "react-native";
|
|
3
|
+
import { formatRelativeTime } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { usePrivateContent } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ChevronRightIcon, OutlineDocumentTextIcon, OutlineLockClosedIcon } from "../presentation/icons";
|
|
6
|
+
import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
7
|
+
import { CreatorIdentity } from "./AccountRef";
|
|
8
|
+
import { Card, CardHeader, headerMedia, InlinePill, KindTile, Note, Row, Title } from "./primitives";
|
|
9
|
+
import type { RefViewProps } from "./types";
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------- page cards
|
|
12
|
+
|
|
13
|
+
/** Pages of the post being rendered. Page cards link to them. */
|
|
14
|
+
export interface PageLinks {
|
|
15
|
+
preview?: (path: string) => string | undefined;
|
|
16
|
+
open?: (path: string) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const PageContext = createContext<PageLinks>({});
|
|
20
|
+
export const PageLinksProvider = PageContext.Provider;
|
|
21
|
+
|
|
22
|
+
/** A link to another page of the same post. Title is the author's label. */
|
|
23
|
+
export function PageCardRef({ id: path, size = "large", params, onPress }: RefViewProps) {
|
|
24
|
+
const { theme } = useAppTheme();
|
|
25
|
+
const pages = useContext(PageContext);
|
|
26
|
+
const title = params?.title || "Linked page";
|
|
27
|
+
const preview = pages.preview?.(path);
|
|
28
|
+
const press = onPress ?? (pages.open ? () => pages.open!(path) : undefined);
|
|
29
|
+
if (size === "inline") return <InlinePill label={title} leading={<OutlineDocumentTextIcon size={12} color={theme.colors.primary} />} onPress={press} />;
|
|
30
|
+
if (size === "small") {
|
|
31
|
+
return <Row leading={<KindTile Icon={OutlineDocumentTextIcon} size={36} />} title={<Title>{title}</Title>} subtitle={preview} onPress={press} />;
|
|
32
|
+
}
|
|
33
|
+
const full = size === "full";
|
|
34
|
+
return (
|
|
35
|
+
<Pressable disabled={!press} onPress={press} accessibilityRole={press ? "link" : undefined}>
|
|
36
|
+
<Card>
|
|
37
|
+
<CardHeader
|
|
38
|
+
media={<KindTile Icon={OutlineDocumentTextIcon} size={headerMedia(full)} />}
|
|
39
|
+
title={title}
|
|
40
|
+
full={full}
|
|
41
|
+
meta="Page in this post"
|
|
42
|
+
menu={press ? <ChevronRightIcon size={16} color={theme.colors.textDim} /> : null}
|
|
43
|
+
/>
|
|
44
|
+
{preview ? (
|
|
45
|
+
<Text size="sm" numberOfLines={full ? 6 : 2} style={{ color: theme.colors.textDim }}>
|
|
46
|
+
{preview}
|
|
47
|
+
</Text>
|
|
48
|
+
) : null}
|
|
49
|
+
</Card>
|
|
50
|
+
</Pressable>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ---------------------------------------------------------------- private content
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Encrypted content. Unlocking needs the viewer's keys, so the host renders it
|
|
58
|
+
* through `renderPrivateContent`. Without that, the public metadata shows.
|
|
59
|
+
*/
|
|
60
|
+
export function PrivateContentRef({ id, size = "large", params, visible }: RefViewProps) {
|
|
61
|
+
const { theme } = useAppTheme();
|
|
62
|
+
const presentation = usePresentation();
|
|
63
|
+
const title = params?.title;
|
|
64
|
+
const meta = usePrivateContent(presentation.renderPrivateContent ? undefined : id, { visible });
|
|
65
|
+
if (presentation.renderPrivateContent) return <>{presentation.renderPrivateContent(id, title, size)}</>;
|
|
66
|
+
|
|
67
|
+
const label = title || "Private content";
|
|
68
|
+
if (size === "inline") return <InlinePill label={label} leading={<OutlineLockClosedIcon size={12} color={theme.colors.primary} />} />;
|
|
69
|
+
const data = meta.data?.data ?? undefined;
|
|
70
|
+
const detail = [data?.ciphertextSize ? `${Math.max(1, Math.round(data.ciphertextSize / 1024))} KB` : undefined, data?.createdAt ? formatRelativeTime(Math.floor(data.createdAt / (data.createdAt > 1e12 ? 1000 : 1))) : undefined]
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.join(" · ");
|
|
73
|
+
if (size === "small") return <Row leading={<KindTile Icon={OutlineLockClosedIcon} size={36} />} title={<Title>{label}</Title>} subtitle={detail || "Locked"} />;
|
|
74
|
+
const full = size === "full";
|
|
75
|
+
return (
|
|
76
|
+
<Card>
|
|
77
|
+
<CardHeader media={<KindTile Icon={OutlineLockClosedIcon} size={headerMedia(full)} />} title={label} full={full} meta={detail ? `Locked · ${detail}` : "Locked"} />
|
|
78
|
+
{data?.authorAddress ? <CreatorIdentity address={data.authorAddress} label="Author" visible={visible} /> : null}
|
|
79
|
+
<Note>Only viewers the author granted access can unlock this.</Note>
|
|
80
|
+
</Card>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { formatRelativeTime, type ListingData } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { useListing } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { TagIcon } from "../presentation/icons";
|
|
7
|
+
import { usePresentation } from "../presentation/runtime";
|
|
8
|
+
import { PersonRow } from "./AccountRef";
|
|
9
|
+
import { useFormattedAmount } from "./assetInfo";
|
|
10
|
+
import { ActionButton, percent, PriceBlock, PrizeThumb, ProvenanceNote, StatusChip, usePrizeLabel } from "./contractParts";
|
|
11
|
+
import { Card, CardHeader, CardSkeleton, DetailLine, headerMedia, InlinePill, Row, RowSkeleton, Title, Unavailable } from "./primitives";
|
|
12
|
+
import type { RefViewProps } from "./types";
|
|
13
|
+
|
|
14
|
+
/** A marketplace listing: live from algod, or its final state after the app was deleted. */
|
|
15
|
+
export function ListingRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
16
|
+
const presentation = usePresentation();
|
|
17
|
+
const listing = useListing(id, { visible });
|
|
18
|
+
const data = listing.data?.data as ListingData | undefined;
|
|
19
|
+
const prizeName = usePrizeLabel(data?.prize, data?.isPrizeBox);
|
|
20
|
+
const price = useFormattedAmount(data?.price, data?.paymentAsset);
|
|
21
|
+
const press = onPress ?? (presentation.onOpenContract ? () => presentation.onOpenContract!("listing", id) : undefined);
|
|
22
|
+
const buy = presentation.actions?.buyListing;
|
|
23
|
+
const sold = data?.status === "sold";
|
|
24
|
+
const retry = listing.isError ? () => void listing.refetch() : undefined;
|
|
25
|
+
|
|
26
|
+
if (size === "inline") {
|
|
27
|
+
return (
|
|
28
|
+
<InlinePill
|
|
29
|
+
label={data ? `${prizeName} · ${sold ? "sold" : price}` : `Listing ${id}`}
|
|
30
|
+
dim={listing.isPending}
|
|
31
|
+
leading={data ? <PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={16} /> : null}
|
|
32
|
+
onPress={press}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (size === "small") {
|
|
38
|
+
if (listing.isPending) return <RowSkeleton shape="rounded" />;
|
|
39
|
+
if (!data) return <Unavailable size="small" label={`Listing ${id}`} Icon={TagIcon} onRetry={retry} />;
|
|
40
|
+
return (
|
|
41
|
+
<Row
|
|
42
|
+
leading={<PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={40} />}
|
|
43
|
+
title={<Title>{prizeName}</Title>}
|
|
44
|
+
subtitle={sold ? `Sold for ${price}` : price}
|
|
45
|
+
trailing={<StatusChip status={data.status} />}
|
|
46
|
+
onPress={press}
|
|
47
|
+
accessibilityLabel={`Open listing for ${prizeName}`}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const full = size === "full";
|
|
53
|
+
if (listing.isPending) return <CardSkeleton media="rounded" value blocks={full ? 2 : 1} action full={full} />;
|
|
54
|
+
if (!data) return <Unavailable size={size} label={`Listing ${id}`} Icon={TagIcon} onRetry={retry} />;
|
|
55
|
+
const active = data.status === "active";
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Card>
|
|
59
|
+
<CardHeader
|
|
60
|
+
media={<PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={headerMedia(full)} />}
|
|
61
|
+
title={prizeName}
|
|
62
|
+
full={full}
|
|
63
|
+
status={<StatusChip status={data.status} />}
|
|
64
|
+
meta={sold && data.closedAt ? `Sold ${formatRelativeTime(data.closedAt)}` : `Listing #${id}`}
|
|
65
|
+
menu={<ContractMenu appId={id} type="application" embedType="NFTListing" />}
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
<PriceBlock label={sold ? "Sold for" : active ? "For sale" : "Price"} amount={data.price} assetId={data.paymentAsset} live={active} />
|
|
69
|
+
|
|
70
|
+
<View style={{ gap: 8 }}>
|
|
71
|
+
{full && data.reservedFor ? <PersonRow address={data.reservedFor} role="Reserved for" roleTone="warn" visible={visible} /> : null}
|
|
72
|
+
{sold && data.buyer ? <PersonRow address={data.buyer} role="Buyer" visible={visible} /> : null}
|
|
73
|
+
<PersonRow address={data.seller} role="Seller" visible={visible} />
|
|
74
|
+
</View>
|
|
75
|
+
|
|
76
|
+
{full ? (
|
|
77
|
+
<View>
|
|
78
|
+
{data.expiration !== "0" ? <DetailLine label={active ? "Expires" : "Expired"}>{formatRelativeTime(Number(data.expiration))}</DetailLine> : null}
|
|
79
|
+
<DetailLine label="Creator royalty">{percent(data.creatorRoyalty)}</DetailLine>
|
|
80
|
+
<DetailLine label="Marketplace fee">{percent(data.marketplaceRoyalties)}</DetailLine>
|
|
81
|
+
{data.gateId !== "0" ? <DetailLine label="Buyers need">{`Gate ${data.gateId}`}</DetailLine> : null}
|
|
82
|
+
{data.closeTxId ? <DetailLine label="Closing transaction">{`${data.closeTxId.slice(0, 8)}…`}</DetailLine> : null}
|
|
83
|
+
</View>
|
|
84
|
+
) : null}
|
|
85
|
+
|
|
86
|
+
<ProvenanceNote entity={listing.data} />
|
|
87
|
+
{active && buy ? <ActionButton label={data.isPrizeBox ? "Buy bundle" : "Buy collectible"} onPress={() => buy(id)} /> : null}
|
|
88
|
+
</Card>
|
|
89
|
+
);
|
|
90
|
+
}
|