@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.
Files changed (138) hide show
  1. package/README.md +137 -2
  2. package/package.json +118 -3
  3. package/src/adapters/index.ts +4 -0
  4. package/src/adapters/txn-graph.ts +138 -0
  5. package/src/components/ASA.tsx +38 -0
  6. package/src/components/ASASearch.tsx +79 -0
  7. package/src/components/Account.tsx +42 -0
  8. package/src/components/AccountSearch.tsx +75 -0
  9. package/src/components/AuctionListing.tsx +40 -0
  10. package/src/components/Collection.tsx +42 -0
  11. package/src/components/DualStakePool.tsx +244 -0
  12. package/src/components/NFDProfile.tsx +45 -0
  13. package/src/components/NFDSearch.tsx +81 -0
  14. package/src/components/NFTListing.tsx +73 -0
  15. package/src/components/NFTSearch.tsx +68 -0
  16. package/src/components/Poll.tsx +39 -0
  17. package/src/components/PollSearch.tsx +79 -0
  18. package/src/components/PrizeBoxBundle.tsx +1 -0
  19. package/src/components/RaffleListing.tsx +40 -0
  20. package/src/components/SelfFetching.tsx +1048 -0
  21. package/src/components/StakingPool.tsx +134 -0
  22. package/src/components/TradeOffer.tsx +47 -0
  23. package/src/components/TradeSearch.tsx +103 -0
  24. package/src/components/TransactionDetails.tsx +37 -0
  25. package/src/components/TransactionSearch.tsx +102 -0
  26. package/src/components/TransactionsGraph.tsx +60 -0
  27. package/src/components/index.ts +41 -0
  28. package/src/fonts/OFL.txt +93 -0
  29. package/src/fonts/SpaceGrotesk_300Light.ttf +0 -0
  30. package/src/fonts/SpaceGrotesk_400Regular.ttf +0 -0
  31. package/src/fonts/SpaceGrotesk_500Medium.ttf +0 -0
  32. package/src/fonts/SpaceGrotesk_600SemiBold.ttf +0 -0
  33. package/src/fonts/SpaceGrotesk_700Bold.ttf +0 -0
  34. package/src/fonts/app.css +5 -0
  35. package/src/graph.ts +3 -0
  36. package/src/hooks/index.ts +17 -0
  37. package/src/hooks/useAlgomdData.ts +1539 -0
  38. package/src/hooks/useAlgorandClient.ts +54 -0
  39. package/src/index.ts +147 -0
  40. package/src/presentation/ASADisplay.tsx +380 -0
  41. package/src/presentation/AccountDisplay.tsx +132 -0
  42. package/src/presentation/AccountMentionInline.tsx +38 -0
  43. package/src/presentation/AccountMentionText.tsx +80 -0
  44. package/src/presentation/AdaptiveImage.tsx +314 -0
  45. package/src/presentation/AssetMention.tsx +87 -0
  46. package/src/presentation/AuctionListingDisplay.tsx +428 -0
  47. package/src/presentation/BundleContents.tsx +228 -0
  48. package/src/presentation/CardContainer.tsx +61 -0
  49. package/src/presentation/CardEntrance.tsx +21 -0
  50. package/src/presentation/CollectionDisplay.tsx +168 -0
  51. package/src/presentation/ContractMenu.tsx +243 -0
  52. package/src/presentation/DualStakePoolDisplay.tsx +335 -0
  53. package/src/presentation/Embeds.tsx +300 -0
  54. package/src/presentation/GateRequirements.tsx +334 -0
  55. package/src/presentation/HEROICONS-LICENSE.txt +21 -0
  56. package/src/presentation/NFDProfileDisplay.tsx +194 -0
  57. package/src/presentation/NFTListingDisplay.tsx +284 -0
  58. package/src/presentation/OnChainActionCard.tsx +557 -0
  59. package/src/presentation/PollDisplay.tsx +222 -0
  60. package/src/presentation/PrizeBoxBundleDisplay.tsx +103 -0
  61. package/src/presentation/PrizeBoxMedia.tsx +46 -0
  62. package/src/presentation/PrizePreview.tsx +296 -0
  63. package/src/presentation/ProgressBar.tsx +50 -0
  64. package/src/presentation/RaffleListingDisplay.tsx +399 -0
  65. package/src/presentation/References.tsx +310 -0
  66. package/src/presentation/ReservedNotice.tsx +73 -0
  67. package/src/presentation/ResultsPanel.tsx +241 -0
  68. package/src/presentation/Sparkline.tsx +70 -0
  69. package/src/presentation/SquishyPressable.tsx +145 -0
  70. package/src/presentation/StakingPoolDisplay.tsx +419 -0
  71. package/src/presentation/StatusBadge.tsx +56 -0
  72. package/src/presentation/TradeOfferDisplay.tsx +275 -0
  73. package/src/presentation/TransactionDisplay.tsx +262 -0
  74. package/src/presentation/WinnerBadge.tsx +58 -0
  75. package/src/presentation/assetHelpers.ts +36 -0
  76. package/src/presentation/assets.ts +7 -0
  77. package/src/presentation/explorer.ts +95 -0
  78. package/src/presentation/format.ts +90 -0
  79. package/src/presentation/gates.ts +100 -0
  80. package/src/presentation/icons.tsx +1178 -0
  81. package/src/presentation/identity.tsx +175 -0
  82. package/src/presentation/index.ts +88 -0
  83. package/src/presentation/media.ts +70 -0
  84. package/src/presentation/pluginColors.ts +8 -0
  85. package/src/presentation/runtime.tsx +280 -0
  86. package/src/presentation/sheets.tsx +7 -0
  87. package/src/presentation/subject.tsx +31 -0
  88. package/src/presentation/textTheme.ts +17 -0
  89. package/src/presentation/themes.json +158 -0
  90. package/src/presentation/variants.ts +14 -0
  91. package/src/provider/AlgomdProvider.tsx +45 -0
  92. package/src/provider/context.ts +18 -0
  93. package/src/provider/imageResolver.ts +12 -0
  94. package/src/provider/index.ts +5 -0
  95. package/src/provider/networks.ts +23 -0
  96. package/src/provider/types.ts +29 -0
  97. package/src/refs/AccountRef.tsx +226 -0
  98. package/src/refs/ApplicationRef.tsx +72 -0
  99. package/src/refs/AssetRef.tsx +142 -0
  100. package/src/refs/AuctionRef.tsx +108 -0
  101. package/src/refs/CollectionRef.tsx +70 -0
  102. package/src/refs/DualStakeRef.tsx +88 -0
  103. package/src/refs/GuildProposalRef.tsx +285 -0
  104. package/src/refs/HostRefs.tsx +82 -0
  105. package/src/refs/ListingRef.tsx +90 -0
  106. package/src/refs/NfdRef.tsx +96 -0
  107. package/src/refs/PollRef.tsx +120 -0
  108. package/src/refs/RaffleRef.tsx +101 -0
  109. package/src/refs/RewardRef.tsx +78 -0
  110. package/src/refs/StakingPoolRef.tsx +136 -0
  111. package/src/refs/SubscriptionRef.tsx +200 -0
  112. package/src/refs/TradeRef.tsx +100 -0
  113. package/src/refs/TransactionRef.tsx +156 -0
  114. package/src/refs/assetInfo.ts +49 -0
  115. package/src/refs/contractParts.tsx +159 -0
  116. package/src/refs/index.tsx +140 -0
  117. package/src/refs/primitives.tsx +588 -0
  118. package/src/refs/types.ts +13 -0
  119. package/src/types/algorand.ts +496 -0
  120. package/src/types/index.ts +1 -0
  121. package/src/ui/CopyButton.tsx +44 -0
  122. package/src/ui/DataStates.tsx +45 -0
  123. package/src/ui/ProgressBar.tsx +64 -0
  124. package/src/ui/SearchSheet.tsx +141 -0
  125. package/src/ui/SizeContainer.tsx +25 -0
  126. package/src/ui/StatusBadge.tsx +51 -0
  127. package/src/ui/index.ts +6 -0
  128. package/src/utils/algomdImageUrl.ts +20 -0
  129. package/src/utils/arc19.ts +120 -0
  130. package/src/utils/arc62.ts +246 -0
  131. package/src/utils/capacity.ts +26 -0
  132. package/src/utils/format.ts +181 -0
  133. package/src/utils/ids.ts +31 -0
  134. package/src/utils/index.ts +6 -0
  135. package/src/utils/nfdDisplay.ts +45 -0
  136. package/src/utils/search.ts +87 -0
  137. package/src/utils/stakingPool.ts +174 -0
  138. package/src/utils/stakingSnapshot.ts +132 -0
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Block explorer links. Each explorer addresses networks and entities its own way, so every
3
+ * fallback explorer link goes through `explorerUrl` with the host's chosen explorer.
4
+ */
5
+ export type ExplorerId = "akita" | "allo" | "lora" | "algosurf";
6
+ export type ExplorerEntity = "transaction" | "account" | "asset" | "application" | "block";
7
+
8
+ export const DEFAULT_EXPLORER: ExplorerId = "akita";
9
+
10
+ export const EXPLORERS: readonly { id: ExplorerId; label: string }[] = [
11
+ { id: "akita", label: "Akita" },
12
+ { id: "allo", label: "Allo" },
13
+ { id: "lora", label: "Lora" },
14
+ { id: "algosurf", label: "AlgoSurf" },
15
+ ];
16
+
17
+ export function isExplorerId(value: unknown): value is ExplorerId {
18
+ return EXPLORERS.some((explorer) => explorer.id === value);
19
+ }
20
+
21
+ export function explorerLabel(explorer: ExplorerId): string {
22
+ return EXPLORERS.find((candidate) => candidate.id === explorer)?.label ?? explorer;
23
+ }
24
+
25
+ // Akita's explorer is a fork of Lora and keeps its routes: /<network>/<entity>/<id>.
26
+ const LORA_ORIGINS: Record<"akita" | "lora", string> = {
27
+ akita: "https://explorer.akita.community",
28
+ lora: "https://lora.algokit.io",
29
+ };
30
+
31
+ const ALLO_PATHS: Record<ExplorerEntity, string> = {
32
+ transaction: "tx",
33
+ account: "account",
34
+ asset: "asset",
35
+ application: "application",
36
+ block: "block",
37
+ };
38
+
39
+ // AlgoSurf serves each network on its own host.
40
+ const ALGOSURF_HOSTS: Record<string, string> = {
41
+ mainnet: "algo.surf",
42
+ testnet: "testnet.algo.surf",
43
+ betanet: "b.algo.surf",
44
+ fnet: "f.algo.surf",
45
+ localnet: "l.algo.surf",
46
+ };
47
+
48
+ export function explorerUrl(
49
+ explorer: ExplorerId,
50
+ network: string,
51
+ entity: ExplorerEntity,
52
+ id: string | number | bigint,
53
+ ): string {
54
+ const value = encodeURIComponent(id.toString());
55
+ switch (explorer) {
56
+ case "allo": {
57
+ const origin = network === "mainnet" ? "https://allo.info" : "https://testnet.allo.info";
58
+ return `${origin}/${ALLO_PATHS[entity]}/${value}`;
59
+ }
60
+ case "algosurf": {
61
+ const origin = `https://${ALGOSURF_HOSTS[network] ?? ALGOSURF_HOSTS.mainnet}`;
62
+ // AlgoSurf resolves a bare transaction ID, asset or application ID, or round from the
63
+ // path; accounts have their own route. A round takes a trailing slash so it is not read
64
+ // as an asset or application ID.
65
+ if (entity === "account") return `${origin}/account/${value}`;
66
+ if (entity === "block") return `${origin}/${value}/`;
67
+ return `${origin}/${value}`;
68
+ }
69
+ default:
70
+ return `${LORA_ORIGINS[explorer]}/${encodeURIComponent(network)}/${entity}/${value}`;
71
+ }
72
+ };
73
+
74
+ const PATH_ENTITIES: Record<string, ExplorerEntity> = {
75
+ tx: "transaction",
76
+ txn: "transaction",
77
+ transaction: "transaction",
78
+ account: "account",
79
+ address: "account",
80
+ asset: "asset",
81
+ app: "application",
82
+ application: "application",
83
+ block: "block",
84
+ };
85
+
86
+ /** Resolves an algomd explorer path such as `tx/<id>` or `application/<id>`. */
87
+ export function explorerUrlForPath(
88
+ explorer: ExplorerId,
89
+ network: string,
90
+ path: string,
91
+ ): string | null {
92
+ const [kind, id] = path.replace(/^\/+/, "").split("/");
93
+ const entity = kind ? PATH_ENTITIES[kind] : undefined;
94
+ return entity && id ? explorerUrl(explorer, network, entity, id) : null;
95
+ }
@@ -0,0 +1,90 @@
1
+ // Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
2
+ export function formatTrimmedNumber(
3
+ value: number,
4
+ maximumFractionDigits = 6,
5
+ ): string {
6
+ return new Intl.NumberFormat("en-US", {
7
+ minimumFractionDigits: 0,
8
+ maximumFractionDigits,
9
+ }).format(value);
10
+ }
11
+
12
+ export function formatPrice(value: number, decimals = 6): string {
13
+ return formatTrimmedNumber(value, Math.min(Math.max(decimals, 0), 6));
14
+ }
15
+
16
+ function parseAtomicAmount(value: bigint | string): bigint | undefined {
17
+ if (typeof value === "bigint") return value >= 0n ? value : undefined;
18
+ const trimmed = value.trim();
19
+ return /^\d+$/.test(trimmed) ? BigInt(trimmed) : undefined;
20
+ }
21
+
22
+ function atomicAmountToDecimal(
23
+ value: bigint | string,
24
+ decimals: number,
25
+ useGrouping: boolean,
26
+ ): string | undefined {
27
+ const amount = parseAtomicAmount(value);
28
+ if (
29
+ amount == null ||
30
+ !Number.isInteger(decimals) ||
31
+ decimals < 0 ||
32
+ decimals > 19
33
+ ) {
34
+ return undefined;
35
+ }
36
+
37
+ const scale = 10n ** BigInt(decimals);
38
+ const whole = amount / scale;
39
+ const fraction = (amount % scale)
40
+ .toString()
41
+ .padStart(decimals, "0")
42
+ .replace(/0+$/, "");
43
+ const wholeText = useGrouping
44
+ ? whole.toLocaleString("en-US")
45
+ : whole.toString();
46
+ return `${wholeText}${fraction ? `.${fraction}` : ""}`;
47
+ }
48
+
49
+ /** Format an on-chain base-unit amount without converting it through a JavaScript number. */
50
+ export function formatAtomicAmount(
51
+ value: bigint | string,
52
+ decimals: number,
53
+ ): string | undefined {
54
+ return atomicAmountToDecimal(value, decimals, true);
55
+ }
56
+
57
+ /** Convert an on-chain base-unit amount to an exact, editable decimal string. */
58
+ export function atomicAmountToInput(
59
+ value: bigint | string,
60
+ decimals: number,
61
+ ): string | undefined {
62
+ return atomicAmountToDecimal(value, decimals, false);
63
+ }
64
+
65
+ const MINUTE_MS = 60_000;
66
+ const HOUR_MS = 60 * MINUTE_MS;
67
+ const DAY_MS = 24 * HOUR_MS;
68
+ const RELATIVE_DAYS = 7;
69
+
70
+ const twoDigits = (value: number) => String(value).padStart(2, "0");
71
+
72
+ /**
73
+ * The shorthand a post's timestamp uses: "now", "5m", "3h", "2d", and past a
74
+ * week the date as MM/DD/YY. Works in either direction from `nowMs`, so
75
+ * countdowns ("ends in 3h") read the same way as post ages.
76
+ */
77
+ export function formatShortDistance(date: Date, nowMs = Date.now()): string {
78
+ const distance = Math.abs(date.getTime() - nowMs);
79
+ if (distance < MINUTE_MS) return "now";
80
+ if (distance < HOUR_MS) return `${Math.floor(distance / MINUTE_MS)}m`;
81
+ if (distance < DAY_MS) return `${Math.floor(distance / HOUR_MS)}h`;
82
+ if (distance < RELATIVE_DAYS * DAY_MS)
83
+ return `${Math.floor(distance / DAY_MS)}d`;
84
+ return `${twoDigits(date.getMonth() + 1)}/${twoDigits(date.getDate())}/${twoDigits(date.getFullYear() % 100)}`;
85
+ }
86
+
87
+ /** True when `formatShortDistance` gives a date rather than a duration. */
88
+ export function isShortDistanceDate(date: Date, nowMs = Date.now()): boolean {
89
+ return Math.abs(date.getTime() - nowMs) >= RELATIVE_DAYS * DAY_MS;
90
+ }
@@ -0,0 +1,100 @@
1
+ // Shared AlgoMD presentation. Edit this library source.
2
+ import type {
3
+ ASA,
4
+ GateOperator,
5
+ GateRule,
6
+ GatingInfo,
7
+ } from "../types/algorand";
8
+ import { formatAddress } from "../utils/format";
9
+ import { formatAtomicAmount } from "./format";
10
+
11
+ const OPERATOR_WORDS: Record<GateOperator, string> = {
12
+ ">=": "at least",
13
+ ">": "more than",
14
+ "<=": "at most",
15
+ "<": "less than",
16
+ "=": "exactly",
17
+ "!=": "other than",
18
+ in: "one of",
19
+ "not in": "none of",
20
+ };
21
+
22
+ function amount(
23
+ raw: string,
24
+ asset: { decimals: number; unitName?: string; name?: string } | undefined,
25
+ assetId: number,
26
+ ): string {
27
+ if (!asset) return `${raw} base units of asset #${assetId}`;
28
+ const value = formatAtomicAmount(raw, asset.decimals) ?? raw;
29
+ return `${value} ${asset.unitName || asset.name || `#${assetId}`}`.trim();
30
+ }
31
+
32
+ /** One gate rule as a plain requirement the viewer can act on, e.g. "Hold at least 1 AKTA". */
33
+ export function describeGateRule(rule: GateRule): string {
34
+ switch (rule.type) {
35
+ case "asset":
36
+ // A collectible reads by name: "Hold Akita #42", not "Hold at least 1 AKITA42".
37
+ if (
38
+ rule.asset &&
39
+ isCollectibleAsset(rule.asset) &&
40
+ rule.amountRaw === "1" &&
41
+ (rule.op === ">=" || rule.op === "=")
42
+ )
43
+ return `Hold ${rule.asset.name || `asset #${rule.assetId}`}`;
44
+ return `Hold ${OPERATOR_WORDS[rule.op]} ${amount(rule.amountRaw, rule.asset, rule.assetId)}`;
45
+ case "staking_amount":
46
+ return `Stake ${OPERATOR_WORDS[rule.op]} ${amount(rule.amountRaw, rule.asset, rule.assetId)}`;
47
+ case "staking_power":
48
+ return `Have ${OPERATOR_WORDS[rule.op]} ${rule.power} staking power in ${rule.asset?.unitName || `asset #${rule.assetId}`}`;
49
+ case "nfd":
50
+ return "Own a verified NFD";
51
+ case "nfd_root":
52
+ return `Own an NFD under ${rule.root}`;
53
+ case "akita_referrer":
54
+ return `Be referred by ${formatAddress(rule.referrer)}`;
55
+ case "merkle_address":
56
+ return `Be on the “${rule.name}” allowlist`;
57
+ case "merkle_asset":
58
+ return `Hold an asset from the “${rule.name}” list`;
59
+ case "poll":
60
+ return `Vote in poll #${rule.pollId}`;
61
+ case "social_activity":
62
+ return `Have an activity score of ${OPERATOR_WORDS[rule.op]} ${rule.value}`;
63
+ case "social_follower_count":
64
+ return `Have ${OPERATOR_WORDS[rule.op]} ${rule.value} followers`;
65
+ case "social_impact":
66
+ return `Have an impact score of ${OPERATOR_WORDS[rule.op]} ${rule.value}`;
67
+ case "social_moderator":
68
+ return "Be an Akita moderator";
69
+ case "social_follower_index":
70
+ return rule.op === "<=" || rule.op === "<"
71
+ ? `Be one of ${formatAddress(rule.user)}'s first ${rule.value} followers`
72
+ : `Follow ${formatAddress(rule.user)}`;
73
+ case "subscription":
74
+ return `Subscribe to ${formatAddress(rule.merchant)}'s plan #${rule.serviceId}`;
75
+ case "subscription_streak":
76
+ return `Stay subscribed to ${formatAddress(rule.merchant)}'s plan #${rule.serviceId} for ${OPERATOR_WORDS[rule.op]} ${rule.streak} periods`;
77
+ }
78
+ }
79
+
80
+ /** One of a kind or a small edition: shown with its art rather than a token icon. */
81
+ export function isCollectibleAsset(asset: ASA): boolean {
82
+ return asset.decimals === 0 && asset.total > 0 && asset.total <= 1000;
83
+ }
84
+
85
+ /** The asset a rule is about, so it can be shown with its icon or art. */
86
+ export function gateRuleAsset(rule: GateRule): ASA | undefined {
87
+ return "asset" in rule ? rule.asset : undefined;
88
+ }
89
+
90
+ /** The requirements behind a gate, in plain words. Empty when the gate's rules are unknown. */
91
+ export function describeGate(gating: GatingInfo): string[] {
92
+ if (gating.rules?.length) return gating.rules.map(describeGateRule);
93
+ const assets = gating.requirements.assets ?? [];
94
+ const lines = assets.map(
95
+ (requirement) =>
96
+ `Hold at least ${requirement.minimumBalance} of asset #${requirement.assetId}`,
97
+ );
98
+ if (gating.requirements.nfdVerified) lines.push("Own a verified NFD");
99
+ return lines;
100
+ }