@b3dotfun/sdk 0.0.83-alpha.4 → 0.0.83-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 (22) hide show
  1. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +3 -4
  2. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
  3. package/dist/cjs/global-account/react/hooks/index.d.ts +0 -1
  4. package/dist/cjs/global-account/react/hooks/index.js +1 -3
  5. package/dist/cjs/global-account/react/hooks/useAccountWallet.js +11 -10
  6. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +4 -5
  7. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
  8. package/dist/esm/global-account/react/hooks/index.d.ts +0 -1
  9. package/dist/esm/global-account/react/hooks/index.js +0 -1
  10. package/dist/esm/global-account/react/hooks/useAccountWallet.js +11 -10
  11. package/dist/types/global-account/react/hooks/index.d.ts +0 -1
  12. package/package.json +1 -1
  13. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +4 -6
  14. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +1 -1
  15. package/src/global-account/react/hooks/index.ts +0 -1
  16. package/src/global-account/react/hooks/useAccountWallet.tsx +12 -11
  17. package/dist/cjs/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
  18. package/dist/cjs/global-account/react/hooks/useBestTransactionPath.js +0 -148
  19. package/dist/esm/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
  20. package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +0 -145
  21. package/dist/types/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
  22. package/src/global-account/react/hooks/useBestTransactionPath.tsx +0 -201
@@ -12,12 +12,12 @@ const utils_1 = require("../../../../shared/utils");
12
12
  const react_2 = require("@headlessui/react");
13
13
  const react_3 = require("react");
14
14
  const react_4 = require("thirdweb/react");
15
- const useAccountWallet_1 = require("../../hooks/useAccountWallet");
16
15
  const ManageAccountButton_1 = require("../custom/ManageAccountButton");
17
16
  function SignIn(props) {
18
17
  const { className } = props;
19
18
  const { automaticallySetFirstEoa, partnerId } = (0, react_1.useB3)();
20
- const { address: globalAddress, ensName, connectedSmartWallet, connectedEOAWallet, isActiveSmartWallet, isActiveEOAWallet, smartWalletIcon, eoaWalletIcon, } = (0, react_1.useAccountWallet)();
19
+ const { address: globalAddress, ensName, connectedSmartWallet, connectedEOAWallet, isActiveSmartWallet, isActiveEOAWallet, smartWalletIcon, } = (0, react_1.useAccountWallet)();
20
+ const { data: walletImage } = (0, react_4.useWalletImage)(connectedEOAWallet?.id);
21
21
  const isMobile = (0, react_1.useIsMobile)();
22
22
  const { logout } = (0, react_1.useAuthentication)(partnerId);
23
23
  const onDisconnect = async () => {
@@ -40,11 +40,10 @@ function SignIn(props) {
40
40
  setActiveWallet(connectedEOAWallet);
41
41
  }
42
42
  }, [connectedEOAWallet, isActiveEOAWallet, setActiveWallet, automaticallySetFirstEoa]);
43
- const walletImage = (0, useAccountWallet_1.useAccountWalletImage)();
44
43
  // Desktop version - original dropdown menu
45
44
  return ((0, jsx_runtime_1.jsx)(react_1.StyleRoot, { children: (0, jsx_runtime_1.jsx)(react_2.Menu, { className: `relative flex items-center ${className || ""}`, as: "div", children: globalAddress ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(react_2.MenuButton, { className: "bg-b3-react-background group flex h-10 items-center gap-1 rounded-xl px-3 focus:outline-none", children: [!!walletImage && ((0, jsx_runtime_1.jsx)(react_1.IPFSMediaRenderer, { src: walletImage, alt: "Wallet Image", className: "bg-b3-react-primary h-6 w-6 rounded-full object-cover opacity-100" })), (0, jsx_runtime_1.jsx)("div", { className: "text-as-primary", children: ensName ? ensName : (0, utils_1.truncateAddress)(globalAddress) })] }), (0, jsx_runtime_1.jsx)(react_2.Transition, { enter: "duration-200 ease-out", enterFrom: "scale-95 opacity-0", enterTo: "scale-100 opacity-100", leave: "duration-300 ease-out", leaveFrom: "scale-100 opacity-100", leaveTo: "scale-95 opacity-0", children: (0, jsx_runtime_1.jsx)(react_2.MenuItems, { className: "b3-root absolute -right-4 top-full min-w-64 rounded-2xl border focus:outline-none lg:right-0", modal: false,
46
45
  // TODO: Figure out why setting anchor on mobile causes z-index issues where it appears under elements
47
- anchor: isMobile ? "top end" : undefined, children: (0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background", children: [connectedEOAWallet ? ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)("border-b3-react-subtle bg-b3-react-background flex cursor-pointer items-center justify-between rounded-xl p-3"), onClick: () => handleSetActiveAccount(connectedEOAWallet?.id), children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center", children: [(0, jsx_runtime_1.jsx)("img", { className: "bg-b3-react-primary h-16 w-16 rounded-full opacity-100", src: eoaWalletIcon, alt: connectedEOAWallet?.id }), (0, jsx_runtime_1.jsxs)("div", { className: "ml-4 grow", children: [ensName && (0, jsx_runtime_1.jsx)("div", { children: ensName }), (0, jsx_runtime_1.jsx)("div", { children: (0, utils_1.truncateAddress)(globalAddress) })] })] }), isActiveEOAWallet && (0, jsx_runtime_1.jsx)(Icon_1.default, { className: "fill-b3-react-primary", name: "check" })] })) : (connectedSmartWallet && ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)("mb-2 flex cursor-pointer items-center justify-between rounded-xl p-3", isActiveSmartWallet
46
+ anchor: isMobile ? "top end" : undefined, children: (0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background", children: [connectedEOAWallet ? ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)("border-b3-react-subtle bg-b3-react-background flex cursor-pointer items-center justify-between rounded-xl p-3"), onClick: () => handleSetActiveAccount(connectedEOAWallet?.id), children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center", children: [(0, jsx_runtime_1.jsx)("img", { className: "bg-b3-react-primary h-16 w-16 rounded-full opacity-100", src: walletImage, alt: connectedEOAWallet?.id }), (0, jsx_runtime_1.jsxs)("div", { className: "ml-4 grow", children: [ensName && (0, jsx_runtime_1.jsx)("div", { children: ensName }), (0, jsx_runtime_1.jsx)("div", { children: (0, utils_1.truncateAddress)(globalAddress) })] })] }), isActiveEOAWallet && (0, jsx_runtime_1.jsx)(Icon_1.default, { className: "fill-b3-react-primary", name: "check" })] })) : (connectedSmartWallet && ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)("mb-2 flex cursor-pointer items-center justify-between rounded-xl p-3", isActiveSmartWallet
48
47
  ? "bg-b3-react-background"
49
48
  : "bg-b3-react-background hover:bg-b3-react-background"), onClick: () => handleSetActiveAccount(connectedSmartWallet?.id), children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center", children: [(0, jsx_runtime_1.jsx)("img", { className: "bg-b3-react-primary h-16 w-16 rounded-full opacity-100", src: smartWalletIcon, alt: connectedSmartWallet?.id }), (0, jsx_runtime_1.jsxs)("div", { className: "grow pl-4", children: [ensName && (0, jsx_runtime_1.jsx)("div", { children: ensName }), (0, jsx_runtime_1.jsx)("div", { children: (0, utils_1.truncateAddress)(globalAddress) }), (0, jsx_runtime_1.jsx)("div", { children: "Smart wallet" })] })] }), isActiveSmartWallet && (0, jsx_runtime_1.jsx)(Icon_1.default, { className: "fill-b3-react-primary", name: "check" })] }))), (0, jsx_runtime_1.jsx)("div", { className: "ml-3", children: (0, jsx_runtime_1.jsx)(ManageAccountButton_1.ManageAccountButton, { ...props, className: "w-[calc(100%-12px)]" }) }), (0, jsx_runtime_1.jsx)("button", { className: "mb-2 w-full space-y-1", onClick: onDisconnect, children: (0, jsx_runtime_1.jsxs)("div", { className: "hover:bg-b3-react-background group flex h-12 items-center rounded-xl px-4 transition-colors", children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { className: "fill-b3-react-primary mr-4 shrink-0 transition-colors", name: "logout" }), (0, jsx_runtime_1.jsx)("div", { className: "text-b3-react-primary mr-auto transition-colors", children: "Disconnect" })] }) })] }) }) })] })) : ((0, jsx_runtime_1.jsx)(react_1.SignInWithB3, { closeAfterLogin: true, onLoginSuccess: async (globalAccount) => {
50
49
  console.log("User authenticated with Global Account!", globalAccount);
@@ -16,7 +16,7 @@ function LoginStepContainer({ children, partnerId }) {
16
16
  },
17
17
  }, !!partnerId);
18
18
  const partnerLogo = partner?.data?.[0]?.loginCustomization?.logoUrl;
19
- return ((0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col items-center justify-center pt-6", children: [partnerLogo && ((0, jsx_runtime_1.jsx)("img", { src: partnerLogo, alt: "Partner Logo", className: "partner-logo mb-6 h-12 w-auto object-contain" })), children] }));
19
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex flex-col items-center justify-center pt-6", children: [partnerLogo && ((0, jsx_runtime_1.jsx)("img", { src: partnerLogo, alt: "Partner Logo", className: "partner-logo mb-6 h-12 w-auto object-contain" })), children] }));
20
20
  }
21
21
  function LoginStep({ onSuccess, chain }) {
22
22
  const { partnerId, theme } = (0, react_1.useB3)();
@@ -6,7 +6,6 @@ export { useAnalytics } from "./useAnalytics";
6
6
  export { useAuthentication } from "./useAuthentication";
7
7
  export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses";
8
8
  export { useB3EnsName } from "./useB3EnsName";
9
- export { useBestTransactionPath } from "./useBestTransactionPath";
10
9
  export { useChainSwitchWithAction } from "./useChainSwitchWithAction";
11
10
  export * from "./useClaim";
12
11
  export { useClient } from "./useClient";
@@ -14,7 +14,7 @@ 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.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.useBestTransactionPath = exports.useB3EnsName = exports.useB3BalanceFromAddresses = exports.useAuthentication = exports.useAnalytics = exports.useAddTWSessionKey = exports.useAccountWallet = exports.useAccountAssets = exports.createWagmiConfig = void 0;
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.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.useAnalytics = exports.useAddTWSessionKey = exports.useAccountWallet = exports.useAccountAssets = exports.createWagmiConfig = void 0;
18
18
  var createWagmiConfig_1 = require("../utils/createWagmiConfig");
19
19
  Object.defineProperty(exports, "createWagmiConfig", { enumerable: true, get: function () { return createWagmiConfig_1.createWagmiConfig; } });
20
20
  var useAccountAssets_1 = require("./useAccountAssets");
@@ -31,8 +31,6 @@ var useB3BalanceFromAddresses_1 = require("./useB3BalanceFromAddresses");
31
31
  Object.defineProperty(exports, "useB3BalanceFromAddresses", { enumerable: true, get: function () { return useB3BalanceFromAddresses_1.useB3BalanceFromAddresses; } });
32
32
  var useB3EnsName_1 = require("./useB3EnsName");
33
33
  Object.defineProperty(exports, "useB3EnsName", { enumerable: true, get: function () { return useB3EnsName_1.useB3EnsName; } });
34
- var useBestTransactionPath_1 = require("./useBestTransactionPath");
35
- Object.defineProperty(exports, "useBestTransactionPath", { enumerable: true, get: function () { return useBestTransactionPath_1.useBestTransactionPath; } });
36
34
  var useChainSwitchWithAction_1 = require("./useChainSwitchWithAction");
37
35
  Object.defineProperty(exports, "useChainSwitchWithAction", { enumerable: true, get: function () { return useChainSwitchWithAction_1.useChainSwitchWithAction; } });
38
36
  __exportStar(require("./useClaim"), exports);
@@ -5,7 +5,6 @@ exports.useAccountWalletImage = useAccountWalletImage;
5
5
  const react_1 = require("../../../global-account/react");
6
6
  const constants_1 = require("../../../shared/constants");
7
7
  const debug_1 = require("../../../shared/utils/debug");
8
- const ipfs_1 = require("../../../shared/utils/ipfs");
9
8
  const react_2 = require("react");
10
9
  const react_3 = require("thirdweb/react");
11
10
  const in_app_1 = require("thirdweb/wallets/in-app");
@@ -22,7 +21,13 @@ function useLastAuthProvider() {
22
21
  return lastAuthProvider;
23
22
  }
24
23
  function useAccountWallet() {
25
- const { account, user } = (0, react_1.useB3)();
24
+ // WOJ: --------------------
25
+ // values from in useB3:
26
+ // const activeAccount = useActiveAccount();
27
+ // const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
28
+ // can we possibly just use useActiveAccount here?
29
+ // --------------------
30
+ const { account } = (0, react_1.useB3)();
26
31
  const activeWallet = (0, react_3.useActiveWallet)();
27
32
  const connectedWallets = (0, react_3.useConnectedWallets)();
28
33
  const connectedSmartWallet = connectedWallets.find(wallet => wallet.id === constants_1.ecosystemWalletId);
@@ -35,7 +40,6 @@ function useAccountWallet() {
35
40
  debug("connectedEOAWallet", connectedEOAWallet);
36
41
  debug("isActiveSmartWallet", isActiveSmartWallet);
37
42
  debug("isActiveEOAWallet", isActiveEOAWallet);
38
- const { data: walletImage } = (0, react_3.useWalletImage)(connectedEOAWallet?.id);
39
43
  // If not EOA sign in, then we need to show the smart wallet icon
40
44
  const lastAuthProvider = useLastAuthProvider();
41
45
  const smartWalletIcon = lastAuthProvider && !connectedEOAWallet
@@ -43,13 +47,12 @@ function useAccountWallet() {
43
47
  : "https://gradvatar.com/0x0000000000000000000000000000000000000000"; // show smart wallet of eoa wallet is gradvatar
44
48
  const { data: profileData } = (0, react_1.useProfile)({ address: account?.address });
45
49
  const ensName = profileData?.displayName?.replace(/\.b3\.fun/g, "");
46
- const avatarUrl = user?.avatar ? (0, ipfs_1.getIpfsUrl)(user?.avatar) : profileData?.avatar;
47
50
  const res = (0, react_2.useMemo)(() => ({
48
51
  wallet: {
49
52
  ...account,
50
53
  ensName,
51
54
  meta: {
52
- icon: avatarUrl || (isActiveSmartWallet ? smartWalletIcon : walletImage) || "",
55
+ icon: "", // deprecated
53
56
  },
54
57
  },
55
58
  address: account?.address,
@@ -59,22 +62,20 @@ function useAccountWallet() {
59
62
  isActiveSmartWallet: isActiveSmartWallet,
60
63
  isActiveEOAWallet: isActiveEOAWallet,
61
64
  smartWalletIcon: smartWalletIcon,
62
- eoaWalletIcon: walletImage,
65
+ eoaWalletIcon: "", // deprecated
63
66
  }), [
64
67
  account,
65
- avatarUrl,
66
68
  connectedEOAWallet,
67
69
  connectedSmartWallet,
68
70
  ensName,
69
71
  isActiveEOAWallet,
70
72
  isActiveSmartWallet,
71
73
  smartWalletIcon,
72
- walletImage,
73
74
  ]);
74
75
  return res;
75
76
  }
76
77
  function useAccountWalletImage() {
77
- const { account, user } = (0, react_1.useB3)();
78
+ const { account } = (0, react_1.useB3)();
78
79
  const activeWallet = (0, react_3.useActiveWallet)();
79
80
  const connectedWallets = (0, react_3.useConnectedWallets)();
80
81
  const connectedSmartWallet = connectedWallets.find(wallet => wallet.id === constants_1.ecosystemWalletId);
@@ -87,6 +88,6 @@ function useAccountWalletImage() {
87
88
  ? in_app_1.socialIcons[lastAuthProvider]
88
89
  : "https://gradvatar.com/0x0000000000000000000000000000000000000000"; // show smart wallet of eoa wallet is gradvatar
89
90
  const { data: profileData } = (0, react_1.useProfile)({ address: account?.address });
90
- const avatarUrl = user?.avatar || profileData?.avatar;
91
+ const avatarUrl = profileData?.avatar;
91
92
  return avatarUrl || (isActiveSmartWallet ? smartWalletIcon : walletImage) || "";
92
93
  }
@@ -5,13 +5,13 @@ import { ecosystemWalletId } from "../../../../shared/constants/index.js";
5
5
  import { cn, truncateAddress } from "../../../../shared/utils/index.js";
6
6
  import { Menu, MenuButton, MenuItems, Transition } from "@headlessui/react";
7
7
  import { useEffect } from "react";
8
- import { useConnectedWallets, useSetActiveWallet } from "thirdweb/react";
9
- import { useAccountWalletImage } from "../../hooks/useAccountWallet.js";
8
+ import { useConnectedWallets, useSetActiveWallet, useWalletImage } from "thirdweb/react";
10
9
  import { ManageAccountButton } from "../custom/ManageAccountButton.js";
11
10
  export function SignIn(props) {
12
11
  const { className } = props;
13
12
  const { automaticallySetFirstEoa, partnerId } = useB3();
14
- const { address: globalAddress, ensName, connectedSmartWallet, connectedEOAWallet, isActiveSmartWallet, isActiveEOAWallet, smartWalletIcon, eoaWalletIcon, } = useAccountWallet();
13
+ const { address: globalAddress, ensName, connectedSmartWallet, connectedEOAWallet, isActiveSmartWallet, isActiveEOAWallet, smartWalletIcon, } = useAccountWallet();
14
+ const { data: walletImage } = useWalletImage(connectedEOAWallet?.id);
15
15
  const isMobile = useIsMobile();
16
16
  const { logout } = useAuthentication(partnerId);
17
17
  const onDisconnect = async () => {
@@ -34,11 +34,10 @@ export function SignIn(props) {
34
34
  setActiveWallet(connectedEOAWallet);
35
35
  }
36
36
  }, [connectedEOAWallet, isActiveEOAWallet, setActiveWallet, automaticallySetFirstEoa]);
37
- const walletImage = useAccountWalletImage();
38
37
  // Desktop version - original dropdown menu
39
38
  return (_jsx(StyleRoot, { children: _jsx(Menu, { className: `relative flex items-center ${className || ""}`, as: "div", children: globalAddress ? (_jsxs(_Fragment, { children: [_jsxs(MenuButton, { className: "bg-b3-react-background group flex h-10 items-center gap-1 rounded-xl px-3 focus:outline-none", children: [!!walletImage && (_jsx(IPFSMediaRenderer, { src: walletImage, alt: "Wallet Image", className: "bg-b3-react-primary h-6 w-6 rounded-full object-cover opacity-100" })), _jsx("div", { className: "text-as-primary", children: ensName ? ensName : truncateAddress(globalAddress) })] }), _jsx(Transition, { enter: "duration-200 ease-out", enterFrom: "scale-95 opacity-0", enterTo: "scale-100 opacity-100", leave: "duration-300 ease-out", leaveFrom: "scale-100 opacity-100", leaveTo: "scale-95 opacity-0", children: _jsx(MenuItems, { className: "b3-root absolute -right-4 top-full min-w-64 rounded-2xl border focus:outline-none lg:right-0", modal: false,
40
39
  // TODO: Figure out why setting anchor on mobile causes z-index issues where it appears under elements
41
- anchor: isMobile ? "top end" : undefined, children: _jsxs("div", { className: "bg-b3-react-background", children: [connectedEOAWallet ? (_jsxs("div", { className: cn("border-b3-react-subtle bg-b3-react-background flex cursor-pointer items-center justify-between rounded-xl p-3"), onClick: () => handleSetActiveAccount(connectedEOAWallet?.id), children: [_jsxs("div", { className: "flex items-center", children: [_jsx("img", { className: "bg-b3-react-primary h-16 w-16 rounded-full opacity-100", src: eoaWalletIcon, alt: connectedEOAWallet?.id }), _jsxs("div", { className: "ml-4 grow", children: [ensName && _jsx("div", { children: ensName }), _jsx("div", { children: truncateAddress(globalAddress) })] })] }), isActiveEOAWallet && _jsx(Icon, { className: "fill-b3-react-primary", name: "check" })] })) : (connectedSmartWallet && (_jsxs("div", { className: cn("mb-2 flex cursor-pointer items-center justify-between rounded-xl p-3", isActiveSmartWallet
40
+ anchor: isMobile ? "top end" : undefined, children: _jsxs("div", { className: "bg-b3-react-background", children: [connectedEOAWallet ? (_jsxs("div", { className: cn("border-b3-react-subtle bg-b3-react-background flex cursor-pointer items-center justify-between rounded-xl p-3"), onClick: () => handleSetActiveAccount(connectedEOAWallet?.id), children: [_jsxs("div", { className: "flex items-center", children: [_jsx("img", { className: "bg-b3-react-primary h-16 w-16 rounded-full opacity-100", src: walletImage, alt: connectedEOAWallet?.id }), _jsxs("div", { className: "ml-4 grow", children: [ensName && _jsx("div", { children: ensName }), _jsx("div", { children: truncateAddress(globalAddress) })] })] }), isActiveEOAWallet && _jsx(Icon, { className: "fill-b3-react-primary", name: "check" })] })) : (connectedSmartWallet && (_jsxs("div", { className: cn("mb-2 flex cursor-pointer items-center justify-between rounded-xl p-3", isActiveSmartWallet
42
41
  ? "bg-b3-react-background"
43
42
  : "bg-b3-react-background hover:bg-b3-react-background"), onClick: () => handleSetActiveAccount(connectedSmartWallet?.id), children: [_jsxs("div", { className: "flex items-center", children: [_jsx("img", { className: "bg-b3-react-primary h-16 w-16 rounded-full opacity-100", src: smartWalletIcon, alt: connectedSmartWallet?.id }), _jsxs("div", { className: "grow pl-4", children: [ensName && _jsx("div", { children: ensName }), _jsx("div", { children: truncateAddress(globalAddress) }), _jsx("div", { children: "Smart wallet" })] })] }), isActiveSmartWallet && _jsx(Icon, { className: "fill-b3-react-primary", name: "check" })] }))), _jsx("div", { className: "ml-3", children: _jsx(ManageAccountButton, { ...props, className: "w-[calc(100%-12px)]" }) }), _jsx("button", { className: "mb-2 w-full space-y-1", onClick: onDisconnect, children: _jsxs("div", { className: "hover:bg-b3-react-background group flex h-12 items-center rounded-xl px-4 transition-colors", children: [_jsx(Icon, { className: "fill-b3-react-primary mr-4 shrink-0 transition-colors", name: "logout" }), _jsx("div", { className: "text-b3-react-primary mr-auto transition-colors", children: "Disconnect" })] }) })] }) }) })] })) : (_jsx(SignInWithB3, { closeAfterLogin: true, onLoginSuccess: async (globalAccount) => {
44
43
  console.log("User authenticated with Global Account!", globalAccount);
@@ -12,7 +12,7 @@ export function LoginStepContainer({ children, partnerId }) {
12
12
  },
13
13
  }, !!partnerId);
14
14
  const partnerLogo = partner?.data?.[0]?.loginCustomization?.logoUrl;
15
- return (_jsxs("div", { className: "flex flex-col items-center justify-center pt-6", children: [partnerLogo && (_jsx("img", { src: partnerLogo, alt: "Partner Logo", className: "partner-logo mb-6 h-12 w-auto object-contain" })), children] }));
15
+ return (_jsxs("div", { className: "bg-b3-react-background flex flex-col items-center justify-center pt-6", children: [partnerLogo && (_jsx("img", { src: partnerLogo, alt: "Partner Logo", className: "partner-logo mb-6 h-12 w-auto object-contain" })), children] }));
16
16
  }
17
17
  export function LoginStep({ onSuccess, chain }) {
18
18
  const { partnerId, theme } = useB3();
@@ -6,7 +6,6 @@ export { useAnalytics } from "./useAnalytics";
6
6
  export { useAuthentication } from "./useAuthentication";
7
7
  export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses";
8
8
  export { useB3EnsName } from "./useB3EnsName";
9
- export { useBestTransactionPath } from "./useBestTransactionPath";
10
9
  export { useChainSwitchWithAction } from "./useChainSwitchWithAction";
11
10
  export * from "./useClaim";
12
11
  export { useClient } from "./useClient";
@@ -6,7 +6,6 @@ export { useAnalytics } from "./useAnalytics.js";
6
6
  export { useAuthentication } from "./useAuthentication.js";
7
7
  export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses.js";
8
8
  export { useB3EnsName } from "./useB3EnsName.js";
9
- export { useBestTransactionPath } from "./useBestTransactionPath.js";
10
9
  export { useChainSwitchWithAction } from "./useChainSwitchWithAction.js";
11
10
  export * from "./useClaim.js";
12
11
  export { useClient } from "./useClient.js";
@@ -1,7 +1,6 @@
1
1
  import { useB3, useProfile } from "../../../global-account/react/index.js";
2
2
  import { ecosystemWalletId } from "../../../shared/constants/index.js";
3
3
  import { debugB3React } from "../../../shared/utils/debug.js";
4
- import { getIpfsUrl } from "../../../shared/utils/ipfs.js";
5
4
  import { useEffect, useMemo, useState } from "react";
6
5
  import { getLastAuthProvider, useActiveWallet, useConnectedWallets, useWalletImage } from "thirdweb/react";
7
6
  import { socialIcons } from "thirdweb/wallets/in-app";
@@ -18,7 +17,13 @@ function useLastAuthProvider() {
18
17
  return lastAuthProvider;
19
18
  }
20
19
  export function useAccountWallet() {
21
- const { account, user } = useB3();
20
+ // WOJ: --------------------
21
+ // values from in useB3:
22
+ // const activeAccount = useActiveAccount();
23
+ // const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
24
+ // can we possibly just use useActiveAccount here?
25
+ // --------------------
26
+ const { account } = useB3();
22
27
  const activeWallet = useActiveWallet();
23
28
  const connectedWallets = useConnectedWallets();
24
29
  const connectedSmartWallet = connectedWallets.find(wallet => wallet.id === ecosystemWalletId);
@@ -31,7 +36,6 @@ export function useAccountWallet() {
31
36
  debug("connectedEOAWallet", connectedEOAWallet);
32
37
  debug("isActiveSmartWallet", isActiveSmartWallet);
33
38
  debug("isActiveEOAWallet", isActiveEOAWallet);
34
- const { data: walletImage } = useWalletImage(connectedEOAWallet?.id);
35
39
  // If not EOA sign in, then we need to show the smart wallet icon
36
40
  const lastAuthProvider = useLastAuthProvider();
37
41
  const smartWalletIcon = lastAuthProvider && !connectedEOAWallet
@@ -39,13 +43,12 @@ export function useAccountWallet() {
39
43
  : "https://gradvatar.com/0x0000000000000000000000000000000000000000"; // show smart wallet of eoa wallet is gradvatar
40
44
  const { data: profileData } = useProfile({ address: account?.address });
41
45
  const ensName = profileData?.displayName?.replace(/\.b3\.fun/g, "");
42
- const avatarUrl = user?.avatar ? getIpfsUrl(user?.avatar) : profileData?.avatar;
43
46
  const res = useMemo(() => ({
44
47
  wallet: {
45
48
  ...account,
46
49
  ensName,
47
50
  meta: {
48
- icon: avatarUrl || (isActiveSmartWallet ? smartWalletIcon : walletImage) || "",
51
+ icon: "", // deprecated
49
52
  },
50
53
  },
51
54
  address: account?.address,
@@ -55,22 +58,20 @@ export function useAccountWallet() {
55
58
  isActiveSmartWallet: isActiveSmartWallet,
56
59
  isActiveEOAWallet: isActiveEOAWallet,
57
60
  smartWalletIcon: smartWalletIcon,
58
- eoaWalletIcon: walletImage,
61
+ eoaWalletIcon: "", // deprecated
59
62
  }), [
60
63
  account,
61
- avatarUrl,
62
64
  connectedEOAWallet,
63
65
  connectedSmartWallet,
64
66
  ensName,
65
67
  isActiveEOAWallet,
66
68
  isActiveSmartWallet,
67
69
  smartWalletIcon,
68
- walletImage,
69
70
  ]);
70
71
  return res;
71
72
  }
72
73
  export function useAccountWalletImage() {
73
- const { account, user } = useB3();
74
+ const { account } = useB3();
74
75
  const activeWallet = useActiveWallet();
75
76
  const connectedWallets = useConnectedWallets();
76
77
  const connectedSmartWallet = connectedWallets.find(wallet => wallet.id === ecosystemWalletId);
@@ -83,6 +84,6 @@ export function useAccountWalletImage() {
83
84
  ? socialIcons[lastAuthProvider]
84
85
  : "https://gradvatar.com/0x0000000000000000000000000000000000000000"; // show smart wallet of eoa wallet is gradvatar
85
86
  const { data: profileData } = useProfile({ address: account?.address });
86
- const avatarUrl = user?.avatar || profileData?.avatar;
87
+ const avatarUrl = profileData?.avatar;
87
88
  return avatarUrl || (isActiveSmartWallet ? smartWalletIcon : walletImage) || "";
88
89
  }
@@ -6,7 +6,6 @@ export { useAnalytics } from "./useAnalytics";
6
6
  export { useAuthentication } from "./useAuthentication";
7
7
  export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses";
8
8
  export { useB3EnsName } from "./useB3EnsName";
9
- export { useBestTransactionPath } from "./useBestTransactionPath";
10
9
  export { useChainSwitchWithAction } from "./useChainSwitchWithAction";
11
10
  export * from "./useClaim";
12
11
  export { useClient } from "./useClient";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.83-alpha.4",
3
+ "version": "0.0.83-alpha.5",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -13,8 +13,7 @@ import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
13
13
  import { cn, truncateAddress } from "@b3dotfun/sdk/shared/utils";
14
14
  import { Menu, MenuButton, MenuItems, Transition } from "@headlessui/react";
15
15
  import { ReactNode, useEffect } from "react";
16
- import { useConnectedWallets, useSetActiveWallet } from "thirdweb/react";
17
- import { useAccountWalletImage } from "../../hooks/useAccountWallet";
16
+ import { useConnectedWallets, useSetActiveWallet, useWalletImage } from "thirdweb/react";
18
17
  import { ManageAccountButton } from "../custom/ManageAccountButton";
19
18
 
20
19
  type SignInProps = {
@@ -40,9 +39,10 @@ export function SignIn(props: SignInWithB3Props) {
40
39
  isActiveSmartWallet,
41
40
  isActiveEOAWallet,
42
41
  smartWalletIcon,
43
- eoaWalletIcon,
44
42
  } = useAccountWallet();
45
43
 
44
+ const { data: walletImage } = useWalletImage(connectedEOAWallet?.id);
45
+
46
46
  const isMobile = useIsMobile();
47
47
  const { logout } = useAuthentication(partnerId);
48
48
  const onDisconnect = async (): Promise<void> => {
@@ -72,8 +72,6 @@ export function SignIn(props: SignInWithB3Props) {
72
72
  }
73
73
  }, [connectedEOAWallet, isActiveEOAWallet, setActiveWallet, automaticallySetFirstEoa]);
74
74
 
75
- const walletImage = useAccountWalletImage();
76
-
77
75
  // Desktop version - original dropdown menu
78
76
  return (
79
77
  <StyleRoot>
@@ -115,7 +113,7 @@ export function SignIn(props: SignInWithB3Props) {
115
113
  <div className="flex items-center">
116
114
  <img
117
115
  className="bg-b3-react-primary h-16 w-16 rounded-full opacity-100"
118
- src={eoaWalletIcon}
116
+ src={walletImage}
119
117
  alt={connectedEOAWallet?.id}
120
118
  />
121
119
  <div className="ml-4 grow">
@@ -40,7 +40,7 @@ export function LoginStepContainer({ children, partnerId }: LoginStepContainerPr
40
40
  const partnerLogo = partner?.data?.[0]?.loginCustomization?.logoUrl;
41
41
 
42
42
  return (
43
- <div className="flex flex-col items-center justify-center pt-6">
43
+ <div className="bg-b3-react-background flex flex-col items-center justify-center pt-6">
44
44
  {partnerLogo && (
45
45
  <img src={partnerLogo} alt="Partner Logo" className="partner-logo mb-6 h-12 w-auto object-contain" />
46
46
  )}
@@ -6,7 +6,6 @@ export { useAnalytics } from "./useAnalytics";
6
6
  export { useAuthentication } from "./useAuthentication";
7
7
  export { useB3BalanceFromAddresses } from "./useB3BalanceFromAddresses";
8
8
  export { useB3EnsName } from "./useB3EnsName";
9
- export { useBestTransactionPath } from "./useBestTransactionPath";
10
9
  export { useChainSwitchWithAction } from "./useChainSwitchWithAction";
11
10
  export * from "./useClaim";
12
11
  export { useClient } from "./useClient";
@@ -1,7 +1,6 @@
1
1
  import { useB3, useProfile } from "@b3dotfun/sdk/global-account/react";
2
2
  import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
3
3
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
4
- import { getIpfsUrl } from "@b3dotfun/sdk/shared/utils/ipfs";
5
4
  import { useEffect, useMemo, useState } from "react";
6
5
  import { getLastAuthProvider, useActiveWallet, useConnectedWallets, useWalletImage } from "thirdweb/react";
7
6
  import { Account, Wallet } from "thirdweb/wallets";
@@ -44,7 +43,13 @@ export function useAccountWallet(): {
44
43
  eoaWalletIcon?: string;
45
44
  smartWalletIcon?: string;
46
45
  } {
47
- const { account, user } = useB3();
46
+ // WOJ: --------------------
47
+ // values from in useB3:
48
+ // const activeAccount = useActiveAccount();
49
+ // const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
50
+ // can we possibly just use useActiveAccount here?
51
+ // --------------------
52
+ const { account } = useB3();
48
53
 
49
54
  const activeWallet = useActiveWallet();
50
55
  const connectedWallets = useConnectedWallets();
@@ -61,8 +66,6 @@ export function useAccountWallet(): {
61
66
  debug("isActiveSmartWallet", isActiveSmartWallet);
62
67
  debug("isActiveEOAWallet", isActiveEOAWallet);
63
68
 
64
- const { data: walletImage } = useWalletImage(connectedEOAWallet?.id);
65
-
66
69
  // If not EOA sign in, then we need to show the smart wallet icon
67
70
  const lastAuthProvider = useLastAuthProvider();
68
71
 
@@ -73,7 +76,6 @@ export function useAccountWallet(): {
73
76
 
74
77
  const { data: profileData } = useProfile({ address: account?.address });
75
78
  const ensName = profileData?.displayName?.replace(/\.b3\.fun/g, "");
76
- const avatarUrl = user?.avatar ? getIpfsUrl(user?.avatar) : profileData?.avatar;
77
79
 
78
80
  const res = useMemo(
79
81
  () => ({
@@ -81,7 +83,7 @@ export function useAccountWallet(): {
81
83
  ...account,
82
84
  ensName,
83
85
  meta: {
84
- icon: avatarUrl || (isActiveSmartWallet ? smartWalletIcon : walletImage) || "",
86
+ icon: "", // deprecated
85
87
  },
86
88
  },
87
89
 
@@ -95,18 +97,16 @@ export function useAccountWallet(): {
95
97
  isActiveEOAWallet: isActiveEOAWallet,
96
98
 
97
99
  smartWalletIcon: smartWalletIcon,
98
- eoaWalletIcon: walletImage,
100
+ eoaWalletIcon: "", // deprecated
99
101
  }),
100
102
  [
101
103
  account,
102
- avatarUrl,
103
104
  connectedEOAWallet,
104
105
  connectedSmartWallet,
105
106
  ensName,
106
107
  isActiveEOAWallet,
107
108
  isActiveSmartWallet,
108
109
  smartWalletIcon,
109
- walletImage,
110
110
  ],
111
111
  );
112
112
 
@@ -114,7 +114,7 @@ export function useAccountWallet(): {
114
114
  }
115
115
 
116
116
  export function useAccountWalletImage(): string {
117
- const { account, user } = useB3();
117
+ const { account } = useB3();
118
118
 
119
119
  const activeWallet = useActiveWallet();
120
120
  const connectedWallets = useConnectedWallets();
@@ -134,7 +134,8 @@ export function useAccountWalletImage(): string {
134
134
  : "https://gradvatar.com/0x0000000000000000000000000000000000000000"; // show smart wallet of eoa wallet is gradvatar
135
135
 
136
136
  const { data: profileData } = useProfile({ address: account?.address });
137
- const avatarUrl = user?.avatar || profileData?.avatar;
137
+
138
+ const avatarUrl = profileData?.avatar;
138
139
 
139
140
  return avatarUrl || (isActiveSmartWallet ? smartWalletIcon : walletImage) || "";
140
141
  }
@@ -1,41 +0,0 @@
1
- import { components } from "../../../anyspend/types/api";
2
- export type TransactionType = "send" | "swap" | "bridge";
3
- export interface SprinterOption {
4
- chainId: number;
5
- balance: bigint;
6
- formattedBalance: string;
7
- }
8
- export interface TransactionPath {
9
- type: "native" | "sprinter" | "anyspend";
10
- hasNativePath: boolean;
11
- hasSprinterPath: boolean;
12
- availableBalance: bigint;
13
- totalCrossChainBalance: number;
14
- sprinterOptions?: SprinterOption[];
15
- }
16
- export interface TransactionPathResult extends TransactionPath {
17
- loading: boolean;
18
- }
19
- interface UseBestTransactionPathProps {
20
- amount: bigint;
21
- token: components["schemas"]["Token"];
22
- address?: string;
23
- transactionType?: TransactionType;
24
- }
25
- /**
26
- * Hook to determine the optimal transaction path based on user's balances across chains
27
- *
28
- * @param props.amount - Amount to transact
29
- * @param props.token - Token (a Token object)
30
- * @param props.address - Target address (optional, defaults to self)
31
- * @param props.transactionType - Type of transaction (optional, defaults to 'send')
32
- *
33
- * - type: The recommended path type ('native', 'sprinter', or 'anyspend')
34
- * - hasNativePath: Whether direct native token transfer is possible (1st best path)
35
- * - hasSprinterPath: Whether bridging via Sprinter is possible (2nd best path)
36
- * - availableBalance: The user's balance of this asset
37
- * - sprinterOptions: Available chains and balances for bridging
38
- * @returns TransactionPathResult object containing path information and loading state
39
- */
40
- export declare function useBestTransactionPath({ amount, token, address, transactionType: _transactionType, }: UseBestTransactionPathProps): TransactionPathResult;
41
- export {};
@@ -1,148 +0,0 @@
1
- "use strict";
2
- "use client";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.useBestTransactionPath = useBestTransactionPath;
5
- const anyspend_1 = require("../../../anyspend");
6
- const react_1 = require("../../../global-account/react");
7
- const react_2 = require("react");
8
- const viem_1 = require("viem");
9
- const supportedSprinterTokenSymbols = ["ETH", "USDC", "WETH"];
10
- /**
11
- * Hook to determine the optimal transaction path based on user's balances across chains
12
- *
13
- * @param props.amount - Amount to transact
14
- * @param props.token - Token (a Token object)
15
- * @param props.address - Target address (optional, defaults to self)
16
- * @param props.transactionType - Type of transaction (optional, defaults to 'send')
17
- *
18
- * - type: The recommended path type ('native', 'sprinter', or 'anyspend')
19
- * - hasNativePath: Whether direct native token transfer is possible (1st best path)
20
- * - hasSprinterPath: Whether bridging via Sprinter is possible (2nd best path)
21
- * - availableBalance: The user's balance of this asset
22
- * - sprinterOptions: Available chains and balances for bridging
23
- * @returns TransactionPathResult object containing path information and loading state
24
- */
25
- function useBestTransactionPath({ amount, token, address, transactionType: _transactionType = "send", }) {
26
- const account = (0, react_1.useAccountWallet)();
27
- const effectiveAddress = address || account?.address;
28
- const isSupportedSprinterToken = supportedSprinterTokenSymbols.includes(token.symbol.toUpperCase());
29
- // Get balances across all chains
30
- const { aggregatedBalances, aggregatedTokenBalances, loading: oneBalanceLoading } = (0, react_1.useOneBalance)();
31
- // Get the token balance using our new hook
32
- const { rawBalance, isLoading: tokenBalanceLoading } = (0, react_1.useTokenBalance)({
33
- token,
34
- address: effectiveAddress,
35
- });
36
- // Check if amount is available natively on destination chain
37
- const hasNativeBalance = (0, react_2.useMemo)(() => {
38
- if (!rawBalance || !amount)
39
- return false;
40
- return rawBalance >= amount;
41
- }, [amount, rawBalance]);
42
- // Calculate non-native token balance using the same logic as hasNativeBalance
43
- const nonNativeTokenBalance = (0, react_2.useMemo)(() => {
44
- if ((0, anyspend_1.isNativeToken)(token.address))
45
- return BigInt(0);
46
- // For sprinter supported tokens, use aggregated balances
47
- if (isSupportedSprinterToken && !oneBalanceLoading && aggregatedBalances) {
48
- const asset = aggregatedBalances.find(asset => asset.symbol === token.symbol);
49
- if (asset) {
50
- const chainBalance = asset.chainBalances.find(cb => cb.chainId === token.chainId);
51
- if (chainBalance) {
52
- return BigInt(chainBalance.balance);
53
- }
54
- }
55
- return BigInt(0);
56
- }
57
- // For non-sprinter tokens, use token balance from our new hook
58
- return rawBalance;
59
- }, [
60
- token.address,
61
- token.symbol,
62
- token.chainId,
63
- isSupportedSprinterToken,
64
- oneBalanceLoading,
65
- aggregatedBalances,
66
- rawBalance,
67
- ]);
68
- const totalCrossChainBalance = (0, react_2.useMemo)(() => {
69
- if (oneBalanceLoading || !aggregatedTokenBalances || !token.symbol)
70
- return 0;
71
- return aggregatedTokenBalances[token.symbol] || 0;
72
- }, [aggregatedTokenBalances, token.symbol, oneBalanceLoading]);
73
- // Calculate available sprinter options and determine if sprinter path is available
74
- const { hasSprinterPath, sprinterOptions } = (0, react_2.useMemo)(() => {
75
- if (!isSupportedSprinterToken || oneBalanceLoading || !aggregatedBalances || !token.symbol || !amount) {
76
- return { hasSprinterPath: false, sprinterOptions: [] };
77
- }
78
- const asset = aggregatedBalances.find(asset => asset.symbol === token.symbol);
79
- if (!asset) {
80
- return { hasSprinterPath: false, sprinterOptions: [] };
81
- }
82
- const options = [];
83
- // Get all chains where user has sufficient balance
84
- for (const chainBalance of asset.chainBalances) {
85
- const balanceBi = BigInt(chainBalance.balance);
86
- if (balanceBi >= amount && chainBalance.chainId !== token.chainId) {
87
- options.push({
88
- chainId: chainBalance.chainId,
89
- balance: balanceBi,
90
- formattedBalance: (0, viem_1.formatUnits)(balanceBi, chainBalance.tokenDecimals),
91
- });
92
- }
93
- }
94
- return {
95
- hasSprinterPath: options.length > 0,
96
- sprinterOptions: options,
97
- };
98
- }, [isSupportedSprinterToken, oneBalanceLoading, aggregatedBalances, token.symbol, token.chainId, amount]);
99
- // Determine the best path
100
- const path = (0, react_2.useMemo)(() => {
101
- const availableBalance = ((0, anyspend_1.isNativeToken)(token.address) ? rawBalance : nonNativeTokenBalance) || BigInt(0);
102
- // Case 1: Native path if available
103
- if (hasNativeBalance) {
104
- return {
105
- type: "native",
106
- hasNativePath: true,
107
- hasSprinterPath,
108
- availableBalance,
109
- totalCrossChainBalance,
110
- sprinterOptions,
111
- };
112
- }
113
- // Case 2: Sprinter path if available
114
- if (hasSprinterPath) {
115
- return {
116
- type: "sprinter",
117
- hasNativePath: false,
118
- hasSprinterPath: true,
119
- availableBalance,
120
- totalCrossChainBalance,
121
- sprinterOptions,
122
- };
123
- }
124
- // Case 3: Fallback to anyspend
125
- return {
126
- type: "anyspend",
127
- hasNativePath: false,
128
- hasSprinterPath: false,
129
- availableBalance,
130
- totalCrossChainBalance,
131
- sprinterOptions: [],
132
- };
133
- }, [
134
- token.address,
135
- rawBalance,
136
- nonNativeTokenBalance,
137
- hasNativeBalance,
138
- hasSprinterPath,
139
- totalCrossChainBalance,
140
- sprinterOptions,
141
- ]);
142
- // Combine all loading states
143
- const loading = oneBalanceLoading || tokenBalanceLoading;
144
- return {
145
- ...path,
146
- loading,
147
- };
148
- }
@@ -1,41 +0,0 @@
1
- import { components } from "../../../anyspend/types/api";
2
- export type TransactionType = "send" | "swap" | "bridge";
3
- export interface SprinterOption {
4
- chainId: number;
5
- balance: bigint;
6
- formattedBalance: string;
7
- }
8
- export interface TransactionPath {
9
- type: "native" | "sprinter" | "anyspend";
10
- hasNativePath: boolean;
11
- hasSprinterPath: boolean;
12
- availableBalance: bigint;
13
- totalCrossChainBalance: number;
14
- sprinterOptions?: SprinterOption[];
15
- }
16
- export interface TransactionPathResult extends TransactionPath {
17
- loading: boolean;
18
- }
19
- interface UseBestTransactionPathProps {
20
- amount: bigint;
21
- token: components["schemas"]["Token"];
22
- address?: string;
23
- transactionType?: TransactionType;
24
- }
25
- /**
26
- * Hook to determine the optimal transaction path based on user's balances across chains
27
- *
28
- * @param props.amount - Amount to transact
29
- * @param props.token - Token (a Token object)
30
- * @param props.address - Target address (optional, defaults to self)
31
- * @param props.transactionType - Type of transaction (optional, defaults to 'send')
32
- *
33
- * - type: The recommended path type ('native', 'sprinter', or 'anyspend')
34
- * - hasNativePath: Whether direct native token transfer is possible (1st best path)
35
- * - hasSprinterPath: Whether bridging via Sprinter is possible (2nd best path)
36
- * - availableBalance: The user's balance of this asset
37
- * - sprinterOptions: Available chains and balances for bridging
38
- * @returns TransactionPathResult object containing path information and loading state
39
- */
40
- export declare function useBestTransactionPath({ amount, token, address, transactionType: _transactionType, }: UseBestTransactionPathProps): TransactionPathResult;
41
- export {};
@@ -1,145 +0,0 @@
1
- "use client";
2
- import { isNativeToken } from "../../../anyspend/index.js";
3
- import { useAccountWallet, useOneBalance, useTokenBalance } from "../../../global-account/react/index.js";
4
- import { useMemo } from "react";
5
- import { formatUnits } from "viem";
6
- const supportedSprinterTokenSymbols = ["ETH", "USDC", "WETH"];
7
- /**
8
- * Hook to determine the optimal transaction path based on user's balances across chains
9
- *
10
- * @param props.amount - Amount to transact
11
- * @param props.token - Token (a Token object)
12
- * @param props.address - Target address (optional, defaults to self)
13
- * @param props.transactionType - Type of transaction (optional, defaults to 'send')
14
- *
15
- * - type: The recommended path type ('native', 'sprinter', or 'anyspend')
16
- * - hasNativePath: Whether direct native token transfer is possible (1st best path)
17
- * - hasSprinterPath: Whether bridging via Sprinter is possible (2nd best path)
18
- * - availableBalance: The user's balance of this asset
19
- * - sprinterOptions: Available chains and balances for bridging
20
- * @returns TransactionPathResult object containing path information and loading state
21
- */
22
- export function useBestTransactionPath({ amount, token, address, transactionType: _transactionType = "send", }) {
23
- const account = useAccountWallet();
24
- const effectiveAddress = address || account?.address;
25
- const isSupportedSprinterToken = supportedSprinterTokenSymbols.includes(token.symbol.toUpperCase());
26
- // Get balances across all chains
27
- const { aggregatedBalances, aggregatedTokenBalances, loading: oneBalanceLoading } = useOneBalance();
28
- // Get the token balance using our new hook
29
- const { rawBalance, isLoading: tokenBalanceLoading } = useTokenBalance({
30
- token,
31
- address: effectiveAddress,
32
- });
33
- // Check if amount is available natively on destination chain
34
- const hasNativeBalance = useMemo(() => {
35
- if (!rawBalance || !amount)
36
- return false;
37
- return rawBalance >= amount;
38
- }, [amount, rawBalance]);
39
- // Calculate non-native token balance using the same logic as hasNativeBalance
40
- const nonNativeTokenBalance = useMemo(() => {
41
- if (isNativeToken(token.address))
42
- return BigInt(0);
43
- // For sprinter supported tokens, use aggregated balances
44
- if (isSupportedSprinterToken && !oneBalanceLoading && aggregatedBalances) {
45
- const asset = aggregatedBalances.find(asset => asset.symbol === token.symbol);
46
- if (asset) {
47
- const chainBalance = asset.chainBalances.find(cb => cb.chainId === token.chainId);
48
- if (chainBalance) {
49
- return BigInt(chainBalance.balance);
50
- }
51
- }
52
- return BigInt(0);
53
- }
54
- // For non-sprinter tokens, use token balance from our new hook
55
- return rawBalance;
56
- }, [
57
- token.address,
58
- token.symbol,
59
- token.chainId,
60
- isSupportedSprinterToken,
61
- oneBalanceLoading,
62
- aggregatedBalances,
63
- rawBalance,
64
- ]);
65
- const totalCrossChainBalance = useMemo(() => {
66
- if (oneBalanceLoading || !aggregatedTokenBalances || !token.symbol)
67
- return 0;
68
- return aggregatedTokenBalances[token.symbol] || 0;
69
- }, [aggregatedTokenBalances, token.symbol, oneBalanceLoading]);
70
- // Calculate available sprinter options and determine if sprinter path is available
71
- const { hasSprinterPath, sprinterOptions } = useMemo(() => {
72
- if (!isSupportedSprinterToken || oneBalanceLoading || !aggregatedBalances || !token.symbol || !amount) {
73
- return { hasSprinterPath: false, sprinterOptions: [] };
74
- }
75
- const asset = aggregatedBalances.find(asset => asset.symbol === token.symbol);
76
- if (!asset) {
77
- return { hasSprinterPath: false, sprinterOptions: [] };
78
- }
79
- const options = [];
80
- // Get all chains where user has sufficient balance
81
- for (const chainBalance of asset.chainBalances) {
82
- const balanceBi = BigInt(chainBalance.balance);
83
- if (balanceBi >= amount && chainBalance.chainId !== token.chainId) {
84
- options.push({
85
- chainId: chainBalance.chainId,
86
- balance: balanceBi,
87
- formattedBalance: formatUnits(balanceBi, chainBalance.tokenDecimals),
88
- });
89
- }
90
- }
91
- return {
92
- hasSprinterPath: options.length > 0,
93
- sprinterOptions: options,
94
- };
95
- }, [isSupportedSprinterToken, oneBalanceLoading, aggregatedBalances, token.symbol, token.chainId, amount]);
96
- // Determine the best path
97
- const path = useMemo(() => {
98
- const availableBalance = (isNativeToken(token.address) ? rawBalance : nonNativeTokenBalance) || BigInt(0);
99
- // Case 1: Native path if available
100
- if (hasNativeBalance) {
101
- return {
102
- type: "native",
103
- hasNativePath: true,
104
- hasSprinterPath,
105
- availableBalance,
106
- totalCrossChainBalance,
107
- sprinterOptions,
108
- };
109
- }
110
- // Case 2: Sprinter path if available
111
- if (hasSprinterPath) {
112
- return {
113
- type: "sprinter",
114
- hasNativePath: false,
115
- hasSprinterPath: true,
116
- availableBalance,
117
- totalCrossChainBalance,
118
- sprinterOptions,
119
- };
120
- }
121
- // Case 3: Fallback to anyspend
122
- return {
123
- type: "anyspend",
124
- hasNativePath: false,
125
- hasSprinterPath: false,
126
- availableBalance,
127
- totalCrossChainBalance,
128
- sprinterOptions: [],
129
- };
130
- }, [
131
- token.address,
132
- rawBalance,
133
- nonNativeTokenBalance,
134
- hasNativeBalance,
135
- hasSprinterPath,
136
- totalCrossChainBalance,
137
- sprinterOptions,
138
- ]);
139
- // Combine all loading states
140
- const loading = oneBalanceLoading || tokenBalanceLoading;
141
- return {
142
- ...path,
143
- loading,
144
- };
145
- }
@@ -1,41 +0,0 @@
1
- import { components } from "@b3dotfun/sdk/anyspend/types/api";
2
- export type TransactionType = "send" | "swap" | "bridge";
3
- export interface SprinterOption {
4
- chainId: number;
5
- balance: bigint;
6
- formattedBalance: string;
7
- }
8
- export interface TransactionPath {
9
- type: "native" | "sprinter" | "anyspend";
10
- hasNativePath: boolean;
11
- hasSprinterPath: boolean;
12
- availableBalance: bigint;
13
- totalCrossChainBalance: number;
14
- sprinterOptions?: SprinterOption[];
15
- }
16
- export interface TransactionPathResult extends TransactionPath {
17
- loading: boolean;
18
- }
19
- interface UseBestTransactionPathProps {
20
- amount: bigint;
21
- token: components["schemas"]["Token"];
22
- address?: string;
23
- transactionType?: TransactionType;
24
- }
25
- /**
26
- * Hook to determine the optimal transaction path based on user's balances across chains
27
- *
28
- * @param props.amount - Amount to transact
29
- * @param props.token - Token (a Token object)
30
- * @param props.address - Target address (optional, defaults to self)
31
- * @param props.transactionType - Type of transaction (optional, defaults to 'send')
32
- *
33
- * - type: The recommended path type ('native', 'sprinter', or 'anyspend')
34
- * - hasNativePath: Whether direct native token transfer is possible (1st best path)
35
- * - hasSprinterPath: Whether bridging via Sprinter is possible (2nd best path)
36
- * - availableBalance: The user's balance of this asset
37
- * - sprinterOptions: Available chains and balances for bridging
38
- * @returns TransactionPathResult object containing path information and loading state
39
- */
40
- export declare function useBestTransactionPath({ amount, token, address, transactionType: _transactionType, }: UseBestTransactionPathProps): TransactionPathResult;
41
- export {};
@@ -1,201 +0,0 @@
1
- "use client";
2
-
3
- import { isNativeToken } from "@b3dotfun/sdk/anyspend";
4
- import { useAccountWallet, useOneBalance, useTokenBalance } from "@b3dotfun/sdk/global-account/react";
5
- import { useMemo } from "react";
6
- import { formatUnits } from "viem";
7
- import { components } from "@b3dotfun/sdk/anyspend/types/api";
8
-
9
- export type TransactionType = "send" | "swap" | "bridge";
10
-
11
- const supportedSprinterTokenSymbols = ["ETH", "USDC", "WETH"] as const;
12
-
13
- export interface SprinterOption {
14
- chainId: number;
15
- balance: bigint;
16
- formattedBalance: string;
17
- }
18
-
19
- export interface TransactionPath {
20
- type: "native" | "sprinter" | "anyspend";
21
- hasNativePath: boolean;
22
- hasSprinterPath: boolean;
23
- availableBalance: bigint;
24
- totalCrossChainBalance: number;
25
- sprinterOptions?: SprinterOption[];
26
- }
27
-
28
- export interface TransactionPathResult extends TransactionPath {
29
- loading: boolean;
30
- }
31
-
32
- interface UseBestTransactionPathProps {
33
- amount: bigint;
34
- token: components["schemas"]["Token"];
35
- address?: string;
36
- transactionType?: TransactionType;
37
- }
38
-
39
- /**
40
- * Hook to determine the optimal transaction path based on user's balances across chains
41
- *
42
- * @param props.amount - Amount to transact
43
- * @param props.token - Token (a Token object)
44
- * @param props.address - Target address (optional, defaults to self)
45
- * @param props.transactionType - Type of transaction (optional, defaults to 'send')
46
- *
47
- * - type: The recommended path type ('native', 'sprinter', or 'anyspend')
48
- * - hasNativePath: Whether direct native token transfer is possible (1st best path)
49
- * - hasSprinterPath: Whether bridging via Sprinter is possible (2nd best path)
50
- * - availableBalance: The user's balance of this asset
51
- * - sprinterOptions: Available chains and balances for bridging
52
- * @returns TransactionPathResult object containing path information and loading state
53
- */
54
- export function useBestTransactionPath({
55
- amount,
56
- token,
57
- address,
58
- transactionType: _transactionType = "send",
59
- }: UseBestTransactionPathProps): TransactionPathResult {
60
- const account = useAccountWallet();
61
- const effectiveAddress = address || account?.address;
62
-
63
- const isSupportedSprinterToken = supportedSprinterTokenSymbols.includes(
64
- token.symbol.toUpperCase() as (typeof supportedSprinterTokenSymbols)[number],
65
- );
66
-
67
- // Get balances across all chains
68
- const { aggregatedBalances, aggregatedTokenBalances, loading: oneBalanceLoading } = useOneBalance();
69
-
70
- // Get the token balance using our new hook
71
- const { rawBalance, isLoading: tokenBalanceLoading } = useTokenBalance({
72
- token,
73
- address: effectiveAddress,
74
- });
75
-
76
- // Check if amount is available natively on destination chain
77
- const hasNativeBalance = useMemo(() => {
78
- if (!rawBalance || !amount) return false;
79
-
80
- return rawBalance >= amount;
81
- }, [amount, rawBalance]);
82
-
83
- // Calculate non-native token balance using the same logic as hasNativeBalance
84
- const nonNativeTokenBalance = useMemo(() => {
85
- if (isNativeToken(token.address)) return BigInt(0);
86
-
87
- // For sprinter supported tokens, use aggregated balances
88
- if (isSupportedSprinterToken && !oneBalanceLoading && aggregatedBalances) {
89
- const asset = aggregatedBalances.find(asset => asset.symbol === token.symbol);
90
- if (asset) {
91
- const chainBalance = asset.chainBalances.find(cb => cb.chainId === token.chainId);
92
- if (chainBalance) {
93
- return BigInt(chainBalance.balance);
94
- }
95
- }
96
- return BigInt(0);
97
- }
98
-
99
- // For non-sprinter tokens, use token balance from our new hook
100
- return rawBalance;
101
- }, [
102
- token.address,
103
- token.symbol,
104
- token.chainId,
105
- isSupportedSprinterToken,
106
- oneBalanceLoading,
107
- aggregatedBalances,
108
- rawBalance,
109
- ]);
110
-
111
- const totalCrossChainBalance = useMemo(() => {
112
- if (oneBalanceLoading || !aggregatedTokenBalances || !token.symbol) return 0;
113
- return aggregatedTokenBalances[token.symbol] || 0;
114
- }, [aggregatedTokenBalances, token.symbol, oneBalanceLoading]);
115
-
116
- // Calculate available sprinter options and determine if sprinter path is available
117
- const { hasSprinterPath, sprinterOptions } = useMemo(() => {
118
- if (!isSupportedSprinterToken || oneBalanceLoading || !aggregatedBalances || !token.symbol || !amount) {
119
- return { hasSprinterPath: false, sprinterOptions: [] };
120
- }
121
-
122
- const asset = aggregatedBalances.find(asset => asset.symbol === token.symbol);
123
- if (!asset) {
124
- return { hasSprinterPath: false, sprinterOptions: [] };
125
- }
126
-
127
- const options: SprinterOption[] = [];
128
-
129
- // Get all chains where user has sufficient balance
130
- for (const chainBalance of asset.chainBalances) {
131
- const balanceBi = BigInt(chainBalance.balance);
132
- if (balanceBi >= amount && chainBalance.chainId !== token.chainId) {
133
- options.push({
134
- chainId: chainBalance.chainId,
135
- balance: balanceBi,
136
- formattedBalance: formatUnits(balanceBi, chainBalance.tokenDecimals),
137
- });
138
- }
139
- }
140
-
141
- return {
142
- hasSprinterPath: options.length > 0,
143
- sprinterOptions: options,
144
- };
145
- }, [isSupportedSprinterToken, oneBalanceLoading, aggregatedBalances, token.symbol, token.chainId, amount]);
146
-
147
- // Determine the best path
148
- const path = useMemo(() => {
149
- const availableBalance = (isNativeToken(token.address) ? rawBalance : nonNativeTokenBalance) || BigInt(0);
150
-
151
- // Case 1: Native path if available
152
- if (hasNativeBalance) {
153
- return {
154
- type: "native" as const,
155
- hasNativePath: true,
156
- hasSprinterPath,
157
- availableBalance,
158
- totalCrossChainBalance,
159
- sprinterOptions,
160
- };
161
- }
162
-
163
- // Case 2: Sprinter path if available
164
- if (hasSprinterPath) {
165
- return {
166
- type: "sprinter" as const,
167
- hasNativePath: false,
168
- hasSprinterPath: true,
169
- availableBalance,
170
- totalCrossChainBalance,
171
- sprinterOptions,
172
- };
173
- }
174
-
175
- // Case 3: Fallback to anyspend
176
- return {
177
- type: "anyspend" as const,
178
- hasNativePath: false,
179
- hasSprinterPath: false,
180
- availableBalance,
181
- totalCrossChainBalance,
182
- sprinterOptions: [],
183
- };
184
- }, [
185
- token.address,
186
- rawBalance,
187
- nonNativeTokenBalance,
188
- hasNativeBalance,
189
- hasSprinterPath,
190
- totalCrossChainBalance,
191
- sprinterOptions,
192
- ]);
193
-
194
- // Combine all loading states
195
- const loading = oneBalanceLoading || tokenBalanceLoading;
196
-
197
- return {
198
- ...path,
199
- loading,
200
- };
201
- }