@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,175 @@
1
+ import React, { useEffect } from "react";
2
+ import {
3
+ View,
4
+ Image as NativeImage,
5
+ Text as NativeText,
6
+ StyleSheet,
7
+ type StyleProp,
8
+ type TextStyle,
9
+ type ViewStyle,
10
+ type LayoutChangeEvent,
11
+ } from "react-native";
12
+ import { Image } from "expo-image";
13
+ import {
14
+ IdentityResolver,
15
+ Text,
16
+ useAppTheme,
17
+ usePresentation,
18
+ type AppIdentity,
19
+ } from "./runtime";
20
+ import { CheckBadgeIcon } from "./icons";
21
+ import { fallbackAvatar } from "./assets";
22
+
23
+ export interface AddressIdentityProps {
24
+ address?: string;
25
+ containerStyle?: StyleProp<ViewStyle>;
26
+ iconSize?: number;
27
+ numberOfLines?: number;
28
+ onIdentityNameChange?: (name: string) => void;
29
+ onLayout?: (event: LayoutChangeEvent) => void;
30
+ textStyle?: StyleProp<TextStyle>;
31
+ }
32
+ export const VERIFIED_BADGE_COLOR = "#60a5fa";
33
+ export const COMMUNITY_VERIFIED_BADGE_COLOR = "#f5c434";
34
+
35
+ /** The app's check colour: gold for a community (an ARC-53 profile), blue for everyone else. */
36
+ export function verifiedBadgeColor(isCommunity?: boolean) {
37
+ return isCommunity ? COMMUNITY_VERIFIED_BADGE_COLOR : VERIFIED_BADGE_COLOR;
38
+ }
39
+
40
+ /** Communities get the app's rounded-square avatar; everyone else a circle. */
41
+ export function avatarRadius(size: number, isCommunity?: boolean) {
42
+ return isCommunity ? Math.round(size * (12 / 44)) : size / 2;
43
+ }
44
+
45
+ export function IdentityBadge({
46
+ identity,
47
+ size = 10,
48
+ }: {
49
+ identity: AppIdentity;
50
+ size?: number;
51
+ }) {
52
+ const { theme } = useAppTheme();
53
+ const Badge = usePresentation().components?.IdentityBadge;
54
+ return Badge ? (
55
+ <Badge
56
+ nfdName={identity.nfdName}
57
+ showVerifiedBadge={identity.showVerifiedBadge}
58
+ isCommunity={identity.isCommunity}
59
+ size={size}
60
+ />
61
+ ) : identity.showVerifiedBadge ? (
62
+ <CheckBadgeIcon
63
+ size={size}
64
+ color={
65
+ identity.verifiedColor ?? verifiedBadgeColor(identity.isCommunity)
66
+ }
67
+ />
68
+ ) : null;
69
+ }
70
+ export function AddressIdentityInline(props: AddressIdentityProps) {
71
+ return (
72
+ <IdentityResolver address={props.address}>
73
+ {(identity) => <ResolvedInline {...props} identity={identity} />}
74
+ </IdentityResolver>
75
+ );
76
+ }
77
+ function ResolvedInline({
78
+ identity,
79
+ containerStyle,
80
+ iconSize = 10,
81
+ numberOfLines = 1,
82
+ onIdentityNameChange,
83
+ onLayout,
84
+ textStyle,
85
+ }: AddressIdentityProps & { identity: AppIdentity }) {
86
+ const { theme } = useAppTheme();
87
+ const avatarSize = Math.max(14, iconSize + 6);
88
+ useEffect(() => {
89
+ onIdentityNameChange?.(identity.name);
90
+ }, [identity.name, onIdentityNameChange]);
91
+ return (
92
+ <View onLayout={onLayout} style={[styles.inline, containerStyle]}>
93
+ <Image
94
+ source={
95
+ identity.avatarUrl ? { uri: identity.avatarUrl } : fallbackAvatar
96
+ }
97
+ contentFit="cover"
98
+ style={{
99
+ width: avatarSize,
100
+ height: avatarSize,
101
+ borderRadius: avatarRadius(avatarSize, identity.isCommunity),
102
+ }}
103
+ />
104
+ <Text
105
+ size="xxs"
106
+ numberOfLines={numberOfLines}
107
+ style={[{ color: theme.colors.textDim }, textStyle]}
108
+ >
109
+ {identity.name}
110
+ </Text>
111
+ <IdentityBadge identity={identity} size={Math.max(9, iconSize)} />
112
+ </View>
113
+ );
114
+ }
115
+ export function AddressIdentityTextInline(
116
+ props: AddressIdentityProps & { includeAtPrefix?: boolean },
117
+ ) {
118
+ return (
119
+ <IdentityResolver address={props.address}>
120
+ {(identity) => <ResolvedTextInline {...props} identity={identity} />}
121
+ </IdentityResolver>
122
+ );
123
+ }
124
+ function ResolvedTextInline({
125
+ identity,
126
+ iconSize = 10,
127
+ includeAtPrefix = false,
128
+ onLayout,
129
+ onIdentityNameChange,
130
+ textStyle,
131
+ }: AddressIdentityProps & {
132
+ identity: AppIdentity;
133
+ includeAtPrefix?: boolean;
134
+ }) {
135
+ const { theme } = useAppTheme();
136
+ const size = Math.max(12, iconSize + 4);
137
+ useEffect(() => {
138
+ onIdentityNameChange?.(identity.name);
139
+ }, [identity.name, onIdentityNameChange]);
140
+ return (
141
+ <NativeText onLayout={onLayout} style={textStyle}>
142
+ <NativeImage
143
+ source={
144
+ identity.avatarUrl ? { uri: identity.avatarUrl } : fallbackAvatar
145
+ }
146
+ style={{
147
+ marginRight: 3,
148
+ width: size,
149
+ height: size,
150
+ borderRadius: avatarRadius(size, identity.isCommunity),
151
+ }}
152
+ />
153
+ <NativeText>
154
+ {" "}
155
+ {includeAtPrefix ? "@" : ""}
156
+ {identity.name}
157
+ </NativeText>
158
+ {identity.showVerifiedBadge ? (
159
+ <NativeText
160
+ style={{
161
+ color:
162
+ identity.verifiedColor ??
163
+ verifiedBadgeColor(identity.isCommunity),
164
+ }}
165
+ >
166
+ {" "}
167
+ ✓
168
+ </NativeText>
169
+ ) : null}
170
+ </NativeText>
171
+ );
172
+ }
173
+ const styles = StyleSheet.create({
174
+ inline: { alignItems: "center", flexDirection: "row", gap: 4, minWidth: 0 },
175
+ });
@@ -0,0 +1,88 @@
1
+ // Shared presentations for hosts that already own data fetching and wallet flows.
2
+ export { AccountDisplay as AccountPresentation } from "./AccountDisplay";
3
+ export { ASADisplay as ASAPresentation } from "./ASADisplay";
4
+ export { CollectionDisplay as CollectionPresentation } from "./CollectionDisplay";
5
+ export { NFDProfileDisplay as NFDProfilePresentation } from "./NFDProfileDisplay";
6
+ export { NFTListingDisplay as NFTListingPresentation } from "./NFTListingDisplay";
7
+ export { PollDisplay as PollPresentation } from "./PollDisplay";
8
+ export { AuctionListingDisplay as AuctionListingPresentation } from "./AuctionListingDisplay";
9
+ export { RaffleListingDisplay as RaffleListingPresentation } from "./RaffleListingDisplay";
10
+ export { TradeOfferDisplay as TradeOfferPresentation } from "./TradeOfferDisplay";
11
+ export {
12
+ TransactionDisplay as TransactionPresentation,
13
+ TransactionFallback,
14
+ } from "./TransactionDisplay";
15
+ export { DualStakePoolDisplay as DualStakePoolPresentation } from "./DualStakePoolDisplay";
16
+ export { StakingPoolDisplay as StakingPoolPresentation } from "./StakingPoolDisplay";
17
+ export type {
18
+ StakingPoolDisplayData,
19
+ StakingPoolRewardDisplayData,
20
+ StakingPoolStatus as StakingPoolPresentationStatus,
21
+ } from "./StakingPoolDisplay";
22
+ export { CardContainer as AlgomdCardContainer } from "./CardContainer";
23
+ export {
24
+ AdaptiveImage,
25
+ ImagePlaceholder,
26
+ useImageBudget,
27
+ getAdaptiveImageLayout,
28
+ } from "./AdaptiveImage";
29
+ export { StatusBadge as AlgomdStatusBadge } from "./StatusBadge";
30
+ export { ProgressBar as AlgomdProgressBar } from "./ProgressBar";
31
+ export { PrizePreview, type PrizePreviewProps } from "./PrizePreview";
32
+ export { PrizeBoxMedia } from "./PrizeBoxMedia";
33
+ export { WinnerBadge } from "./WinnerBadge";
34
+ export {
35
+ ContractMenu as AlgomdContractMenu,
36
+ type ContractMenuProps,
37
+ } from "./ContractMenu";
38
+ export * from "./OnChainActionCard";
39
+ export {
40
+ AddressIdentityInline,
41
+ AddressIdentityTextInline,
42
+ type AddressIdentityProps,
43
+ avatarRadius,
44
+ verifiedBadgeColor,
45
+ VERIFIED_BADGE_COLOR,
46
+ COMMUNITY_VERIFIED_BADGE_COLOR,
47
+ } from "./identity";
48
+ export {
49
+ formatAtomicAmount,
50
+ atomicAmountToInput,
51
+ formatTrimmedNumber,
52
+ formatPrice,
53
+ } from "./format";
54
+ export { getAssetIconSource, getAssetUnitName, isAlgo } from "./assetHelpers";
55
+ export {
56
+ getMediaDimensions,
57
+ setMediaDimensions,
58
+ clearMediaDimensions,
59
+ clearPresentationCaches,
60
+ type MediaDimensions,
61
+ } from "./media";
62
+ export { AlgomdPresentationProvider, IdentityResolver, usePresentation } from "./runtime";
63
+ export type {
64
+ AppPresentation,
65
+ PresentationTheme,
66
+ PresentationTextProps,
67
+ GradientProps,
68
+ IdentityResolverProps,
69
+ IdentityBadgeProps,
70
+ } from "./runtime";
71
+
72
+ export * from "./References";
73
+ export { AccountMentionInline } from "./AccountMentionInline";
74
+
75
+ export * from "./Embeds";
76
+ export * from "./variants";
77
+ export { AccountMentionText } from "./AccountMentionText";
78
+ export { AssetMention } from "./AssetMention";
79
+ export {
80
+ DEFAULT_EXPLORER,
81
+ EXPLORERS,
82
+ explorerLabel,
83
+ explorerUrl,
84
+ explorerUrlForPath,
85
+ isExplorerId,
86
+ type ExplorerEntity,
87
+ type ExplorerId,
88
+ } from "./explorer";
@@ -0,0 +1,70 @@
1
+ /**
2
+ * In-memory cache of natural media dimensions keyed by Algorand asset id.
3
+ *
4
+ * Populated opportunistically: the collectibles grid and any other list that
5
+ * renders a thumbnail via `expo-image` writes the source w/h on `onLoad`.
6
+ * The NFT detail screen reads the entry on mount to seed its container's
7
+ * aspectRatio so the hero image never reflows from a 1:1 placeholder.
8
+ *
9
+ * Cold deep-links (no prior thumbnail render) still fall back to measuring
10
+ * via onLoad — the reflow is unavoidable without backend-stored dimensions.
11
+ */
12
+
13
+ export interface MediaDimensions {
14
+ width: number;
15
+ height: number;
16
+ }
17
+
18
+ const MAX_MEDIA_DIMENSION_CACHE_SIZE = 500;
19
+ const cache = new Map<string, MediaDimensions>();
20
+
21
+ function key(assetId: string | number): string {
22
+ return String(assetId);
23
+ }
24
+
25
+ export function getMediaDimensions(
26
+ assetId: string | number,
27
+ ): MediaDimensions | undefined {
28
+ const cacheKey = key(assetId);
29
+ const dims = cache.get(cacheKey);
30
+ if (!dims) return undefined;
31
+
32
+ cache.delete(cacheKey);
33
+ cache.set(cacheKey, dims);
34
+ return dims;
35
+ }
36
+
37
+ export function setMediaDimensions(
38
+ assetId: string | number,
39
+ dims:
40
+ | MediaDimensions
41
+ | { width?: number; height?: number }
42
+ | undefined
43
+ | null,
44
+ ): void {
45
+ if (!dims || !dims.width || !dims.height) return;
46
+ const cacheKey = key(assetId);
47
+ cache.delete(cacheKey);
48
+ cache.set(cacheKey, { width: dims.width, height: dims.height });
49
+
50
+ while (cache.size > MAX_MEDIA_DIMENSION_CACHE_SIZE) {
51
+ const oldestKey = cache.keys().next().value;
52
+ if (!oldestKey) break;
53
+ cache.delete(oldestKey);
54
+ }
55
+ }
56
+
57
+ export function clearMediaDimensions(): void {
58
+ cache.clear();
59
+ }
60
+
61
+ const privateMaps = new Set<Map<unknown, unknown>>();
62
+ export function createAkitaPlaintextMap<K, V>(_name: string): Map<K, V> {
63
+ const map = new Map<K, V>();
64
+ privateMaps.add(map);
65
+ return map;
66
+ }
67
+ export function clearPresentationCaches() {
68
+ clearMediaDimensions();
69
+ for (const map of privateMaps) map.clear();
70
+ }
@@ -0,0 +1,8 @@
1
+ // Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
2
+ /** Each plugin's brand colour, matching the app's plugin settings. */
3
+ export const PLUGIN_COLORS = {
4
+ Auction: "#f97316",
5
+ Marketplace: "#ec4899",
6
+ Raffle: "#14b8a6",
7
+ StakingPool: "#a855f7",
8
+ } as const;
@@ -0,0 +1,280 @@
1
+ import React, { createContext, useContext, useId } from "react";
2
+ import {
3
+ View,
4
+ Text as NativeText,
5
+ StyleSheet,
6
+ type TextProps,
7
+ type ViewStyle,
8
+ } from "react-native";
9
+ import Svg, {
10
+ Defs,
11
+ LinearGradient as SvgGradient,
12
+ Rect,
13
+ Stop,
14
+ } from "react-native-svg";
15
+ import * as Linking from "expo-linking";
16
+ import { formatAddress } from "../utils/format";
17
+ import {
18
+ DEFAULT_EXPLORER,
19
+ explorerUrlForPath,
20
+ type ExplorerId,
21
+ } from "./explorer";
22
+ import themes from "./themes.json";
23
+ import { sizes, fonts } from "./textTheme";
24
+
25
+ export interface PresentationTheme {
26
+ colors: {
27
+ background: string;
28
+ accentBackground: string;
29
+ border: string;
30
+ text: string;
31
+ textDim: string;
32
+ primary: string;
33
+ /** Sky accent for upcoming states and countdowns. Falls back to primary. */
34
+ secondary?: string;
35
+ primaryText: string;
36
+ success: string;
37
+ error: string;
38
+ warning: string;
39
+ warningText: string;
40
+ palette: { akitaGreen: string };
41
+ };
42
+ gradients: {
43
+ interactive: readonly string[];
44
+ interactiveLocations?: readonly number[];
45
+ interactiveText: string;
46
+ };
47
+ typography: { primary: { medium: string } };
48
+ }
49
+ export interface AppIdentity {
50
+ address?: string;
51
+ name: string;
52
+ tag?: string;
53
+ avatarUrl?: string;
54
+ hasNfd?: boolean;
55
+ nfdName?: string;
56
+ isCommunity?: boolean;
57
+ showVerifiedBadge?: boolean;
58
+ verifiedColor?: string;
59
+ }
60
+ export interface IdentityResolverProps {
61
+ address?: string;
62
+ children: (identity: AppIdentity) => React.ReactNode;
63
+ }
64
+ export interface IdentityBadgeProps {
65
+ nfdName?: string;
66
+ showVerifiedBadge?: boolean;
67
+ isCommunity?: boolean;
68
+ size?: number;
69
+ }
70
+ export type GuildVoteChoice = "approve" | "reject" | "abstain";
71
+
72
+ export type PresentationTextProps = TextProps & {
73
+ size?: keyof typeof sizes;
74
+ weight?: keyof typeof fonts;
75
+ };
76
+ export interface GradientProps {
77
+ colors: readonly string[];
78
+ locations?: readonly number[];
79
+ start: { x: number; y: number };
80
+ end: { x: number; y: number };
81
+ style?: ViewStyle;
82
+ children?: React.ReactNode;
83
+ }
84
+ export interface AppPresentation {
85
+ mode?: "light" | "dark";
86
+ network?: "localnet" | "testnet" | "mainnet";
87
+ theme?: PresentationTheme;
88
+ identities?: Record<string, AppIdentity>;
89
+ showNfdSuffix?: boolean;
90
+ /** The block explorer links open on when the host does not handle them. Defaults to Akita's. */
91
+ explorer?: ExplorerId;
92
+ onOpenExplorer?: (path: string) => void;
93
+ onViewContract?: (id: string) => void;
94
+ onOpenAccount?: (address: string) => void;
95
+ onOpenAsset?: (assetId: string) => void;
96
+ onOpenApplication?: (appId: string) => void;
97
+ /** Maps an ipfs:// or https:// image to a sized URL, e.g. through an image proxy. */
98
+ resolveImageUrl?: (src: string, width: number) => string;
99
+ /** A human name for an application id, e.g. a known plugin. */
100
+ applicationLabel?: (appId: string) => string | undefined;
101
+ onOpenNfd?: (name: string) => void;
102
+ onOpenCollection?: (id: string) => void;
103
+ onOpenTransaction?: (txId: string) => void;
104
+ /** Opens a contract reference (listing, auction, raffle, poll) in the host. */
105
+ onOpenContract?: (kind: string, appId: string) => void;
106
+ /** The signed-in account, so views can address the viewer (e.g. "Reserved for you"). */
107
+ viewerAddress?: string;
108
+ /**
109
+ * On-chain actions need the host's wallet. A view shows an action button only
110
+ * when the host provides its handler.
111
+ */
112
+ actions?: {
113
+ buyListing?: (appId: string) => void;
114
+ bid?: (appId: string) => void;
115
+ enterRaffle?: (appId: string) => void;
116
+ vote?: (appId: string, optionIndexes: number[]) => void;
117
+ claimReward?: (disbursementId: string) => void;
118
+ subscribe?: (owner: string, serviceId: string) => void;
119
+ dualStakeMint?: (appId: string) => void;
120
+ dualStakeRedeem?: (appId: string) => void;
121
+ acceptTrade?: (offerId: string) => void;
122
+ /** Guild proposal actions. A returned promise shows progress on the card; a rejection shows its message. */
123
+ guildVote?: (guildAppId: string, proposalId: string, vote: GuildVoteChoice) => void | Promise<void>;
124
+ guildSubmit?: (guildAppId: string, proposalId: string) => void | Promise<void>;
125
+ guildFinalize?: (guildAppId: string, proposalId: string) => void | Promise<void>;
126
+ guildExecute?: (guildAppId: string, proposalId: string) => void | Promise<void>;
127
+ };
128
+ /**
129
+ * Why the viewer can't act on this Guild's proposals here, e.g. a chat that
130
+ * only acts for its own Guild. A returned note replaces the card's actions.
131
+ */
132
+ guildActionBlock?: (guildAppId: string) => string | undefined;
133
+ /**
134
+ * Renders private content, which needs the viewer's keys to unlock. Without
135
+ * it, a private-content reference shows its public metadata only.
136
+ */
137
+ renderPrivateContent?: (
138
+ id: string,
139
+ title: string | undefined,
140
+ size: "inline" | "small" | "large" | "full",
141
+ ) => React.ReactNode;
142
+ /**
143
+ * Renders an account's badges, which belong to the host app (their art and
144
+ * how they are earned). Large account cards show them; without it they show none.
145
+ */
146
+ renderAccountBadges?: (address: string) => React.ReactNode;
147
+ components?: {
148
+ Text?: React.ComponentType<PresentationTextProps>;
149
+ LinearGradient?: React.ComponentType<GradientProps>;
150
+ IdentityResolver?: React.ComponentType<IdentityResolverProps>;
151
+ IdentityBadge?: React.ComponentType<IdentityBadgeProps>;
152
+ PortalProvider?: React.ComponentType<{ children: React.ReactNode }>;
153
+ };
154
+ }
155
+ const Presentation = createContext<AppPresentation>({});
156
+ export function AppPresentationProvider({
157
+ children,
158
+ ...value
159
+ }: AppPresentation & { children: React.ReactNode }) {
160
+ return (
161
+ <Presentation.Provider value={value}>{children}</Presentation.Provider>
162
+ );
163
+ }
164
+ export const AlgomdPresentationProvider = AppPresentationProvider;
165
+ export function usePresentation() {
166
+ return useContext(Presentation);
167
+ }
168
+ export function useAppTheme(): { theme: PresentationTheme } {
169
+ const context = usePresentation();
170
+ return {
171
+ theme: context.theme ?? {
172
+ ...themes[context.mode ?? "dark"],
173
+ typography: { primary: fonts },
174
+ },
175
+ };
176
+ }
177
+ export function Text(props: PresentationTextProps) {
178
+ const CustomText = usePresentation().components?.Text;
179
+ return CustomText ? <CustomText {...props} /> : <DefaultText {...props} />;
180
+ }
181
+ function DefaultText({
182
+ size = "sm",
183
+ weight = "normal",
184
+ style,
185
+ ...props
186
+ }: PresentationTextProps) {
187
+ const { theme } = useAppTheme();
188
+ return (
189
+ <NativeText
190
+ {...props}
191
+ style={[
192
+ {
193
+ fontSize: sizes[size][0],
194
+ lineHeight: sizes[size][1],
195
+ fontFamily: fonts[weight],
196
+ color: theme.colors.text,
197
+ },
198
+ style,
199
+ ]}
200
+ />
201
+ );
202
+ }
203
+ export function LinearGradient(props: GradientProps) {
204
+ const CustomGradient = usePresentation().components?.LinearGradient;
205
+ return CustomGradient ? (
206
+ <CustomGradient {...props} />
207
+ ) : (
208
+ <DefaultGradient {...props} />
209
+ );
210
+ }
211
+ function DefaultGradient({
212
+ colors,
213
+ locations,
214
+ start,
215
+ end,
216
+ style,
217
+ children,
218
+ }: GradientProps) {
219
+ const id = `gradient${useId().replace(/[^a-zA-Z0-9]/g, "")}`;
220
+ return (
221
+ <View style={[style, { overflow: "hidden" }]}>
222
+ <Svg style={StyleSheet.absoluteFill} width="100%" height="100%">
223
+ <Defs>
224
+ <SvgGradient
225
+ id={id}
226
+ x1={`${start.x * 100}%`}
227
+ y1={`${start.y * 100}%`}
228
+ x2={`${end.x * 100}%`}
229
+ y2={`${end.y * 100}%`}
230
+ >
231
+ {colors.map((color, i) => (
232
+ <Stop
233
+ key={i}
234
+ offset={locations?.[i] ?? i / (colors.length - 1)}
235
+ stopColor={color}
236
+ />
237
+ ))}
238
+ </SvgGradient>
239
+ </Defs>
240
+ <Rect width="100%" height="100%" fill={`url(#${id})`} />
241
+ </Svg>
242
+ {children}
243
+ </View>
244
+ );
245
+ }
246
+ export function IdentityResolver({ address, children }: IdentityResolverProps) {
247
+ const context = usePresentation();
248
+ const Resolver = context.components?.IdentityResolver;
249
+ return Resolver ? (
250
+ <Resolver address={address}>{children}</Resolver>
251
+ ) : (
252
+ <>
253
+ {children(
254
+ context.identities?.[address ?? ""] ?? {
255
+ address,
256
+ name: formatAddress(address ?? ""),
257
+ },
258
+ )}
259
+ </>
260
+ );
261
+ }
262
+ export function useProfileDisplayPreferences() {
263
+ return { showNfdSuffix: usePresentation().showNfdSuffix ?? false };
264
+ }
265
+ export { formatNfdName } from "../utils/nfdDisplay";
266
+ export function useOpenExplorer() {
267
+ const {
268
+ onOpenExplorer,
269
+ onViewContract,
270
+ network = "mainnet",
271
+ explorer = DEFAULT_EXPLORER,
272
+ } = usePresentation();
273
+ return (path: string) => {
274
+ if (onOpenExplorer) return onOpenExplorer(path);
275
+ if (onViewContract && path.startsWith("application/"))
276
+ return onViewContract(path.slice("application/".length));
277
+ const url = explorerUrlForPath(explorer, network, path);
278
+ if (url) return Linking.openURL(url);
279
+ };
280
+ }
@@ -0,0 +1,7 @@
1
+ export {
2
+ default,
3
+ BottomSheetModal,
4
+ BottomSheetBackdrop,
5
+ BottomSheetView,
6
+ BottomSheetScrollView,
7
+ } from "@gorhom/bottom-sheet";
@@ -0,0 +1,31 @@
1
+ // Shared AlgoMD presentation. Edit this library source.
2
+ import React, { createContext, useContext } from "react";
3
+
4
+ const Subject = createContext<string | undefined>(undefined);
5
+
6
+ /**
7
+ * Marks the asset a page is about, such as a collectible's own page. A listing,
8
+ * auction or raffle whose only item is that asset then leaves out its art, name
9
+ * and collection, which the page already shows above it.
10
+ */
11
+ export function AssetSubjectProvider({
12
+ assetId,
13
+ children,
14
+ }: {
15
+ assetId?: string | number | bigint;
16
+ children: React.ReactNode;
17
+ }) {
18
+ return (
19
+ <Subject.Provider value={assetId == null ? undefined : String(assetId)}>
20
+ {children}
21
+ </Subject.Provider>
22
+ );
23
+ }
24
+
25
+ /** True when the page around this block is about exactly this asset. */
26
+ export function useIsAssetSubject(
27
+ assetId: string | number | bigint | undefined,
28
+ ): boolean {
29
+ const subject = useContext(Subject);
30
+ return subject != null && assetId != null && String(assetId) === subject;
31
+ }
@@ -0,0 +1,17 @@
1
+ // Shared AlgoMD presentation. Edit this library source.
2
+ export const sizes = {
3
+ xxl: [36, 44],
4
+ xl: [24, 34],
5
+ lg: [20, 32],
6
+ md: [18, 26],
7
+ sm: [16, 24],
8
+ xs: [14, 21],
9
+ xxs: [12, 18],
10
+ };
11
+ export const fonts = {
12
+ light: "spaceGroteskLight",
13
+ normal: "spaceGroteskRegular",
14
+ medium: "spaceGroteskMedium",
15
+ semiBold: "spaceGroteskSemiBold",
16
+ bold: "spaceGroteskBold",
17
+ };