@b3dotfun/sdk 0.0.83-test.0 → 0.0.84-alpha.0
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.
- package/dist/cjs/anyspend/constants/index.d.ts +1 -1
- package/dist/cjs/anyspend/constants/index.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpend.js +21 -12
- package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.js +1 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -6
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +2 -4
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +47 -177
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +28 -0
- package/dist/cjs/anyspend/react/components/common/InsufficientDepositPayment.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +5 -4
- package/dist/cjs/anyspend/react/components/common/OrderToken.js +2 -2
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmountFiat.js +1 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmountNew.js +2 -2
- package/dist/cjs/anyspend/react/components/common/PaymentStripeWeb2.js +4 -6
- package/dist/cjs/anyspend/react/components/common/PaymentVendorUI.js +41 -2
- package/dist/cjs/anyspend/react/components/common/TransferCryptoDetails.js +1 -1
- package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +2 -3
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +0 -3
- package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/cjs/anyspend/react/hooks/useConnectedUserProfile.js +5 -8
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
- package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/cjs/anyspend/react/hooks/useHyperliquidTransfer.js +133 -0
- package/dist/cjs/anyspend/react/providers/AnyspendProvider.js +1 -13
- package/dist/cjs/anyspend/types/chain.d.ts +10 -2
- package/dist/cjs/anyspend/types/chain.js +1 -0
- package/dist/cjs/anyspend/utils/address.d.ts +11 -0
- package/dist/cjs/anyspend/utils/address.js +15 -0
- package/dist/cjs/anyspend/utils/chain.d.ts +58 -1
- package/dist/cjs/anyspend/utils/chain.js +94 -4
- package/dist/cjs/anyspend/utils/token.d.ts +4 -0
- package/dist/cjs/anyspend/utils/token.js +35 -6
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +3 -4
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +12 -57
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/cjs/global-account/react/hooks/index.d.ts +0 -2
- package/dist/cjs/global-account/react/hooks/index.js +1 -5
- package/dist/cjs/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +63 -72
- package/dist/cjs/global-account/react/hooks/useTWAuth.d.ts +0 -3
- package/dist/cjs/global-account/react/hooks/useTWAuth.js +0 -8
- package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +24 -54
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/cjs/shared/utils/payment.utils.d.ts +1 -0
- package/dist/cjs/shared/utils/payment.utils.js +9 -0
- package/dist/esm/anyspend/constants/index.d.ts +1 -1
- package/dist/esm/anyspend/constants/index.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +22 -13
- package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -7
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +4 -6
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +45 -175
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethodDisplay.js +25 -0
- package/dist/esm/anyspend/react/components/common/InsufficientDepositPayment.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +6 -5
- package/dist/esm/anyspend/react/components/common/OrderToken.js +3 -3
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderTokenAmountFiat.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderTokenAmountNew.js +3 -3
- package/dist/esm/anyspend/react/components/common/PaymentStripeWeb2.js +2 -4
- package/dist/esm/anyspend/react/components/common/PaymentVendorUI.js +9 -3
- package/dist/esm/anyspend/react/components/common/TransferCryptoDetails.js +2 -2
- package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +3 -4
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +0 -3
- package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/esm/anyspend/react/hooks/useConnectedUserProfile.js +6 -9
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +2 -12
- package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/esm/anyspend/react/hooks/useHyperliquidTransfer.js +127 -0
- package/dist/esm/anyspend/react/providers/AnyspendProvider.js +1 -13
- package/dist/esm/anyspend/types/chain.d.ts +10 -2
- package/dist/esm/anyspend/types/chain.js +1 -0
- package/dist/esm/anyspend/utils/address.d.ts +11 -0
- package/dist/esm/anyspend/utils/address.js +14 -0
- package/dist/esm/anyspend/utils/chain.d.ts +58 -1
- package/dist/esm/anyspend/utils/chain.js +91 -4
- package/dist/esm/anyspend/utils/token.d.ts +4 -0
- package/dist/esm/anyspend/utils/token.js +32 -6
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +4 -5
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +12 -57
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +1 -1
- package/dist/esm/global-account/react/hooks/index.d.ts +0 -2
- package/dist/esm/global-account/react/hooks/index.js +0 -2
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +63 -72
- package/dist/esm/global-account/react/hooks/useTWAuth.d.ts +0 -3
- package/dist/esm/global-account/react/hooks/useTWAuth.js +0 -8
- package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +24 -54
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/esm/shared/utils/payment.utils.d.ts +1 -0
- package/dist/esm/shared/utils/payment.utils.js +9 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/constants/index.d.ts +1 -1
- package/dist/types/anyspend/react/components/common/CryptoPaymentMethodDisplay.d.ts +15 -0
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useConnectedUserProfile.d.ts +2 -1
- package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +0 -2
- package/dist/types/anyspend/react/hooks/useHyperliquidTransfer.d.ts +37 -0
- package/dist/types/anyspend/types/chain.d.ts +10 -2
- package/dist/types/anyspend/utils/address.d.ts +11 -0
- package/dist/types/anyspend/utils/chain.d.ts +58 -1
- package/dist/types/anyspend/utils/token.d.ts +4 -0
- package/dist/types/global-account/react/hooks/index.d.ts +0 -2
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/types/global-account/react/hooks/useTWAuth.d.ts +0 -3
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/types/shared/utils/payment.utils.d.ts +1 -0
- package/package.json +1 -1
- package/src/anyspend/constants/index.ts +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +31 -13
- package/src/anyspend/react/components/AnySpendCollectorClubPurchase.tsx +1 -1
- package/src/anyspend/react/components/AnySpendCustom.tsx +9 -29
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +7 -30
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +22 -253
- package/src/anyspend/react/components/common/CryptoPaymentMethodDisplay.tsx +64 -0
- package/src/anyspend/react/components/common/InsufficientDepositPayment.tsx +2 -2
- package/src/anyspend/react/components/common/OrderDetails.tsx +6 -5
- package/src/anyspend/react/components/common/OrderToken.tsx +5 -5
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +3 -3
- package/src/anyspend/react/components/common/OrderTokenAmountFiat.tsx +3 -3
- package/src/anyspend/react/components/common/OrderTokenAmountNew.tsx +6 -6
- package/src/anyspend/react/components/common/PaymentStripeWeb2.tsx +3 -5
- package/src/anyspend/react/components/common/PaymentVendorUI.tsx +26 -2
- package/src/anyspend/react/components/common/TransferCryptoDetails.tsx +2 -2
- package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +3 -5
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +0 -4
- package/src/anyspend/react/hooks/useConnectedUserProfile.ts +7 -10
- package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +2 -15
- package/src/anyspend/react/hooks/useHyperliquidTransfer.ts +152 -0
- package/src/anyspend/react/providers/AnyspendProvider.tsx +7 -22
- package/src/anyspend/types/chain.ts +10 -1
- package/src/anyspend/utils/address.ts +15 -0
- package/src/anyspend/utils/chain.ts +115 -5
- package/src/anyspend/utils/token.ts +36 -7
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +6 -2
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +4 -6
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +22 -77
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +1 -1
- package/src/global-account/react/hooks/index.ts +0 -2
- package/src/global-account/react/hooks/useAccountWallet.tsx +12 -11
- package/src/global-account/react/hooks/useAuthentication.ts +85 -88
- package/src/global-account/react/hooks/useTWAuth.tsx +0 -10
- package/src/global-account/react/hooks/useTurnkeyAuth.ts +26 -59
- package/src/shared/utils/payment.utils.ts +10 -1
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +0 -73
- package/dist/cjs/global-account/react/hooks/useAuth.d.ts +0 -76
- package/dist/cjs/global-account/react/hooks/useAuth.js +0 -338
- package/dist/cjs/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/dist/cjs/global-account/react/hooks/useBestTransactionPath.js +0 -148
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +0 -70
- package/dist/esm/global-account/react/hooks/useAuth.d.ts +0 -76
- package/dist/esm/global-account/react/hooks/useAuth.js +0 -332
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +0 -145
- package/dist/types/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +0 -10
- package/dist/types/global-account/react/hooks/useAuth.d.ts +0 -76
- package/dist/types/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +0 -80
- package/src/global-account/react/hooks/useAuth.ts +0 -380
- package/src/global-account/react/hooks/useBestTransactionPath.tsx +0 -201
|
@@ -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,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
|
|
3
|
-
*
|
|
4
|
-
* This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
|
|
5
|
-
* ensuring that when users connect via wagmi, the active wallet is properly set.
|
|
6
|
-
*
|
|
7
|
-
* Place this hook in components that stay mounted throughout the user flow
|
|
8
|
-
* (not in components that unmount during navigation).
|
|
9
|
-
*/
|
|
10
|
-
export declare function useAutoSetActiveWalletFromWagmi(): void;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Wallet } from "thirdweb/wallets";
|
|
2
|
-
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
3
|
-
/**
|
|
4
|
-
* Unified authentication hook that uses Turnkey for authentication
|
|
5
|
-
* This replaces the previous Thirdweb-based authentication
|
|
6
|
-
*
|
|
7
|
-
* This hook provides 1:1 feature parity with useAuthentication.ts
|
|
8
|
-
*/
|
|
9
|
-
export declare function useAuth(): {
|
|
10
|
-
authenticate: (turnkeySessionJwt: string, partnerId: string) => Promise<import("@feathersjs/authentication").AuthenticationResult>;
|
|
11
|
-
reAuthenticate: () => Promise<import("@feathersjs/authentication").AuthenticationResult>;
|
|
12
|
-
logout: (callback?: () => void) => Promise<void>;
|
|
13
|
-
isAuthenticated: boolean;
|
|
14
|
-
isReady: boolean;
|
|
15
|
-
isConnecting: boolean;
|
|
16
|
-
isConnected: boolean;
|
|
17
|
-
wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
|
|
18
|
-
preAuthenticate: typeof preAuthenticate;
|
|
19
|
-
connect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
|
|
20
|
-
isAuthenticating: boolean;
|
|
21
|
-
onConnect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
|
|
22
|
-
user: {
|
|
23
|
-
email?: string | undefined;
|
|
24
|
-
telNumber?: string | undefined;
|
|
25
|
-
username?: string | undefined;
|
|
26
|
-
ens?: string | undefined;
|
|
27
|
-
avatar?: string | undefined;
|
|
28
|
-
preferences?: {} | undefined;
|
|
29
|
-
referredBy?: string | {} | undefined;
|
|
30
|
-
sourceApp?: string | undefined;
|
|
31
|
-
referralCode?: string | undefined;
|
|
32
|
-
userGroups?: number[] | undefined;
|
|
33
|
-
isMigratedFromBSMNT?: boolean | undefined;
|
|
34
|
-
privyLinkedAccounts?: {
|
|
35
|
-
name?: string | undefined;
|
|
36
|
-
address?: string | undefined;
|
|
37
|
-
email?: string | undefined;
|
|
38
|
-
chain_type?: string | undefined;
|
|
39
|
-
lv?: number | undefined;
|
|
40
|
-
wallet_client_type?: string | undefined;
|
|
41
|
-
smart_wallet_type?: string | undefined;
|
|
42
|
-
subject?: string | undefined;
|
|
43
|
-
type: string;
|
|
44
|
-
}[] | undefined;
|
|
45
|
-
twProfiles?: {
|
|
46
|
-
type: string;
|
|
47
|
-
details: {
|
|
48
|
-
id?: string | undefined;
|
|
49
|
-
name?: string | undefined;
|
|
50
|
-
address?: string | undefined;
|
|
51
|
-
email?: string | undefined;
|
|
52
|
-
phone?: string | undefined;
|
|
53
|
-
username?: string | undefined;
|
|
54
|
-
fid?: string | undefined;
|
|
55
|
-
};
|
|
56
|
-
}[] | undefined;
|
|
57
|
-
turnkeySubOrgs?: {
|
|
58
|
-
hasDelegatedUser?: boolean | undefined;
|
|
59
|
-
subOrgId: string;
|
|
60
|
-
accounts: Record<string, any>[];
|
|
61
|
-
}[] | undefined;
|
|
62
|
-
_id: string | {};
|
|
63
|
-
userId: string;
|
|
64
|
-
smartAccountAddress: string;
|
|
65
|
-
createdAt: number;
|
|
66
|
-
updatedAt: number;
|
|
67
|
-
partnerIds: {
|
|
68
|
-
privyId?: string | undefined;
|
|
69
|
-
thirdwebId?: string | undefined;
|
|
70
|
-
turnkeyId?: string | undefined;
|
|
71
|
-
turnkeyOtpId?: string | undefined;
|
|
72
|
-
};
|
|
73
|
-
} | undefined;
|
|
74
|
-
refetchUser: () => Promise<import("@feathersjs/authentication").AuthenticationResult>;
|
|
75
|
-
setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
|
|
76
|
-
};
|
|
@@ -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,80 +0,0 @@
|
|
|
1
|
-
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
2
|
-
import { useCallback, useEffect, useRef } from "react";
|
|
3
|
-
import { useSetActiveWallet } from "thirdweb/react";
|
|
4
|
-
import { WalletId, createWallet } from "thirdweb/wallets";
|
|
5
|
-
import { useAccount } from "wagmi";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
|
|
9
|
-
*
|
|
10
|
-
* This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
|
|
11
|
-
* ensuring that when users connect via wagmi, the active wallet is properly set.
|
|
12
|
-
*
|
|
13
|
-
* Place this hook in components that stay mounted throughout the user flow
|
|
14
|
-
* (not in components that unmount during navigation).
|
|
15
|
-
*/
|
|
16
|
-
export function useAutoSetActiveWalletFromWagmi() {
|
|
17
|
-
const { address: wagmiAddress, connector: wagmiConnector } = useAccount();
|
|
18
|
-
const setActiveWallet = useSetActiveWallet();
|
|
19
|
-
const prevWagmiAddress = useRef<string | undefined>(undefined);
|
|
20
|
-
|
|
21
|
-
// Map wagmi connector names to thirdweb wallet IDs
|
|
22
|
-
const getThirdwebWalletId = useCallback((connectorName: string): WalletId | null => {
|
|
23
|
-
const walletMap: Record<string, WalletId> = {
|
|
24
|
-
MetaMask: "io.metamask",
|
|
25
|
-
"Coinbase Wallet": "com.coinbase.wallet",
|
|
26
|
-
Rainbow: "me.rainbow",
|
|
27
|
-
WalletConnect: "walletConnect",
|
|
28
|
-
Phantom: "app.phantom",
|
|
29
|
-
};
|
|
30
|
-
return walletMap[connectorName] || null;
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
// Create thirdweb wallet from wagmi connector
|
|
34
|
-
const createThirdwebWalletFromConnector = useCallback(
|
|
35
|
-
async (connectorName: string) => {
|
|
36
|
-
const walletId = getThirdwebWalletId(connectorName);
|
|
37
|
-
if (!walletId) {
|
|
38
|
-
console.warn(`No thirdweb wallet ID found for connector: ${connectorName}`);
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const thirdwebWallet = createWallet(walletId);
|
|
44
|
-
await thirdwebWallet.connect({ client });
|
|
45
|
-
return thirdwebWallet;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.error(`Failed to create thirdweb wallet for ${connectorName}:`, error);
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
[getThirdwebWalletId],
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
// Listen for wagmi wallet connections and automatically set active wallet
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
const isNewConnection = wagmiAddress && wagmiAddress !== prevWagmiAddress.current;
|
|
57
|
-
|
|
58
|
-
if (isNewConnection && wagmiConnector?.name) {
|
|
59
|
-
prevWagmiAddress.current = wagmiAddress;
|
|
60
|
-
|
|
61
|
-
const setupThirdwebWallet = async () => {
|
|
62
|
-
try {
|
|
63
|
-
const thirdwebWallet = await createThirdwebWalletFromConnector(wagmiConnector.name);
|
|
64
|
-
if (thirdwebWallet) {
|
|
65
|
-
setActiveWallet(thirdwebWallet);
|
|
66
|
-
console.log(`Auto-set active wallet for ${wagmiConnector.name}`);
|
|
67
|
-
}
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error("Failed to auto-set active wallet:", error);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
setupThirdwebWallet();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!wagmiAddress) {
|
|
77
|
-
prevWagmiAddress.current = undefined;
|
|
78
|
-
}
|
|
79
|
-
}, [wagmiAddress, wagmiConnector?.name, setActiveWallet, createThirdwebWalletFromConnector]);
|
|
80
|
-
}
|