@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,96 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { formatAlgo, formatRelativeTime, shortAddress } from "@akita-protocol/algomd-core";
|
|
3
|
+
import { useNfd } from "@akita-protocol/algomd-core/react";
|
|
4
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
5
|
+
import { AtSymbolIcon } from "../presentation/icons";
|
|
6
|
+
import { Text, usePresentation } from "../presentation/runtime";
|
|
7
|
+
import { PersonRow } from "./AccountRef";
|
|
8
|
+
import { PriceBlock } from "./contractParts";
|
|
9
|
+
import {
|
|
10
|
+
Avatar,
|
|
11
|
+
Card,
|
|
12
|
+
CardHeader,
|
|
13
|
+
CardSkeleton,
|
|
14
|
+
DetailLine,
|
|
15
|
+
headerMedia,
|
|
16
|
+
InlinePill,
|
|
17
|
+
Inset,
|
|
18
|
+
Row,
|
|
19
|
+
RowSkeleton,
|
|
20
|
+
Section,
|
|
21
|
+
StatusBadge,
|
|
22
|
+
Title,
|
|
23
|
+
Unavailable,
|
|
24
|
+
} from "./primitives";
|
|
25
|
+
import type { RefViewProps } from "./types";
|
|
26
|
+
|
|
27
|
+
const title = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
28
|
+
|
|
29
|
+
/** An NFD by name, at any size. */
|
|
30
|
+
export function NfdRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
31
|
+
const presentation = usePresentation();
|
|
32
|
+
const nfd = useNfd(id, { visible });
|
|
33
|
+
const data = nfd.data?.data;
|
|
34
|
+
const name = data?.name ?? id;
|
|
35
|
+
const press = onPress ?? (presentation.onOpenNfd ? () => presentation.onOpenNfd!(name) : undefined);
|
|
36
|
+
const forSale = data?.state === "forSale" && data.sellAmount;
|
|
37
|
+
const retry = nfd.isError ? () => void nfd.refetch() : undefined;
|
|
38
|
+
const category = data?.category && data.category !== "common" ? title(data.category) : undefined;
|
|
39
|
+
|
|
40
|
+
if (size === "inline") {
|
|
41
|
+
return <InlinePill label={name} dim={nfd.isPending} leading={<Avatar uri={data?.avatar} size={16} initial={name} />} onPress={press} />;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (size === "small") {
|
|
45
|
+
if (nfd.isPending) return <RowSkeleton />;
|
|
46
|
+
if (!data) return <Unavailable size="small" label={name} Icon={AtSymbolIcon} detail="No NFD has this name." onRetry={retry} />;
|
|
47
|
+
return (
|
|
48
|
+
<Row
|
|
49
|
+
leading={<Avatar uri={data.avatar} size={36} initial={name} />}
|
|
50
|
+
title={<Title>{name}</Title>}
|
|
51
|
+
subtitle={forSale ? `For sale · ${formatAlgo(data.sellAmount!, { maxFraction: 2 })} ALGO` : data.owner ? `Owned by ${shortAddress(data.owner)}` : title(data.state ?? "")}
|
|
52
|
+
trailing={category ? <StatusBadge label={category} /> : undefined}
|
|
53
|
+
onPress={press}
|
|
54
|
+
accessibilityLabel={`Open ${name}`}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const full = size === "full";
|
|
60
|
+
if (nfd.isPending) return <CardSkeleton blocks={1} full={full} />;
|
|
61
|
+
if (!data) return <Unavailable size={size} label={name} Icon={AtSymbolIcon} detail="No NFD has this name." onRetry={retry} />;
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Card>
|
|
65
|
+
<CardHeader
|
|
66
|
+
media={<Avatar uri={data.avatar} size={headerMedia(full)} initial={name} />}
|
|
67
|
+
title={name}
|
|
68
|
+
titleLines={1}
|
|
69
|
+
full={full}
|
|
70
|
+
status={forSale ? <StatusBadge label="For sale" tone="good" /> : category ? <StatusBadge label={category} /> : undefined}
|
|
71
|
+
meta={data.expires ? `Expires ${formatRelativeTime(data.expires)}` : undefined}
|
|
72
|
+
menu={<ContractMenu appId={data.appId ?? name} type="application" embedType="NFDProfile" embedProp="name" embedValue={name} />}
|
|
73
|
+
/>
|
|
74
|
+
{forSale ? <PriceBlock label="For sale" amount={data.sellAmount!} assetId="0" live /> : null}
|
|
75
|
+
{data.owner ? <PersonRow address={data.owner} role="Owner" visible={visible} /> : null}
|
|
76
|
+
{full ? (
|
|
77
|
+
<>
|
|
78
|
+
{data.depositAccount && data.depositAccount !== data.owner ? <PersonRow address={data.depositAccount} role="Receives payments" visible={visible} /> : null}
|
|
79
|
+
{data.verifiedAddresses.length ? (
|
|
80
|
+
<Section label={`Verified addresses · ${data.verifiedAddresses.length}`}>
|
|
81
|
+
<Inset>
|
|
82
|
+
{data.verifiedAddresses.map((a) => (
|
|
83
|
+
<DetailLine key={a} label={a === data.owner ? "Owner" : a === data.depositAccount ? "Payments" : "Linked"}>
|
|
84
|
+
<Text size="xs" weight="medium" selectable numberOfLines={1}>
|
|
85
|
+
{shortAddress(a, 6, 6)}
|
|
86
|
+
</Text>
|
|
87
|
+
</DetailLine>
|
|
88
|
+
))}
|
|
89
|
+
</Inset>
|
|
90
|
+
</Section>
|
|
91
|
+
) : null}
|
|
92
|
+
</>
|
|
93
|
+
) : null}
|
|
94
|
+
</Card>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Pressable, StyleSheet, View } from "react-native";
|
|
3
|
+
import { formatRelativeTime, type PollData } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { usePoll } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { ChartBarIcon } from "../presentation/icons";
|
|
7
|
+
import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
8
|
+
import { ActionButton, plural, ProvenanceNote, StatusChip } from "./contractParts";
|
|
9
|
+
import { Card, CardHeader, CardSkeleton, DetailLine, headerMedia, InlinePill, KindTile, Note, Row, RowSkeleton, Title, Unavailable, usePalette } from "./primitives";
|
|
10
|
+
import type { RefViewProps } from "./types";
|
|
11
|
+
|
|
12
|
+
/** A poll: live tallies, or the final tallies after the app was deleted. */
|
|
13
|
+
export function PollRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
14
|
+
const { theme } = useAppTheme();
|
|
15
|
+
const presentation = usePresentation();
|
|
16
|
+
const poll = usePoll(id, { visible });
|
|
17
|
+
const data = poll.data?.data as PollData | undefined;
|
|
18
|
+
const press = onPress ?? (presentation.onOpenContract ? () => presentation.onOpenContract!("poll", id) : undefined);
|
|
19
|
+
const retry = poll.isError ? () => void poll.refetch() : undefined;
|
|
20
|
+
|
|
21
|
+
if (size === "inline") {
|
|
22
|
+
return <InlinePill label={data?.question || `Poll ${id}`} dim={poll.isPending} leading={<ChartBarIcon size={12} color={theme.colors.primary} />} onPress={press} />;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (size === "small") {
|
|
26
|
+
if (poll.isPending) return <RowSkeleton shape="rounded" />;
|
|
27
|
+
if (!data) return <Unavailable size="small" label={`Poll ${id}`} Icon={ChartBarIcon} onRetry={retry} />;
|
|
28
|
+
const end = Number(data.endTime);
|
|
29
|
+
return (
|
|
30
|
+
<Row
|
|
31
|
+
leading={<KindTile Icon={ChartBarIcon} size={40} />}
|
|
32
|
+
title={<Title>{data.question}</Title>}
|
|
33
|
+
subtitle={`${plural(data.totalVotes, "vote")} · ${data.status === "active" ? `ends ${formatRelativeTime(end)}` : `ended ${formatRelativeTime(end)}`}`}
|
|
34
|
+
trailing={<StatusChip status={data.status} />}
|
|
35
|
+
onPress={press}
|
|
36
|
+
accessibilityLabel={`Open poll: ${data.question}`}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (poll.isPending) return <CardSkeleton media="rounded" blocks={3} full={size === "full"} />;
|
|
42
|
+
if (!data) return <Unavailable size={size} label={`Poll ${id}`} Icon={ChartBarIcon} onRetry={retry} />;
|
|
43
|
+
return <PollCard id={id} data={data} full={size === "full"} entity={poll.data} />;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function PollCard({ id, data, full, entity }: { id: string; data: PollData; full: boolean; entity: Parameters<typeof ProvenanceNote>[0]["entity"] }) {
|
|
47
|
+
const { theme, inset, tone } = usePalette();
|
|
48
|
+
const vote = usePresentation().actions?.vote;
|
|
49
|
+
const [picked, setPicked] = useState<number[]>([]);
|
|
50
|
+
const total = Number(data.totalVotes) || 0;
|
|
51
|
+
const max = Math.max(1, Number(data.maxSelected) || 1);
|
|
52
|
+
const canVote = data.status === "active" && Boolean(vote);
|
|
53
|
+
const leader = Math.max(0, ...data.options.map((o) => Number(o.votes)));
|
|
54
|
+
|
|
55
|
+
const toggle = (i: number) =>
|
|
56
|
+
setPicked((p) => (p.includes(i) ? p.filter((x) => x !== i) : max === 1 ? [i] : p.length < max ? [...p, i] : p));
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<Card>
|
|
60
|
+
<CardHeader
|
|
61
|
+
media={<KindTile Icon={ChartBarIcon} size={headerMedia(full)} />}
|
|
62
|
+
title={data.question}
|
|
63
|
+
titleLines={4}
|
|
64
|
+
full={full}
|
|
65
|
+
status={<StatusChip status={data.status} />}
|
|
66
|
+
meta={`${data.status === "active" ? "Ends" : "Ended"} ${formatRelativeTime(Number(data.endTime))}`}
|
|
67
|
+
menu={<ContractMenu appId={id} type="application" embedType="Poll" />}
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
<View style={{ gap: 8 }}>
|
|
71
|
+
{data.options.map((o, i) => {
|
|
72
|
+
const votes = Number(o.votes);
|
|
73
|
+
const share = total ? votes / total : 0;
|
|
74
|
+
const selected = picked.includes(i);
|
|
75
|
+
const winning = data.status !== "active" && votes === leader && votes > 0;
|
|
76
|
+
return (
|
|
77
|
+
<Pressable
|
|
78
|
+
key={i}
|
|
79
|
+
disabled={!canVote}
|
|
80
|
+
onPress={() => toggle(i)}
|
|
81
|
+
accessibilityRole={canVote ? "checkbox" : undefined}
|
|
82
|
+
accessibilityState={canVote ? { checked: selected } : undefined}
|
|
83
|
+
style={[styles.option, { backgroundColor: selected ? `${theme.colors.primary}2E` : inset }]}
|
|
84
|
+
>
|
|
85
|
+
<View style={[styles.bar, { width: `${share * 100}%`, backgroundColor: winning ? `${tone("good")}2E` : selected ? `${theme.colors.primary}26` : `${theme.colors.textDim}1F` }]} />
|
|
86
|
+
<Text size="xs" weight={winning || selected ? "bold" : "medium"} numberOfLines={2} style={{ flex: 1 }}>
|
|
87
|
+
{o.label}
|
|
88
|
+
</Text>
|
|
89
|
+
<Text size="xs" weight="bold" style={{ color: winning ? tone("good") : theme.colors.textDim }}>
|
|
90
|
+
{total ? `${Math.round(share * 100)}%` : "0%"}
|
|
91
|
+
</Text>
|
|
92
|
+
</Pressable>
|
|
93
|
+
);
|
|
94
|
+
})}
|
|
95
|
+
</View>
|
|
96
|
+
|
|
97
|
+
<Note>
|
|
98
|
+
{`${plural(data.totalVotes, "vote")}${data.voters !== undefined ? ` from ${plural(data.voters, "voter")}` : ""}${max > 1 ? ` · pick up to ${max}` : ""}${canVote && !picked.length ? " · tap an option to vote" : ""}`}
|
|
99
|
+
</Note>
|
|
100
|
+
|
|
101
|
+
{full && data.gateId !== "0" ? <DetailLine label="Voters need">{`Gate ${data.gateId}`}</DetailLine> : null}
|
|
102
|
+
|
|
103
|
+
<ProvenanceNote entity={entity} />
|
|
104
|
+
{canVote && picked.length ? <ActionButton label={picked.length > 1 ? `Vote for ${picked.length} options` : "Vote"} onPress={() => vote!(id, picked)} /> : null}
|
|
105
|
+
</Card>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const styles = StyleSheet.create({
|
|
110
|
+
option: {
|
|
111
|
+
alignItems: "center",
|
|
112
|
+
borderRadius: 10,
|
|
113
|
+
flexDirection: "row",
|
|
114
|
+
gap: 8,
|
|
115
|
+
overflow: "hidden",
|
|
116
|
+
paddingHorizontal: 12,
|
|
117
|
+
paddingVertical: 10,
|
|
118
|
+
},
|
|
119
|
+
bar: { bottom: 0, left: 0, position: "absolute", top: 0 },
|
|
120
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { formatRelativeTime, type RaffleData } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { useRaffle } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { TicketIcon } from "../presentation/icons";
|
|
7
|
+
import { usePresentation } from "../presentation/runtime";
|
|
8
|
+
import { PersonRow } from "./AccountRef";
|
|
9
|
+
import { useAssetInfo } from "./assetInfo";
|
|
10
|
+
import { ActionButton, plural, PrizeThumb, ProvenanceNote, StatusChip, timeLeft, useNow, usePrizeLabel } from "./contractParts";
|
|
11
|
+
import { Card, CardHeader, CardSkeleton, DetailLine, headerMedia, InlinePill, Note, Row, RowSkeleton, Section, Stat, StatRow, Title, Unavailable } from "./primitives";
|
|
12
|
+
import type { RefViewProps } from "./types";
|
|
13
|
+
|
|
14
|
+
/** A raffle: live state, or its final state and per-entrant tickets after deletion. */
|
|
15
|
+
export function RaffleRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
16
|
+
const presentation = usePresentation();
|
|
17
|
+
const raffle = useRaffle(id, { visible });
|
|
18
|
+
const data = raffle.data?.data as RaffleData | 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 ticket = useAssetInfo(data?.ticketAsset);
|
|
23
|
+
const press = onPress ?? (presentation.onOpenContract ? () => presentation.onOpenContract!("raffle", id) : undefined);
|
|
24
|
+
const enter = presentation.actions?.enterRaffle;
|
|
25
|
+
const retry = raffle.isError ? () => void raffle.refetch() : undefined;
|
|
26
|
+
|
|
27
|
+
if (size === "inline") {
|
|
28
|
+
return (
|
|
29
|
+
<InlinePill
|
|
30
|
+
label={data ? `${prizeName} · raffle` : `Raffle ${id}`}
|
|
31
|
+
dim={raffle.isPending}
|
|
32
|
+
leading={data ? <PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={16} /> : null}
|
|
33
|
+
onPress={press}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (size === "small") {
|
|
39
|
+
if (raffle.isPending) return <RowSkeleton shape="rounded" />;
|
|
40
|
+
if (!data) return <Unavailable size="small" label={`Raffle ${id}`} Icon={TicketIcon} onRetry={retry} />;
|
|
41
|
+
return (
|
|
42
|
+
<Row
|
|
43
|
+
leading={<PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={40} />}
|
|
44
|
+
title={<Title>{prizeName}</Title>}
|
|
45
|
+
subtitle={`${plural(data.ticketCount, "ticket")} · ${plural(data.entryCount, "entrant")}${live ? ` · ends ${formatRelativeTime(Number(data.endTimestamp), now)}` : ""}`}
|
|
46
|
+
trailing={<StatusChip status={data.status} />}
|
|
47
|
+
onPress={press}
|
|
48
|
+
accessibilityLabel={`Open raffle for ${prizeName}`}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const full = size === "full";
|
|
54
|
+
if (raffle.isPending) return <CardSkeleton media="rounded" blocks={2} action full={full} />;
|
|
55
|
+
if (!data) return <Unavailable size={size} label={`Raffle ${id}`} Icon={TicketIcon} onRetry={retry} />;
|
|
56
|
+
const winnerIsSeller = data.failed || (data.winner && data.winner === data.seller);
|
|
57
|
+
const entries = (data.entries ?? []).slice(0, 10);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<Card>
|
|
61
|
+
<CardHeader
|
|
62
|
+
media={<PrizeThumb prize={data.prize} isPrizeBox={data.isPrizeBox} size={headerMedia(full)} />}
|
|
63
|
+
title={prizeName}
|
|
64
|
+
full={full}
|
|
65
|
+
status={<StatusChip status={data.status} />}
|
|
66
|
+
meta={timeLeft(Number(data.endTimestamp), Number(data.startTimestamp), now)}
|
|
67
|
+
menu={<ContractMenu appId={id} type="application" embedType="RaffleListing" />}
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
<StatRow>
|
|
71
|
+
<Stat label="Tickets">{data.ticketCount}</Stat>
|
|
72
|
+
<Stat label="Entrants">{data.entryCount}</Stat>
|
|
73
|
+
<Stat label="Paid in" align="right">{ticket.label}</Stat>
|
|
74
|
+
</StatRow>
|
|
75
|
+
|
|
76
|
+
{data.winner && !winnerIsSeller ? <PersonRow address={data.winner} role="Winner" roleTone="good" visible={visible} /> : null}
|
|
77
|
+
{data.failed ? <Note tone="warn">Not enough people entered, so the prize went back to the seller.</Note> : null}
|
|
78
|
+
{full ? <PersonRow address={data.seller} role="Seller" visible={visible} /> : null}
|
|
79
|
+
|
|
80
|
+
{full ? (
|
|
81
|
+
<View>
|
|
82
|
+
<DetailLine label="Tickets per entrant">{`${data.minTickets}–${data.maxTickets}`}</DetailLine>
|
|
83
|
+
{data.minEntries !== "0" ? <DetailLine label="Needs at least">{plural(data.minEntries, "entrant")}</DetailLine> : null}
|
|
84
|
+
</View>
|
|
85
|
+
) : null}
|
|
86
|
+
|
|
87
|
+
{full && entries.length ? (
|
|
88
|
+
<Section label="Entries">
|
|
89
|
+
<View style={{ gap: 8 }}>
|
|
90
|
+
{entries.map((e) => (
|
|
91
|
+
<PersonRow key={e.entrant} address={e.entrant} role={plural(e.tickets, "ticket")} visible={visible} />
|
|
92
|
+
))}
|
|
93
|
+
</View>
|
|
94
|
+
</Section>
|
|
95
|
+
) : null}
|
|
96
|
+
|
|
97
|
+
<ProvenanceNote entity={raffle.data} />
|
|
98
|
+
{data.status === "live" && enter ? <ActionButton label="Enter raffle" onPress={() => enter(id)} /> : null}
|
|
99
|
+
</Card>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { formatRelativeTime } from "@akita-protocol/algomd-core";
|
|
3
|
+
import { useReward } from "@akita-protocol/algomd-core/react";
|
|
4
|
+
import { GiftIcon } from "../presentation/icons";
|
|
5
|
+
import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
6
|
+
import { PersonRow } from "./AccountRef";
|
|
7
|
+
import { ActionButton, plural, ProvenanceNote, StatusChip } from "./contractParts";
|
|
8
|
+
import { Card, CardHeader, CardSkeleton, headerMedia, InlinePill, KindTile, Row, RowSkeleton, Stat, StatRow, Title, Unavailable } from "./primitives";
|
|
9
|
+
import type { RefViewProps } from "./types";
|
|
10
|
+
|
|
11
|
+
/** Share of the disbursement already claimed. Unit-free, so it needs no asset. */
|
|
12
|
+
function claimedShare(distributed: string, amount: string): string {
|
|
13
|
+
const total = Number(amount);
|
|
14
|
+
if (!total) return "—";
|
|
15
|
+
const p = (Number(distributed) / total) * 100;
|
|
16
|
+
return `${p >= 99.5 || p === 0 ? Math.round(p) : p < 1 ? "<1" : Math.round(p)}%`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A reward disbursement in the Rewards singleton. */
|
|
20
|
+
export function RewardRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
21
|
+
const { theme } = useAppTheme();
|
|
22
|
+
const presentation = usePresentation();
|
|
23
|
+
const reward = useReward(id, { visible });
|
|
24
|
+
const data = reward.data?.data ?? undefined;
|
|
25
|
+
const claim = presentation.actions?.claimReward;
|
|
26
|
+
const press = onPress ?? (presentation.onOpenContract ? () => presentation.onOpenContract!("reward", id) : undefined);
|
|
27
|
+
const title = data?.title || `Reward ${id}`;
|
|
28
|
+
// A claimable disbursement with nothing left reads as done, not open.
|
|
29
|
+
const status = data?.status === "claimable" && Number(data.allocations) === 0 ? "claimed" : data?.status ?? "";
|
|
30
|
+
const retry = reward.isError ? () => void reward.refetch() : undefined;
|
|
31
|
+
const when = data
|
|
32
|
+
? data.status === "locked"
|
|
33
|
+
? `Unlocks ${formatRelativeTime(Number(data.unlockAt))}`
|
|
34
|
+
: Number(data.expiresAt) && Number(data.expiresAt) < 4_000_000_000
|
|
35
|
+
? `${data.status === "expired" ? "Expired" : "Expires"} ${formatRelativeTime(Number(data.expiresAt))}`
|
|
36
|
+
: "No expiry"
|
|
37
|
+
: "";
|
|
38
|
+
|
|
39
|
+
if (size === "inline") return <InlinePill label={title} dim={reward.isPending} leading={<GiftIcon size={12} color={theme.colors.primary} />} onPress={press} />;
|
|
40
|
+
|
|
41
|
+
if (size === "small") {
|
|
42
|
+
if (reward.isPending) return <RowSkeleton shape="rounded" />;
|
|
43
|
+
if (!data) return <Unavailable size="small" label={title} Icon={GiftIcon} onRetry={retry} />;
|
|
44
|
+
return (
|
|
45
|
+
<Row
|
|
46
|
+
leading={<KindTile Icon={GiftIcon} size={40} />}
|
|
47
|
+
title={<Title>{title}</Title>}
|
|
48
|
+
subtitle={`${plural(data.allocations, "claim")} left · ${when}`}
|
|
49
|
+
trailing={<StatusChip status={status} />}
|
|
50
|
+
onPress={press}
|
|
51
|
+
accessibilityLabel={`Open reward ${title}`}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const full = size === "full";
|
|
57
|
+
if (reward.isPending) return <CardSkeleton media="rounded" blocks={1} full={full} />;
|
|
58
|
+
if (!data) return <Unavailable size={size} label={title} Icon={GiftIcon} onRetry={retry} />;
|
|
59
|
+
const open = Number(data.allocations) > 0;
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Card>
|
|
63
|
+
<CardHeader media={<KindTile Icon={GiftIcon} size={headerMedia(full)} />} title={title} full={full} status={<StatusChip status={status} />} meta={when} />
|
|
64
|
+
{data.note ? (
|
|
65
|
+
<Text size="sm" style={{ color: theme.colors.textDim }}>
|
|
66
|
+
{data.note}
|
|
67
|
+
</Text>
|
|
68
|
+
) : null}
|
|
69
|
+
<StatRow>
|
|
70
|
+
<Stat label="Claims left">{Number(data.allocations).toLocaleString()}</Stat>
|
|
71
|
+
<Stat label="Claimed" align="right">{claimedShare(data.distributed, data.amount)}</Stat>
|
|
72
|
+
</StatRow>
|
|
73
|
+
{full && data.creator ? <PersonRow address={data.creator} role="From" visible={visible} /> : null}
|
|
74
|
+
<ProvenanceNote entity={reward.data} />
|
|
75
|
+
{data.status === "claimable" && open && claim ? <ActionButton label="Claim" onPress={() => claim(id)} /> : null}
|
|
76
|
+
</Card>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StyleSheet, View } from "react-native";
|
|
3
|
+
import { formatDuration, formatRelativeTime, type StakingPoolData, type StakingPoolReward } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { useStakingPool } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { FireIcon } from "../presentation/icons";
|
|
7
|
+
import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
8
|
+
import { CreatorIdentity } from "./AccountRef";
|
|
9
|
+
import { AssetRef } from "./AssetRef";
|
|
10
|
+
import { useFormattedAmount } from "./assetInfo";
|
|
11
|
+
import { ProvenanceNote, StatusChip, useNow } from "./contractParts";
|
|
12
|
+
import { Card, CardHeader, CardSkeleton, Chip, headerMedia, InlinePill, Inset, KindTile, Note, Row, RowSkeleton, Section, Stat, StatRow, Title, Unavailable } from "./primitives";
|
|
13
|
+
import type { RefViewProps } from "./types";
|
|
14
|
+
|
|
15
|
+
const POOL_TYPE_LABEL: Record<string, string> = {
|
|
16
|
+
none: "Open entry",
|
|
17
|
+
heartbeat: "Online stake",
|
|
18
|
+
soft: "Soft stake",
|
|
19
|
+
hard: "Hard stake",
|
|
20
|
+
lock: "Locked stake",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function timing(p: StakingPoolData, now: number): string {
|
|
24
|
+
const signup = Number(p.signupAt);
|
|
25
|
+
const start = Number(p.startAt);
|
|
26
|
+
const end = Number(p.endAt);
|
|
27
|
+
if (p.status === "draft") return "Not finalized yet";
|
|
28
|
+
if (now < signup) return `Signups open ${formatRelativeTime(signup, now)}`;
|
|
29
|
+
if (now < start) return `Starts ${formatRelativeTime(start, now)}`;
|
|
30
|
+
if (end && now < end) return `Ends ${formatRelativeTime(end, now)}`;
|
|
31
|
+
return end ? `Ended ${formatRelativeTime(end, now)}` : "Running";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function RewardLine({ reward }: { reward: StakingPoolReward }) {
|
|
35
|
+
const rate = useFormattedAmount(reward.rate, reward.asset);
|
|
36
|
+
const every = Number(reward.interval) ? ` every ${formatDuration(Number(reward.interval))}` : "";
|
|
37
|
+
const how =
|
|
38
|
+
reward.distribution === "percentage"
|
|
39
|
+
? `${Number(reward.rate) / 1000}% of stake${every}`
|
|
40
|
+
: reward.distribution === "shuffle"
|
|
41
|
+
? `${rate} to ${reward.winnerCount || "?"} winners${every}`
|
|
42
|
+
: reward.distribution === "even"
|
|
43
|
+
? `${rate} shared evenly${every}`
|
|
44
|
+
: `${rate} per staker${every}`;
|
|
45
|
+
return (
|
|
46
|
+
<View style={styles.reward}>
|
|
47
|
+
<AssetRef id={reward.asset} size="inline" />
|
|
48
|
+
<Text size="xs" weight="medium" numberOfLines={2} style={{ flex: 1, textAlign: "right" }}>
|
|
49
|
+
{how}
|
|
50
|
+
</Text>
|
|
51
|
+
</View>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A staking pool: live header and rewards, or the header of a deleted pool. */
|
|
56
|
+
export function StakingPoolRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
57
|
+
const { theme } = useAppTheme();
|
|
58
|
+
const presentation = usePresentation();
|
|
59
|
+
const pool = useStakingPool(id, { visible });
|
|
60
|
+
const data = pool.data?.data ?? undefined;
|
|
61
|
+
const live = data && data.status !== "ended" && data.status !== "closed";
|
|
62
|
+
const now = useNow(1000, Boolean(live) && size !== "inline");
|
|
63
|
+
const press = onPress ?? (presentation.onOpenContract ? () => presentation.onOpenContract!("staking-pool", id) : undefined);
|
|
64
|
+
const title = data?.title || `Staking pool ${id}`;
|
|
65
|
+
const retry = pool.isError ? () => void pool.refetch() : undefined;
|
|
66
|
+
|
|
67
|
+
if (size === "inline") return <InlinePill label={title} dim={pool.isPending} leading={<FireIcon size={12} color={theme.colors.primary} />} onPress={press} />;
|
|
68
|
+
|
|
69
|
+
if (size === "small") {
|
|
70
|
+
if (pool.isPending) return <RowSkeleton shape="rounded" />;
|
|
71
|
+
if (!data) return <Unavailable size="small" label={title} Icon={FireIcon} onRetry={retry} />;
|
|
72
|
+
return (
|
|
73
|
+
<Row
|
|
74
|
+
leading={<KindTile Icon={FireIcon} size={40} />}
|
|
75
|
+
title={<Title>{title}</Title>}
|
|
76
|
+
subtitle={`${POOL_TYPE_LABEL[data.poolType] ?? data.poolType} · ${entries(data)} · ${timing(data, now)}`}
|
|
77
|
+
trailing={<StatusChip status={data.status} />}
|
|
78
|
+
onPress={press}
|
|
79
|
+
accessibilityLabel={`Open staking pool ${title}`}
|
|
80
|
+
/>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const full = size === "full";
|
|
85
|
+
if (pool.isPending) return <CardSkeleton media="rounded" blocks={2} full={full} />;
|
|
86
|
+
if (!data) return <Unavailable size={size} label={title} Icon={FireIcon} onRetry={retry} />;
|
|
87
|
+
const rewards = data.rewards ?? [];
|
|
88
|
+
const shown = full ? rewards : rewards.slice(0, 2);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Card>
|
|
92
|
+
<CardHeader
|
|
93
|
+
media={<KindTile Icon={FireIcon} size={headerMedia(full)} />}
|
|
94
|
+
title={title}
|
|
95
|
+
full={full}
|
|
96
|
+
status={<StatusChip status={data.status} />}
|
|
97
|
+
meta={timing(data, now)}
|
|
98
|
+
menu={<ContractMenu appId={id} type="application" embedType="StakingPool" />}
|
|
99
|
+
/>
|
|
100
|
+
|
|
101
|
+
<StatRow>
|
|
102
|
+
<Stat label="Type">{POOL_TYPE_LABEL[data.poolType] ?? data.poolType}</Stat>
|
|
103
|
+
<Stat label="Stakers">{data.maxEntries !== "0" ? `${data.entryCount} / ${data.maxEntries}` : data.entryCount}</Stat>
|
|
104
|
+
<Stat label="Rewards" align="right">{data.rewards ? String(data.rewards.length) : "—"}</Stat>
|
|
105
|
+
</StatRow>
|
|
106
|
+
|
|
107
|
+
{shown.length ? (
|
|
108
|
+
<Section label="Rewards">
|
|
109
|
+
<Inset>
|
|
110
|
+
{shown.map((r) => (
|
|
111
|
+
<RewardLine key={r.id} reward={r} />
|
|
112
|
+
))}
|
|
113
|
+
{rewards.length > shown.length ? <Note>{`And ${rewards.length - shown.length} more`}</Note> : null}
|
|
114
|
+
</Inset>
|
|
115
|
+
</Section>
|
|
116
|
+
) : null}
|
|
117
|
+
|
|
118
|
+
{data.allowLateSignups || (full && data.gateId !== "0") ? (
|
|
119
|
+
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 6 }}>
|
|
120
|
+
{data.allowLateSignups ? <Chip label="Late signups allowed" /> : null}
|
|
121
|
+
{full && data.gateId !== "0" ? <Chip label={`Gate ${data.gateId}`} /> : null}
|
|
122
|
+
</View>
|
|
123
|
+
) : null}
|
|
124
|
+
|
|
125
|
+
{full && data.creator ? <CreatorIdentity address={data.creator} visible={visible} /> : null}
|
|
126
|
+
|
|
127
|
+
<ProvenanceNote entity={pool.data} />
|
|
128
|
+
</Card>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const entries = (p: StakingPoolData) => `${p.entryCount}${p.maxEntries !== "0" ? `/${p.maxEntries}` : ""} stakers`;
|
|
133
|
+
|
|
134
|
+
const styles = StyleSheet.create({
|
|
135
|
+
reward: { alignItems: "center", flexDirection: "row", gap: 12, justifyContent: "space-between", paddingVertical: 8 },
|
|
136
|
+
});
|