@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
@@ -1,23 +0,0 @@
1
- const baseUrl = process.env.NEXT_PUBLIC_BASEMENT_API_URL ||
2
- process.env.NEXT_PUBLIC_FEATHERS_API ||
3
- "https://basement-feathers-api-production.up.railway.app";
4
- export async function fetchBsmntProfile(username, address) {
5
- let response;
6
- const queryUsername = username?.includes(".b3.fun") ? username : `${username}.b3.fun`;
7
- try {
8
- if (username) {
9
- response = await fetch(`${baseUrl}/profiles/?username=${queryUsername}`);
10
- }
11
- else if (address) {
12
- response = await fetch(`${baseUrl}/profiles/?linkedAccounts[$elemMatch][normalizedAddress]=${String(address).toLowerCase() || ""}`);
13
- }
14
- const json = await response?.json();
15
- if (json.data.length == 0)
16
- throw new Error(`Profile not found`);
17
- return json.data[0];
18
- }
19
- catch (error) {
20
- console.error("Error fetching profile", error);
21
- throw error;
22
- }
23
- }
@@ -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,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 +0,0 @@
1
- export declare function fetchBsmntProfile(username?: string, address?: string): Promise<any>;
@@ -1,14 +0,0 @@
1
- import { fetchBsmntProfile } from "@b3dotfun/sdk/shared/utils/fetchBsmntProfile";
2
- import { useQuery } from "@tanstack/react-query";
3
-
4
- export interface UseProfileOptions {
5
- address?: string;
6
- }
7
-
8
- export const useBsmntProfile = ({ address }: UseProfileOptions) => {
9
- return useQuery({
10
- queryKey: ["useBsmntProfile", address],
11
- queryFn: () => fetchBsmntProfile(undefined, address),
12
- enabled: !!address,
13
- });
14
- };
@@ -1,198 +0,0 @@
1
- "use client";
2
-
3
- import { getB3NameByAddress, getEnsName } from "@b3dotfun/sdk/shared/utils/b3Ens";
4
- import { fetchBsmntProfile } from "@b3dotfun/sdk/shared/utils/fetchBsmntProfile";
5
- import { useQueries, useQuery } from "@tanstack/react-query";
6
-
7
- export function useOnchainName(address: string | undefined) {
8
- const { data: bsmntName, isLoading: isLoadingBsmnt } = useQuery({
9
- queryKey: ["useOnchainName/bsmntName", address?.toLowerCase()],
10
- queryFn: async () => {
11
- if (!address) return null;
12
- try {
13
- const response = await fetchBsmntProfile(undefined, address);
14
- return response?.username?.replace(/\.b3\.fun/g, "") || null;
15
- } catch (error) {
16
- return null;
17
- }
18
- },
19
- enabled: !!address,
20
- });
21
-
22
- const { data: b3Name, isLoading: isLoadingB3 } = useQuery({
23
- queryKey: ["b3-name", address?.toLowerCase()],
24
- queryFn: async () => {
25
- if (!address) return null;
26
- try {
27
- const response = await getB3NameByAddress(address);
28
- return response?.name?.replace(/\.b3\.fun/g, "") || null;
29
- } catch (error) {
30
- return null;
31
- }
32
- },
33
- enabled: !!address,
34
- });
35
-
36
- const { data: ensName, isLoading: isLoadingEns } = useQuery({
37
- queryKey: ["ens-name", address?.toLowerCase()],
38
- queryFn: async () => {
39
- if (!address) return null;
40
- try {
41
- const corsProxyUrl =
42
- "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
- } catch (error) {
47
- console.error("Error fetching ENS name:", error);
48
- return null;
49
- }
50
- },
51
- enabled: !!address,
52
- });
53
-
54
- return {
55
- name: bsmntName || b3Name || ensName || null,
56
- isLoading: isLoadingBsmnt || isLoadingB3 || isLoadingEns,
57
- b3Name,
58
- ensName,
59
- };
60
- }
61
-
62
- export function useOnchainNames(addresses: string[]) {
63
- const queries = addresses.map(address => ({
64
- queryKey: ["onchain-name", address.toLowerCase()],
65
- queryFn: async () => {
66
- try {
67
- // Try B3 name first
68
- const b3Response = await getB3NameByAddress(address);
69
- if (b3Response?.name) {
70
- return b3Response.name;
71
- }
72
-
73
- // Fall back to ENS
74
- const corsProxyUrl =
75
- "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${address}`);
76
- const ensResponse = await fetch(corsProxyUrl);
77
- const ensData = await ensResponse.json();
78
- return ensData?.ens || null;
79
- } catch (error) {
80
- console.error("Error fetching onchain name:", error);
81
- return null;
82
- }
83
- },
84
- enabled: !!address,
85
- }));
86
-
87
- const results = useQueries({ queries });
88
-
89
- return {
90
- names: results.map(result => result.data),
91
- isLoading: results.some(result => result.isLoading),
92
- };
93
- }
94
-
95
- // Add a new hook to resolve ENS/B3 names to addresses
96
- export function useResolveOnchainName(name: string | undefined) {
97
- const { data: address, isLoading } = useQuery({
98
- queryKey: ["name-resolve", name?.toLowerCase()],
99
- queryFn: async () => {
100
- if (!name) return null;
101
- try {
102
- const isB3Name = name.startsWith("@") || name.toLowerCase().endsWith(".b3");
103
-
104
- if (isB3Name) {
105
- // If contains and @, remove @ and add .b3.fun
106
- if (name.includes("@")) {
107
- name = name.replace("@", "").replace(".b3.fun", "") + ".b3.fun";
108
- }
109
-
110
- // Try B3 name resolution first
111
- try {
112
- const b3Response = await getEnsName(name);
113
- const b3Data = await b3Response.json();
114
- if (b3Data?.addresses?.["60"]) {
115
- return b3Data.addresses["60"];
116
- }
117
- } catch (error) {}
118
-
119
- // Fall back to ENS only if it's a .b3 name (not @)
120
- if (!name.startsWith("@")) {
121
- const corsProxyUrl =
122
- "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${name}`);
123
- const ensResponse = await fetch(corsProxyUrl);
124
- const ensData = await ensResponse.json();
125
- return ensData?.address || null;
126
- }
127
- return null;
128
- } else {
129
- // Try ENS resolution first
130
- const corsProxyUrl =
131
- "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${name}`);
132
- const ensResponse = await fetch(corsProxyUrl);
133
- const ensData = await ensResponse.json();
134
- if (ensData?.address) {
135
- return ensData.address;
136
- }
137
-
138
- // Fall back to B3 name resolution
139
- try {
140
- const b3Response = await getEnsName(
141
- name.replace("@", "").replace(".b3.fun", "").replace(".b3", "") + ".b3.fun",
142
- );
143
- const b3Data = await b3Response.json();
144
- return b3Data?.addresses?.["60"] || null;
145
- } catch (error) {
146
- return null;
147
- }
148
- }
149
- } catch (error) {
150
- console.error("Error resolving name:", error);
151
- return null;
152
- }
153
- },
154
- enabled: !!name,
155
- });
156
-
157
- return {
158
- address,
159
- isLoading,
160
- };
161
- }
162
-
163
- // Add a new hook to fetch ENS profile image
164
- export function useOnchainPFP(name: string | undefined) {
165
- const { address } = useResolveOnchainName(name);
166
-
167
- const { data: pfp, isLoading } = useQuery({
168
- queryKey: ["ens-pfp", name?.toLowerCase()],
169
- queryFn: async () => {
170
- if (!name) return null;
171
- try {
172
- // First try ENS avatar
173
- const corsProxyUrl = "https://proxy.basement.fun/?url=" + encodeURIComponent(`https://api.ensdata.net/${name}`);
174
- const response = await fetch(corsProxyUrl);
175
- const data = await response.json();
176
-
177
- if (data?.avatar) {
178
- // If it's an IPFS URL, convert it to a gateway URL
179
- if (data.avatar.startsWith("ipfs://")) {
180
- return data.avatar.replace("ipfs://", "https://ipfs.io/ipfs/");
181
- }
182
- return data.avatar;
183
- }
184
- return null;
185
- } catch (error) {
186
- console.error("Error fetching ENS PFP:", error);
187
- return null;
188
- }
189
- },
190
- enabled: !!name,
191
- });
192
-
193
- return {
194
- pfp,
195
- isLoading,
196
- address,
197
- };
198
- }
@@ -1,29 +0,0 @@
1
- const baseUrl =
2
- process.env.NEXT_PUBLIC_BASEMENT_API_URL ||
3
- process.env.NEXT_PUBLIC_FEATHERS_API ||
4
- "https://basement-feathers-api-production.up.railway.app";
5
-
6
- export async function fetchBsmntProfile(username?: string, address?: string) {
7
- let response: Response | undefined;
8
-
9
- const queryUsername = username?.includes(".b3.fun") ? username : `${username}.b3.fun`;
10
-
11
- try {
12
- if (username) {
13
- response = await fetch(`${baseUrl}/profiles/?username=${queryUsername}`);
14
- } else if (address) {
15
- response = await fetch(
16
- `${baseUrl}/profiles/?linkedAccounts[$elemMatch][normalizedAddress]=${String(address).toLowerCase() || ""}`,
17
- );
18
- }
19
-
20
- const json = await response?.json();
21
-
22
- if (json.data.length == 0) throw new Error(`Profile not found`);
23
-
24
- return json.data[0];
25
- } catch (error) {
26
- console.error("Error fetching profile", error);
27
- throw error;
28
- }
29
- }