@b3dotfun/sdk 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +2 -5
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +2 -2
  3. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +2 -1
  4. package/dist/cjs/global-account/react/hooks/index.d.ts +0 -2
  5. package/dist/cjs/global-account/react/hooks/index.js +1 -5
  6. package/dist/cjs/global-account/react/hooks/useAccountWallet.js +2 -3
  7. package/dist/cjs/global-account/react/hooks/useProfile.d.ts +27 -0
  8. package/dist/cjs/global-account/react/hooks/useProfile.js +65 -0
  9. package/dist/esm/anyspend/react/components/AnySpend.js +3 -6
  10. package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -3
  11. package/dist/esm/anyspend/react/components/common/OrderDetails.js +3 -2
  12. package/dist/esm/global-account/react/hooks/index.d.ts +0 -2
  13. package/dist/esm/global-account/react/hooks/index.js +0 -2
  14. package/dist/esm/global-account/react/hooks/useAccountWallet.js +3 -4
  15. package/dist/esm/global-account/react/hooks/useProfile.d.ts +27 -0
  16. package/dist/esm/global-account/react/hooks/useProfile.js +63 -0
  17. package/dist/types/global-account/react/hooks/index.d.ts +0 -2
  18. package/dist/types/global-account/react/hooks/useProfile.d.ts +27 -0
  19. package/package.json +23 -22
  20. package/src/anyspend/react/components/AnySpend.tsx +3 -7
  21. package/src/anyspend/react/components/AnySpendCustom.tsx +3 -3
  22. package/src/anyspend/react/components/common/OrderDetails.tsx +4 -2
  23. package/src/global-account/react/hooks/index.ts +0 -2
  24. package/src/global-account/react/hooks/useAccountWallet.tsx +3 -4
  25. package/src/global-account/react/hooks/useProfile.ts +102 -0
  26. package/dist/cjs/global-account/react/hooks/useBsmntProfile.d.ts +0 -4
  27. package/dist/cjs/global-account/react/hooks/useBsmntProfile.js +0 -13
  28. package/dist/cjs/global-account/react/hooks/useOnchainName.d.ts +0 -19
  29. package/dist/cjs/global-account/react/hooks/useOnchainName.js +0 -193
  30. package/dist/cjs/shared/utils/fetchBsmntProfile.d.ts +0 -1
  31. package/dist/cjs/shared/utils/fetchBsmntProfile.js +0 -26
  32. package/dist/esm/global-account/react/hooks/useBsmntProfile.d.ts +0 -4
  33. package/dist/esm/global-account/react/hooks/useBsmntProfile.js +0 -9
  34. package/dist/esm/global-account/react/hooks/useOnchainName.d.ts +0 -19
  35. package/dist/esm/global-account/react/hooks/useOnchainName.js +0 -187
  36. package/dist/esm/shared/utils/fetchBsmntProfile.d.ts +0 -1
  37. package/dist/esm/shared/utils/fetchBsmntProfile.js +0 -23
  38. package/dist/types/global-account/react/hooks/useBsmntProfile.d.ts +0 -4
  39. package/dist/types/global-account/react/hooks/useOnchainName.d.ts +0 -19
  40. package/dist/types/shared/utils/fetchBsmntProfile.d.ts +0 -1
  41. package/src/global-account/react/hooks/useBsmntProfile.ts +0 -14
  42. package/src/global-account/react/hooks/useOnchainName.tsx +0 -198
  43. package/src/shared/utils/fetchBsmntProfile.ts +0 -29
@@ -25,7 +25,7 @@ import {
25
25
  useAccountWallet,
26
26
  useChainSwitchWithAction,
27
27
  useModalStore,
28
- useOnchainName,
28
+ useProfile,
29
29
  } from "@b3dotfun/sdk/global-account/react";
30
30
  import { useRouter, useSearchParams } from "@b3dotfun/sdk/shared/react/hooks";
31
31
  import { cn } from "@b3dotfun/sdk/shared/utils";
@@ -218,7 +218,9 @@ export const OrderDetails = memo(function OrderDetails({
218
218
  const tournament =
219
219
  order.type === "join_tournament" || order.type === "fund_tournament" ? order.metadata.tournament : undefined;
220
220
 
221
- const { name: recipientName } = useOnchainName(order.recipientAddress);
221
+ const profile = useProfile({ address: order.recipientAddress });
222
+ const recipientName = profile.data?.name?.replace(/\.b3\.fun/g, "");
223
+
222
224
  const account = useAccountWallet();
223
225
 
224
226
  const { data: walletClient } = useWalletClient();
@@ -5,7 +5,6 @@ export { useAuthentication } from "./useAuthentication";
5
5
  export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses";
6
6
  export { useB3EnsName } from "./useB3EnsName";
7
7
  export { useBestTransactionPath } from "./useBestTransactionPath";
8
- export { useBsmntProfile } from "./useBsmntProfile";
9
8
  export { useChainSwitchWithAction } from "./useChainSwitchWithAction";
10
9
  export { useClaim } from "./useClaim";
11
10
  export { useConnect } from "./useConnect";
@@ -18,7 +17,6 @@ export { useIsMobile } from "./useIsMobile";
18
17
  export { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect";
19
18
  export { useMediaQuery } from "./useMediaQuery";
20
19
  export { useNativeBalance, useNativeBalanceFromRPC } from "./useNativeBalance";
21
- export { useOnchainName } from "./useOnchainName";
22
20
  export { useOneBalance } from "./useOneBalance";
23
21
  export {
24
22
  useProfile,
@@ -1,10 +1,9 @@
1
- import { useB3 } from "@b3dotfun/sdk/global-account/react";
1
+ import { useB3, useProfile } from "@b3dotfun/sdk/global-account/react";
2
2
  import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
3
3
  import { useEffect, useMemo, useState } from "react";
4
4
  import { getLastAuthProvider, useActiveWallet, useConnectedWallets, useWalletImage } from "thirdweb/react";
5
5
  import { Account, Wallet } from "thirdweb/wallets";
6
6
  import { socialIcons } from "thirdweb/wallets/in-app";
7
- import { useBsmntProfile } from "./useBsmntProfile";
8
7
 
9
8
  function useLastAuthProvider(): string | null {
10
9
  const [lastAuthProvider, setLastAuthProvider] = useState<string | null>(null);
@@ -62,8 +61,8 @@ export function useAccountWallet(): {
62
61
  ? socialIcons[lastAuthProvider as keyof typeof socialIcons]
63
62
  : "https://gradvatar.com/0x0000000000000000000000000000000000000000"; // show smart wallet of eoa wallet is gradvatar
64
63
 
65
- const { data: profileData } = useBsmntProfile({ address: account?.address });
66
- const ensName = profileData?.username?.replace(/\.b3\.fun/g, "");
64
+ const { data: profileData } = useProfile({ address: account?.address });
65
+ const ensName = profileData?.displayName?.replace(/\.b3\.fun/g, "");
67
66
  const avatarUrl = profileData?.avatar;
68
67
 
69
68
  const res = useMemo(
@@ -28,6 +28,15 @@ export interface PreferenceRequestBody {
28
28
  timestamp: number;
29
29
  }
30
30
 
31
+ // TypeScript interface for display name request body
32
+ export interface DisplayNameRequestBody {
33
+ key: string;
34
+ displayName: string;
35
+ signature: string;
36
+ signer: string;
37
+ timestamp: number;
38
+ }
39
+
31
40
  const PROFILES_API_URL = "https://profiles.b3.fun";
32
41
 
33
42
  async function fetchProfile({
@@ -85,6 +94,34 @@ async function setProfilePreference({
85
94
  return response.json();
86
95
  }
87
96
 
97
+ async function setDisplayName({
98
+ key,
99
+ displayName,
100
+ signature,
101
+ signer,
102
+ timestamp,
103
+ }: DisplayNameRequestBody): Promise<{ success: boolean }> {
104
+ const response = await fetch(`${PROFILES_API_URL}/display-name`, {
105
+ method: "POST",
106
+ headers: {
107
+ "Content-Type": "application/json",
108
+ },
109
+ body: JSON.stringify({
110
+ key,
111
+ displayName,
112
+ signature,
113
+ signer,
114
+ timestamp,
115
+ }),
116
+ });
117
+
118
+ if (!response.ok) {
119
+ throw new Error(`Failed to set display name: ${response.statusText}`);
120
+ }
121
+
122
+ return response.json();
123
+ }
124
+
88
125
  export function useProfile(
89
126
  {
90
127
  address,
@@ -138,4 +175,69 @@ export function useProfilePreference() {
138
175
  return { setPreference };
139
176
  }
140
177
 
178
+ export function useDisplayName() {
179
+ const setName = async (
180
+ key: string,
181
+ displayName: string,
182
+ signerAddress: string,
183
+ signMessage: (message: string) => Promise<string>,
184
+ ) => {
185
+ const timestamp = Math.floor(Date.now() / 1000);
186
+ const message = `SetDisplayName:${key}:${displayName}:${timestamp}`;
187
+
188
+ try {
189
+ const signature = await signMessage(message);
190
+
191
+ return setDisplayName({
192
+ key,
193
+ displayName,
194
+ signature,
195
+ signer: signerAddress,
196
+ timestamp,
197
+ });
198
+ } catch (error) {
199
+ throw new Error(`Failed to set display name: ${error}`);
200
+ }
201
+ };
202
+
203
+ return { setName };
204
+ }
205
+
206
+ export function useProfileSettings() {
207
+ const { setPreference } = useProfilePreference();
208
+ const { setName } = useDisplayName();
209
+
210
+ const updateSettings = async (
211
+ key: string,
212
+ signerAddress: string,
213
+ signMessage: (message: string) => Promise<string>,
214
+ settings: {
215
+ preferredType?: string;
216
+ displayName?: string;
217
+ },
218
+ ) => {
219
+ const results: { preference?: any; displayName?: any } = {};
220
+
221
+ try {
222
+ if (settings.preferredType) {
223
+ results.preference = await setPreference(key, settings.preferredType, signerAddress, signMessage);
224
+ }
225
+
226
+ if (settings.displayName) {
227
+ results.displayName = await setName(key, settings.displayName, signerAddress, signMessage);
228
+ }
229
+
230
+ return results;
231
+ } catch (error) {
232
+ throw new Error(`Failed to update profile settings: ${error}`);
233
+ }
234
+ };
235
+
236
+ return {
237
+ setPreference,
238
+ setDisplayName: setName,
239
+ updateSettings,
240
+ };
241
+ }
242
+
141
243
  export default useProfile;
@@ -1,4 +0,0 @@
1
- export interface UseProfileOptions {
2
- address?: string;
3
- }
4
- export declare const useBsmntProfile: ({ address }: UseProfileOptions) => import("@tanstack/react-query").UseQueryResult<any, Error>;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useBsmntProfile = void 0;
4
- const fetchBsmntProfile_1 = require("../../../shared/utils/fetchBsmntProfile");
5
- const react_query_1 = require("@tanstack/react-query");
6
- const useBsmntProfile = ({ address }) => {
7
- return (0, react_query_1.useQuery)({
8
- queryKey: ["useBsmntProfile", address],
9
- queryFn: () => (0, fetchBsmntProfile_1.fetchBsmntProfile)(undefined, address),
10
- enabled: !!address,
11
- });
12
- };
13
- exports.useBsmntProfile = useBsmntProfile;
@@ -1,19 +0,0 @@
1
- export declare function useOnchainName(address: string | undefined): {
2
- name: any;
3
- isLoading: boolean;
4
- b3Name: string | null | undefined;
5
- ensName: any;
6
- };
7
- export declare function useOnchainNames(addresses: string[]): {
8
- names: any[];
9
- isLoading: boolean;
10
- };
11
- export declare function useResolveOnchainName(name: string | undefined): {
12
- address: any;
13
- isLoading: boolean;
14
- };
15
- export declare function useOnchainPFP(name: string | undefined): {
16
- pfp: any;
17
- isLoading: boolean;
18
- address: any;
19
- };
@@ -1,193 +0,0 @@
1
- "use strict";
2
- "use client";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.useOnchainName = useOnchainName;
5
- exports.useOnchainNames = useOnchainNames;
6
- exports.useResolveOnchainName = useResolveOnchainName;
7
- exports.useOnchainPFP = useOnchainPFP;
8
- const b3Ens_1 = require("../../../shared/utils/b3Ens");
9
- const fetchBsmntProfile_1 = require("../../../shared/utils/fetchBsmntProfile");
10
- const react_query_1 = require("@tanstack/react-query");
11
- function useOnchainName(address) {
12
- const { data: bsmntName, isLoading: isLoadingBsmnt } = (0, react_query_1.useQuery)({
13
- queryKey: ["useOnchainName/bsmntName", address?.toLowerCase()],
14
- queryFn: async () => {
15
- if (!address)
16
- return null;
17
- try {
18
- const response = await (0, fetchBsmntProfile_1.fetchBsmntProfile)(undefined, address);
19
- return response?.username?.replace(/\.b3\.fun/g, "") || null;
20
- }
21
- catch (error) {
22
- return null;
23
- }
24
- },
25
- enabled: !!address,
26
- });
27
- const { data: b3Name, isLoading: isLoadingB3 } = (0, react_query_1.useQuery)({
28
- queryKey: ["b3-name", address?.toLowerCase()],
29
- queryFn: async () => {
30
- if (!address)
31
- return null;
32
- try {
33
- const response = await (0, b3Ens_1.getB3NameByAddress)(address);
34
- return response?.name?.replace(/\.b3\.fun/g, "") || null;
35
- }
36
- catch (error) {
37
- return null;
38
- }
39
- },
40
- enabled: !!address,
41
- });
42
- const { data: ensName, isLoading: isLoadingEns } = (0, react_query_1.useQuery)({
43
- queryKey: ["ens-name", address?.toLowerCase()],
44
- queryFn: async () => {
45
- if (!address)
46
- return null;
47
- try {
48
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${address}`);
49
- const response = await fetch(corsProxyUrl);
50
- const data = await response.json();
51
- return data?.ens || null;
52
- }
53
- catch (error) {
54
- console.error("Error fetching ENS name:", error);
55
- return null;
56
- }
57
- },
58
- enabled: !!address,
59
- });
60
- return {
61
- name: bsmntName || b3Name || ensName || null,
62
- isLoading: isLoadingBsmnt || isLoadingB3 || isLoadingEns,
63
- b3Name,
64
- ensName,
65
- };
66
- }
67
- function useOnchainNames(addresses) {
68
- const queries = addresses.map(address => ({
69
- queryKey: ["onchain-name", address.toLowerCase()],
70
- queryFn: async () => {
71
- try {
72
- // Try B3 name first
73
- const b3Response = await (0, b3Ens_1.getB3NameByAddress)(address);
74
- if (b3Response?.name) {
75
- return b3Response.name;
76
- }
77
- // Fall back to ENS
78
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${address}`);
79
- const ensResponse = await fetch(corsProxyUrl);
80
- const ensData = await ensResponse.json();
81
- return ensData?.ens || null;
82
- }
83
- catch (error) {
84
- console.error("Error fetching onchain name:", error);
85
- return null;
86
- }
87
- },
88
- enabled: !!address,
89
- }));
90
- const results = (0, react_query_1.useQueries)({ queries });
91
- return {
92
- names: results.map(result => result.data),
93
- isLoading: results.some(result => result.isLoading),
94
- };
95
- }
96
- // Add a new hook to resolve ENS/B3 names to addresses
97
- function useResolveOnchainName(name) {
98
- const { data: address, isLoading } = (0, react_query_1.useQuery)({
99
- queryKey: ["name-resolve", name?.toLowerCase()],
100
- queryFn: async () => {
101
- if (!name)
102
- return null;
103
- try {
104
- const isB3Name = name.startsWith("@") || name.toLowerCase().endsWith(".b3");
105
- if (isB3Name) {
106
- // If contains and @, remove @ and add .b3.fun
107
- if (name.includes("@")) {
108
- name = name.replace("@", "").replace(".b3.fun", "") + ".b3.fun";
109
- }
110
- // Try B3 name resolution first
111
- try {
112
- const b3Response = await (0, b3Ens_1.getEnsName)(name);
113
- const b3Data = await b3Response.json();
114
- if (b3Data?.addresses?.["60"]) {
115
- return b3Data.addresses["60"];
116
- }
117
- }
118
- catch (error) { }
119
- // Fall back to ENS only if it's a .b3 name (not @)
120
- if (!name.startsWith("@")) {
121
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${name}`);
122
- const ensResponse = await fetch(corsProxyUrl);
123
- const ensData = await ensResponse.json();
124
- return ensData?.address || null;
125
- }
126
- return null;
127
- }
128
- else {
129
- // Try ENS resolution first
130
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${name}`);
131
- const ensResponse = await fetch(corsProxyUrl);
132
- const ensData = await ensResponse.json();
133
- if (ensData?.address) {
134
- return ensData.address;
135
- }
136
- // Fall back to B3 name resolution
137
- try {
138
- const b3Response = await (0, b3Ens_1.getEnsName)(name.replace("@", "").replace(".b3.fun", "").replace(".b3", "") + ".b3.fun");
139
- const b3Data = await b3Response.json();
140
- return b3Data?.addresses?.["60"] || null;
141
- }
142
- catch (error) {
143
- return null;
144
- }
145
- }
146
- }
147
- catch (error) {
148
- console.error("Error resolving name:", error);
149
- return null;
150
- }
151
- },
152
- enabled: !!name,
153
- });
154
- return {
155
- address,
156
- isLoading,
157
- };
158
- }
159
- // Add a new hook to fetch ENS profile image
160
- function useOnchainPFP(name) {
161
- const { address } = useResolveOnchainName(name);
162
- const { data: pfp, isLoading } = (0, react_query_1.useQuery)({
163
- queryKey: ["ens-pfp", name?.toLowerCase()],
164
- queryFn: async () => {
165
- if (!name)
166
- return null;
167
- try {
168
- // First try ENS avatar
169
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${name}`);
170
- const response = await fetch(corsProxyUrl);
171
- const data = await response.json();
172
- if (data?.avatar) {
173
- // If it's an IPFS URL, convert it to a gateway URL
174
- if (data.avatar.startsWith("ipfs://")) {
175
- return data.avatar.replace("ipfs://", "https://ipfs.io/ipfs/");
176
- }
177
- return data.avatar;
178
- }
179
- return null;
180
- }
181
- catch (error) {
182
- console.error("Error fetching ENS PFP:", error);
183
- return null;
184
- }
185
- },
186
- enabled: !!name,
187
- });
188
- return {
189
- pfp,
190
- isLoading,
191
- address,
192
- };
193
- }
@@ -1 +0,0 @@
1
- export declare function fetchBsmntProfile(username?: string, address?: string): Promise<any>;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchBsmntProfile = fetchBsmntProfile;
4
- const baseUrl = process.env.NEXT_PUBLIC_BASEMENT_API_URL ||
5
- process.env.NEXT_PUBLIC_FEATHERS_API ||
6
- "https://basement-feathers-api-production.up.railway.app";
7
- async function fetchBsmntProfile(username, address) {
8
- let response;
9
- const queryUsername = username?.includes(".b3.fun") ? username : `${username}.b3.fun`;
10
- try {
11
- if (username) {
12
- response = await fetch(`${baseUrl}/profiles/?username=${queryUsername}`);
13
- }
14
- else if (address) {
15
- response = await fetch(`${baseUrl}/profiles/?linkedAccounts[$elemMatch][normalizedAddress]=${String(address).toLowerCase() || ""}`);
16
- }
17
- const json = await response?.json();
18
- if (json.data.length == 0)
19
- throw new Error(`Profile not found`);
20
- return json.data[0];
21
- }
22
- catch (error) {
23
- console.error("Error fetching profile", error);
24
- throw error;
25
- }
26
- }
@@ -1,4 +0,0 @@
1
- export interface UseProfileOptions {
2
- address?: string;
3
- }
4
- export declare const useBsmntProfile: ({ address }: UseProfileOptions) => import("@tanstack/react-query").UseQueryResult<any, Error>;
@@ -1,9 +0,0 @@
1
- import { fetchBsmntProfile } from "../../../shared/utils/fetchBsmntProfile.js";
2
- import { useQuery } from "@tanstack/react-query";
3
- export const useBsmntProfile = ({ address }) => {
4
- return useQuery({
5
- queryKey: ["useBsmntProfile", address],
6
- queryFn: () => fetchBsmntProfile(undefined, address),
7
- enabled: !!address,
8
- });
9
- };
@@ -1,19 +0,0 @@
1
- export declare function useOnchainName(address: string | undefined): {
2
- name: any;
3
- isLoading: boolean;
4
- b3Name: string | null | undefined;
5
- ensName: any;
6
- };
7
- export declare function useOnchainNames(addresses: string[]): {
8
- names: any[];
9
- isLoading: boolean;
10
- };
11
- export declare function useResolveOnchainName(name: string | undefined): {
12
- address: any;
13
- isLoading: boolean;
14
- };
15
- export declare function useOnchainPFP(name: string | undefined): {
16
- pfp: any;
17
- isLoading: boolean;
18
- address: any;
19
- };
@@ -1,187 +0,0 @@
1
- "use client";
2
- import { getB3NameByAddress, getEnsName } from "../../../shared/utils/b3Ens.js";
3
- import { fetchBsmntProfile } from "../../../shared/utils/fetchBsmntProfile.js";
4
- import { useQueries, useQuery } from "@tanstack/react-query";
5
- export function useOnchainName(address) {
6
- const { data: bsmntName, isLoading: isLoadingBsmnt } = useQuery({
7
- queryKey: ["useOnchainName/bsmntName", address?.toLowerCase()],
8
- queryFn: async () => {
9
- if (!address)
10
- return null;
11
- try {
12
- const response = await fetchBsmntProfile(undefined, address);
13
- return response?.username?.replace(/\.b3\.fun/g, "") || null;
14
- }
15
- catch (error) {
16
- return null;
17
- }
18
- },
19
- enabled: !!address,
20
- });
21
- const { data: b3Name, isLoading: isLoadingB3 } = useQuery({
22
- queryKey: ["b3-name", address?.toLowerCase()],
23
- queryFn: async () => {
24
- if (!address)
25
- return null;
26
- try {
27
- const response = await getB3NameByAddress(address);
28
- return response?.name?.replace(/\.b3\.fun/g, "") || null;
29
- }
30
- catch (error) {
31
- return null;
32
- }
33
- },
34
- enabled: !!address,
35
- });
36
- const { data: ensName, isLoading: isLoadingEns } = useQuery({
37
- queryKey: ["ens-name", address?.toLowerCase()],
38
- queryFn: async () => {
39
- if (!address)
40
- return null;
41
- try {
42
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${address}`);
43
- const response = await fetch(corsProxyUrl);
44
- const data = await response.json();
45
- return data?.ens || null;
46
- }
47
- catch (error) {
48
- console.error("Error fetching ENS name:", error);
49
- return null;
50
- }
51
- },
52
- enabled: !!address,
53
- });
54
- return {
55
- name: bsmntName || b3Name || ensName || null,
56
- isLoading: isLoadingBsmnt || isLoadingB3 || isLoadingEns,
57
- b3Name,
58
- ensName,
59
- };
60
- }
61
- export function useOnchainNames(addresses) {
62
- const queries = addresses.map(address => ({
63
- queryKey: ["onchain-name", address.toLowerCase()],
64
- queryFn: async () => {
65
- try {
66
- // Try B3 name first
67
- const b3Response = await getB3NameByAddress(address);
68
- if (b3Response?.name) {
69
- return b3Response.name;
70
- }
71
- // Fall back to ENS
72
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${address}`);
73
- const ensResponse = await fetch(corsProxyUrl);
74
- const ensData = await ensResponse.json();
75
- return ensData?.ens || null;
76
- }
77
- catch (error) {
78
- console.error("Error fetching onchain name:", error);
79
- return null;
80
- }
81
- },
82
- enabled: !!address,
83
- }));
84
- const results = useQueries({ queries });
85
- return {
86
- names: results.map(result => result.data),
87
- isLoading: results.some(result => result.isLoading),
88
- };
89
- }
90
- // Add a new hook to resolve ENS/B3 names to addresses
91
- export function useResolveOnchainName(name) {
92
- const { data: address, isLoading } = useQuery({
93
- queryKey: ["name-resolve", name?.toLowerCase()],
94
- queryFn: async () => {
95
- if (!name)
96
- return null;
97
- try {
98
- const isB3Name = name.startsWith("@") || name.toLowerCase().endsWith(".b3");
99
- if (isB3Name) {
100
- // If contains and @, remove @ and add .b3.fun
101
- if (name.includes("@")) {
102
- name = name.replace("@", "").replace(".b3.fun", "") + ".b3.fun";
103
- }
104
- // Try B3 name resolution first
105
- try {
106
- const b3Response = await getEnsName(name);
107
- const b3Data = await b3Response.json();
108
- if (b3Data?.addresses?.["60"]) {
109
- return b3Data.addresses["60"];
110
- }
111
- }
112
- catch (error) { }
113
- // Fall back to ENS only if it's a .b3 name (not @)
114
- if (!name.startsWith("@")) {
115
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${name}`);
116
- const ensResponse = await fetch(corsProxyUrl);
117
- const ensData = await ensResponse.json();
118
- return ensData?.address || null;
119
- }
120
- return null;
121
- }
122
- else {
123
- // Try ENS resolution first
124
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${name}`);
125
- const ensResponse = await fetch(corsProxyUrl);
126
- const ensData = await ensResponse.json();
127
- if (ensData?.address) {
128
- return ensData.address;
129
- }
130
- // Fall back to B3 name resolution
131
- try {
132
- const b3Response = await getEnsName(name.replace("@", "").replace(".b3.fun", "").replace(".b3", "") + ".b3.fun");
133
- const b3Data = await b3Response.json();
134
- return b3Data?.addresses?.["60"] || null;
135
- }
136
- catch (error) {
137
- return null;
138
- }
139
- }
140
- }
141
- catch (error) {
142
- console.error("Error resolving name:", error);
143
- return null;
144
- }
145
- },
146
- enabled: !!name,
147
- });
148
- return {
149
- address,
150
- isLoading,
151
- };
152
- }
153
- // Add a new hook to fetch ENS profile image
154
- export function useOnchainPFP(name) {
155
- const { address } = useResolveOnchainName(name);
156
- const { data: pfp, isLoading } = useQuery({
157
- queryKey: ["ens-pfp", name?.toLowerCase()],
158
- queryFn: async () => {
159
- if (!name)
160
- return null;
161
- try {
162
- // First try ENS avatar
163
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${name}`);
164
- const response = await fetch(corsProxyUrl);
165
- const data = await response.json();
166
- if (data?.avatar) {
167
- // If it's an IPFS URL, convert it to a gateway URL
168
- if (data.avatar.startsWith("ipfs://")) {
169
- return data.avatar.replace("ipfs://", "https://ipfs.io/ipfs/");
170
- }
171
- return data.avatar;
172
- }
173
- return null;
174
- }
175
- catch (error) {
176
- console.error("Error fetching ENS PFP:", error);
177
- return null;
178
- }
179
- },
180
- enabled: !!name,
181
- });
182
- return {
183
- pfp,
184
- isLoading,
185
- address,
186
- };
187
- }
@@ -1 +0,0 @@
1
- export declare function fetchBsmntProfile(username?: string, address?: string): Promise<any>;