@b3dotfun/sdk 0.0.83 → 0.0.84-alpha.1
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 +23 -9
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -3
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +2 -4
- 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/CryptoReceiveSection.js +2 -1
- 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/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 +20 -1
- package/dist/cjs/anyspend/utils/chain.js +73 -4
- package/dist/cjs/anyspend/utils/token.d.ts +7 -0
- package/dist/cjs/anyspend/utils/token.js +26 -7
- 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/steps/LoginStep.js +1 -1
- package/dist/cjs/global-account/react/hooks/index.d.ts +0 -1
- package/dist/cjs/global-account/react/hooks/index.js +1 -3
- package/dist/cjs/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/cjs/global-account/react/hooks/useFirstEOA.d.ts +2 -2
- 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 +24 -10
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -4
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +4 -6
- 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/CryptoReceiveSection.js +2 -1
- 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/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 +20 -1
- package/dist/esm/anyspend/utils/chain.js +70 -4
- package/dist/esm/anyspend/utils/token.d.ts +7 -0
- package/dist/esm/anyspend/utils/token.js +25 -7
- 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/steps/LoginStep.js +1 -1
- package/dist/esm/global-account/react/hooks/index.d.ts +0 -1
- package/dist/esm/global-account/react/hooks/index.js +0 -1
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +11 -10
- package/dist/esm/global-account/react/hooks/useFirstEOA.d.ts +2 -2
- package/dist/esm/shared/utils/payment.utils.d.ts +1 -0
- package/dist/esm/shared/utils/payment.utils.js +9 -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 +20 -1
- package/dist/types/anyspend/utils/token.d.ts +7 -0
- package/dist/types/global-account/react/hooks/index.d.ts +0 -1
- package/dist/types/global-account/react/hooks/useFirstEOA.d.ts +2 -2
- 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 +36 -9
- package/src/anyspend/react/components/AnySpendCustom.tsx +9 -25
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +7 -30
- package/src/anyspend/react/components/common/CryptoPaymentMethodDisplay.tsx +64 -0
- package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +16 -5
- 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/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 +84 -4
- package/src/anyspend/utils/token.ts +27 -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/steps/LoginStep.tsx +1 -1
- package/src/global-account/react/hooks/index.ts +0 -1
- package/src/global-account/react/hooks/useAccountWallet.tsx +12 -11
- package/src/shared/utils/payment.utils.ts +10 -1
- 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/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/dist/esm/global-account/react/hooks/useBestTransactionPath.js +0 -145
- package/dist/types/global-account/react/hooks/useBestTransactionPath.d.ts +0 -41
- package/src/global-account/react/hooks/useBestTransactionPath.tsx +0 -201
|
@@ -12,7 +12,7 @@ import { loadGA4Script } from "@b3dotfun/sdk/global-account/utils/analytics";
|
|
|
12
12
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
13
13
|
import "@relayprotocol/relay-kit-ui/styles.css";
|
|
14
14
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
15
|
-
import { useCallback, useEffect, useState } from "react";
|
|
15
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
16
16
|
import {
|
|
17
17
|
getLastAuthProvider,
|
|
18
18
|
ThirdwebProvider,
|
|
@@ -92,7 +92,11 @@ export function B3Provider({
|
|
|
92
92
|
useEffect(() => {
|
|
93
93
|
setClientType(clientType);
|
|
94
94
|
}, [clientType]);
|
|
95
|
-
|
|
95
|
+
|
|
96
|
+
const wagmiConfig = useMemo(
|
|
97
|
+
() => createWagmiConfig({ partnerId, rpcUrls, connectors, overrideDefaultConnectors }),
|
|
98
|
+
[partnerId, rpcUrls, connectors, overrideDefaultConnectors],
|
|
99
|
+
);
|
|
96
100
|
|
|
97
101
|
return (
|
|
98
102
|
<ThirdwebProvider>
|
|
@@ -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={
|
|
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
|
-
|
|
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:
|
|
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:
|
|
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
|
|
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
|
-
|
|
137
|
+
|
|
138
|
+
const avatarUrl = profileData?.avatar;
|
|
138
139
|
|
|
139
140
|
return avatarUrl || (isActiveSmartWallet ? smartWalletIcon : walletImage) || "";
|
|
140
141
|
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { VENDOR_DISPLAY_NAMES } from "@b3dotfun/sdk/anyspend/constants";
|
|
1
|
+
import { STRIPE_CONFIG, VENDOR_DISPLAY_NAMES } from "@b3dotfun/sdk/anyspend/constants";
|
|
2
2
|
import { components } from "@b3dotfun/sdk/anyspend/types/api";
|
|
3
|
+
import { loadStripe } from "@stripe/stripe-js";
|
|
4
|
+
|
|
5
|
+
let stripePromise: ReturnType<typeof loadStripe> | null = null;
|
|
6
|
+
export function getStripePromise() {
|
|
7
|
+
if (!stripePromise) {
|
|
8
|
+
stripePromise = loadStripe(STRIPE_CONFIG.publishableKey);
|
|
9
|
+
}
|
|
10
|
+
return stripePromise;
|
|
11
|
+
}
|
|
3
12
|
|
|
4
13
|
export function getVendorDisplayName(vendor?: components["schemas"]["OnrampMetadata"]["vendor"]): string {
|
|
5
14
|
switch (vendor) {
|
|
@@ -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 {};
|