@b3dotfun/sdk 0.0.83-alpha.3 → 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 (46) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +3 -2
  2. package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +2 -4
  3. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
  4. package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +28 -0
  5. package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
  6. package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.js +5 -8
  7. package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
  8. package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
  9. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +3 -4
  10. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
  11. package/dist/cjs/global-account/react/hooks/index.d.ts +0 -1
  12. package/dist/cjs/global-account/react/hooks/index.js +1 -3
  13. package/dist/cjs/global-account/react/hooks/useAccountWallet.js +11 -10
  14. package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -2
  15. package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +4 -6
  16. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
  17. package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +25 -0
  18. package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
  19. package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.js +6 -9
  20. package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
  21. package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
  22. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +4 -5
  23. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
  24. package/dist/esm/global-account/react/hooks/index.d.ts +0 -1
  25. package/dist/esm/global-account/react/hooks/index.js +0 -1
  26. package/dist/esm/global-account/react/hooks/useAccountWallet.js +11 -10
  27. package/dist/types/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
  28. package/dist/types/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
  29. package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
  30. package/dist/types/global-account/react/hooks/index.d.ts +0 -1
  31. package/package.json +1 -1
  32. package/src/anyspend/react/components/AnySpendCustom.tsx +7 -23
  33. package/src/anyspend/react/components/common/CryptoPaySection.tsx +7 -30
  34. package/src/anyspend/react/components/common/CryptoPaymentMethodDisplay.tsx +64 -0
  35. package/src/anyspend/react/hooks/useConnectedUserProfile.ts +7 -10
  36. package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +2 -15
  37. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +4 -6
  38. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +1 -1
  39. package/src/global-account/react/hooks/index.ts +0 -1
  40. package/src/global-account/react/hooks/useAccountWallet.tsx +12 -11
  41. package/dist/cjs/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
  42. package/dist/cjs/global-account/react/hooks/useBestTransactionPath.js +0 -148
  43. package/dist/esm/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
  44. package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +0 -145
  45. package/dist/types/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
  46. package/src/global-account/react/hooks/useBestTransactionPath.tsx +0 -201
@@ -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
- }