@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,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,268 @@
|
|
|
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 PresentationTextProps = TextProps & {
|
|
71
|
+
size?: keyof typeof sizes;
|
|
72
|
+
weight?: keyof typeof fonts;
|
|
73
|
+
};
|
|
74
|
+
export interface GradientProps {
|
|
75
|
+
colors: readonly string[];
|
|
76
|
+
locations?: readonly number[];
|
|
77
|
+
start: { x: number; y: number };
|
|
78
|
+
end: { x: number; y: number };
|
|
79
|
+
style?: ViewStyle;
|
|
80
|
+
children?: React.ReactNode;
|
|
81
|
+
}
|
|
82
|
+
export interface AppPresentation {
|
|
83
|
+
mode?: "light" | "dark";
|
|
84
|
+
network?: "localnet" | "testnet" | "mainnet";
|
|
85
|
+
theme?: PresentationTheme;
|
|
86
|
+
identities?: Record<string, AppIdentity>;
|
|
87
|
+
showNfdSuffix?: boolean;
|
|
88
|
+
/** The block explorer links open on when the host does not handle them. Defaults to Akita's. */
|
|
89
|
+
explorer?: ExplorerId;
|
|
90
|
+
onOpenExplorer?: (path: string) => void;
|
|
91
|
+
onViewContract?: (id: string) => void;
|
|
92
|
+
onOpenAccount?: (address: string) => void;
|
|
93
|
+
onOpenAsset?: (assetId: string) => void;
|
|
94
|
+
onOpenApplication?: (appId: string) => void;
|
|
95
|
+
/** Maps an ipfs:// or https:// image to a sized URL, e.g. through an image proxy. */
|
|
96
|
+
resolveImageUrl?: (src: string, width: number) => string;
|
|
97
|
+
/** A human name for an application id, e.g. a known plugin. */
|
|
98
|
+
applicationLabel?: (appId: string) => string | undefined;
|
|
99
|
+
onOpenNfd?: (name: string) => void;
|
|
100
|
+
onOpenCollection?: (id: string) => void;
|
|
101
|
+
onOpenTransaction?: (txId: string) => void;
|
|
102
|
+
/** Opens a contract reference (listing, auction, raffle, poll) in the host. */
|
|
103
|
+
onOpenContract?: (kind: string, appId: string) => void;
|
|
104
|
+
/** The signed-in account, so views can address the viewer (e.g. "Reserved for you"). */
|
|
105
|
+
viewerAddress?: string;
|
|
106
|
+
/**
|
|
107
|
+
* On-chain actions need the host's wallet. A view shows an action button only
|
|
108
|
+
* when the host provides its handler.
|
|
109
|
+
*/
|
|
110
|
+
actions?: {
|
|
111
|
+
buyListing?: (appId: string) => void;
|
|
112
|
+
bid?: (appId: string) => void;
|
|
113
|
+
enterRaffle?: (appId: string) => void;
|
|
114
|
+
vote?: (appId: string, optionIndexes: number[]) => void;
|
|
115
|
+
claimReward?: (disbursementId: string) => void;
|
|
116
|
+
subscribe?: (owner: string, serviceId: string) => void;
|
|
117
|
+
dualStakeMint?: (appId: string) => void;
|
|
118
|
+
dualStakeRedeem?: (appId: string) => void;
|
|
119
|
+
acceptTrade?: (offerId: string) => void;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Renders private content, which needs the viewer's keys to unlock. Without
|
|
123
|
+
* it, a private-content reference shows its public metadata only.
|
|
124
|
+
*/
|
|
125
|
+
renderPrivateContent?: (
|
|
126
|
+
id: string,
|
|
127
|
+
title: string | undefined,
|
|
128
|
+
size: "inline" | "small" | "large" | "full",
|
|
129
|
+
) => React.ReactNode;
|
|
130
|
+
/**
|
|
131
|
+
* Renders an account's badges, which belong to the host app (their art and
|
|
132
|
+
* how they are earned). Large account cards show them; without it they show none.
|
|
133
|
+
*/
|
|
134
|
+
renderAccountBadges?: (address: string) => React.ReactNode;
|
|
135
|
+
components?: {
|
|
136
|
+
Text?: React.ComponentType<PresentationTextProps>;
|
|
137
|
+
LinearGradient?: React.ComponentType<GradientProps>;
|
|
138
|
+
IdentityResolver?: React.ComponentType<IdentityResolverProps>;
|
|
139
|
+
IdentityBadge?: React.ComponentType<IdentityBadgeProps>;
|
|
140
|
+
PortalProvider?: React.ComponentType<{ children: React.ReactNode }>;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const Presentation = createContext<AppPresentation>({});
|
|
144
|
+
export function AppPresentationProvider({
|
|
145
|
+
children,
|
|
146
|
+
...value
|
|
147
|
+
}: AppPresentation & { children: React.ReactNode }) {
|
|
148
|
+
return (
|
|
149
|
+
<Presentation.Provider value={value}>{children}</Presentation.Provider>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
export const AlgomdPresentationProvider = AppPresentationProvider;
|
|
153
|
+
export function usePresentation() {
|
|
154
|
+
return useContext(Presentation);
|
|
155
|
+
}
|
|
156
|
+
export function useAppTheme(): { theme: PresentationTheme } {
|
|
157
|
+
const context = usePresentation();
|
|
158
|
+
return {
|
|
159
|
+
theme: context.theme ?? {
|
|
160
|
+
...themes[context.mode ?? "dark"],
|
|
161
|
+
typography: { primary: fonts },
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
export function Text(props: PresentationTextProps) {
|
|
166
|
+
const CustomText = usePresentation().components?.Text;
|
|
167
|
+
return CustomText ? <CustomText {...props} /> : <DefaultText {...props} />;
|
|
168
|
+
}
|
|
169
|
+
function DefaultText({
|
|
170
|
+
size = "sm",
|
|
171
|
+
weight = "normal",
|
|
172
|
+
style,
|
|
173
|
+
...props
|
|
174
|
+
}: PresentationTextProps) {
|
|
175
|
+
const { theme } = useAppTheme();
|
|
176
|
+
return (
|
|
177
|
+
<NativeText
|
|
178
|
+
{...props}
|
|
179
|
+
style={[
|
|
180
|
+
{
|
|
181
|
+
fontSize: sizes[size][0],
|
|
182
|
+
lineHeight: sizes[size][1],
|
|
183
|
+
fontFamily: fonts[weight],
|
|
184
|
+
color: theme.colors.text,
|
|
185
|
+
},
|
|
186
|
+
style,
|
|
187
|
+
]}
|
|
188
|
+
/>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
export function LinearGradient(props: GradientProps) {
|
|
192
|
+
const CustomGradient = usePresentation().components?.LinearGradient;
|
|
193
|
+
return CustomGradient ? (
|
|
194
|
+
<CustomGradient {...props} />
|
|
195
|
+
) : (
|
|
196
|
+
<DefaultGradient {...props} />
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
function DefaultGradient({
|
|
200
|
+
colors,
|
|
201
|
+
locations,
|
|
202
|
+
start,
|
|
203
|
+
end,
|
|
204
|
+
style,
|
|
205
|
+
children,
|
|
206
|
+
}: GradientProps) {
|
|
207
|
+
const id = `gradient${useId().replace(/[^a-zA-Z0-9]/g, "")}`;
|
|
208
|
+
return (
|
|
209
|
+
<View style={[style, { overflow: "hidden" }]}>
|
|
210
|
+
<Svg style={StyleSheet.absoluteFill} width="100%" height="100%">
|
|
211
|
+
<Defs>
|
|
212
|
+
<SvgGradient
|
|
213
|
+
id={id}
|
|
214
|
+
x1={`${start.x * 100}%`}
|
|
215
|
+
y1={`${start.y * 100}%`}
|
|
216
|
+
x2={`${end.x * 100}%`}
|
|
217
|
+
y2={`${end.y * 100}%`}
|
|
218
|
+
>
|
|
219
|
+
{colors.map((color, i) => (
|
|
220
|
+
<Stop
|
|
221
|
+
key={i}
|
|
222
|
+
offset={locations?.[i] ?? i / (colors.length - 1)}
|
|
223
|
+
stopColor={color}
|
|
224
|
+
/>
|
|
225
|
+
))}
|
|
226
|
+
</SvgGradient>
|
|
227
|
+
</Defs>
|
|
228
|
+
<Rect width="100%" height="100%" fill={`url(#${id})`} />
|
|
229
|
+
</Svg>
|
|
230
|
+
{children}
|
|
231
|
+
</View>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
export function IdentityResolver({ address, children }: IdentityResolverProps) {
|
|
235
|
+
const context = usePresentation();
|
|
236
|
+
const Resolver = context.components?.IdentityResolver;
|
|
237
|
+
return Resolver ? (
|
|
238
|
+
<Resolver address={address}>{children}</Resolver>
|
|
239
|
+
) : (
|
|
240
|
+
<>
|
|
241
|
+
{children(
|
|
242
|
+
context.identities?.[address ?? ""] ?? {
|
|
243
|
+
address,
|
|
244
|
+
name: formatAddress(address ?? ""),
|
|
245
|
+
},
|
|
246
|
+
)}
|
|
247
|
+
</>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
export function useProfileDisplayPreferences() {
|
|
251
|
+
return { showNfdSuffix: usePresentation().showNfdSuffix ?? false };
|
|
252
|
+
}
|
|
253
|
+
export { formatNfdName } from "../utils/nfdDisplay";
|
|
254
|
+
export function useOpenExplorer() {
|
|
255
|
+
const {
|
|
256
|
+
onOpenExplorer,
|
|
257
|
+
onViewContract,
|
|
258
|
+
network = "mainnet",
|
|
259
|
+
explorer = DEFAULT_EXPLORER,
|
|
260
|
+
} = usePresentation();
|
|
261
|
+
return (path: string) => {
|
|
262
|
+
if (onOpenExplorer) return onOpenExplorer(path);
|
|
263
|
+
if (onViewContract && path.startsWith("application/"))
|
|
264
|
+
return onViewContract(path.slice("application/".length));
|
|
265
|
+
const url = explorerUrlForPath(explorer, network, path);
|
|
266
|
+
if (url) return Linking.openURL(url);
|
|
267
|
+
};
|
|
268
|
+
}
|
|
@@ -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
|
+
};
|