@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,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
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import React, { Fragment } from "react";
|
|
2
|
+
import { Text as NativeText, View, type TextProps } from "react-native";
|
|
3
|
+
import { parseContent, type Ref as CoreRef, type Size } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { useAlgomdClient } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { AccountRef } from "./AccountRef";
|
|
6
|
+
import { ApplicationRef } from "./ApplicationRef";
|
|
7
|
+
import { AssetRef } from "./AssetRef";
|
|
8
|
+
import { AuctionRef } from "./AuctionRef";
|
|
9
|
+
import { CollectionRef } from "./CollectionRef";
|
|
10
|
+
import { ListingRef } from "./ListingRef";
|
|
11
|
+
import { NfdRef } from "./NfdRef";
|
|
12
|
+
import { PollRef } from "./PollRef";
|
|
13
|
+
import { RaffleRef } from "./RaffleRef";
|
|
14
|
+
import { TransactionRef } from "./TransactionRef";
|
|
15
|
+
import { StakingPoolRef } from "./StakingPoolRef";
|
|
16
|
+
import { RewardRef } from "./RewardRef";
|
|
17
|
+
import { SubscriptionRef } from "./SubscriptionRef";
|
|
18
|
+
import { TradeRef } from "./TradeRef";
|
|
19
|
+
import { DualStakeRef } from "./DualStakeRef";
|
|
20
|
+
import { GuildProposalRef } from "./GuildProposalRef";
|
|
21
|
+
import { PageCardRef, PageLinksProvider, PrivateContentRef, type PageLinks } from "./HostRefs";
|
|
22
|
+
import type { RefViewProps } from "./types";
|
|
23
|
+
|
|
24
|
+
export { AccountRef } from "./AccountRef";
|
|
25
|
+
export { AssetRef } from "./AssetRef";
|
|
26
|
+
export { ApplicationRef } from "./ApplicationRef";
|
|
27
|
+
export { NfdRef } from "./NfdRef";
|
|
28
|
+
export { CollectionRef } from "./CollectionRef";
|
|
29
|
+
export { ListingRef } from "./ListingRef";
|
|
30
|
+
export { AuctionRef } from "./AuctionRef";
|
|
31
|
+
export { RaffleRef } from "./RaffleRef";
|
|
32
|
+
export { PollRef } from "./PollRef";
|
|
33
|
+
export { TransactionRef, summarizeTransaction, type TxSummary } from "./TransactionRef";
|
|
34
|
+
export { StakingPoolRef } from "./StakingPoolRef";
|
|
35
|
+
export { RewardRef } from "./RewardRef";
|
|
36
|
+
export { SubscriptionRef } from "./SubscriptionRef";
|
|
37
|
+
export { TradeRef } from "./TradeRef";
|
|
38
|
+
export { DualStakeRef } from "./DualStakeRef";
|
|
39
|
+
export { GuildProposalRef } from "./GuildProposalRef";
|
|
40
|
+
export { PageCardRef, PageLinksProvider, PrivateContentRef, type PageLinks } from "./HostRefs";
|
|
41
|
+
export { useAssetInfo, useFormattedAmount, ALGO_ASSET, type AssetInfo } from "./assetInfo";
|
|
42
|
+
export { Amount, StatusChip, ProvenanceNote, useNow } from "./contractParts";
|
|
43
|
+
export * from "./primitives";
|
|
44
|
+
export type { RefViewProps } from "./types";
|
|
45
|
+
|
|
46
|
+
/** Views for kinds rebuilt on @akita-protocol/algomd-core. Other kinds go to `fallback`. */
|
|
47
|
+
export const REF_VIEWS: Record<string, React.ComponentType<RefViewProps>> = {
|
|
48
|
+
account: AccountRef,
|
|
49
|
+
asset: AssetRef,
|
|
50
|
+
application: ApplicationRef,
|
|
51
|
+
nfd: NfdRef,
|
|
52
|
+
collection: CollectionRef,
|
|
53
|
+
listing: ListingRef,
|
|
54
|
+
auction: AuctionRef,
|
|
55
|
+
raffle: RaffleRef,
|
|
56
|
+
poll: PollRef,
|
|
57
|
+
transaction: TransactionRef,
|
|
58
|
+
"staking-pool": StakingPoolRef,
|
|
59
|
+
reward: RewardRef,
|
|
60
|
+
subscription: SubscriptionRef,
|
|
61
|
+
trade: TradeRef,
|
|
62
|
+
"dual-stake": DualStakeRef,
|
|
63
|
+
"guild-proposal": GuildProposalRef,
|
|
64
|
+
"page-card": PageCardRef,
|
|
65
|
+
"private-content": PrivateContentRef,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export interface RefProps extends RefViewProps {
|
|
69
|
+
kind: string;
|
|
70
|
+
/** Renders kinds without a view here, e.g. the host's existing components during migration. */
|
|
71
|
+
fallback?: (ref: CoreRef & { size: Size }) => React.ReactNode;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* One reference: `<Ref kind="asset" id="31566704" size="inline" />`.
|
|
76
|
+
* Block sizes sit in a View, so they fill the width on the web too, where a
|
|
77
|
+
* host's plain block parent would otherwise shrink a pressable card to fit.
|
|
78
|
+
*/
|
|
79
|
+
export function Ref({ kind, fallback, ...props }: RefProps) {
|
|
80
|
+
const Component = REF_VIEWS[kind];
|
|
81
|
+
if (Component) {
|
|
82
|
+
return props.size === "inline" ? <Component {...props} /> : <View><Component {...props} /></View>;
|
|
83
|
+
}
|
|
84
|
+
return <>{fallback?.({ kind, id: props.id, params: props.params, size: props.size ?? "large" }) ?? null}</>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface RefContentProps {
|
|
88
|
+
content: string;
|
|
89
|
+
/** Renders a run of plain text (markdown) with the inline refs that follow it. Defaults to a plain Text. */
|
|
90
|
+
renderText?: (children: React.ReactNode[], key: string) => React.ReactNode;
|
|
91
|
+
textProps?: TextProps;
|
|
92
|
+
/** Size for refs stored without one. Default `large`. */
|
|
93
|
+
defaultSize?: Size;
|
|
94
|
+
fallback?: RefProps["fallback"];
|
|
95
|
+
visible?: boolean;
|
|
96
|
+
/** Pages of this post, for page cards. */
|
|
97
|
+
pages?: PageLinks;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Renders AlgoMD content: text with inline refs flows as one Text run, and
|
|
102
|
+
* every other ref is its own block. Parsing uses the client's registry.
|
|
103
|
+
*/
|
|
104
|
+
export function RefContent({ content, renderText, textProps, defaultSize = "large", fallback, visible, pages }: RefContentProps) {
|
|
105
|
+
const client = useAlgomdClient();
|
|
106
|
+
const segments = parseContent(content, client.registry);
|
|
107
|
+
const out: React.ReactNode[] = [];
|
|
108
|
+
let run: React.ReactNode[] = [];
|
|
109
|
+
const flush = (key: string) => {
|
|
110
|
+
if (!run.length) return;
|
|
111
|
+
const children = run;
|
|
112
|
+
run = [];
|
|
113
|
+
out.push(renderText ? <Fragment key={key}>{renderText(children, key)}</Fragment> : <NativeText key={key} {...textProps}>{children}</NativeText>);
|
|
114
|
+
};
|
|
115
|
+
let afterBlock = false;
|
|
116
|
+
segments.forEach((s, i) => {
|
|
117
|
+
if (s.type === "text") {
|
|
118
|
+
// Blocks bring their own spacing; newlines next to them would add blank lines.
|
|
119
|
+
const next = segments[i + 1];
|
|
120
|
+
const beforeBlock = next?.type !== "text" && next !== undefined && (next.ref.size ?? defaultSize) !== "inline";
|
|
121
|
+
let text = afterBlock ? s.content.replace(/^\s*\n/, "") : s.content;
|
|
122
|
+
if (beforeBlock) text = text.replace(/\n\s*$/, "");
|
|
123
|
+
afterBlock = false;
|
|
124
|
+
if (text) run.push(text);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const size = s.ref.size ?? defaultSize;
|
|
128
|
+
const node = <Ref key={`r${i}`} kind={s.ref.kind} id={s.ref.id} params={s.ref.params} size={size} fallback={fallback} visible={visible} />;
|
|
129
|
+
if (size === "inline") {
|
|
130
|
+
afterBlock = false;
|
|
131
|
+
run.push(node);
|
|
132
|
+
} else {
|
|
133
|
+
afterBlock = true;
|
|
134
|
+
flush(`t${i}`);
|
|
135
|
+
out.push(<View key={`b${i}`} style={{ marginVertical: 6 }}>{node}</View>);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
flush("tail");
|
|
139
|
+
return pages ? <PageLinksProvider value={pages}>{out}</PageLinksProvider> : <>{out}</>;
|
|
140
|
+
}
|