@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,54 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { AlgorandClient } from '@algorandfoundation/algokit-utils'
|
|
3
|
+
import { AlgodClient } from '@algorandfoundation/algokit-utils/algod-client'
|
|
4
|
+
import algosdk from 'algosdk'
|
|
5
|
+
import { makeEmptyTransactionSigner } from '@algorandfoundation/algokit-utils/transact'
|
|
6
|
+
import { useAlgomd } from '../provider/context'
|
|
7
|
+
import { NETWORK_DEFAULTS } from '../provider/networks'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a memoized AlgorandClient from provider config.
|
|
11
|
+
*
|
|
12
|
+
* Registers an empty default signer for explicitly simulated read calls.
|
|
13
|
+
*/
|
|
14
|
+
export function useAlgorandClient(): AlgorandClient {
|
|
15
|
+
const { config } = useAlgomd()
|
|
16
|
+
|
|
17
|
+
return useMemo(() => {
|
|
18
|
+
const defaults = NETWORK_DEFAULTS[config.network]
|
|
19
|
+
const server = config.algodServer ?? defaults.algodServer
|
|
20
|
+
const port = config.algodPort ?? defaults.algodPort
|
|
21
|
+
const token = config.algodToken ?? defaults.algodToken ?? ''
|
|
22
|
+
|
|
23
|
+
const client = AlgorandClient.fromClients({
|
|
24
|
+
algod: new AlgodClient({
|
|
25
|
+
baseUrl: server,
|
|
26
|
+
port,
|
|
27
|
+
token,
|
|
28
|
+
headers: config.headers,
|
|
29
|
+
}),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// Register an empty signer so explicitly simulated read methods can run
|
|
33
|
+
// without a real signer. This is safe — algomd-rn is a display library.
|
|
34
|
+
client.setDefaultSigner(makeEmptyTransactionSigner())
|
|
35
|
+
|
|
36
|
+
return client
|
|
37
|
+
}, [config.network, config.algodServer, config.algodPort, config.algodToken, config.headers])
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a memoized Indexer client from provider config.
|
|
42
|
+
* Returns null if indexer is not configured.
|
|
43
|
+
*/
|
|
44
|
+
export function useIndexerClient(): algosdk.Indexer | null {
|
|
45
|
+
const { config } = useAlgomd()
|
|
46
|
+
|
|
47
|
+
return useMemo(() => {
|
|
48
|
+
const defaults = NETWORK_DEFAULTS[config.network]
|
|
49
|
+
const server = config.indexerServer ?? defaults.indexerServer
|
|
50
|
+
if (!server) return null
|
|
51
|
+
const token = config.indexerToken ?? defaults.indexerToken ?? ''
|
|
52
|
+
return new algosdk.Indexer(token, server, '', config.headers)
|
|
53
|
+
}, [config.network, config.indexerServer, config.indexerToken, config.headers])
|
|
54
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// Provider
|
|
2
|
+
export {
|
|
3
|
+
AlgomdProvider,
|
|
4
|
+
useAlgomd,
|
|
5
|
+
defaultResolveImageUrl,
|
|
6
|
+
NETWORK_DEFAULTS,
|
|
7
|
+
} from "./provider";
|
|
8
|
+
export type { AlgomdConfig, AlgomdNetwork } from "./provider";
|
|
9
|
+
|
|
10
|
+
// Self-fetching Components
|
|
11
|
+
export {
|
|
12
|
+
Account,
|
|
13
|
+
ASA,
|
|
14
|
+
Collection,
|
|
15
|
+
NFTListing,
|
|
16
|
+
NFDProfile,
|
|
17
|
+
TransactionDetails,
|
|
18
|
+
Poll,
|
|
19
|
+
RaffleListing,
|
|
20
|
+
StakingPool,
|
|
21
|
+
AuctionListing,
|
|
22
|
+
TradeOffer,
|
|
23
|
+
DualStakePool,
|
|
24
|
+
// Display-only (no self-fetch)
|
|
25
|
+
AccountDisplay,
|
|
26
|
+
ASADisplay,
|
|
27
|
+
CollectionDisplay,
|
|
28
|
+
NFTListingDisplay,
|
|
29
|
+
NFDProfileDisplay,
|
|
30
|
+
TransactionDetailsDisplay,
|
|
31
|
+
PollDisplay,
|
|
32
|
+
RaffleListingDisplay,
|
|
33
|
+
StakingPoolDisplay,
|
|
34
|
+
AuctionListingDisplay,
|
|
35
|
+
TradeOfferDisplay,
|
|
36
|
+
DualStakePoolDisplay,
|
|
37
|
+
// Search
|
|
38
|
+
AccountSearch,
|
|
39
|
+
ASASearch,
|
|
40
|
+
NFTSearch,
|
|
41
|
+
NFDSearch,
|
|
42
|
+
TransactionSearch,
|
|
43
|
+
PollSearch,
|
|
44
|
+
TradeSearch,
|
|
45
|
+
} from "./components";
|
|
46
|
+
export type {
|
|
47
|
+
DualStakePoolProps,
|
|
48
|
+
StakingPoolProps,
|
|
49
|
+
StakingPoolSelfFetchProps,
|
|
50
|
+
} from "./components";
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
createAlgomdDataProvider,
|
|
54
|
+
type CreateAlgomdDataProviderOptions,
|
|
55
|
+
} from "./adapters";
|
|
56
|
+
|
|
57
|
+
// Hooks
|
|
58
|
+
export {
|
|
59
|
+
useAlgorandClient,
|
|
60
|
+
useIndexerClient,
|
|
61
|
+
useAccountData,
|
|
62
|
+
useASAData,
|
|
63
|
+
useAssetCollection,
|
|
64
|
+
useAssetPriceHistory,
|
|
65
|
+
useAssetCirculatingSupply,
|
|
66
|
+
useCollectionData,
|
|
67
|
+
useTransactionData,
|
|
68
|
+
useNFDProfileData,
|
|
69
|
+
usePollData,
|
|
70
|
+
useRaffleData,
|
|
71
|
+
useStakingPoolData,
|
|
72
|
+
useAuctionData,
|
|
73
|
+
useNFTListingData,
|
|
74
|
+
useTradeOfferData,
|
|
75
|
+
} from "./hooks";
|
|
76
|
+
|
|
77
|
+
// Shared UI
|
|
78
|
+
export {
|
|
79
|
+
SizeContainer,
|
|
80
|
+
CopyButton,
|
|
81
|
+
StatusBadge,
|
|
82
|
+
ProgressBar,
|
|
83
|
+
SearchSheet,
|
|
84
|
+
} from "./ui";
|
|
85
|
+
export { LoadingSkeleton, ErrorState } from "./ui/DataStates";
|
|
86
|
+
|
|
87
|
+
// Types
|
|
88
|
+
export type {
|
|
89
|
+
AlgorandAccount,
|
|
90
|
+
ASA as ASAType,
|
|
91
|
+
AssetPricePoint,
|
|
92
|
+
Collection as CollectionType,
|
|
93
|
+
NFTListing as NFTListingType,
|
|
94
|
+
NFDProfile as NFDProfileType,
|
|
95
|
+
TransactionDetails as TransactionDetailsType,
|
|
96
|
+
RaffleListing as RaffleListingType,
|
|
97
|
+
StakingPool as StakingPoolType,
|
|
98
|
+
StakingPoolReward,
|
|
99
|
+
StakingPoolStatus,
|
|
100
|
+
StakingPoolStakingType,
|
|
101
|
+
StakingPoolDistributionType,
|
|
102
|
+
PrizeBoxBundle,
|
|
103
|
+
PrizeBoxHolding,
|
|
104
|
+
AuctionListing as AuctionListingType,
|
|
105
|
+
AuctionRaffle,
|
|
106
|
+
TradeOffer as TradeOfferType,
|
|
107
|
+
DualStakePool as DualStakePoolType,
|
|
108
|
+
DualStakeAction,
|
|
109
|
+
DualStakeActionParams,
|
|
110
|
+
Poll as PollType,
|
|
111
|
+
PollOption,
|
|
112
|
+
GatingInfo,
|
|
113
|
+
Application,
|
|
114
|
+
ComponentSize,
|
|
115
|
+
SearchResult,
|
|
116
|
+
SearchableEntity,
|
|
117
|
+
} from "./types";
|
|
118
|
+
|
|
119
|
+
// Utilities
|
|
120
|
+
export {
|
|
121
|
+
formatAddress,
|
|
122
|
+
formatNumber,
|
|
123
|
+
formatCurrency,
|
|
124
|
+
formatDate,
|
|
125
|
+
formatRelativeTime,
|
|
126
|
+
formatAssetAmount,
|
|
127
|
+
formatBaseUnitAmount,
|
|
128
|
+
normalizeAppId,
|
|
129
|
+
normalizeAssetId,
|
|
130
|
+
isCapacityFull,
|
|
131
|
+
searchEntities,
|
|
132
|
+
resolveArc19Url,
|
|
133
|
+
resolveAssetUrl,
|
|
134
|
+
} from "./utils";
|
|
135
|
+
|
|
136
|
+
export { AppPresentationProvider } from "./presentation/runtime";
|
|
137
|
+
export { AssetSubjectProvider } from "./presentation/subject";
|
|
138
|
+
export type { AppPresentation, AppIdentity } from "./presentation/runtime";
|
|
139
|
+
|
|
140
|
+
export * from "./presentation";
|
|
141
|
+
|
|
142
|
+
export { normalizeAlgomdImageUrl } from "./utils/algomdImageUrl";
|
|
143
|
+
export {
|
|
144
|
+
stakingSnapshotFromProps,
|
|
145
|
+
deriveStakingPoolStatus,
|
|
146
|
+
} from "./utils/stakingSnapshot";
|
|
147
|
+
export * from "./refs";
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
// Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Image, View } from "react-native";
|
|
4
|
+
import { CheckBadgeIcon } from "./icons";
|
|
5
|
+
import { LinearGradient, Text } from "./runtime";
|
|
6
|
+
import { useAppTheme } from "./runtime";
|
|
7
|
+
import { CardContainer } from "./CardContainer";
|
|
8
|
+
import { ContractMenu } from "./ContractMenu";
|
|
9
|
+
import { AdaptiveImage, useImageBudget } from "./AdaptiveImage";
|
|
10
|
+
import {
|
|
11
|
+
OnChainActionCard,
|
|
12
|
+
OnChainActionHeader,
|
|
13
|
+
OnChainMetric,
|
|
14
|
+
OnChainMetricGrid,
|
|
15
|
+
} from "./OnChainActionCard";
|
|
16
|
+
import {
|
|
17
|
+
formatAssetAmount,
|
|
18
|
+
formatCompactBaseUnitAmount,
|
|
19
|
+
} from "../utils/format";
|
|
20
|
+
import { formatPrice } from "./format";
|
|
21
|
+
import type { ASA as ASAType } from "../types/algorand";
|
|
22
|
+
import { algoIcon } from "./assets";
|
|
23
|
+
import { useIsAssetSubject } from "./subject";
|
|
24
|
+
import { Sparkline } from "./Sparkline";
|
|
25
|
+
import type { AssetPricePoint } from "../types/algorand";
|
|
26
|
+
|
|
27
|
+
/** OnChainActionCard's inner padding, which sparklines bleed through. */
|
|
28
|
+
const CARD_PADDING = 16;
|
|
29
|
+
|
|
30
|
+
const SUBSCRIPT_DIGITS = "\u2080\u2081\u2082\u2083\u2084\u2085\u2086\u2087\u2088\u2089";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* USD in two decimals where that keeps the real number ($1,234.50, $0.25).
|
|
34
|
+
* Smaller prices keep two significant figures ($0.012, $0.0012), and from
|
|
35
|
+
* three leading zeros on the zeros are counted in a subscript ($0.0\u20845 for
|
|
36
|
+
* $0.00005).
|
|
37
|
+
*/
|
|
38
|
+
export function formatUsdPrice(value: number): string {
|
|
39
|
+
if (!Number.isFinite(value) || value <= 0) return "$0";
|
|
40
|
+
if (value >= 0.1) {
|
|
41
|
+
return `$${value.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
|
|
42
|
+
}
|
|
43
|
+
const zeros = Math.floor(-Math.log10(value));
|
|
44
|
+
const digits = Math.round(value * 10 ** (zeros + 2));
|
|
45
|
+
// Rounding can carry into the next place, e.g. 0.0999 to 0.10.
|
|
46
|
+
if (digits >= 100) return formatUsdPrice(10 ** -zeros);
|
|
47
|
+
const significant = String(digits).replace(/0$/, "");
|
|
48
|
+
if (zeros <= 2) return `$0.${"0".repeat(zeros)}${significant}`;
|
|
49
|
+
const count = String(zeros)
|
|
50
|
+
.split("")
|
|
51
|
+
.map((digit) => SUBSCRIPT_DIGITS[Number(digit)])
|
|
52
|
+
.join("");
|
|
53
|
+
return `$0.0${count}${significant}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A supply for a card: compact from a million, else at most two decimals (27.39, 0.0042). */
|
|
57
|
+
export function formatSupply(raw: string | number | bigint, decimals: number): string {
|
|
58
|
+
const compact = formatCompactBaseUnitAmount(raw, decimals);
|
|
59
|
+
const [whole, fraction] = compact.split(".");
|
|
60
|
+
if (!fraction || /[A-Z]$/.test(compact)) return compact;
|
|
61
|
+
if (whole.replace(/[-,]/g, "") !== "0") {
|
|
62
|
+
const cut = fraction.slice(0, 2).replace(/0+$/, "");
|
|
63
|
+
return cut ? `${whole}.${cut}` : whole;
|
|
64
|
+
}
|
|
65
|
+
// Under one unit, keep two significant figures.
|
|
66
|
+
const lead = fraction.search(/[1-9]/);
|
|
67
|
+
return lead < 0 ? "0" : `0.${fraction.slice(0, lead + 2).replace(/0+$/, "")}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A share of the total that never rounds to 0% or 100% when it is neither. */
|
|
71
|
+
export function formatShare(percent: number): string {
|
|
72
|
+
if (percent < 0.01) return "<0.01%";
|
|
73
|
+
if (percent > 99.99) return ">99.99%";
|
|
74
|
+
const digits = percent < 1 || percent > 99 ? 2 : percent < 10 || percent > 90 ? 1 : 0;
|
|
75
|
+
return `${Number(percent.toFixed(digits))}%`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The change across the series and the span it covers, e.g. "+4.2% · 7d". */
|
|
79
|
+
export function priceChange(points: readonly AssetPricePoint[]) {
|
|
80
|
+
if (points.length < 2) return undefined;
|
|
81
|
+
const first = points[0];
|
|
82
|
+
const last = points[points.length - 1];
|
|
83
|
+
const percent = first.price > 0 ? ((last.price - first.price) / first.price) * 100 : 0;
|
|
84
|
+
const hours = (last.time - first.time) / 3_600_000;
|
|
85
|
+
const span = hours < 36 ? `${Math.max(1, Math.round(hours))}h` : `${Math.round(hours / 24)}d`;
|
|
86
|
+
const sign = Math.abs(percent) < 0.05 ? "" : percent > 0 ? "+" : "\u2212";
|
|
87
|
+
return {
|
|
88
|
+
up: percent >= 0,
|
|
89
|
+
// Under a twentieth of a percent reads as no change, e.g. a stablecoin.
|
|
90
|
+
flat: Math.abs(percent) < 0.05,
|
|
91
|
+
label: `${Math.abs(percent) < 0.05 ? "0" : `${sign}${Math.abs(percent).toFixed(Math.abs(percent) < 10 ? 1 : 0)}`}% · ${span}`,
|
|
92
|
+
latest: last.price,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface ASADisplayProps {
|
|
97
|
+
data: ASAType;
|
|
98
|
+
compact?: boolean;
|
|
99
|
+
/** Small and medium cards put a token's price and sparkline on one row with its name. */
|
|
100
|
+
dense?: boolean;
|
|
101
|
+
showDetails?: boolean;
|
|
102
|
+
imageUrl?: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function ASADisplay({
|
|
106
|
+
data,
|
|
107
|
+
compact,
|
|
108
|
+
dense,
|
|
109
|
+
showDetails,
|
|
110
|
+
imageUrl,
|
|
111
|
+
}: ASADisplayProps) {
|
|
112
|
+
const { theme } = useAppTheme();
|
|
113
|
+
const maxImageHeight = useImageBudget(160);
|
|
114
|
+
// On the asset's own page its art and name are already shown above.
|
|
115
|
+
const onSubjectPage = useIsAssetSubject(data.id);
|
|
116
|
+
|
|
117
|
+
if (compact) {
|
|
118
|
+
return (
|
|
119
|
+
<CardContainer compact>
|
|
120
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 3 }}>
|
|
121
|
+
{imageUrl && (
|
|
122
|
+
<Image
|
|
123
|
+
source={{ uri: imageUrl }}
|
|
124
|
+
style={{ width: 14, height: 14, borderRadius: 7 }}
|
|
125
|
+
/>
|
|
126
|
+
)}
|
|
127
|
+
<Text size="xxs" weight="semiBold" numberOfLines={1}>
|
|
128
|
+
{data.name}
|
|
129
|
+
</Text>
|
|
130
|
+
</View>
|
|
131
|
+
</CardContainer>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// A 1 of 1, or an ARC-3 fractional NFT whose total is exactly one whole unit
|
|
136
|
+
// (e.g. total 10000 with 4 decimals).
|
|
137
|
+
const isCollectible =
|
|
138
|
+
(data.totalRaw ?? String(Math.trunc(data.total))) ===
|
|
139
|
+
`1${"0".repeat(Math.max(0, data.decimals))}`;
|
|
140
|
+
// Zero-decimal assets with more than one unit are numbered editions.
|
|
141
|
+
const isEdition = !isCollectible && data.decimals === 0;
|
|
142
|
+
const supply = formatSupply(data.totalRaw ?? String(Math.trunc(data.total)), data.decimals);
|
|
143
|
+
const kind = isCollectible ? "Collectible" : isEdition ? "Edition" : "Token";
|
|
144
|
+
const history = !isCollectible && !isEdition ? data.usdPriceHistory ?? [] : [];
|
|
145
|
+
const change = priceChange(history);
|
|
146
|
+
const changeColor = !change || change.flat
|
|
147
|
+
? theme.colors.textDim
|
|
148
|
+
: change.up
|
|
149
|
+
? theme.colors.success
|
|
150
|
+
: theme.colors.error;
|
|
151
|
+
const subtitle =
|
|
152
|
+
(isCollectible || isEdition) && data.collection ? (
|
|
153
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
|
|
154
|
+
{data.collection.avatarUrl ? (
|
|
155
|
+
<Image
|
|
156
|
+
source={{ uri: data.collection.avatarUrl }}
|
|
157
|
+
style={{ width: 16, height: 16, borderRadius: 8 }}
|
|
158
|
+
/>
|
|
159
|
+
) : null}
|
|
160
|
+
<Text
|
|
161
|
+
size="xs"
|
|
162
|
+
numberOfLines={1}
|
|
163
|
+
style={{ color: theme.colors.textDim, flexShrink: 1 }}
|
|
164
|
+
>
|
|
165
|
+
{data.collection.name}
|
|
166
|
+
</Text>
|
|
167
|
+
</View>
|
|
168
|
+
) : (
|
|
169
|
+
`${data.unitName ? `${data.unitName} · ` : ""}#${data.id}`
|
|
170
|
+
);
|
|
171
|
+
const algoPrice =
|
|
172
|
+
data.price != null ? (
|
|
173
|
+
<OnChainMetric
|
|
174
|
+
label="Price"
|
|
175
|
+
valueIcon={
|
|
176
|
+
<Image
|
|
177
|
+
source={algoIcon}
|
|
178
|
+
style={{ width: 16, height: 16, borderRadius: 8 }}
|
|
179
|
+
/>
|
|
180
|
+
}
|
|
181
|
+
value={`${formatPrice(data.price)} ALGO`}
|
|
182
|
+
/>
|
|
183
|
+
) : null;
|
|
184
|
+
// ARC-62 circulating supply, with its share of the total when it is not all of it.
|
|
185
|
+
const circulating =
|
|
186
|
+
!isCollectible && !isEdition && data.circulatingSupplyRaw != null
|
|
187
|
+
? (() => {
|
|
188
|
+
const total = data.totalRaw ? BigInt(data.totalRaw) : BigInt(Math.trunc(data.total));
|
|
189
|
+
const current = BigInt(data.circulatingSupplyRaw);
|
|
190
|
+
// Basis points of a millionth, so tiny and near-total shares still read true.
|
|
191
|
+
const percent = total > BigInt(0) ? Number((current * BigInt(100_000_000)) / total) / 1_000_000 : 100;
|
|
192
|
+
return {
|
|
193
|
+
value: formatSupply(data.circulatingSupplyRaw, data.decimals),
|
|
194
|
+
share: current >= total ? null : `${formatShare(percent)} of total`,
|
|
195
|
+
};
|
|
196
|
+
})()
|
|
197
|
+
: undefined;
|
|
198
|
+
// A collectible without a price has nothing to list under its title.
|
|
199
|
+
const facts = isCollectible && !algoPrice ? null : (
|
|
200
|
+
<OnChainMetricGrid>
|
|
201
|
+
{change ? null : algoPrice}
|
|
202
|
+
{/* A single collectible needs no supply line; editions and tokens do. */}
|
|
203
|
+
{isCollectible ? null : (
|
|
204
|
+
<OnChainMetric
|
|
205
|
+
label={isEdition ? "Editions" : "Total supply"}
|
|
206
|
+
value={supply}
|
|
207
|
+
secondary={
|
|
208
|
+
!isEdition && (showDetails || circulating || change)
|
|
209
|
+
? `${data.decimals} decimal${data.decimals === 1 ? "" : "s"}`
|
|
210
|
+
: null
|
|
211
|
+
}
|
|
212
|
+
/>
|
|
213
|
+
)}
|
|
214
|
+
{circulating ? (
|
|
215
|
+
<OnChainMetric
|
|
216
|
+
label="Circulating"
|
|
217
|
+
value={circulating.value}
|
|
218
|
+
secondary={circulating.share}
|
|
219
|
+
/>
|
|
220
|
+
) : null}
|
|
221
|
+
</OnChainMetricGrid>
|
|
222
|
+
);
|
|
223
|
+
// A token's price leads, with its recent trend drawn beside it.
|
|
224
|
+
const market = change ? (
|
|
225
|
+
<View style={{ flexDirection: "row", alignItems: "flex-end", gap: 16 }}>
|
|
226
|
+
<View
|
|
227
|
+
accessible
|
|
228
|
+
accessibilityLabel={`Price ${formatUsdPrice(change.latest)}, ${change.label.replace("·", "over")}`}
|
|
229
|
+
style={{ gap: 2 }}
|
|
230
|
+
>
|
|
231
|
+
<Text size="xxs" weight="medium" style={{ color: theme.colors.textDim }}>
|
|
232
|
+
Price
|
|
233
|
+
</Text>
|
|
234
|
+
<Text size="lg" weight="semiBold" numberOfLines={1}>
|
|
235
|
+
{formatUsdPrice(change.latest)}
|
|
236
|
+
</Text>
|
|
237
|
+
<Text size="xs" weight="medium" style={{ color: changeColor }}>
|
|
238
|
+
{change.label}
|
|
239
|
+
</Text>
|
|
240
|
+
</View>
|
|
241
|
+
{/* The line runs past the card padding and off its right edge. */}
|
|
242
|
+
<View style={{ flex: 1, minWidth: 0, paddingBottom: 2, marginRight: -CARD_PADDING }}>
|
|
243
|
+
<Sparkline
|
|
244
|
+
id={String(data.id)}
|
|
245
|
+
values={history.map((point) => point.price)}
|
|
246
|
+
color={changeColor}
|
|
247
|
+
height={44}
|
|
248
|
+
/>
|
|
249
|
+
</View>
|
|
250
|
+
</View>
|
|
251
|
+
) : null;
|
|
252
|
+
const header = (
|
|
253
|
+
<OnChainActionHeader
|
|
254
|
+
title={data.name}
|
|
255
|
+
titleAccessory={
|
|
256
|
+
data.verified ? (
|
|
257
|
+
<CheckBadgeIcon size={18} color={theme.colors.primary} />
|
|
258
|
+
) : null
|
|
259
|
+
}
|
|
260
|
+
subtitle={subtitle}
|
|
261
|
+
menu={<ContractMenu appId={data.id} type="asset" />}
|
|
262
|
+
/>
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const tokenIcon = (size: number) =>
|
|
266
|
+
imageUrl ? (
|
|
267
|
+
<Image
|
|
268
|
+
source={{ uri: imageUrl }}
|
|
269
|
+
style={{
|
|
270
|
+
width: size,
|
|
271
|
+
height: size,
|
|
272
|
+
borderRadius: size / 2,
|
|
273
|
+
backgroundColor: theme.colors.background,
|
|
274
|
+
}}
|
|
275
|
+
/>
|
|
276
|
+
) : (
|
|
277
|
+
<LinearGradient
|
|
278
|
+
colors={theme.gradients.interactive}
|
|
279
|
+
locations={theme.gradients.interactiveLocations}
|
|
280
|
+
start={{ x: 0, y: 0 }}
|
|
281
|
+
end={{ x: 1, y: 1 }}
|
|
282
|
+
style={{
|
|
283
|
+
width: size,
|
|
284
|
+
height: size,
|
|
285
|
+
borderRadius: size / 2,
|
|
286
|
+
alignItems: "center",
|
|
287
|
+
justifyContent: "center",
|
|
288
|
+
}}
|
|
289
|
+
>
|
|
290
|
+
<Text
|
|
291
|
+
size="xxs"
|
|
292
|
+
weight="bold"
|
|
293
|
+
numberOfLines={1}
|
|
294
|
+
style={{ color: theme.gradients.interactiveText }}
|
|
295
|
+
>
|
|
296
|
+
{(data.unitName || data.name || "?").slice(0, 4).toUpperCase()}
|
|
297
|
+
</Text>
|
|
298
|
+
</LinearGradient>
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
// On a small card a token reads as one line: icon, name, trend and price.
|
|
302
|
+
if (dense && change) {
|
|
303
|
+
return (
|
|
304
|
+
<OnChainActionCard
|
|
305
|
+
accessibilityLabel={`${data.name}, ${formatUsdPrice(change.latest)}, ${change.label.replace("·", "over")}`}
|
|
306
|
+
>
|
|
307
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
|
|
308
|
+
{tokenIcon(40)}
|
|
309
|
+
<View style={{ flexShrink: 1, minWidth: 0, gap: 1 }}>
|
|
310
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 4 }}>
|
|
311
|
+
<Text size="sm" weight="semiBold" numberOfLines={1} style={{ flexShrink: 1 }}>
|
|
312
|
+
{data.name}
|
|
313
|
+
</Text>
|
|
314
|
+
{data.verified ? (
|
|
315
|
+
<View style={{ flexShrink: 0 }}>
|
|
316
|
+
<CheckBadgeIcon size={14} color={theme.colors.primary} />
|
|
317
|
+
</View>
|
|
318
|
+
) : null}
|
|
319
|
+
</View>
|
|
320
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 5 }}>
|
|
321
|
+
<Text size="xs" numberOfLines={1} style={{ color: theme.colors.textDim, flexShrink: 0 }}>
|
|
322
|
+
{data.unitName || `#${data.id}`}
|
|
323
|
+
</Text>
|
|
324
|
+
<Text size="xs" weight="semiBold" numberOfLines={1} style={{ flexShrink: 0 }}>
|
|
325
|
+
{formatUsdPrice(change.latest)}
|
|
326
|
+
</Text>
|
|
327
|
+
<Text size="xs" weight="medium" numberOfLines={1} style={{ color: changeColor, flexShrink: 0 }}>
|
|
328
|
+
{change.label.split(" · ")[0]}
|
|
329
|
+
</Text>
|
|
330
|
+
</View>
|
|
331
|
+
</View>
|
|
332
|
+
<View style={{ flexGrow: 1, flexShrink: 1, flexBasis: 48, minWidth: 48, maxWidth: 120 + CARD_PADDING, marginRight: -CARD_PADDING }}>
|
|
333
|
+
<Sparkline
|
|
334
|
+
id={`${data.id}-dense`}
|
|
335
|
+
values={history.map((point) => point.price)}
|
|
336
|
+
color={changeColor}
|
|
337
|
+
height={32}
|
|
338
|
+
/>
|
|
339
|
+
</View>
|
|
340
|
+
</View>
|
|
341
|
+
</OnChainActionCard>
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Collectibles lead with their art; fungible tokens lead with their icon and numbers.
|
|
346
|
+
if ((isCollectible || isEdition) && imageUrl) {
|
|
347
|
+
return (
|
|
348
|
+
<OnChainActionCard
|
|
349
|
+
accessibilityLabel={`${data.name}, ${kind.toLowerCase()}`}
|
|
350
|
+
media={
|
|
351
|
+
onSubjectPage ? undefined : (
|
|
352
|
+
<AdaptiveImage
|
|
353
|
+
uri={imageUrl}
|
|
354
|
+
assetId={data.id}
|
|
355
|
+
maxHeight={maxImageHeight}
|
|
356
|
+
borderRadiusTop={0}
|
|
357
|
+
fill
|
|
358
|
+
/>
|
|
359
|
+
)
|
|
360
|
+
}
|
|
361
|
+
>
|
|
362
|
+
{header}
|
|
363
|
+
{facts}
|
|
364
|
+
</OnChainActionCard>
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return (
|
|
369
|
+
<OnChainActionCard
|
|
370
|
+
accessibilityLabel={`${data.name}, ${kind.toLowerCase()}`}
|
|
371
|
+
>
|
|
372
|
+
<View style={{ flexDirection: "row", alignItems: "center", gap: 12 }}>
|
|
373
|
+
{tokenIcon(52)}
|
|
374
|
+
<View style={{ flex: 1, minWidth: 0 }}>{header}</View>
|
|
375
|
+
</View>
|
|
376
|
+
{market}
|
|
377
|
+
{facts}
|
|
378
|
+
</OnChainActionCard>
|
|
379
|
+
);
|
|
380
|
+
}
|