@akita-protocol/algomd-rn 0.0.0-stage → 1.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -2
- package/package.json +118 -3
- package/src/adapters/index.ts +4 -0
- package/src/adapters/txn-graph.ts +138 -0
- package/src/components/ASA.tsx +38 -0
- package/src/components/ASASearch.tsx +79 -0
- package/src/components/Account.tsx +42 -0
- package/src/components/AccountSearch.tsx +75 -0
- package/src/components/AuctionListing.tsx +40 -0
- package/src/components/Collection.tsx +42 -0
- package/src/components/DualStakePool.tsx +244 -0
- package/src/components/NFDProfile.tsx +45 -0
- package/src/components/NFDSearch.tsx +81 -0
- package/src/components/NFTListing.tsx +73 -0
- package/src/components/NFTSearch.tsx +68 -0
- package/src/components/Poll.tsx +39 -0
- package/src/components/PollSearch.tsx +79 -0
- package/src/components/PrizeBoxBundle.tsx +1 -0
- package/src/components/RaffleListing.tsx +40 -0
- package/src/components/SelfFetching.tsx +1048 -0
- package/src/components/StakingPool.tsx +134 -0
- package/src/components/TradeOffer.tsx +47 -0
- package/src/components/TradeSearch.tsx +103 -0
- package/src/components/TransactionDetails.tsx +37 -0
- package/src/components/TransactionSearch.tsx +102 -0
- package/src/components/TransactionsGraph.tsx +60 -0
- package/src/components/index.ts +41 -0
- package/src/fonts/OFL.txt +93 -0
- package/src/fonts/SpaceGrotesk_300Light.ttf +0 -0
- package/src/fonts/SpaceGrotesk_400Regular.ttf +0 -0
- package/src/fonts/SpaceGrotesk_500Medium.ttf +0 -0
- package/src/fonts/SpaceGrotesk_600SemiBold.ttf +0 -0
- package/src/fonts/SpaceGrotesk_700Bold.ttf +0 -0
- package/src/fonts/app.css +5 -0
- package/src/graph.ts +3 -0
- package/src/hooks/index.ts +17 -0
- package/src/hooks/useAlgomdData.ts +1539 -0
- package/src/hooks/useAlgorandClient.ts +54 -0
- package/src/index.ts +147 -0
- package/src/presentation/ASADisplay.tsx +380 -0
- package/src/presentation/AccountDisplay.tsx +132 -0
- package/src/presentation/AccountMentionInline.tsx +38 -0
- package/src/presentation/AccountMentionText.tsx +80 -0
- package/src/presentation/AdaptiveImage.tsx +314 -0
- package/src/presentation/AssetMention.tsx +87 -0
- package/src/presentation/AuctionListingDisplay.tsx +428 -0
- package/src/presentation/BundleContents.tsx +228 -0
- package/src/presentation/CardContainer.tsx +61 -0
- package/src/presentation/CardEntrance.tsx +21 -0
- package/src/presentation/CollectionDisplay.tsx +168 -0
- package/src/presentation/ContractMenu.tsx +243 -0
- package/src/presentation/DualStakePoolDisplay.tsx +335 -0
- package/src/presentation/Embeds.tsx +300 -0
- package/src/presentation/GateRequirements.tsx +334 -0
- package/src/presentation/HEROICONS-LICENSE.txt +21 -0
- package/src/presentation/NFDProfileDisplay.tsx +194 -0
- package/src/presentation/NFTListingDisplay.tsx +284 -0
- package/src/presentation/OnChainActionCard.tsx +557 -0
- package/src/presentation/PollDisplay.tsx +222 -0
- package/src/presentation/PrizeBoxBundleDisplay.tsx +103 -0
- package/src/presentation/PrizeBoxMedia.tsx +46 -0
- package/src/presentation/PrizePreview.tsx +296 -0
- package/src/presentation/ProgressBar.tsx +50 -0
- package/src/presentation/RaffleListingDisplay.tsx +399 -0
- package/src/presentation/References.tsx +310 -0
- package/src/presentation/ReservedNotice.tsx +73 -0
- package/src/presentation/ResultsPanel.tsx +241 -0
- package/src/presentation/Sparkline.tsx +70 -0
- package/src/presentation/SquishyPressable.tsx +145 -0
- package/src/presentation/StakingPoolDisplay.tsx +419 -0
- package/src/presentation/StatusBadge.tsx +56 -0
- package/src/presentation/TradeOfferDisplay.tsx +275 -0
- package/src/presentation/TransactionDisplay.tsx +262 -0
- package/src/presentation/WinnerBadge.tsx +58 -0
- package/src/presentation/assetHelpers.ts +36 -0
- package/src/presentation/assets.ts +7 -0
- package/src/presentation/explorer.ts +95 -0
- package/src/presentation/format.ts +90 -0
- package/src/presentation/gates.ts +100 -0
- package/src/presentation/icons.tsx +1178 -0
- package/src/presentation/identity.tsx +175 -0
- package/src/presentation/index.ts +88 -0
- package/src/presentation/media.ts +70 -0
- package/src/presentation/pluginColors.ts +8 -0
- package/src/presentation/runtime.tsx +280 -0
- package/src/presentation/sheets.tsx +7 -0
- package/src/presentation/subject.tsx +31 -0
- package/src/presentation/textTheme.ts +17 -0
- package/src/presentation/themes.json +158 -0
- package/src/presentation/variants.ts +14 -0
- package/src/provider/AlgomdProvider.tsx +45 -0
- package/src/provider/context.ts +18 -0
- package/src/provider/imageResolver.ts +12 -0
- package/src/provider/index.ts +5 -0
- package/src/provider/networks.ts +23 -0
- package/src/provider/types.ts +29 -0
- package/src/refs/AccountRef.tsx +226 -0
- package/src/refs/ApplicationRef.tsx +72 -0
- package/src/refs/AssetRef.tsx +142 -0
- package/src/refs/AuctionRef.tsx +108 -0
- package/src/refs/CollectionRef.tsx +70 -0
- package/src/refs/DualStakeRef.tsx +88 -0
- package/src/refs/GuildProposalRef.tsx +285 -0
- package/src/refs/HostRefs.tsx +82 -0
- package/src/refs/ListingRef.tsx +90 -0
- package/src/refs/NfdRef.tsx +96 -0
- package/src/refs/PollRef.tsx +120 -0
- package/src/refs/RaffleRef.tsx +101 -0
- package/src/refs/RewardRef.tsx +78 -0
- package/src/refs/StakingPoolRef.tsx +136 -0
- package/src/refs/SubscriptionRef.tsx +200 -0
- package/src/refs/TradeRef.tsx +100 -0
- package/src/refs/TransactionRef.tsx +156 -0
- package/src/refs/assetInfo.ts +49 -0
- package/src/refs/contractParts.tsx +159 -0
- package/src/refs/index.tsx +140 -0
- package/src/refs/primitives.tsx +588 -0
- package/src/refs/types.ts +13 -0
- package/src/types/algorand.ts +496 -0
- package/src/types/index.ts +1 -0
- package/src/ui/CopyButton.tsx +44 -0
- package/src/ui/DataStates.tsx +45 -0
- package/src/ui/ProgressBar.tsx +64 -0
- package/src/ui/SearchSheet.tsx +141 -0
- package/src/ui/SizeContainer.tsx +25 -0
- package/src/ui/StatusBadge.tsx +51 -0
- package/src/ui/index.ts +6 -0
- package/src/utils/algomdImageUrl.ts +20 -0
- package/src/utils/arc19.ts +120 -0
- package/src/utils/arc62.ts +246 -0
- package/src/utils/capacity.ts +26 -0
- package/src/utils/format.ts +181 -0
- package/src/utils/ids.ts +31 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/nfdDisplay.ts +45 -0
- package/src/utils/search.ts +87 -0
- package/src/utils/stakingPool.ts +174 -0
- package/src/utils/stakingSnapshot.ts +132 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
{
|
|
2
|
+
"light": {
|
|
3
|
+
"colors": {
|
|
4
|
+
"palette": {
|
|
5
|
+
"zinc950": "#09090b",
|
|
6
|
+
"zinc900": "#18181b",
|
|
7
|
+
"zinc800": "#27272a",
|
|
8
|
+
"zinc700": "#3f3f46",
|
|
9
|
+
"zinc600": "#52525b",
|
|
10
|
+
"zinc500": "#71717a",
|
|
11
|
+
"zinc400": "#a1a1aa",
|
|
12
|
+
"zinc300": "#d4d4d8",
|
|
13
|
+
"zinc200": "#e4e4e7",
|
|
14
|
+
"zinc100": "#f4f4f5",
|
|
15
|
+
"zinc50": "#fafafa",
|
|
16
|
+
"angry300": "#fca5a5",
|
|
17
|
+
"angry600": "#dc2626",
|
|
18
|
+
"happy300": "#86efac",
|
|
19
|
+
"happy500": "#22c55e",
|
|
20
|
+
"warning300": "#fcd34d",
|
|
21
|
+
"warning500": "#f59e0b",
|
|
22
|
+
"warning600": "#d97706",
|
|
23
|
+
"overlay20": "rgba(25, 16, 21, 0.2)",
|
|
24
|
+
"overlay50": "rgba(25, 16, 21, 0.5)",
|
|
25
|
+
"hyperspaceMint": "#b9fff3",
|
|
26
|
+
"hyperspaceSky": "#8bc9ff",
|
|
27
|
+
"hyperspacePeriwinkle": "#a8a9ff",
|
|
28
|
+
"hyperspaceLilac": "#eac2ff",
|
|
29
|
+
"akitaGreen": "#44f8bd",
|
|
30
|
+
"akitaGold": "#f5c434",
|
|
31
|
+
"akitaYellow": "#FFEB00",
|
|
32
|
+
"akitaDarkBlue": "#0039CB",
|
|
33
|
+
"akitaLightBlue": "#00F0FF",
|
|
34
|
+
"white": "#FFFFFF",
|
|
35
|
+
"black": "#000000"
|
|
36
|
+
},
|
|
37
|
+
"transparent": "rgba(0, 0, 0, 0)",
|
|
38
|
+
"text": "#27272a",
|
|
39
|
+
"textDim": "#52525b",
|
|
40
|
+
"background": "#FFFFFF",
|
|
41
|
+
"accentBackground": "#f4f4f5",
|
|
42
|
+
"border": "#d4d4d8",
|
|
43
|
+
"tint": "#27272a",
|
|
44
|
+
"tintInactive": "#71717a",
|
|
45
|
+
"separator": "#d4d4d8",
|
|
46
|
+
"error": "#dc2626",
|
|
47
|
+
"errorBackground": "#fca5a5",
|
|
48
|
+
"success": "#22c55e",
|
|
49
|
+
"successBackground": "#86efac",
|
|
50
|
+
"warning": "#fcd34d",
|
|
51
|
+
"warningText": "#d97706",
|
|
52
|
+
"primary": "#6a6aa1",
|
|
53
|
+
"secondary": "#4f7391",
|
|
54
|
+
"primaryText": "#FFFFFF",
|
|
55
|
+
"secondaryText": "#FFFFFF",
|
|
56
|
+
"interactiveGradient": [
|
|
57
|
+
"#557570",
|
|
58
|
+
"#4f7391",
|
|
59
|
+
"#6a6aa1",
|
|
60
|
+
"#7c6787"
|
|
61
|
+
],
|
|
62
|
+
"interactiveText": "#FFFFFF"
|
|
63
|
+
},
|
|
64
|
+
"gradients": {
|
|
65
|
+
"interactive": [
|
|
66
|
+
"#557570",
|
|
67
|
+
"#4f7391",
|
|
68
|
+
"#6a6aa1",
|
|
69
|
+
"#7c6787"
|
|
70
|
+
],
|
|
71
|
+
"interactiveLocations": [
|
|
72
|
+
0,
|
|
73
|
+
0.42,
|
|
74
|
+
0.65,
|
|
75
|
+
1
|
|
76
|
+
],
|
|
77
|
+
"interactiveText": "#FFFFFF"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"dark": {
|
|
81
|
+
"colors": {
|
|
82
|
+
"palette": {
|
|
83
|
+
"zinc950": "#09090b",
|
|
84
|
+
"zinc900": "#18181b",
|
|
85
|
+
"zinc800": "#27272a",
|
|
86
|
+
"zinc700": "#3f3f46",
|
|
87
|
+
"zinc600": "#52525b",
|
|
88
|
+
"zinc500": "#71717a",
|
|
89
|
+
"zinc400": "#a1a1aa",
|
|
90
|
+
"zinc300": "#d4d4d8",
|
|
91
|
+
"zinc200": "#e4e4e7",
|
|
92
|
+
"zinc100": "#f4f4f5",
|
|
93
|
+
"zinc50": "#fafafa",
|
|
94
|
+
"angry300": "#fca5a5",
|
|
95
|
+
"angry600": "#dc2626",
|
|
96
|
+
"happy300": "#86efac",
|
|
97
|
+
"happy500": "#22c55e",
|
|
98
|
+
"warning300": "#fcd34d",
|
|
99
|
+
"warning500": "#f59e0b",
|
|
100
|
+
"warning600": "#d97706",
|
|
101
|
+
"overlay20": "rgba(25, 16, 21, 0.2)",
|
|
102
|
+
"overlay50": "rgba(25, 16, 21, 0.5)",
|
|
103
|
+
"hyperspaceMint": "#b9fff3",
|
|
104
|
+
"hyperspaceSky": "#8bc9ff",
|
|
105
|
+
"hyperspacePeriwinkle": "#a8a9ff",
|
|
106
|
+
"hyperspaceLilac": "#eac2ff",
|
|
107
|
+
"akitaGreen": "#44f8bd",
|
|
108
|
+
"akitaGold": "#f5c434",
|
|
109
|
+
"akitaYellow": "#FFEB00",
|
|
110
|
+
"akitaDarkBlue": "#0039CB",
|
|
111
|
+
"akitaLightBlue": "#00F0FF",
|
|
112
|
+
"white": "#FFFFFF",
|
|
113
|
+
"black": "#000000"
|
|
114
|
+
},
|
|
115
|
+
"transparent": "rgba(0, 0, 0, 0)",
|
|
116
|
+
"text": "#f4f4f5",
|
|
117
|
+
"textDim": "#a1a1aa",
|
|
118
|
+
"background": "#09090b",
|
|
119
|
+
"accentBackground": "#18181b",
|
|
120
|
+
"border": "#27272a",
|
|
121
|
+
"tint": "#fafafa",
|
|
122
|
+
"tintInactive": "#d4d4d8",
|
|
123
|
+
"separator": "#27272a",
|
|
124
|
+
"error": "#dc2626",
|
|
125
|
+
"errorBackground": "#fca5a5",
|
|
126
|
+
"success": "#22c55e",
|
|
127
|
+
"successBackground": "#86efac",
|
|
128
|
+
"warning": "#fcd34d",
|
|
129
|
+
"warningText": "#d97706",
|
|
130
|
+
"primary": "#a8a9ff",
|
|
131
|
+
"secondary": "#8bc9ff",
|
|
132
|
+
"primaryText": "#09090b",
|
|
133
|
+
"secondaryText": "#09090b",
|
|
134
|
+
"interactiveGradient": [
|
|
135
|
+
"#b9fff3",
|
|
136
|
+
"#8bc9ff",
|
|
137
|
+
"#a8a9ff",
|
|
138
|
+
"#eac2ff"
|
|
139
|
+
],
|
|
140
|
+
"interactiveText": "#09090b"
|
|
141
|
+
},
|
|
142
|
+
"gradients": {
|
|
143
|
+
"interactive": [
|
|
144
|
+
"#b9fff3",
|
|
145
|
+
"#8bc9ff",
|
|
146
|
+
"#a8a9ff",
|
|
147
|
+
"#eac2ff"
|
|
148
|
+
],
|
|
149
|
+
"interactiveLocations": [
|
|
150
|
+
0,
|
|
151
|
+
0.42,
|
|
152
|
+
0.65,
|
|
153
|
+
1
|
|
154
|
+
],
|
|
155
|
+
"interactiveText": "#09090b"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ComponentSize } from "../types/algorand";
|
|
2
|
+
|
|
3
|
+
export interface ReferenceVariantProps {
|
|
4
|
+
size?: ComponentSize;
|
|
5
|
+
/** A compact reference; false explicitly keeps the card at the chosen width. */
|
|
6
|
+
compact?: boolean;
|
|
7
|
+
/** Text-only reference that can be nested directly inside native Text. */
|
|
8
|
+
inline?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Small is an entity reference, not a width-constrained version of the full card. */
|
|
12
|
+
export function isCompactReference({ size, compact, inline }: ReferenceVariantProps): boolean {
|
|
13
|
+
return !!inline || (compact ?? size === "sm");
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { useMemo } from 'react'
|
|
2
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
3
|
+
import { AlgomdContext, type AlgomdContextValue } from './context'
|
|
4
|
+
import type { AlgomdConfig } from './types'
|
|
5
|
+
import { defaultResolveImageUrl } from './imageResolver'
|
|
6
|
+
|
|
7
|
+
interface AlgomdProviderProps {
|
|
8
|
+
config: AlgomdConfig
|
|
9
|
+
/** Share cache with consuming app's react-query. If omitted, creates an internal one. */
|
|
10
|
+
queryClient?: QueryClient
|
|
11
|
+
children: React.ReactNode
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const defaultQueryClient = new QueryClient({
|
|
15
|
+
defaultOptions: {
|
|
16
|
+
queries: {
|
|
17
|
+
staleTime: 60_000,
|
|
18
|
+
retry: 2,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export function AlgomdProvider({ config, queryClient, children }: AlgomdProviderProps) {
|
|
24
|
+
const contextValue = useMemo<AlgomdContextValue>(() => ({
|
|
25
|
+
config,
|
|
26
|
+
resolveImageUrl: config.resolveImageUrl ?? defaultResolveImageUrl,
|
|
27
|
+
}), [config])
|
|
28
|
+
|
|
29
|
+
const content = (
|
|
30
|
+
<AlgomdContext.Provider value={contextValue}>
|
|
31
|
+
{children}
|
|
32
|
+
</AlgomdContext.Provider>
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
// If a queryClient is provided (shared), don't wrap with another QueryClientProvider
|
|
36
|
+
if (queryClient) {
|
|
37
|
+
return content
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<QueryClientProvider client={defaultQueryClient}>
|
|
42
|
+
{content}
|
|
43
|
+
</QueryClientProvider>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react'
|
|
2
|
+
import type { AlgomdConfig } from './types'
|
|
3
|
+
import { defaultResolveImageUrl } from './imageResolver'
|
|
4
|
+
|
|
5
|
+
export interface AlgomdContextValue {
|
|
6
|
+
config: AlgomdConfig
|
|
7
|
+
resolveImageUrl: (src: string, width: number, quality?: number) => string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const AlgomdContext = createContext<AlgomdContextValue | null>(null)
|
|
11
|
+
|
|
12
|
+
export function useAlgomd(): AlgomdContextValue {
|
|
13
|
+
const ctx = useContext(AlgomdContext)
|
|
14
|
+
if (!ctx) {
|
|
15
|
+
throw new Error('useAlgomd must be used within an <AlgomdProvider>')
|
|
16
|
+
}
|
|
17
|
+
return ctx
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default image URL resolver using Akita CDN proxy.
|
|
3
|
+
* Transforms IPFS and HTTP(S) URLs into optimized CDN URLs.
|
|
4
|
+
*/
|
|
5
|
+
export function defaultResolveImageUrl(src: string, width: number, quality = 75): string {
|
|
6
|
+
if (!src.startsWith('ipfs://') && !src.startsWith('https://') && !src.startsWith('http://'))
|
|
7
|
+
return src
|
|
8
|
+
const format = src.includes('.gif') ? 'gif' : 'jpeg'
|
|
9
|
+
const params = [`${width}x`, `q${quality}`, format]
|
|
10
|
+
const resolved = src.replace('ipfs://', 'https://ipfs.akita.community/ipfs/')
|
|
11
|
+
return `https://imageproxy.akita.community/${params.join(',')}/${resolved}`
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AlgomdNetwork } from './types'
|
|
2
|
+
|
|
3
|
+
export const NETWORK_DEFAULTS: Record<AlgomdNetwork, {
|
|
4
|
+
algodServer: string
|
|
5
|
+
algodPort?: number
|
|
6
|
+
algodToken?: string
|
|
7
|
+
indexerServer: string
|
|
8
|
+
indexerToken?: string
|
|
9
|
+
}> = {
|
|
10
|
+
mainnet: {
|
|
11
|
+
algodServer: 'https://mainnet-api.4160.nodely.dev',
|
|
12
|
+
indexerServer: 'https://mainnet-idx.4160.nodely.dev',
|
|
13
|
+
},
|
|
14
|
+
testnet: {
|
|
15
|
+
algodServer: 'https://testnet-api.4160.nodely.dev',
|
|
16
|
+
indexerServer: 'https://testnet-idx.4160.nodely.dev',
|
|
17
|
+
},
|
|
18
|
+
localnet: {
|
|
19
|
+
algodServer: 'http://localhost:4001',
|
|
20
|
+
algodToken: 'a'.repeat(64),
|
|
21
|
+
indexerServer: 'http://localhost:8980',
|
|
22
|
+
},
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type AlgomdNetwork = "mainnet" | "testnet" | "localnet";
|
|
2
|
+
|
|
3
|
+
export interface AlgomdConfig {
|
|
4
|
+
/** Network - determines default algod/indexer URLs */
|
|
5
|
+
network: AlgomdNetwork;
|
|
6
|
+
/** Override algod server URL */
|
|
7
|
+
algodServer?: string;
|
|
8
|
+
algodPort?: number;
|
|
9
|
+
algodToken?: string;
|
|
10
|
+
/** Override indexer server URL (needed for Transaction) */
|
|
11
|
+
indexerServer?: string;
|
|
12
|
+
indexerToken?: string;
|
|
13
|
+
/** Extra HTTP headers to send to algod/indexer */
|
|
14
|
+
headers?: Record<string, string>;
|
|
15
|
+
/** Override NFD API URL (default: https://api.nf.domains) */
|
|
16
|
+
nfdApiUrl?: string;
|
|
17
|
+
/** Optional Akita backend URL for backend-backed embeds like collections */
|
|
18
|
+
backendUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Recent USD prices for an asset, oldest first, for token sparklines. Hosts
|
|
21
|
+
* supply this because price APIs such as Vestige do not allow browser origins.
|
|
22
|
+
* Leave it out and token cards show no sparkline.
|
|
23
|
+
*/
|
|
24
|
+
fetchAssetPriceHistory?: (
|
|
25
|
+
assetId: number,
|
|
26
|
+
) => Promise<import("../types/algorand").AssetPricePoint[]>;
|
|
27
|
+
/** Override image URL resolver (default: Akita CDN proxy) */
|
|
28
|
+
resolveImageUrl?: (src: string, width: number, quality?: number) => string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Pressable, View } from "react-native";
|
|
3
|
+
import { formatAlgo, shortAddress, type NfdData } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { useAccount, useEntity, useIdentity } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { ChevronRightIcon } from "../presentation/icons";
|
|
7
|
+
import { Text, useAppTheme, usePresentation } from "../presentation/runtime";
|
|
8
|
+
import {
|
|
9
|
+
Avatar,
|
|
10
|
+
Card,
|
|
11
|
+
CardHeader,
|
|
12
|
+
CardSkeleton,
|
|
13
|
+
DetailLine,
|
|
14
|
+
headerMedia,
|
|
15
|
+
InlinePill,
|
|
16
|
+
Inset,
|
|
17
|
+
Row,
|
|
18
|
+
SectionLabel,
|
|
19
|
+
Stat,
|
|
20
|
+
StatRow,
|
|
21
|
+
StatusBadge,
|
|
22
|
+
Title,
|
|
23
|
+
usePalette,
|
|
24
|
+
VerifiedMark,
|
|
25
|
+
type Tone,
|
|
26
|
+
} from "./primitives";
|
|
27
|
+
import type { RefViewProps } from "./types";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An account at any size. Inline and small read only the cached identity
|
|
31
|
+
* (NFD → host profile → short address), so mentions in a feed never poll
|
|
32
|
+
* balances. Large and full also load the live account.
|
|
33
|
+
*/
|
|
34
|
+
export function AccountRef({ id: address, size = "large", onPress, visible }: RefViewProps) {
|
|
35
|
+
const presentation = usePresentation();
|
|
36
|
+
const identity = useIdentity(address, { visible });
|
|
37
|
+
const id = identity.data?.data;
|
|
38
|
+
const press = onPress ?? (presentation.onOpenAccount ? () => presentation.onOpenAccount!(address) : undefined);
|
|
39
|
+
const name = id?.name ?? shortAddress(address);
|
|
40
|
+
const verified = id?.nameVerified ?? false;
|
|
41
|
+
|
|
42
|
+
if (size === "inline") {
|
|
43
|
+
return (
|
|
44
|
+
<InlinePill
|
|
45
|
+
label={name}
|
|
46
|
+
dim={identity.isPending}
|
|
47
|
+
leading={<Avatar uri={id?.avatar} size={16} initial={name} />}
|
|
48
|
+
trailing={verified ? <VerifiedMark size={10} /> : null}
|
|
49
|
+
onPress={press}
|
|
50
|
+
accessibilityLabel={`Open ${name}`}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (size === "small") {
|
|
56
|
+
return (
|
|
57
|
+
<Row
|
|
58
|
+
leading={<Avatar uri={id?.avatar} size={36} initial={name} />}
|
|
59
|
+
title={<Title verified={verified}>{name}</Title>}
|
|
60
|
+
subtitle={id?.name ? (id.nfd && id.nameSource !== "nfd" ? `${id.nfd} · ${id.short}` : id.short) : undefined}
|
|
61
|
+
onPress={press}
|
|
62
|
+
accessibilityLabel={`Open ${name}`}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return <AccountCard address={address} full={size === "full"} visible={visible} />;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function AccountCard({ address, full, visible }: { address: string; full: boolean; visible?: boolean }) {
|
|
71
|
+
const { theme } = useAppTheme();
|
|
72
|
+
const identity = useIdentity(address, { visible });
|
|
73
|
+
const account = useAccount(address, { visible });
|
|
74
|
+
// The identity chain already loaded this through the shared cache.
|
|
75
|
+
const nfd = useEntity<NfdData>("nfd-address", address, { visible, enabled: full });
|
|
76
|
+
const id = identity.data?.data;
|
|
77
|
+
const acct = account.data?.data;
|
|
78
|
+
|
|
79
|
+
if (identity.isPending && account.isPending) return <CardSkeleton full={full} />;
|
|
80
|
+
|
|
81
|
+
const name = id?.name ?? shortAddress(address);
|
|
82
|
+
const sourceLabel =
|
|
83
|
+
id?.nameSource === "nfd" ? "NFD (verified)" : id?.nameSource && id.nameSource !== "address" ? "Profile (self-chosen)" : "None";
|
|
84
|
+
const nfdName = nfd.data?.data?.name;
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<Card>
|
|
88
|
+
<CardHeader
|
|
89
|
+
media={<Avatar uri={id?.avatar} size={headerMedia(full)} initial={name} />}
|
|
90
|
+
title={name}
|
|
91
|
+
verified={id?.nameVerified}
|
|
92
|
+
titleLines={1}
|
|
93
|
+
full={full}
|
|
94
|
+
status={acct?.authAddr ? <StatusBadge label="Rekeyed" tone="warn" /> : undefined}
|
|
95
|
+
meta={
|
|
96
|
+
<Text size="xxs" selectable numberOfLines={full ? 3 : 1} style={{ color: theme.colors.textDim, flexShrink: 1 }}>
|
|
97
|
+
{full ? address : shortAddress(address, 6, 6)}
|
|
98
|
+
</Text>
|
|
99
|
+
}
|
|
100
|
+
menu={<ContractMenu appId={address} type="account" embedType="Account" embedProp="address" />}
|
|
101
|
+
/>
|
|
102
|
+
|
|
103
|
+
<StatRow>
|
|
104
|
+
<Stat label="Balance" grow={2}>{acct ? `${formatAlgo(acct.amount, { maxFraction: 2 })} ALGO` : "—"}</Stat>
|
|
105
|
+
<Stat label="Assets">{acct ? String(acct.totalAssets) : "—"}</Stat>
|
|
106
|
+
<Stat label="Apps" align="right">{acct ? String(acct.totalApps) : "—"}</Stat>
|
|
107
|
+
</StatRow>
|
|
108
|
+
|
|
109
|
+
{full ? (
|
|
110
|
+
<View>
|
|
111
|
+
<DetailLine label="Name from">{sourceLabel}</DetailLine>
|
|
112
|
+
{nfdName && nfdName !== name ? <DetailLine label="NFD">{nfdName}</DetailLine> : null}
|
|
113
|
+
{acct ? <DetailLine label="Minimum balance">{`${formatAlgo(acct.minBalance, { maxFraction: 3 })} ALGO`}</DetailLine> : null}
|
|
114
|
+
{acct?.authAddr ? (
|
|
115
|
+
<DetailLine label="Signs with">
|
|
116
|
+
<AccountRef id={acct.authAddr} size="inline" />
|
|
117
|
+
</DetailLine>
|
|
118
|
+
) : null}
|
|
119
|
+
</View>
|
|
120
|
+
) : null}
|
|
121
|
+
</Card>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function useHandle(address: string, visible?: boolean) {
|
|
126
|
+
const identity = useIdentity(address, { visible });
|
|
127
|
+
const id = identity.data?.data;
|
|
128
|
+
const name = id?.name ?? shortAddress(address);
|
|
129
|
+
const short = id?.short ?? shortAddress(address);
|
|
130
|
+
// An unnamed account shows its short address once.
|
|
131
|
+
const handle = id?.nfd && id.nfd !== name ? `@${id.nfd}` : short !== name ? short : undefined;
|
|
132
|
+
return { id, name, handle, pending: identity.isPending };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface PersonRowProps {
|
|
136
|
+
address: string;
|
|
137
|
+
/** What this account is to the subject: "Seller", "Winner", "40 tickets". */
|
|
138
|
+
role?: string;
|
|
139
|
+
roleTone?: Tone;
|
|
140
|
+
visible?: boolean;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* An account in its role, as the Akita marketplace shows a seller: avatar,
|
|
145
|
+
* name and handle on a nested surface, the role at the end. It opens the
|
|
146
|
+
* account through the host.
|
|
147
|
+
*/
|
|
148
|
+
export function PersonRow({ address, role, roleTone, visible }: PersonRowProps) {
|
|
149
|
+
const { theme, tone } = usePalette();
|
|
150
|
+
const presentation = usePresentation();
|
|
151
|
+
const { id, name, handle } = useHandle(address, visible);
|
|
152
|
+
const press = presentation.onOpenAccount ? () => presentation.onOpenAccount!(address) : undefined;
|
|
153
|
+
const body = (
|
|
154
|
+
<Inset style={{ flexDirection: "row", alignItems: "center", gap: 10, paddingVertical: 10, paddingHorizontal: 12 }}>
|
|
155
|
+
<Avatar uri={id?.avatar} size={36} initial={name} />
|
|
156
|
+
<View style={{ flex: 1, minWidth: 0, gap: 1 }}>
|
|
157
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 4 }}>
|
|
158
|
+
<Text size="xs" weight="semiBold" numberOfLines={1} style={{ flexShrink: 1 }}>
|
|
159
|
+
{name}
|
|
160
|
+
</Text>
|
|
161
|
+
{id?.nameVerified ? <VerifiedMark size={12} /> : null}
|
|
162
|
+
</View>
|
|
163
|
+
{handle ? (
|
|
164
|
+
<Text size="xxs" numberOfLines={1} style={{ color: theme.colors.textDim }}>
|
|
165
|
+
{handle}
|
|
166
|
+
</Text>
|
|
167
|
+
) : null}
|
|
168
|
+
</View>
|
|
169
|
+
{role ? (
|
|
170
|
+
<Text size="xs" weight={roleTone ? "bold" : "medium"} numberOfLines={1} style={{ color: tone(roleTone ?? "neutral"), flexShrink: 0 }}>
|
|
171
|
+
{role}
|
|
172
|
+
</Text>
|
|
173
|
+
) : null}
|
|
174
|
+
</Inset>
|
|
175
|
+
);
|
|
176
|
+
if (!press) return body;
|
|
177
|
+
return (
|
|
178
|
+
<Pressable accessibilityRole="button" accessibilityLabel={`Open ${name}${role ? `, ${role}` : ""}`} onPress={press}>
|
|
179
|
+
{body}
|
|
180
|
+
</Pressable>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The creator of a card's subject: a label, then avatar, name and handle, as
|
|
186
|
+
* on the Akita subscriptions screen. It opens the account through the host.
|
|
187
|
+
*/
|
|
188
|
+
export function CreatorIdentity({ address, label = "Creator", visible }: { address: string; label?: string; visible?: boolean }) {
|
|
189
|
+
const { theme } = useAppTheme();
|
|
190
|
+
const presentation = usePresentation();
|
|
191
|
+
const { id, name, handle } = useHandle(address, visible);
|
|
192
|
+
const press = presentation.onOpenAccount ? () => presentation.onOpenAccount!(address) : undefined;
|
|
193
|
+
|
|
194
|
+
const row = (
|
|
195
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
|
|
196
|
+
<Avatar uri={id?.avatar} size={40} initial={name} />
|
|
197
|
+
<View style={{ flex: 1, minWidth: 0, gap: 1 }}>
|
|
198
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 4 }}>
|
|
199
|
+
<Text size="sm" weight="bold" numberOfLines={1} style={{ flexShrink: 1 }}>
|
|
200
|
+
{name}
|
|
201
|
+
</Text>
|
|
202
|
+
{id?.nameVerified ? <VerifiedMark size={13} /> : null}
|
|
203
|
+
</View>
|
|
204
|
+
{handle ? (
|
|
205
|
+
<Text size="xxs" numberOfLines={1} style={{ color: theme.colors.textDim }}>
|
|
206
|
+
{handle}
|
|
207
|
+
</Text>
|
|
208
|
+
) : null}
|
|
209
|
+
</View>
|
|
210
|
+
{press ? <ChevronRightIcon size={16} color={theme.colors.textDim} /> : null}
|
|
211
|
+
</View>
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
<View style={{ gap: 8 }}>
|
|
216
|
+
<SectionLabel>{label}</SectionLabel>
|
|
217
|
+
{press ? (
|
|
218
|
+
<Pressable accessibilityRole="button" accessibilityLabel={`Open ${name}`} onPress={press}>
|
|
219
|
+
{row}
|
|
220
|
+
</Pressable>
|
|
221
|
+
) : (
|
|
222
|
+
row
|
|
223
|
+
)}
|
|
224
|
+
</View>
|
|
225
|
+
);
|
|
226
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { shortAddress } from "@akita-protocol/algomd-core";
|
|
4
|
+
import { useApplication } from "@akita-protocol/algomd-core/react";
|
|
5
|
+
import { ContractMenu } from "../presentation/ContractMenu";
|
|
6
|
+
import { CubeIcon } from "../presentation/icons";
|
|
7
|
+
import { useAppTheme, usePresentation } from "../presentation/runtime";
|
|
8
|
+
import { PersonRow } from "./AccountRef";
|
|
9
|
+
import { StatusChip } from "./contractParts";
|
|
10
|
+
import { Card, CardHeader, CardSkeleton, DetailLine, headerMedia, InlinePill, KindTile, Row, RowSkeleton, Title, Unavailable } from "./primitives";
|
|
11
|
+
import type { RefViewProps } from "./types";
|
|
12
|
+
|
|
13
|
+
function useLabel(id: string): { name: string; known: boolean } {
|
|
14
|
+
const known = usePresentation().applicationLabel?.(id);
|
|
15
|
+
return { name: known ?? `App ${id}`, known: Boolean(known) };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** An application (smart contract) at any size. Hosts name known apps with `applicationLabel`. */
|
|
19
|
+
export function ApplicationRef({ id, size = "large", onPress, visible }: RefViewProps) {
|
|
20
|
+
const { theme } = useAppTheme();
|
|
21
|
+
const presentation = usePresentation();
|
|
22
|
+
const { name, known } = useLabel(id);
|
|
23
|
+
const app = useApplication(size === "inline" ? undefined : id, { visible });
|
|
24
|
+
const press = onPress ?? (presentation.onOpenApplication ? () => presentation.onOpenApplication!(id) : undefined);
|
|
25
|
+
const retry = app.isError ? () => void app.refetch() : undefined;
|
|
26
|
+
|
|
27
|
+
if (size === "inline") {
|
|
28
|
+
return <InlinePill label={name} leading={<CubeIcon size={12} color={theme.colors.primary} />} onPress={press} accessibilityLabel={`Open ${name}`} />;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const data = app.data?.data;
|
|
32
|
+
const deleted = app.data?.status === "archived";
|
|
33
|
+
|
|
34
|
+
if (size === "small") {
|
|
35
|
+
if (app.isPending) return <RowSkeleton shape="rounded" />;
|
|
36
|
+
if (!data) return <Unavailable size="small" label={name} Icon={CubeIcon} onRetry={retry} />;
|
|
37
|
+
return (
|
|
38
|
+
<Row
|
|
39
|
+
leading={<KindTile Icon={CubeIcon} size={36} dim={deleted} />}
|
|
40
|
+
title={<Title>{name}</Title>}
|
|
41
|
+
subtitle={known ? `App ${id}` : data.creator ? `Created by ${shortAddress(data.creator)}` : undefined}
|
|
42
|
+
trailing={deleted ? <StatusChip status="deleted" /> : undefined}
|
|
43
|
+
onPress={press}
|
|
44
|
+
accessibilityLabel={`Open ${name}`}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const full = size === "full";
|
|
50
|
+
if (app.isPending) return <CardSkeleton media="rounded" blocks={1} full={full} />;
|
|
51
|
+
if (!data) return <Unavailable size={size} label={name} Icon={CubeIcon} onRetry={retry} />;
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<Card>
|
|
55
|
+
<CardHeader
|
|
56
|
+
media={<KindTile Icon={CubeIcon} size={headerMedia(full)} dim={deleted} />}
|
|
57
|
+
title={name}
|
|
58
|
+
full={full}
|
|
59
|
+
status={<StatusChip status={deleted ? "deleted" : "active"} />}
|
|
60
|
+
meta={known ? `App ${id}` : undefined}
|
|
61
|
+
menu={<ContractMenu appId={id} type="application" />}
|
|
62
|
+
/>
|
|
63
|
+
{data.creator ? <PersonRow address={data.creator} role="Creator" visible={visible} /> : null}
|
|
64
|
+
{full ? (
|
|
65
|
+
<View>
|
|
66
|
+
{data.createdRound ? <DetailLine label="Created in round">{Number(data.createdRound).toLocaleString()}</DetailLine> : null}
|
|
67
|
+
{deleted ? <DetailLine label="Deleted in round">{data.deletedRound ? Number(data.deletedRound).toLocaleString() : "Unknown"}</DetailLine> : null}
|
|
68
|
+
</View>
|
|
69
|
+
) : null}
|
|
70
|
+
</Card>
|
|
71
|
+
);
|
|
72
|
+
}
|