@akita-protocol/algomd-rn 1.0.0-alpha.11 → 1.0.0-alpha.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akita-protocol/algomd-rn",
3
- "version": "1.0.0-alpha.11",
3
+ "version": "1.0.0-alpha.12",
4
4
  "main": "src/index.ts",
5
5
  "types": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -79,7 +79,7 @@
79
79
  "vite": "^6.4.3"
80
80
  },
81
81
  "dependencies": {
82
- "@akita-protocol/algomd-core": "1.0.0-alpha.11"
82
+ "@akita-protocol/algomd-core": "1.0.0-alpha.12"
83
83
  },
84
84
  "exports": {
85
85
  ".": "./src/index.ts",
@@ -669,13 +669,14 @@ function mapNfdProperties(
669
669
  return result;
670
670
  }
671
671
 
672
- function nfdAvatarUrl(
672
+ function nfdImageUrl(
673
673
  value: string | undefined,
674
674
  resolveImageUrl: (src: string, width: number) => string,
675
+ width: number,
675
676
  ): string | undefined {
676
677
  if (!value || !/^(?:https?:\/\/|ipfs:\/\/|data:image\/)/i.test(value))
677
678
  return undefined;
678
- return resolveImageUrl(value, 160);
679
+ return resolveImageUrl(value, width);
679
680
  }
680
681
 
681
682
  export function useNFDProfileData(name: string | undefined) {
@@ -711,9 +712,15 @@ export function useNFDProfileData(name: string | undefined) {
711
712
  const validCreatedAt = Number.isNaN(createdAt.getTime())
712
713
  ? new Date(0)
713
714
  : createdAt;
714
- const avatar = nfdAvatarUrl(
715
+ const avatar = nfdImageUrl(
715
716
  nfdField(verifiedProperties, userDefinedProperties, "avatar"),
716
717
  resolveImageUrl,
718
+ 160,
719
+ );
720
+ const banner = nfdImageUrl(
721
+ nfdField(verifiedProperties, userDefinedProperties, "banner"),
722
+ resolveImageUrl,
723
+ 1200,
717
724
  );
718
725
  return {
719
726
  id: scalarString(nfd.appID) ?? scalarString(nfd.appId) ?? name,
@@ -721,7 +728,10 @@ export function useNFDProfileData(name: string | undefined) {
721
728
  address,
722
729
  avatar,
723
730
  bio: nfdField(verifiedProperties, userDefinedProperties, "bio"),
731
+ nickname: nfdField(verifiedProperties, userDefinedProperties, "name"),
732
+ banner,
724
733
  properties: mapNfdProperties(verifiedProperties, userDefinedProperties),
734
+ verifiedProperties: mapNfdProperties(verifiedProperties, {}),
725
735
  verified:
726
736
  canonicalConfiguredAddress != null &&
727
737
  verifiedAddresses.includes(canonicalConfiguredAddress),
@@ -1,15 +1,26 @@
1
1
  // Shared AlgoMD presentation, migrated from akita-rn. Edit this library source.
2
- import React from "react";
2
+ import React, { useEffect, useState } from "react";
3
3
  import { Image, View } from "react-native";
4
- import { CheckBadgeIcon } from "./icons";
4
+ import * as Linking from "expo-linking";
5
+ import {
6
+ DiscordLogoIcon,
7
+ GitHubLogoIcon,
8
+ NFD_ORANGE,
9
+ NfdIcon,
10
+ OutlineEnvelopeIcon,
11
+ OutlineGlobeAltIcon,
12
+ TelegramLogoIcon,
13
+ XLogoIcon,
14
+ } from "./icons";
5
15
 
6
16
  import type { NFDProfile as NFDProfileType } from "../types/algorand";
7
17
  import { Text } from "./runtime";
8
18
  import { useProfileDisplayPreferences } from "./runtime";
9
19
  import { LinearGradient } from "./runtime";
10
20
  import { useAppTheme } from "./runtime";
21
+ import { usePresentation } from "./runtime";
11
22
  import { formatNfdName } from "./runtime";
12
- import { AddressIdentityInline, avatarRadius, verifiedBadgeColor } from "./identity";
23
+ import { IdentityBadge, avatarRadius } from "./identity";
13
24
  import { CardContainer } from "./CardContainer";
14
25
  import { ContractMenu } from "./ContractMenu";
15
26
  import {
@@ -17,16 +28,152 @@ import {
17
28
  OnChainActionCard,
18
29
  OnChainActionHeader,
19
30
  } from "./OnChainActionCard";
31
+ import { SquishyPressable } from "./SquishyPressable";
20
32
 
21
33
  import { fallbackAvatar as FALLBACK_AVATAR } from "./assets";
22
- const SOCIAL_FIELDS = [
23
- { key: "twitter", label: "Twitter" },
24
- { key: "discord", label: "Discord" },
25
- { key: "github", label: "GitHub" },
26
- { key: "website", label: "Website" },
27
- { key: "domain", label: "Website" },
28
- { key: "telegram", label: "Telegram" },
29
- ] as const;
34
+
35
+ type VerifiedLinkType =
36
+ | "x"
37
+ | "discord"
38
+ | "telegram"
39
+ | "github"
40
+ | "website"
41
+ | "email";
42
+
43
+ interface VerifiedLink {
44
+ type: VerifiedLinkType;
45
+ label: string;
46
+ url: string;
47
+ faviconUrl?: string;
48
+ }
49
+
50
+ /** Tile colours, as on the profile's verified links. */
51
+ const LINK_COLORS: Record<VerifiedLinkType, string> = {
52
+ x: "#000000",
53
+ discord: "#5865F2",
54
+ telegram: "#0088CC",
55
+ github: "#171515",
56
+ website: "#0f766e",
57
+ email: "#dc2626",
58
+ };
59
+
60
+ const IMAGE_URL = /^(?:https?:\/\/|ipfs:\/\/|data:image\/)/i;
61
+
62
+ function websiteUrl(domain: string) {
63
+ return /^https?:\/\//i.test(domain) ? domain : `https://${domain}`;
64
+ }
65
+
66
+ function faviconUrl(
67
+ domain: string,
68
+ resolveImageUrl: ((src: string, width: number) => string) | undefined,
69
+ ) {
70
+ // Only through the host's image proxy, so the card itself never calls a third party.
71
+ if (!resolveImageUrl) return undefined;
72
+ try {
73
+ const { hostname } = new URL(websiteUrl(domain));
74
+ return resolveImageUrl(
75
+ `https://www.google.com/s2/favicons?domain=${encodeURIComponent(hostname)}&sz=64`,
76
+ 64,
77
+ );
78
+ } catch {
79
+ return undefined;
80
+ }
81
+ }
82
+
83
+ /** A handle on its service, or a full link as some profiles store it. */
84
+ function serviceUrl(base: string, value: string) {
85
+ return /^https?:\/\//i.test(value) ? value : `${base}${value.replace(/^@/, "")}`;
86
+ }
87
+
88
+ /** The links NF Domains has verified, in the profile's order. */
89
+ function verifiedLinks(
90
+ properties: Record<string, string>,
91
+ resolveImageUrl: ((src: string, width: number) => string) | undefined,
92
+ ): VerifiedLink[] {
93
+ const value = (...keys: string[]) =>
94
+ keys.map((key) => properties[key]?.trim()).find(Boolean);
95
+ const links: VerifiedLink[] = [];
96
+ const twitter = value("twitter", "x");
97
+ if (twitter) links.push({ type: "x", label: "X", url: serviceUrl("https://x.com/", twitter) });
98
+ const discord = value("discord");
99
+ if (discord)
100
+ links.push({ type: "discord", label: "Discord", url: serviceUrl("https://discord.gg/", discord) });
101
+ const telegram = value("telegram");
102
+ if (telegram)
103
+ links.push({ type: "telegram", label: "Telegram", url: serviceUrl("https://t.me/", telegram) });
104
+ const github = value("github");
105
+ if (github)
106
+ links.push({ type: "github", label: "GitHub", url: serviceUrl("https://github.com/", github) });
107
+ const domain = value("domain", "website");
108
+ if (domain)
109
+ links.push({
110
+ type: "website",
111
+ label: "Website",
112
+ url: websiteUrl(domain),
113
+ faviconUrl: faviconUrl(domain, resolveImageUrl),
114
+ });
115
+ const email = value("email");
116
+ if (email) links.push({ type: "email", label: "Email", url: `mailto:${email}` });
117
+ return links;
118
+ }
119
+
120
+ function VerifiedLinkIcon({ type, size }: { type: VerifiedLinkType; size: number }) {
121
+ switch (type) {
122
+ case "x":
123
+ return <XLogoIcon size={size - 1} color="#fff" />;
124
+ case "discord":
125
+ return <DiscordLogoIcon size={size} color="#fff" />;
126
+ case "telegram":
127
+ return <TelegramLogoIcon size={size} color="#fff" />;
128
+ case "github":
129
+ return <GitHubLogoIcon size={size} color="#fff" />;
130
+ case "website":
131
+ return <OutlineGlobeAltIcon size={size} color="#fff" />;
132
+ case "email":
133
+ return <OutlineEnvelopeIcon size={size} color="#fff" />;
134
+ }
135
+ }
136
+
137
+ function VerifiedLinkTile({ link }: { link: VerifiedLink }) {
138
+ const { theme } = useAppTheme();
139
+ const [showFavicon, setShowFavicon] = useState(!!link.faviconUrl);
140
+ useEffect(() => setShowFavicon(!!link.faviconUrl), [link.faviconUrl]);
141
+ const favicon = showFavicon ? link.faviconUrl : undefined;
142
+ return (
143
+ <SquishyPressable
144
+ accessibilityRole="link"
145
+ accessibilityLabel={link.label}
146
+ onPress={() => Linking.openURL(link.url)}
147
+ pressedScale={0.94}
148
+ >
149
+ <View
150
+ style={{
151
+ width: 32,
152
+ height: 32,
153
+ borderRadius: 8,
154
+ borderCurve: "continuous",
155
+ alignItems: "center",
156
+ justifyContent: "center",
157
+ overflow: "hidden",
158
+ backgroundColor: favicon ? theme.colors.background : LINK_COLORS[link.type],
159
+ borderColor: favicon ? theme.colors.border : "transparent",
160
+ borderWidth: favicon ? 1 : 0,
161
+ }}
162
+ >
163
+ {favicon ? (
164
+ <Image
165
+ source={{ uri: favicon }}
166
+ style={{ width: 18, height: 18, borderRadius: 4 }}
167
+ resizeMode="contain"
168
+ onError={() => setShowFavicon(false)}
169
+ />
170
+ ) : (
171
+ <VerifiedLinkIcon type={link.type} size={17} />
172
+ )}
173
+ </View>
174
+ </SquishyPressable>
175
+ );
176
+ }
30
177
 
31
178
  export interface NFDProfileDisplayProps {
32
179
  data: NFDProfileType;
@@ -41,7 +188,12 @@ export function NFDProfileDisplay({
41
188
  }: NFDProfileDisplayProps) {
42
189
  const { theme } = useAppTheme();
43
190
  const { showNfdSuffix } = useProfileDisplayPreferences();
191
+ const { resolveImageUrl } = usePresentation();
192
+ // The tag follows the viewer's .algo suffix setting, as on profiles.
44
193
  const displayName = formatNfdName(data.name, { showNfdSuffix });
194
+ // As on the profile header: the display name, else the NFD's name without .algo.
195
+ const profileName =
196
+ data.nickname?.trim() || data.name.trim().replace(/\.algo$/i, "");
45
197
 
46
198
  if (compact) {
47
199
  return (
@@ -63,16 +215,18 @@ export function NFDProfileDisplay({
63
215
  );
64
216
  }
65
217
 
66
- const socialLinks = SOCIAL_FIELDS.filter(
67
- ({ key }) =>
68
- data.properties?.[key] && (key !== "domain" || !data.properties?.website),
218
+ const links = verifiedLinks(
219
+ data.verifiedProperties ?? data.properties ?? {},
220
+ resolveImageUrl,
69
221
  );
70
222
 
71
- const banner = data.properties?.banner;
223
+ const legacyBanner = data.properties?.banner;
224
+ const banner =
225
+ data.banner ?? (legacyBanner && IMAGE_URL.test(legacyBanner) ? legacyBanner : undefined);
72
226
 
73
227
  return (
74
228
  <OnChainActionCard
75
- accessibilityLabel={`${displayName} NFD profile`}
229
+ accessibilityLabel={`${profileName}, @${displayName}, NFD profile`}
76
230
  testID={`nfd-card-${data.id}`}
77
231
  media={
78
232
  banner ? (
@@ -111,14 +265,20 @@ export function NFDProfileDisplay({
111
265
  <View style={{ flex: 1 }}>
112
266
  <OnChainActionHeader
113
267
  eyebrow="NFD"
114
- title={displayName}
268
+ eyebrowColor={NFD_ORANGE}
269
+ eyebrowIcon={<NfdIcon size={11} />}
270
+ title={profileName}
271
+ subtitle={`@${displayName}`}
115
272
  titleAccessory={
116
- data.verified ? (
117
- <CheckBadgeIcon
118
- size={17}
119
- color={verifiedBadgeColor(data.isCommunity)}
120
- />
121
- ) : undefined
273
+ <IdentityBadge
274
+ identity={{
275
+ name: displayName,
276
+ nfdName: data.name,
277
+ showVerifiedBadge: data.verified,
278
+ isCommunity: data.isCommunity,
279
+ }}
280
+ size={17}
281
+ />
122
282
  }
123
283
  menu={
124
284
  /^\d+$/.test(data.id) ? (
@@ -133,17 +293,6 @@ export function NFDProfileDisplay({
133
293
  </View>
134
294
  </View>
135
295
 
136
- <View style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
137
- <Text
138
- size="xxs"
139
- weight="medium"
140
- style={{ color: theme.colors.textDim }}
141
- >
142
- Resolves to
143
- </Text>
144
- <AddressIdentityInline address={data.address} />
145
- </View>
146
-
147
296
  {data.bio ? (
148
297
  <Text
149
298
  size="xs"
@@ -154,27 +303,10 @@ export function NFDProfileDisplay({
154
303
  </Text>
155
304
  ) : null}
156
305
 
157
- {socialLinks.length > 0 ? (
158
- <View style={{ flexDirection: "row", flexWrap: "wrap", gap: 6 }}>
159
- {socialLinks.map(({ key, label }) => (
160
- <View
161
- key={key}
162
- style={{
163
- backgroundColor: `${theme.colors.primary}12`,
164
- borderCurve: "continuous",
165
- borderRadius: 8,
166
- paddingHorizontal: 9,
167
- paddingVertical: 5,
168
- }}
169
- >
170
- <Text
171
- size="xxs"
172
- weight="medium"
173
- style={{ color: theme.colors.primary }}
174
- >
175
- {label}
176
- </Text>
177
- </View>
306
+ {links.length > 0 ? (
307
+ <View style={{ flexDirection: "row", flexWrap: "wrap", gap: 8 }}>
308
+ {links.map((link) => (
309
+ <VerifiedLinkTile key={link.type} link={link} />
178
310
  ))}
179
311
  </View>
180
312
  ) : null}
@@ -1283,3 +1283,125 @@ export function GuildIcon({
1283
1283
  </Svg>
1284
1284
  );
1285
1285
  }
1286
+
1287
+ /** The NFD mark, in NF Domains orange by default. Same art as akita-rn assets/icons/nfd-icon.png. */
1288
+ export const NFD_ORANGE = "#ff602d";
1289
+ export function NfdIcon({
1290
+ size = 20,
1291
+ color = NFD_ORANGE,
1292
+ }: {
1293
+ size?: number;
1294
+ color?: string;
1295
+ }) {
1296
+ return (
1297
+ <Svg width={size} height={size} viewBox="0 0 24 24" fill={color}>
1298
+ <Path d="M0 0L12 12V0H24V24H0Z" />
1299
+ </Svg>
1300
+ );
1301
+ }
1302
+
1303
+ // Verified-link marks, the same art akita-rn's profile About tab draws in its link tiles.
1304
+ export function XLogoIcon({
1305
+ size = 20,
1306
+ color,
1307
+ }: {
1308
+ size?: number;
1309
+ color?: string;
1310
+ }) {
1311
+ return (
1312
+ <Svg width={size} height={size} viewBox="0 0 24 24" fill={color}>
1313
+ <Path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" />
1314
+ </Svg>
1315
+ );
1316
+ }
1317
+ export function DiscordLogoIcon({
1318
+ size = 20,
1319
+ color,
1320
+ }: {
1321
+ size?: number;
1322
+ color?: string;
1323
+ }) {
1324
+ return (
1325
+ <Svg width={size} height={size} viewBox="0 0 24 24" fill={color}>
1326
+ <Path d="M20.317 4.369A19.791 19.791 0 0 0 15.36 2.85a13.803 13.803 0 0 0-.635 1.322 18.27 18.27 0 0 0-5.49 0A13.384 13.384 0 0 0 8.59 2.85a19.736 19.736 0 0 0-4.95 1.523C.512 9.046-.337 13.606.087 18.103a19.9 19.9 0 0 0 6.073 3.074 14.6 14.6 0 0 0 1.302-2.112 12.953 12.953 0 0 1-2.048-.979c.172-.126.34-.256.502-.391a14.249 14.249 0 0 0 12.168 0c.164.135.332.265.502.391-.65.383-1.338.712-2.052.981.376.733.813 1.439 1.304 2.11a19.868 19.868 0 0 0 6.077-3.076c.5-5.214-.855-9.733-3.598-13.732ZM8.02 15.331c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.418 2.157-2.418 1.21 0 2.176 1.095 2.157 2.418 0 1.334-.956 2.419-2.157 2.419Zm7.974 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.418 2.157-2.418 1.21 0 2.176 1.095 2.157 2.418 0 1.334-.947 2.419-2.157 2.419Z" />
1327
+ </Svg>
1328
+ );
1329
+ }
1330
+ export function TelegramLogoIcon({
1331
+ size = 20,
1332
+ color,
1333
+ }: {
1334
+ size?: number;
1335
+ color?: string;
1336
+ }) {
1337
+ return (
1338
+ <Svg width={size} height={size} viewBox="0 0 24 24" fill={color}>
1339
+ <Path d="M21.94 4.11 18.73 19.25c-.24 1.07-.87 1.33-1.76.83l-4.9-3.61-2.36 2.27c-.26.26-.48.48-.99.48l.35-4.99 9.08-8.2c.39-.35-.09-.55-.61-.2L6.32 12.9l-4.83-1.51c-1.05-.33-1.07-1.05.22-1.55L20.6 2.56c.87-.32 1.63.2 1.34 1.55Z" />
1340
+ </Svg>
1341
+ );
1342
+ }
1343
+ export function GitHubLogoIcon({
1344
+ size = 20,
1345
+ color,
1346
+ }: {
1347
+ size?: number;
1348
+ color?: string;
1349
+ }) {
1350
+ return (
1351
+ <Svg width={size} height={size} viewBox="0 0 24 24" fill={color}>
1352
+ <Path d="M12 .5C5.65.5.5 5.65.5 12c0 5.09 3.29 9.39 7.86 10.91.58.1.79-.25.79-.56v-2.15c-3.2.7-3.88-1.36-3.88-1.36-.52-1.33-1.28-1.69-1.28-1.69-1.05-.72.08-.7.08-.7 1.16.08 1.77 1.19 1.77 1.19 1.03 1.76 2.7 1.25 3.36.96.1-.75.4-1.25.73-1.54-2.55-.29-5.23-1.28-5.23-5.69 0-1.26.45-2.29 1.19-3.09-.12-.29-.52-1.46.11-3.05 0 0 .98-.31 3.18 1.18A11.06 11.06 0 0 1 12 6.02c.98 0 1.95.13 2.87.39 2.2-1.49 3.17-1.18 3.17-1.18.63 1.59.23 2.76.11 3.05.74.8 1.19 1.83 1.19 3.09 0 4.42-2.69 5.39-5.25 5.68.42.36.78 1.06.78 2.14v3.16c0 .31.21.67.8.56A11.51 11.51 0 0 0 23.5 12C23.5 5.65 18.35.5 12 .5Z" />
1353
+ </Svg>
1354
+ );
1355
+ }
1356
+ function OutlineIcon({
1357
+ size,
1358
+ color,
1359
+ d,
1360
+ }: {
1361
+ size: number;
1362
+ color?: string;
1363
+ d: string;
1364
+ }) {
1365
+ return (
1366
+ <Svg
1367
+ width={size}
1368
+ height={size}
1369
+ viewBox="0 0 24 24"
1370
+ fill="none"
1371
+ stroke={color}
1372
+ strokeWidth={1.5}
1373
+ >
1374
+ <Path {...{ strokeLinecap: "round", strokeLinejoin: "round", d }} />
1375
+ </Svg>
1376
+ );
1377
+ }
1378
+ export function OutlineGlobeAltIcon({
1379
+ size = 24,
1380
+ color,
1381
+ }: {
1382
+ size?: number;
1383
+ color?: string;
1384
+ }) {
1385
+ return (
1386
+ <OutlineIcon
1387
+ size={size}
1388
+ color={color}
1389
+ d="M12 21a9.004 9.004 0 0 0 8.716-6.747M12 21a9.004 9.004 0 0 1-8.716-6.747M12 21c2.485 0 4.5-4.03 4.5-9S14.485 3 12 3m0 18c-2.485 0-4.5-4.03-4.5-9S9.515 3 12 3m0 0a8.997 8.997 0 0 1 7.843 4.582M12 3a8.997 8.997 0 0 0-7.843 4.582m15.686 0A11.953 11.953 0 0 1 12 10.5c-2.998 0-5.74-1.1-7.843-2.918m15.686 0A8.959 8.959 0 0 1 21 12c0 .778-.099 1.533-.284 2.253m0 0A17.919 17.919 0 0 1 12 16.5c-3.162 0-6.133-.815-8.716-2.247m0 0A9.015 9.015 0 0 1 3 12c0-1.605.42-3.113 1.157-4.418"
1390
+ />
1391
+ );
1392
+ }
1393
+ export function OutlineEnvelopeIcon({
1394
+ size = 24,
1395
+ color,
1396
+ }: {
1397
+ size?: number;
1398
+ color?: string;
1399
+ }) {
1400
+ return (
1401
+ <OutlineIcon
1402
+ size={size}
1403
+ color={color}
1404
+ d="M21.75 6.75v10.5a2.25 2.25 0 0 1-2.25 2.25h-15a2.25 2.25 0 0 1-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0 0 19.5 4.5h-15a2.25 2.25 0 0 0-2.25 2.25m19.5 0v.243a2.25 2.25 0 0 1-1.07 1.916l-7.5 4.615a2.25 2.25 0 0 1-2.36 0L3.32 8.91a2.25 2.25 0 0 1-1.07-1.916V6.75"
1405
+ />
1406
+ );
1407
+ }
@@ -18,7 +18,16 @@ export interface NFDProfile {
18
18
  address: string;
19
19
  avatar?: string;
20
20
  bio?: string;
21
+ /** The profile's display name (the NFD's `name` property), e.g. "Akita". */
22
+ nickname?: string;
23
+ /** Banner image URL, ready to draw. */
24
+ banner?: string;
21
25
  properties: Record<string, string>;
26
+ /**
27
+ * The properties NF Domains has verified (twitter, discord, telegram, github,
28
+ * domain, email). The card links only these; without it, it reads `properties`.
29
+ */
30
+ verifiedProperties?: Record<string, string>;
22
31
  verified: boolean;
23
32
  /** An ARC-53 community profile, which the app draws with a square avatar and a gold check. */
24
33
  isCommunity?: boolean;