@b3dotfun/sdk 0.1.0-alpha.3 → 0.1.0-alpha.5

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 (34) hide show
  1. package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +1 -2
  2. package/dist/cjs/global-account/react/components/AccountAssets/AccountAssets.js +7 -3
  3. package/dist/cjs/global-account/react/components/ManageAccount/NFTContent.js +2 -2
  4. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +12 -1
  5. package/dist/cjs/global-account/react/hooks/index.d.ts +1 -0
  6. package/dist/cjs/global-account/react/hooks/index.js +4 -2
  7. package/dist/cjs/global-account/react/hooks/useSimBalance.js +10 -15
  8. package/dist/cjs/global-account/react/hooks/useSimCollectibles.d.ts +45 -0
  9. package/dist/cjs/global-account/react/hooks/useSimCollectibles.js +190 -0
  10. package/dist/cjs/global-account/react/utils/simdune.d.ts +7 -0
  11. package/dist/cjs/global-account/react/utils/simdune.js +21 -0
  12. package/dist/esm/anyspend/react/providers/AnyspendProvider.js +1 -2
  13. package/dist/esm/global-account/react/components/AccountAssets/AccountAssets.js +7 -3
  14. package/dist/esm/global-account/react/components/ManageAccount/NFTContent.js +3 -3
  15. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -2
  16. package/dist/esm/global-account/react/hooks/index.d.ts +1 -0
  17. package/dist/esm/global-account/react/hooks/index.js +1 -0
  18. package/dist/esm/global-account/react/hooks/useSimBalance.js +10 -15
  19. package/dist/esm/global-account/react/hooks/useSimCollectibles.d.ts +45 -0
  20. package/dist/esm/global-account/react/hooks/useSimCollectibles.js +187 -0
  21. package/dist/esm/global-account/react/utils/simdune.d.ts +7 -0
  22. package/dist/esm/global-account/react/utils/simdune.js +17 -0
  23. package/dist/types/global-account/react/hooks/index.d.ts +1 -0
  24. package/dist/types/global-account/react/hooks/useSimCollectibles.d.ts +45 -0
  25. package/dist/types/global-account/react/utils/simdune.d.ts +7 -0
  26. package/package.json +1 -1
  27. package/src/anyspend/react/providers/AnyspendProvider.tsx +2 -5
  28. package/src/global-account/react/components/AccountAssets/AccountAssets.tsx +25 -13
  29. package/src/global-account/react/components/ManageAccount/NFTContent.tsx +4 -4
  30. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +13 -2
  31. package/src/global-account/react/hooks/index.ts +1 -0
  32. package/src/global-account/react/hooks/useSimBalance.ts +10 -16
  33. package/src/global-account/react/hooks/useSimCollectibles.ts +238 -0
  34. package/src/global-account/react/utils/simdune.ts +20 -0
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.AnyspendProvider = void 0;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
- const react_1 = require("../../../global-account/react");
7
6
  const FeatureFlagsContext_1 = require("../contexts/FeatureFlagsContext");
8
7
  const StripeRedirectHandler_1 = require("./StripeRedirectHandler");
9
8
  /**
@@ -30,6 +29,6 @@ const StripeRedirectHandler_1 = require("./StripeRedirectHandler");
30
29
  * ```
31
30
  */
32
31
  const AnyspendProvider = function AnyspendProvider({ children, featureFlags }) {
33
- return ((0, jsx_runtime_1.jsx)(FeatureFlagsContext_1.FeatureFlagsProvider, { featureFlags: featureFlags, children: (0, jsx_runtime_1.jsxs)(react_1.TooltipProvider, { children: [(0, jsx_runtime_1.jsx)(StripeRedirectHandler_1.StripeRedirectHandler, {}), children] }) }));
32
+ return ((0, jsx_runtime_1.jsxs)(FeatureFlagsContext_1.FeatureFlagsProvider, { featureFlags: featureFlags, children: [(0, jsx_runtime_1.jsx)(StripeRedirectHandler_1.StripeRedirectHandler, {}), children] }));
34
33
  };
35
34
  exports.AnyspendProvider = AnyspendProvider;
@@ -21,6 +21,10 @@ function AccountAssets({ nfts, isLoading }) {
21
21
  }, {});
22
22
  const collections = Object.values(groupedNFTs || {});
23
23
  const [expandedCollections, setExpandedCollections] = (0, react_1.useState)(() => new Set(collections.map(c => c.collection_id)));
24
+ const [failedImages, setFailedImages] = (0, react_1.useState)(() => new Set());
25
+ const handleImageError = (imageId) => {
26
+ setFailedImages(prev => new Set(prev).add(imageId));
27
+ };
24
28
  if (isLoading) {
25
29
  return ((0, jsx_runtime_1.jsx)("div", { className: "flex flex-col gap-3", children: [...Array(2)].map((_, i) => ((0, jsx_runtime_1.jsxs)("div", { className: "animate-pulse", children: [(0, jsx_runtime_1.jsx)("div", { className: "bg-b3-react-muted mb-3 h-6 w-48 rounded" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex gap-3", children: [(0, jsx_runtime_1.jsx)("div", { className: "bg-b3-react-muted h-[98px] w-[98px] shrink-0 rounded-lg" }), (0, jsx_runtime_1.jsx)("div", { className: "bg-b3-react-muted h-[98px] w-[98px] shrink-0 rounded-lg" })] })] }, i))) }));
26
30
  }
@@ -39,11 +43,11 @@ function AccountAssets({ nfts, isLoading }) {
39
43
  return next;
40
44
  });
41
45
  };
42
- return ((0, jsx_runtime_1.jsx)("div", { className: "flex flex-col gap-3 px-4", children: collections.map(collection => {
46
+ return ((0, jsx_runtime_1.jsx)("div", { className: "flex flex-col gap-3", children: collections.map(collection => {
43
47
  const isExpanded = expandedCollections.has(collection.collection_id);
44
- return ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-3", children: [(0, jsx_runtime_1.jsxs)("button", { onClick: () => toggleCollection(collection.collection_id), className: "flex w-full items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-1", children: [collection.collection_image && ((0, jsx_runtime_1.jsx)("img", { src: collection.collection_image, alt: collection.collection_name, className: "h-5 w-5 shrink-0 rounded object-cover" })), (0, jsx_runtime_1.jsxs)("p", { className: "font-neue-montreal-medium text-[14px] text-[#3f3f46]", children: [collection.collection_name, " (", collection.nfts.length, ")"] })] }), (0, jsx_runtime_1.jsx)("svg", { className: `h-[18px] w-[18px] shrink-0 transition-transform ${isExpanded ? "rotate-180" : ""}`, viewBox: "0 0 18 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("path", { d: "M4.5 6.75L9 11.25L13.5 6.75", stroke: "#51525C", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), isExpanded && ((0, jsx_runtime_1.jsx)("div", { className: "flex gap-3 overflow-x-auto", children: collection.nfts.map(nft => ((0, jsx_runtime_1.jsx)("div", { className: "relative h-[98px] w-[98px] shrink-0 overflow-hidden rounded-lg", children: (0, jsx_runtime_1.jsx)("img", { src: nft.previews?.image_medium_url ||
48
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col gap-3", children: [(0, jsx_runtime_1.jsxs)("button", { onClick: () => toggleCollection(collection.collection_id), className: "flex w-full items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-1", children: [collection.collection_image && !failedImages.has(`collection-${collection.collection_id}`) && ((0, jsx_runtime_1.jsx)("img", { src: collection.collection_image, alt: collection.collection_name, className: "h-5 w-5 shrink-0 rounded object-cover", onError: () => handleImageError(`collection-${collection.collection_id}`) })), (0, jsx_runtime_1.jsxs)("p", { className: "font-neue-montreal-medium text-[14px] text-[#3f3f46]", children: [collection.collection_name, " (", collection.nfts.length, ")"] })] }), (0, jsx_runtime_1.jsx)("svg", { className: `h-[18px] w-[18px] shrink-0 transition-transform ${isExpanded ? "rotate-180" : ""}`, viewBox: "0 0 18 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("path", { d: "M4.5 6.75L9 11.25L13.5 6.75", stroke: "#51525C", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), isExpanded && ((0, jsx_runtime_1.jsx)("div", { className: "flex gap-3 overflow-x-auto", children: collection.nfts.map(nft => ((0, jsx_runtime_1.jsx)("div", { className: "bg-b3-react-muted relative h-[98px] w-[98px] shrink-0 overflow-hidden rounded-lg", children: !failedImages.has(nft.nft_id) && ((0, jsx_runtime_1.jsx)("img", { src: nft.previews?.image_medium_url ||
45
49
  nft.extra_metadata?.image_original_url ||
46
50
  nft.collection?.image_url ||
47
- "", alt: nft.name || "NFT", className: "h-full w-full object-cover" }) }, nft.nft_id))) }))] }, collection.collection_id));
51
+ "", alt: nft.name || "NFT", className: "h-full w-full object-cover", onError: () => handleImageError(nft.nft_id) })) }, nft.nft_id))) }))] }, collection.collection_id));
48
52
  }) }));
49
53
  }
@@ -9,7 +9,7 @@ const NFTContent = () => {
9
9
  const activeWallet = (0, react_1.useActiveWallet)();
10
10
  const activeAccount = activeWallet?.getAccount();
11
11
  const activeAddress = activeAccount?.address;
12
- const { data: nfts, isLoading } = (0, hooks_1.useAccountAssets)(activeAddress);
13
- return ((0, jsx_runtime_1.jsx)("div", { style: { minHeight: "100px" }, children: nfts?.nftResponse ? ((0, jsx_runtime_1.jsx)(__1.AccountAssets, { nfts: nfts.nftResponse, isLoading: isLoading })) : ((0, jsx_runtime_1.jsx)("div", { className: "py-12 text-center text-gray-500", children: "No NFTs found" })) }));
12
+ const { data: nfts, isLoading } = (0, hooks_1.useSimCollectibles)(activeAddress, [1, 8453], { filterSpam: true });
13
+ return ((0, jsx_runtime_1.jsx)("div", { style: { minHeight: "100px" }, children: nfts ? ((0, jsx_runtime_1.jsx)(__1.AccountAssets, { nfts: nfts, isLoading: isLoading })) : ((0, jsx_runtime_1.jsx)("div", { className: "py-12 text-center text-gray-500", children: "No NFTs found" })) }));
14
14
  };
15
15
  exports.default = NFTContent;
@@ -18,7 +18,18 @@ const MAX_REFETCH_ATTEMPTS = 20;
18
18
  */
19
19
  function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false, source = "signInWithB3Button", signersEnabled = false, }) {
20
20
  const { automaticallySetFirstEoa, enableTurnkey } = (0, react_1.useB3Config)();
21
- const { user, refetchUser } = (0, react_1.useAuthentication)(partnerId);
21
+ const { user, refetchUser, logout } = (0, react_1.useAuthentication)(partnerId);
22
+ // FIXME Logout before login to ensure a clean state
23
+ const hasLoggedOutRef = (0, react_2.useRef)(false);
24
+ (0, react_2.useEffect)(() => {
25
+ if (hasLoggedOutRef.current)
26
+ return;
27
+ if (source !== "requestPermissions") {
28
+ debug("Logging out before login");
29
+ logout();
30
+ hasLoggedOutRef.current = true;
31
+ }
32
+ }, [source, logout]);
22
33
  const [step, setStep] = (0, react_2.useState)(source === "requestPermissions" ? null : "login");
23
34
  const [sessionKeyAdded, setSessionKeyAdded] = (0, react_2.useState)(source === "requestPermissions" ? true : false);
24
35
  const { setB3ModalContentType, setB3ModalOpen, isOpen, contentType } = (0, react_1.useModalStore)();
@@ -31,6 +31,7 @@ export { useRemoveSessionKey } from "./useRemoveSessionKey";
31
31
  export { useRouter } from "./useRouter";
32
32
  export { useSearchParamsSSR } from "./useSearchParamsSSR";
33
33
  export { useSimBalance, useSimSvmBalance, useSimTokenBalance } from "./useSimBalance";
34
+ export { useSimCollectibles } from "./useSimCollectibles";
34
35
  export { useSiwe } from "./useSiwe";
35
36
  export { useTokenBalance } from "./useTokenBalance";
36
37
  export { useTokenBalanceDirect } from "./useTokenBalanceDirect";
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.useURLParams = exports.useUnifiedChainSwitchAndExecute = exports.useTurnkeyAuth = exports.useTokensFromAddress = exports.useTokenPriceWithFallback = exports.useTokenPrice = exports.useTokenFromUrl = exports.useTokenData = exports.useTokenBalancesByChain = exports.useTokenBalanceDirect = exports.useTokenBalance = exports.useSiwe = exports.useSimTokenBalance = exports.useSimSvmBalance = exports.useSimBalance = exports.useSearchParamsSSR = exports.useRouter = exports.useRemoveSessionKey = exports.useQueryBSMNT = exports.useQueryB3 = exports.useProfileSettings = exports.useProfilePreference = exports.useProfile = exports.useDisplayName = exports.useOneBalance = exports.useNotifications = exports.useNativeBalanceFromRPC = exports.useNativeBalance = exports.useMediaQuery = exports.useIsomorphicLayoutEffect = exports.useIsMobile = exports.useHasMounted = exports.useHandleConnectWithPrivy = exports.useGlobalAccount = exports.useGetGeo = exports.useGetAllTWSigners = exports.useFirstEOA = exports.useExchangeRate = exports.useConnect = exports.useClient = exports.useChainSwitchWithAction = exports.useB3EnsName = exports.useB3BalanceFromAddresses = exports.useAuthentication = exports.useAuth = exports.useAnalytics = exports.useAddTWSessionKey = exports.useAccountWallet = exports.useAccountAssets = exports.createWagmiConfig = void 0;
18
- exports.useUser = void 0;
17
+ exports.useUnifiedChainSwitchAndExecute = exports.useTurnkeyAuth = exports.useTokensFromAddress = exports.useTokenPriceWithFallback = exports.useTokenPrice = exports.useTokenFromUrl = exports.useTokenData = exports.useTokenBalancesByChain = exports.useTokenBalanceDirect = exports.useTokenBalance = exports.useSiwe = exports.useSimCollectibles = exports.useSimTokenBalance = exports.useSimSvmBalance = exports.useSimBalance = exports.useSearchParamsSSR = exports.useRouter = exports.useRemoveSessionKey = exports.useQueryBSMNT = exports.useQueryB3 = exports.useProfileSettings = exports.useProfilePreference = exports.useProfile = exports.useDisplayName = exports.useOneBalance = exports.useNotifications = exports.useNativeBalanceFromRPC = exports.useNativeBalance = exports.useMediaQuery = exports.useIsomorphicLayoutEffect = exports.useIsMobile = exports.useHasMounted = exports.useHandleConnectWithPrivy = exports.useGlobalAccount = exports.useGetGeo = exports.useGetAllTWSigners = exports.useFirstEOA = exports.useExchangeRate = exports.useConnect = exports.useClient = exports.useChainSwitchWithAction = exports.useB3EnsName = exports.useB3BalanceFromAddresses = exports.useAuthentication = exports.useAuth = exports.useAnalytics = exports.useAddTWSessionKey = exports.useAccountWallet = exports.useAccountAssets = exports.createWagmiConfig = void 0;
18
+ exports.useUser = exports.useURLParams = void 0;
19
19
  var createWagmiConfig_1 = require("../utils/createWagmiConfig");
20
20
  Object.defineProperty(exports, "createWagmiConfig", { enumerable: true, get: function () { return createWagmiConfig_1.createWagmiConfig; } });
21
21
  var useAccountAssets_1 = require("./useAccountAssets");
@@ -87,6 +87,8 @@ var useSimBalance_1 = require("./useSimBalance");
87
87
  Object.defineProperty(exports, "useSimBalance", { enumerable: true, get: function () { return useSimBalance_1.useSimBalance; } });
88
88
  Object.defineProperty(exports, "useSimSvmBalance", { enumerable: true, get: function () { return useSimBalance_1.useSimSvmBalance; } });
89
89
  Object.defineProperty(exports, "useSimTokenBalance", { enumerable: true, get: function () { return useSimBalance_1.useSimTokenBalance; } });
90
+ var useSimCollectibles_1 = require("./useSimCollectibles");
91
+ Object.defineProperty(exports, "useSimCollectibles", { enumerable: true, get: function () { return useSimCollectibles_1.useSimCollectibles; } });
90
92
  var useSiwe_1 = require("./useSiwe");
91
93
  Object.defineProperty(exports, "useSiwe", { enumerable: true, get: function () { return useSiwe_1.useSiwe; } });
92
94
  var useTokenBalance_1 = require("./useTokenBalance");
@@ -4,14 +4,16 @@ exports.useSimBalance = useSimBalance;
4
4
  exports.useSimSvmBalance = useSimSvmBalance;
5
5
  exports.useSimTokenBalance = useSimTokenBalance;
6
6
  const react_query_1 = require("@tanstack/react-query");
7
+ const simdune_1 = require("../utils/simdune");
7
8
  async function fetchSimBalance(address, chainIdsParam) {
8
9
  if (!address)
9
10
  throw new Error("Address is required");
10
11
  const chainIds = chainIdsParam.length === 0 ? "mainnet" : chainIdsParam.join(",");
11
- let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/v1/evm/balances/${address}?metadata=logo&chain_ids=${chainIds}&exclude_spam_tokens=true`;
12
- if (process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET) {
13
- url += `&localkey=${process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET}`;
14
- }
12
+ const queryParams = new URLSearchParams();
13
+ queryParams.append("metadata", "logo");
14
+ queryParams.append("chain_ids", chainIds);
15
+ queryParams.append("exclude_spam_tokens", "true");
16
+ const url = (0, simdune_1.buildSimduneUrl)(`/v1/evm/balances/${address}`, queryParams);
15
17
  const response = await fetch(url);
16
18
  if (!response.ok) {
17
19
  throw new Error(`Failed to fetch balance: ${response.statusText}`);
@@ -26,10 +28,9 @@ async function fetchSimTokenBalance(walletAddress, tokenAddress, chainId) {
26
28
  throw new Error("Token address is required");
27
29
  if (!chainId)
28
30
  throw new Error("Chain ID is required");
29
- let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/v1/evm/balances/${walletAddress}/token/${tokenAddress}?chain_ids=${chainId}`;
30
- if (process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET) {
31
- url += `&localkey=${process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET}`;
32
- }
31
+ const queryParams = new URLSearchParams();
32
+ queryParams.append("chain_ids", chainId.toString());
33
+ const url = (0, simdune_1.buildSimduneUrl)(`/v1/evm/balances/${walletAddress}/token/${tokenAddress}`, queryParams);
33
34
  const response = await fetch(url);
34
35
  if (!response.ok) {
35
36
  throw new Error(`Failed to fetch token balance: ${response.statusText}`);
@@ -47,13 +48,7 @@ async function fetchSimSvmBalance(address, chains, limit) {
47
48
  if (limit) {
48
49
  queryParams.append("limit", limit.toString());
49
50
  }
50
- let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/beta/svm/balances/${address}`;
51
- if (queryParams.toString()) {
52
- url += `?${queryParams.toString()}`;
53
- }
54
- if (process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET) {
55
- url += `${queryParams.toString() ? "&" : "?"}localkey=${process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET}`;
56
- }
51
+ const url = (0, simdune_1.buildSimduneUrl)(`/beta/svm/balances/${address}`, queryParams.toString() ? queryParams : undefined);
57
52
  const response = await fetch(url);
58
53
  if (!response.ok) {
59
54
  throw new Error(`Failed to fetch SVM balance: ${response.statusText}`);
@@ -0,0 +1,45 @@
1
+ import type { SimpleHashNFTResponse } from "../../../global-account/types/simplehash.types";
2
+ export interface SimCollectibleMetadata {
3
+ uri: string;
4
+ attributes?: Array<{
5
+ trait_type: string;
6
+ value: string;
7
+ display_type?: string | null;
8
+ }>;
9
+ }
10
+ export interface SimCollectibleEntry {
11
+ contract_address: string;
12
+ token_standard: "ERC721" | "ERC1155";
13
+ token_id: string;
14
+ chain: string;
15
+ chain_id: number;
16
+ name?: string;
17
+ description?: string;
18
+ symbol?: string;
19
+ image_url?: string;
20
+ last_sale_price?: string;
21
+ metadata?: SimCollectibleMetadata;
22
+ is_spam?: boolean;
23
+ spam_score?: number;
24
+ explanations?: string[];
25
+ balance?: string;
26
+ last_acquired?: string;
27
+ }
28
+ export interface SimCollectiblesResponse {
29
+ address: string;
30
+ entries: SimCollectibleEntry[];
31
+ next_offset?: string;
32
+ request_time: string;
33
+ response_time: string;
34
+ }
35
+ /**
36
+ * Hook to fetch NFT collectibles from Simdune API.
37
+ * Returns data in SimpleHash format for compatibility with AccountAssets component.
38
+ * @param address - Wallet address to fetch collectibles for
39
+ * @param chainIdsParam - Optional array of chain IDs to filter by
40
+ * @param options - Optional parameters (limit, filterSpam)
41
+ */
42
+ export declare function useSimCollectibles(address?: string, chainIdsParam?: number[], options?: {
43
+ limit?: number;
44
+ filterSpam?: boolean;
45
+ }): import("@tanstack/react-query").UseQueryResult<SimpleHashNFTResponse, Error>;
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSimCollectibles = useSimCollectibles;
4
+ const react_query_1 = require("@tanstack/react-query");
5
+ const simdune_1 = require("../utils/simdune");
6
+ /**
7
+ * Safely parse a balance string to a number, capping at MAX_SAFE_INTEGER
8
+ * to prevent overflow issues with large ERC1155 balances.
9
+ */
10
+ function safeParseBalance(balance) {
11
+ if (!balance)
12
+ return 1;
13
+ const parsed = parseInt(balance, 10);
14
+ if (Number.isNaN(parsed))
15
+ return 1;
16
+ return Math.min(parsed, Number.MAX_SAFE_INTEGER);
17
+ }
18
+ async function fetchSimCollectibles(address, chainIdsParam, options) {
19
+ if (!address)
20
+ throw new Error("Address is required");
21
+ const queryParams = new URLSearchParams();
22
+ if (chainIdsParam && chainIdsParam.length > 0) {
23
+ queryParams.append("chain_ids", chainIdsParam.join(","));
24
+ }
25
+ if (options?.limit) {
26
+ queryParams.append("limit", options.limit.toString());
27
+ }
28
+ if (options?.filterSpam !== undefined) {
29
+ queryParams.append("filter_spam", options.filterSpam.toString());
30
+ }
31
+ const url = (0, simdune_1.buildSimduneUrl)(`/v1/evm/collectibles/${address}`, queryParams);
32
+ const response = await fetch(url);
33
+ if (!response.ok) {
34
+ throw new Error(`Failed to fetch collectibles: ${response.statusText}`);
35
+ }
36
+ const data = await response.json();
37
+ return data;
38
+ }
39
+ /**
40
+ * Transforms Simdune collectibles response to SimpleHash NFT format
41
+ * for compatibility with existing AccountAssets component
42
+ */
43
+ function transformToSimpleHashFormat(data) {
44
+ const nfts = data.entries.map(entry => ({
45
+ nft_id: `${entry.chain}.${entry.contract_address}.${entry.token_id}`,
46
+ chain: entry.chain,
47
+ contract_address: entry.contract_address,
48
+ token_id: entry.token_id,
49
+ name: entry.name || "",
50
+ description: entry.description || "",
51
+ previews: {
52
+ image_small_url: entry.image_url || "",
53
+ image_medium_url: entry.image_url || "",
54
+ image_large_url: entry.image_url || "",
55
+ image_opengraph_url: entry.image_url || "",
56
+ blurhash: "",
57
+ predominant_color: "",
58
+ },
59
+ image_url: entry.image_url || "",
60
+ image_properties: {
61
+ width: 0,
62
+ height: 0,
63
+ size: 0,
64
+ mime_type: "",
65
+ exif_orientation: null,
66
+ },
67
+ video_url: null,
68
+ video_properties: null,
69
+ audio_url: null,
70
+ audio_properties: null,
71
+ model_url: null,
72
+ model_properties: null,
73
+ other_url: null,
74
+ other_properties: null,
75
+ background_color: null,
76
+ external_url: null,
77
+ created_date: "",
78
+ status: "minted",
79
+ token_count: 1,
80
+ owner_count: 1,
81
+ owners: [
82
+ {
83
+ owner_address: data.address,
84
+ quantity: safeParseBalance(entry.balance),
85
+ quantity_string: entry.balance || "1",
86
+ first_acquired_date: entry.last_acquired || "",
87
+ last_acquired_date: entry.last_acquired || "",
88
+ },
89
+ ],
90
+ contract: {
91
+ type: entry.token_standard,
92
+ name: entry.name || "",
93
+ symbol: entry.symbol || null,
94
+ deployed_by: "",
95
+ deployed_via_contract: "",
96
+ owned_by: "",
97
+ has_multiple_collections: false,
98
+ },
99
+ collection: {
100
+ collection_id: entry.contract_address,
101
+ name: entry.symbol || "Unknown Collection",
102
+ description: null,
103
+ image_url: entry.image_url || "",
104
+ image_properties: {
105
+ width: 0,
106
+ height: 0,
107
+ mime_type: "",
108
+ },
109
+ banner_image_url: null,
110
+ category: null,
111
+ is_nsfw: null,
112
+ external_url: null,
113
+ twitter_username: null,
114
+ discord_url: null,
115
+ instagram_username: null,
116
+ medium_username: null,
117
+ telegram_url: null,
118
+ marketplace_pages: [],
119
+ metaplex_mint: null,
120
+ metaplex_candy_machine: null,
121
+ metaplex_first_verified_creator: null,
122
+ floor_prices: [],
123
+ top_bids: [],
124
+ distinct_owner_count: 0,
125
+ distinct_nft_count: 0,
126
+ total_quantity: 0,
127
+ chains: [entry.chain],
128
+ top_contracts: [entry.contract_address],
129
+ collection_royalties: [],
130
+ },
131
+ last_sale: entry.last_sale_price
132
+ ? {
133
+ price: entry.last_sale_price,
134
+ }
135
+ : null,
136
+ primary_sale: null,
137
+ first_created: {
138
+ minted_to: data.address,
139
+ quantity: 1,
140
+ quantity_string: "1",
141
+ timestamp: "",
142
+ block_number: 0,
143
+ transaction: "",
144
+ transaction_initiator: "",
145
+ },
146
+ rarity: {
147
+ rank: null,
148
+ score: null,
149
+ unique_attributes: null,
150
+ },
151
+ royalty: [],
152
+ extra_metadata: {
153
+ attributes: (entry.metadata?.attributes || []).map(attr => ({
154
+ trait_type: attr.trait_type,
155
+ value: attr.value,
156
+ display_type: attr.display_type ?? null,
157
+ })),
158
+ image_original_url: entry.image_url || "",
159
+ animation_original_url: null,
160
+ metadata_original_url: entry.metadata?.uri || "",
161
+ },
162
+ }));
163
+ return {
164
+ next_cursor: data.next_offset || null,
165
+ next: null,
166
+ previous: null,
167
+ nfts,
168
+ };
169
+ }
170
+ /**
171
+ * Hook to fetch NFT collectibles from Simdune API.
172
+ * Returns data in SimpleHash format for compatibility with AccountAssets component.
173
+ * @param address - Wallet address to fetch collectibles for
174
+ * @param chainIdsParam - Optional array of chain IDs to filter by
175
+ * @param options - Optional parameters (limit, filterSpam)
176
+ */
177
+ function useSimCollectibles(address, chainIdsParam, options) {
178
+ return (0, react_query_1.useQuery)({
179
+ queryKey: ["simCollectibles", address, chainIdsParam, options],
180
+ queryFn: async () => {
181
+ if (!address)
182
+ throw new Error("Address is required");
183
+ const data = await fetchSimCollectibles(address, chainIdsParam, options);
184
+ return transformToSimpleHashFormat(data);
185
+ },
186
+ enabled: Boolean(address),
187
+ staleTime: 30 * 1000,
188
+ gcTime: 5 * 60 * 1000,
189
+ });
190
+ }
@@ -0,0 +1,7 @@
1
+ export declare const SIMDUNE_API_HOST = "https://simdune-api.sean-430.workers.dev";
2
+ /**
3
+ * Builds a Simdune API URL with the proxy wrapper and optional dev mode key.
4
+ * @param endpoint - The Simdune API endpoint (e.g., "/v1/evm/balances/0x...")
5
+ * @param queryParams - Optional URLSearchParams to append
6
+ */
7
+ export declare function buildSimduneUrl(endpoint: string, queryParams?: URLSearchParams): string;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SIMDUNE_API_HOST = void 0;
4
+ exports.buildSimduneUrl = buildSimduneUrl;
5
+ exports.SIMDUNE_API_HOST = "https://simdune-api.sean-430.workers.dev";
6
+ /**
7
+ * Builds a Simdune API URL with the proxy wrapper and optional dev mode key.
8
+ * @param endpoint - The Simdune API endpoint (e.g., "/v1/evm/balances/0x...")
9
+ * @param queryParams - Optional URLSearchParams to append
10
+ */
11
+ function buildSimduneUrl(endpoint, queryParams) {
12
+ const baseUrl = `${exports.SIMDUNE_API_HOST}/?url=https://api.sim.dune.com${endpoint}`;
13
+ let url = baseUrl;
14
+ if (queryParams && queryParams.toString()) {
15
+ url += `?${queryParams.toString()}`;
16
+ }
17
+ if (process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET) {
18
+ url += `${queryParams?.toString() ? "&" : "?"}localkey=${process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET}`;
19
+ }
20
+ return url;
21
+ }
@@ -1,6 +1,5 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { TooltipProvider } from "../../../global-account/react/index.js";
4
3
  import { FeatureFlagsProvider } from "../contexts/FeatureFlagsContext.js";
5
4
  import { StripeRedirectHandler } from "./StripeRedirectHandler.js";
6
5
  /**
@@ -27,5 +26,5 @@ import { StripeRedirectHandler } from "./StripeRedirectHandler.js";
27
26
  * ```
28
27
  */
29
28
  export const AnyspendProvider = function AnyspendProvider({ children, featureFlags }) {
30
- return (_jsx(FeatureFlagsProvider, { featureFlags: featureFlags, children: _jsxs(TooltipProvider, { children: [_jsx(StripeRedirectHandler, {}), children] }) }));
29
+ return (_jsxs(FeatureFlagsProvider, { featureFlags: featureFlags, children: [_jsx(StripeRedirectHandler, {}), children] }));
31
30
  };
@@ -18,6 +18,10 @@ export function AccountAssets({ nfts, isLoading }) {
18
18
  }, {});
19
19
  const collections = Object.values(groupedNFTs || {});
20
20
  const [expandedCollections, setExpandedCollections] = useState(() => new Set(collections.map(c => c.collection_id)));
21
+ const [failedImages, setFailedImages] = useState(() => new Set());
22
+ const handleImageError = (imageId) => {
23
+ setFailedImages(prev => new Set(prev).add(imageId));
24
+ };
21
25
  if (isLoading) {
22
26
  return (_jsx("div", { className: "flex flex-col gap-3", children: [...Array(2)].map((_, i) => (_jsxs("div", { className: "animate-pulse", children: [_jsx("div", { className: "bg-b3-react-muted mb-3 h-6 w-48 rounded" }), _jsxs("div", { className: "flex gap-3", children: [_jsx("div", { className: "bg-b3-react-muted h-[98px] w-[98px] shrink-0 rounded-lg" }), _jsx("div", { className: "bg-b3-react-muted h-[98px] w-[98px] shrink-0 rounded-lg" })] })] }, i))) }));
23
27
  }
@@ -36,11 +40,11 @@ export function AccountAssets({ nfts, isLoading }) {
36
40
  return next;
37
41
  });
38
42
  };
39
- return (_jsx("div", { className: "flex flex-col gap-3 px-4", children: collections.map(collection => {
43
+ return (_jsx("div", { className: "flex flex-col gap-3", children: collections.map(collection => {
40
44
  const isExpanded = expandedCollections.has(collection.collection_id);
41
- return (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsxs("button", { onClick: () => toggleCollection(collection.collection_id), className: "flex w-full items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-1", children: [collection.collection_image && (_jsx("img", { src: collection.collection_image, alt: collection.collection_name, className: "h-5 w-5 shrink-0 rounded object-cover" })), _jsxs("p", { className: "font-neue-montreal-medium text-[14px] text-[#3f3f46]", children: [collection.collection_name, " (", collection.nfts.length, ")"] })] }), _jsx("svg", { className: `h-[18px] w-[18px] shrink-0 transition-transform ${isExpanded ? "rotate-180" : ""}`, viewBox: "0 0 18 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M4.5 6.75L9 11.25L13.5 6.75", stroke: "#51525C", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), isExpanded && (_jsx("div", { className: "flex gap-3 overflow-x-auto", children: collection.nfts.map(nft => (_jsx("div", { className: "relative h-[98px] w-[98px] shrink-0 overflow-hidden rounded-lg", children: _jsx("img", { src: nft.previews?.image_medium_url ||
45
+ return (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsxs("button", { onClick: () => toggleCollection(collection.collection_id), className: "flex w-full items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-1", children: [collection.collection_image && !failedImages.has(`collection-${collection.collection_id}`) && (_jsx("img", { src: collection.collection_image, alt: collection.collection_name, className: "h-5 w-5 shrink-0 rounded object-cover", onError: () => handleImageError(`collection-${collection.collection_id}`) })), _jsxs("p", { className: "font-neue-montreal-medium text-[14px] text-[#3f3f46]", children: [collection.collection_name, " (", collection.nfts.length, ")"] })] }), _jsx("svg", { className: `h-[18px] w-[18px] shrink-0 transition-transform ${isExpanded ? "rotate-180" : ""}`, viewBox: "0 0 18 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M4.5 6.75L9 11.25L13.5 6.75", stroke: "#51525C", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), isExpanded && (_jsx("div", { className: "flex gap-3 overflow-x-auto", children: collection.nfts.map(nft => (_jsx("div", { className: "bg-b3-react-muted relative h-[98px] w-[98px] shrink-0 overflow-hidden rounded-lg", children: !failedImages.has(nft.nft_id) && (_jsx("img", { src: nft.previews?.image_medium_url ||
42
46
  nft.extra_metadata?.image_original_url ||
43
47
  nft.collection?.image_url ||
44
- "", alt: nft.name || "NFT", className: "h-full w-full object-cover" }) }, nft.nft_id))) }))] }, collection.collection_id));
48
+ "", alt: nft.name || "NFT", className: "h-full w-full object-cover", onError: () => handleImageError(nft.nft_id) })) }, nft.nft_id))) }))] }, collection.collection_id));
45
49
  }) }));
46
50
  }
@@ -1,13 +1,13 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useActiveWallet } from "thirdweb/react";
3
3
  import { AccountAssets } from "..";
4
- import { useAccountAssets } from "../../hooks/index.js";
4
+ import { useSimCollectibles } from "../../hooks/index.js";
5
5
  const NFTContent = () => {
6
6
  // Get active wallet state
7
7
  const activeWallet = useActiveWallet();
8
8
  const activeAccount = activeWallet?.getAccount();
9
9
  const activeAddress = activeAccount?.address;
10
- const { data: nfts, isLoading } = useAccountAssets(activeAddress);
11
- return (_jsx("div", { style: { minHeight: "100px" }, children: nfts?.nftResponse ? (_jsx(AccountAssets, { nfts: nfts.nftResponse, isLoading: isLoading })) : (_jsx("div", { className: "py-12 text-center text-gray-500", children: "No NFTs found" })) }));
10
+ const { data: nfts, isLoading } = useSimCollectibles(activeAddress, [1, 8453], { filterSpam: true });
11
+ return (_jsx("div", { style: { minHeight: "100px" }, children: nfts ? (_jsx(AccountAssets, { nfts: nfts, isLoading: isLoading })) : (_jsx("div", { className: "py-12 text-center text-gray-500", children: "No NFTs found" })) }));
12
12
  };
13
13
  export default NFTContent;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Loading, useAuthentication, useAuthStore, useB3Config, useGetAllTWSigners, useModalStore, } from "../../../../global-account/react/index.js";
3
3
  import { debugB3React } from "../../../../shared/utils/debug.js";
4
- import { useCallback, useEffect, useState } from "react";
4
+ import { useCallback, useEffect, useRef, useState } from "react";
5
5
  import { useActiveAccount } from "thirdweb/react";
6
6
  import { TurnkeyAuthModal } from "../TurnkeyAuthModal.js";
7
7
  import { SignInWithB3Privy } from "./SignInWithB3Privy.js";
@@ -15,7 +15,18 @@ const MAX_REFETCH_ATTEMPTS = 20;
15
15
  */
16
16
  export function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin = false, source = "signInWithB3Button", signersEnabled = false, }) {
17
17
  const { automaticallySetFirstEoa, enableTurnkey } = useB3Config();
18
- const { user, refetchUser } = useAuthentication(partnerId);
18
+ const { user, refetchUser, logout } = useAuthentication(partnerId);
19
+ // FIXME Logout before login to ensure a clean state
20
+ const hasLoggedOutRef = useRef(false);
21
+ useEffect(() => {
22
+ if (hasLoggedOutRef.current)
23
+ return;
24
+ if (source !== "requestPermissions") {
25
+ debug("Logging out before login");
26
+ logout();
27
+ hasLoggedOutRef.current = true;
28
+ }
29
+ }, [source, logout]);
19
30
  const [step, setStep] = useState(source === "requestPermissions" ? null : "login");
20
31
  const [sessionKeyAdded, setSessionKeyAdded] = useState(source === "requestPermissions" ? true : false);
21
32
  const { setB3ModalContentType, setB3ModalOpen, isOpen, contentType } = useModalStore();
@@ -31,6 +31,7 @@ export { useRemoveSessionKey } from "./useRemoveSessionKey";
31
31
  export { useRouter } from "./useRouter";
32
32
  export { useSearchParamsSSR } from "./useSearchParamsSSR";
33
33
  export { useSimBalance, useSimSvmBalance, useSimTokenBalance } from "./useSimBalance";
34
+ export { useSimCollectibles } from "./useSimCollectibles";
34
35
  export { useSiwe } from "./useSiwe";
35
36
  export { useTokenBalance } from "./useTokenBalance";
36
37
  export { useTokenBalanceDirect } from "./useTokenBalanceDirect";
@@ -31,6 +31,7 @@ export { useRemoveSessionKey } from "./useRemoveSessionKey.js";
31
31
  export { useRouter } from "./useRouter.js";
32
32
  export { useSearchParamsSSR } from "./useSearchParamsSSR.js";
33
33
  export { useSimBalance, useSimSvmBalance, useSimTokenBalance } from "./useSimBalance.js";
34
+ export { useSimCollectibles } from "./useSimCollectibles.js";
34
35
  export { useSiwe } from "./useSiwe.js";
35
36
  export { useTokenBalance } from "./useTokenBalance.js";
36
37
  export { useTokenBalanceDirect } from "./useTokenBalanceDirect.js";
@@ -1,12 +1,14 @@
1
1
  import { useQuery } from "@tanstack/react-query";
2
+ import { buildSimduneUrl } from "../utils/simdune.js";
2
3
  async function fetchSimBalance(address, chainIdsParam) {
3
4
  if (!address)
4
5
  throw new Error("Address is required");
5
6
  const chainIds = chainIdsParam.length === 0 ? "mainnet" : chainIdsParam.join(",");
6
- let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/v1/evm/balances/${address}?metadata=logo&chain_ids=${chainIds}&exclude_spam_tokens=true`;
7
- if (process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET) {
8
- url += `&localkey=${process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET}`;
9
- }
7
+ const queryParams = new URLSearchParams();
8
+ queryParams.append("metadata", "logo");
9
+ queryParams.append("chain_ids", chainIds);
10
+ queryParams.append("exclude_spam_tokens", "true");
11
+ const url = buildSimduneUrl(`/v1/evm/balances/${address}`, queryParams);
10
12
  const response = await fetch(url);
11
13
  if (!response.ok) {
12
14
  throw new Error(`Failed to fetch balance: ${response.statusText}`);
@@ -21,10 +23,9 @@ async function fetchSimTokenBalance(walletAddress, tokenAddress, chainId) {
21
23
  throw new Error("Token address is required");
22
24
  if (!chainId)
23
25
  throw new Error("Chain ID is required");
24
- let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/v1/evm/balances/${walletAddress}/token/${tokenAddress}?chain_ids=${chainId}`;
25
- if (process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET) {
26
- url += `&localkey=${process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET}`;
27
- }
26
+ const queryParams = new URLSearchParams();
27
+ queryParams.append("chain_ids", chainId.toString());
28
+ const url = buildSimduneUrl(`/v1/evm/balances/${walletAddress}/token/${tokenAddress}`, queryParams);
28
29
  const response = await fetch(url);
29
30
  if (!response.ok) {
30
31
  throw new Error(`Failed to fetch token balance: ${response.statusText}`);
@@ -42,13 +43,7 @@ async function fetchSimSvmBalance(address, chains, limit) {
42
43
  if (limit) {
43
44
  queryParams.append("limit", limit.toString());
44
45
  }
45
- let url = `https://simdune-api.sean-430.workers.dev/?url=https://api.sim.dune.com/beta/svm/balances/${address}`;
46
- if (queryParams.toString()) {
47
- url += `?${queryParams.toString()}`;
48
- }
49
- if (process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET) {
50
- url += `${queryParams.toString() ? "&" : "?"}localkey=${process.env.NEXT_PUBLIC_DEVMODE_SHARED_SECRET}`;
51
- }
46
+ const url = buildSimduneUrl(`/beta/svm/balances/${address}`, queryParams.toString() ? queryParams : undefined);
52
47
  const response = await fetch(url);
53
48
  if (!response.ok) {
54
49
  throw new Error(`Failed to fetch SVM balance: ${response.statusText}`);