@b3dotfun/sdk 0.0.65-alpha.1 → 0.0.65-alpha.2
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/react/components/AnySpend.js +1 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +1 -1
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +5 -5
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +2 -10
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +1 -1
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +6 -14
- package/dist/esm/anyspend/react/components/AnySpend.js +1 -1
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +1 -1
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +5 -5
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -10
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +1 -1
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +6 -14
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +1 -1
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +1 -1
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +5 -4
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +2 -13
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +1 -1
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +6 -12
|
@@ -102,7 +102,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
102
102
|
});
|
|
103
103
|
const [selectedSrcToken, setSelectedSrcToken] = (0, react_4.useState)(srcTokenFromUrl);
|
|
104
104
|
const { data: srcTokenMetadata } = (0, react_2.useTokenData)(selectedSrcToken?.chainId, selectedSrcToken?.address);
|
|
105
|
-
const [srcAmount, setSrcAmount] = (0, react_4.useState)(searchParams.get("fromAmount") || "0
|
|
105
|
+
const [srcAmount, setSrcAmount] = (0, react_4.useState)(searchParams.get("fromAmount") || "0");
|
|
106
106
|
// State for onramp amount
|
|
107
107
|
const [srcAmountOnRamp, setSrcAmountOnRamp] = (0, react_4.useState)(searchParams.get("fromAmount") || "5");
|
|
108
108
|
// State for destination chain/token selection
|
|
@@ -128,7 +128,7 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
|
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
130
|
if (paymentType === "crypto") {
|
|
131
|
-
if (
|
|
131
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
132
132
|
setActivePanel(useAnyspendFlow_1.PanelView.CRYPTO_PAYMENT_METHOD);
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
@@ -38,7 +38,7 @@ function AnySpendDepositHype(props) {
|
|
|
38
38
|
}
|
|
39
39
|
function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, onSuccess, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, }) {
|
|
40
40
|
// Use shared flow hook
|
|
41
|
-
const { activePanel, setActivePanel, orderId, setOrderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, dstAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, anyspendQuote, isLoadingAnyspendQuote, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = (0, useAnyspendFlow_1.useAnyspendFlow)({
|
|
41
|
+
const { activePanel, setActivePanel, orderId, setOrderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, dstAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, effectiveCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, anyspendQuote, isLoadingAnyspendQuote, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = (0, useAnyspendFlow_1.useAnyspendFlow)({
|
|
42
42
|
paymentType,
|
|
43
43
|
recipientAddress,
|
|
44
44
|
loadOrder,
|
|
@@ -85,7 +85,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
if (paymentType === "crypto") {
|
|
88
|
-
if (
|
|
88
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
89
89
|
return { text: "Choose payment method", disable: false, error: false, loading: false };
|
|
90
90
|
}
|
|
91
91
|
return { text: "Continue to deposit", disable: false, error: false, loading: false };
|
|
@@ -99,6 +99,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
99
99
|
return { text: "Continue to deposit", disable: false, error: false, loading: false };
|
|
100
100
|
}, [
|
|
101
101
|
activeInputAmountInWei,
|
|
102
|
+
effectiveCryptoPaymentMethod,
|
|
102
103
|
isLoadingAnyspendQuote,
|
|
103
104
|
isCreatingOrder,
|
|
104
105
|
isCreatingOnrampOrder,
|
|
@@ -106,7 +107,6 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
106
107
|
anyspendQuote,
|
|
107
108
|
dstAmount,
|
|
108
109
|
paymentType,
|
|
109
|
-
selectedCryptoPaymentMethod,
|
|
110
110
|
selectedFiatPaymentMethod,
|
|
111
111
|
]);
|
|
112
112
|
const onMainButtonClick = async () => {
|
|
@@ -117,7 +117,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
if (paymentType === "crypto") {
|
|
120
|
-
if (
|
|
120
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
121
121
|
setActivePanel(useAnyspendFlow_1.PanelView.CRYPTO_PAYMENT_METHOD);
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
@@ -131,7 +131,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
131
131
|
await handleFiatOrder();
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
|
-
const mainView = ((0, jsx_runtime_1.jsxs)("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("h1", { className: "text-as-primary text-xl font-bold", children: paymentType === "crypto" ? "Deposit Crypto" : "Fund with Fiat" }) }) }), (0, jsx_runtime_1.jsx)("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: (0, jsx_runtime_1.jsxs)("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [paymentType === "crypto" ? ((0, jsx_runtime_1.jsx)(CryptoPaySection_1.CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, isSrcInputDirty: isSrcInputDirty, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod:
|
|
134
|
+
const mainView = ((0, jsx_runtime_1.jsxs)("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("h1", { className: "text-as-primary text-xl font-bold", children: paymentType === "crypto" ? "Deposit Crypto" : "Fund with Fiat" }) }) }), (0, jsx_runtime_1.jsx)("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: (0, jsx_runtime_1.jsxs)("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [paymentType === "crypto" ? ((0, jsx_runtime_1.jsx)(CryptoPaySection_1.CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, isSrcInputDirty: isSrcInputDirty, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: effectiveCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(useAnyspendFlow_1.PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : ((0, jsx_runtime_1.jsx)(react_2.motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, children: (0, jsx_runtime_1.jsx)(PanelOnramp_1.PanelOnramp, { srcAmountOnRamp: srcAmount, setSrcAmountOnRamp: setSrcAmount, selectedPaymentMethod: selectedFiatPaymentMethod, setActivePanel: setActivePanel, _recipientAddress: recipientAddress, destinationToken: anyspend_1.B3_TOKEN, destinationChainId: chains_1.base.id, dstTokenSymbol: exports.HYPE_TOKEN_DETAILS.SYMBOL, hideDstToken: true, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: useAnyspendFlow_1.PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: useAnyspendFlow_1.PanelView.RECIPIENT_SELECTION, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.FEE_DETAIL), customUsdInputValues: customUsdInputValues }) })), (0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.cn)("relative -my-1 flex h-0 items-center justify-center", paymentType === "fiat" && "hidden"), children: (0, jsx_runtime_1.jsx)(react_1.Button, { variant: "ghost", className: (0, cn_1.cn)("swap-direction-button border-as-stroke bg-as-surface-primary z-10 h-10 w-10 cursor-default rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl"), children: (0, jsx_runtime_1.jsx)("div", { className: "relative flex items-center justify-center transition-opacity", children: (0, jsx_runtime_1.jsx)(lucide_react_1.ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }) }), paymentType === "crypto" && ((0, jsx_runtime_1.jsx)(CryptoReceiveSection_1.CryptoReceiveSection, { isDepositMode: false, isBuyMode: true, selectedRecipientAddress: selectedRecipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(useAnyspendFlow_1.PanelView.RECIPIENT_SELECTION), setRecipientAddress: setSelectedRecipientAddress, recipientAddressFromProps: recipientAddress, globalAddress: globalAddress, dstAmount: dstAmount, dstToken: anyspend_1.B3_TOKEN, dstTokenSymbol: exports.HYPE_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: exports.HYPE_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: chains_1.base.id, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
|
|
135
135
|
setIsSrcInputDirty(false);
|
|
136
136
|
setSrcAmount(value);
|
|
137
137
|
}, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.FEE_DETAIL), selectedCryptoPaymentMethod: selectedCryptoPaymentMethod }))] }) }), (0, jsx_runtime_1.jsx)(react_2.motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: (0, cn_1.cn)("mt-4 flex w-full max-w-[460px] flex-col gap-2"), children: (0, jsx_runtime_1.jsx)(react_1.ShinyButton, { accentColor: "hsl(var(--as-brand))", disabled: btnInfo.disable, onClick: onMainButtonClick, className: (0, cn_1.cn)("as-main-button relative w-full", btnInfo.error ? "!bg-as-red" : btnInfo.disable ? "!bg-as-on-surface-2" : "!bg-as-brand"), textClassName: (0, cn_1.cn)(btnInfo.error ? "text-white" : btnInfo.disable ? "text-as-secondary" : "text-white"), children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-center gap-2", children: [btnInfo.loading && (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-4 w-4 animate-spin" }), btnInfo.text] }) }) }), mainFooter ? mainFooter : null] }));
|
|
@@ -17,26 +17,19 @@ const ChainTokenIcon_1 = require("./ChainTokenIcon");
|
|
|
17
17
|
function OrderTokenAmount({ disabled, inputValue, onChangeInput, context, address, chainId, setChainId, token, setToken, hideTokenSelect = false, canEditAmount = true, className, innerClassName, amountClassName, tokenSelectClassName, onTokenSelect, walletAddress, }) {
|
|
18
18
|
// Track previous token to detect changes
|
|
19
19
|
const prevTokenRef = (0, react_1.useRef)(token.address);
|
|
20
|
-
// Track if initial balance has been set
|
|
21
|
-
const initialBalanceSetRef = (0, react_1.useRef)(false);
|
|
22
20
|
// Only get token balance when context is "from" (for setting max amount)
|
|
23
21
|
const { rawBalance } = (0, react_2.useTokenBalance)({
|
|
24
22
|
token,
|
|
25
23
|
address: context === "from" && walletAddress ? walletAddress : undefined,
|
|
26
24
|
});
|
|
27
|
-
// Reset balance ref when token address or chain changes
|
|
28
|
-
(0, react_1.useEffect)(() => {
|
|
29
|
-
initialBalanceSetRef.current = false;
|
|
30
|
-
}, [token.address, token.chainId]);
|
|
31
25
|
(0, react_1.useEffect)(() => {
|
|
32
26
|
// Only handle "from" context
|
|
33
27
|
if (context !== "from")
|
|
34
28
|
return;
|
|
35
29
|
// Check if token changed or if this is the initial load with balance
|
|
36
30
|
const isTokenChanged = prevTokenRef.current !== token.address;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
console.log(`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}, Initial: ${isInitialLoad}`);
|
|
31
|
+
if (isTokenChanged && rawBalance) {
|
|
32
|
+
console.log(`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}`);
|
|
40
33
|
// Calculate max amount with gas reserve for native tokens
|
|
41
34
|
let maxAmount;
|
|
42
35
|
if ((0, token_1.isNativeToken)(token.address)) {
|
|
@@ -52,7 +45,6 @@ function OrderTokenAmount({ disabled, inputValue, onChangeInput, context, addres
|
|
|
52
45
|
onChangeInput((0, viem_1.formatUnits)(maxAmount, token.decimals));
|
|
53
46
|
// Update refs
|
|
54
47
|
prevTokenRef.current = token.address;
|
|
55
|
-
initialBalanceSetRef.current = true;
|
|
56
48
|
}
|
|
57
49
|
}, [token.address, token.chainId, token.decimals, chainId, context, onChangeInput, rawBalance]);
|
|
58
50
|
const handleTokenSelect = (newToken) => {
|
|
@@ -42,7 +42,7 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
42
42
|
const defaultDstToken = anyspend_1.B3_TOKEN; // Default destination token
|
|
43
43
|
const [selectedSrcToken, setSelectedSrcToken] = (0, react_3.useState)(defaultSrcToken);
|
|
44
44
|
const [selectedDstToken, setSelectedDstToken] = (0, react_3.useState)(defaultDstToken);
|
|
45
|
-
const [srcAmount, setSrcAmount] = (0, react_3.useState)(paymentType === "fiat" ? "5" : "0
|
|
45
|
+
const [srcAmount, setSrcAmount] = (0, react_3.useState)(paymentType === "fiat" ? "5" : "0");
|
|
46
46
|
const [dstAmount, setDstAmount] = (0, react_3.useState)("");
|
|
47
47
|
const [isSrcInputDirty, setIsSrcInputDirty] = (0, react_3.useState)(true);
|
|
48
48
|
// Derive destination chain ID from token or prop (cannot change)
|
|
@@ -12,7 +12,6 @@ const invariant_1 = __importDefault(require("invariant"));
|
|
|
12
12
|
const react_1 = require("react");
|
|
13
13
|
const sonner_1 = require("sonner");
|
|
14
14
|
const thirdweb_2 = require("thirdweb");
|
|
15
|
-
const react_2 = require("thirdweb/react");
|
|
16
15
|
const viem_1 = require("viem");
|
|
17
16
|
const wagmi_1 = require("wagmi");
|
|
18
17
|
const components_1 = require("../components");
|
|
@@ -25,7 +24,6 @@ const partnerId = String(process.env.PUBLIC_THIRDWEB_PARTNER_ID ||
|
|
|
25
24
|
function useUnifiedChainSwitchAndExecute() {
|
|
26
25
|
const { switchChainAsync } = (0, wagmi_1.useSwitchChain)();
|
|
27
26
|
const [isSwitchingOrExecuting, setIsSwitchingOrExecuting] = (0, react_1.useState)(false);
|
|
28
|
-
const activeWallet = (0, react_2.useActiveWallet)();
|
|
29
27
|
const { isActiveSmartWallet, isActiveEOAWallet, connectedEOAWallet } = (0, useAccountWallet_1.useAccountWallet)();
|
|
30
28
|
const { account: aaAccount } = (0, components_1.useB3)();
|
|
31
29
|
// Handle EOA wallet chain switch and execute transaction
|
|
@@ -40,18 +38,18 @@ function useUnifiedChainSwitchAndExecute() {
|
|
|
40
38
|
sonner_1.toast.error(`Chain ${targetChainId} is not supported`);
|
|
41
39
|
return;
|
|
42
40
|
}
|
|
43
|
-
const currentChainId =
|
|
41
|
+
const currentChainId = connectedEOAWallet?.getChain()?.id;
|
|
44
42
|
const onCorrectChain = currentChainId === targetChainId;
|
|
45
43
|
// Helper function to execute the transaction
|
|
46
44
|
const executeTransaction = async () => {
|
|
47
|
-
const signer =
|
|
45
|
+
const signer = connectedEOAWallet?.getAccount();
|
|
48
46
|
if (!signer) {
|
|
49
47
|
throw new Error("No account connected");
|
|
50
48
|
}
|
|
51
49
|
// Coinbase Smart Wallet specific chain switching (different behavior from other wallets)
|
|
52
50
|
const walletChain = connectedEOAWallet.getChain();
|
|
53
51
|
if (walletChain?.id !== targetChainId) {
|
|
54
|
-
|
|
52
|
+
connectedEOAWallet?.switchChain((0, supported_1.getThirdwebChain)(targetChainId));
|
|
55
53
|
}
|
|
56
54
|
(0, invariant_1.default)((0, viem_1.isAddress)(params.to), "params.to is not a valid address");
|
|
57
55
|
const result = await signer.sendTransaction({
|
|
@@ -103,7 +101,7 @@ function useUnifiedChainSwitchAndExecute() {
|
|
|
103
101
|
finally {
|
|
104
102
|
setIsSwitchingOrExecuting(false);
|
|
105
103
|
}
|
|
106
|
-
}, [connectedEOAWallet,
|
|
104
|
+
}, [connectedEOAWallet, switchChainAsync]);
|
|
107
105
|
// Handle AA wallet transaction (no chain switch needed for AA)
|
|
108
106
|
const handleAASendTransaction = (0, react_1.useCallback)(async (targetChainId, params) => {
|
|
109
107
|
if (!aaAccount) {
|
|
@@ -159,14 +157,8 @@ function useUnifiedChainSwitchAndExecute() {
|
|
|
159
157
|
if (isActiveSmartWallet) {
|
|
160
158
|
return handleAASendTransaction(targetChainId, params);
|
|
161
159
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
sonner_1.toast.error("No wallet connected");
|
|
167
|
-
return undefined;
|
|
168
|
-
}
|
|
169
|
-
}, [isActiveSmartWallet, isActiveEOAWallet, handleAASendTransaction, handleEOASwitchChainAndSendTransaction]);
|
|
160
|
+
return handleEOASwitchChainAndSendTransaction(targetChainId, params);
|
|
161
|
+
}, [isActiveSmartWallet, handleAASendTransaction, handleEOASwitchChainAndSendTransaction]);
|
|
170
162
|
return {
|
|
171
163
|
switchChainAndExecute,
|
|
172
164
|
switchChainAndExecuteWithEOA: handleEOASwitchChainAndSendTransaction,
|
|
@@ -95,7 +95,7 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
95
95
|
});
|
|
96
96
|
const [selectedSrcToken, setSelectedSrcToken] = useState(srcTokenFromUrl);
|
|
97
97
|
const { data: srcTokenMetadata } = useTokenData(selectedSrcToken?.chainId, selectedSrcToken?.address);
|
|
98
|
-
const [srcAmount, setSrcAmount] = useState(searchParams.get("fromAmount") || "0
|
|
98
|
+
const [srcAmount, setSrcAmount] = useState(searchParams.get("fromAmount") || "0");
|
|
99
99
|
// State for onramp amount
|
|
100
100
|
const [srcAmountOnRamp, setSrcAmountOnRamp] = useState(searchParams.get("fromAmount") || "5");
|
|
101
101
|
// State for destination chain/token selection
|
|
@@ -122,7 +122,7 @@ function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddres
|
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
124
|
if (paymentType === "crypto") {
|
|
125
|
-
if (
|
|
125
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
126
126
|
setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD);
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
@@ -31,7 +31,7 @@ export function AnySpendDepositHype(props) {
|
|
|
31
31
|
}
|
|
32
32
|
function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, onSuccess, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, }) {
|
|
33
33
|
// Use shared flow hook
|
|
34
|
-
const { activePanel, setActivePanel, orderId, setOrderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, dstAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, anyspendQuote, isLoadingAnyspendQuote, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = useAnyspendFlow({
|
|
34
|
+
const { activePanel, setActivePanel, orderId, setOrderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, dstAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, effectiveCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, anyspendQuote, isLoadingAnyspendQuote, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = useAnyspendFlow({
|
|
35
35
|
paymentType,
|
|
36
36
|
recipientAddress,
|
|
37
37
|
loadOrder,
|
|
@@ -78,7 +78,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
if (paymentType === "crypto") {
|
|
81
|
-
if (
|
|
81
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
82
82
|
return { text: "Choose payment method", disable: false, error: false, loading: false };
|
|
83
83
|
}
|
|
84
84
|
return { text: "Continue to deposit", disable: false, error: false, loading: false };
|
|
@@ -92,6 +92,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
92
92
|
return { text: "Continue to deposit", disable: false, error: false, loading: false };
|
|
93
93
|
}, [
|
|
94
94
|
activeInputAmountInWei,
|
|
95
|
+
effectiveCryptoPaymentMethod,
|
|
95
96
|
isLoadingAnyspendQuote,
|
|
96
97
|
isCreatingOrder,
|
|
97
98
|
isCreatingOnrampOrder,
|
|
@@ -99,7 +100,6 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
99
100
|
anyspendQuote,
|
|
100
101
|
dstAmount,
|
|
101
102
|
paymentType,
|
|
102
|
-
selectedCryptoPaymentMethod,
|
|
103
103
|
selectedFiatPaymentMethod,
|
|
104
104
|
]);
|
|
105
105
|
const onMainButtonClick = async () => {
|
|
@@ -110,7 +110,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
if (paymentType === "crypto") {
|
|
113
|
-
if (
|
|
113
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
114
114
|
setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD);
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
@@ -124,7 +124,7 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
124
124
|
await handleFiatOrder();
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [_jsx("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: _jsx("div", { children: _jsx("h1", { className: "text-as-primary text-xl font-bold", children: paymentType === "crypto" ? "Deposit Crypto" : "Fund with Fiat" }) }) }), _jsx("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [paymentType === "crypto" ? (_jsx(CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, isSrcInputDirty: isSrcInputDirty, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod:
|
|
127
|
+
const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [_jsx("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: _jsx("div", { children: _jsx("h1", { className: "text-as-primary text-xl font-bold", children: paymentType === "crypto" ? "Deposit Crypto" : "Fund with Fiat" }) }) }), _jsx("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [paymentType === "crypto" ? (_jsx(CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, isSrcInputDirty: isSrcInputDirty, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: effectiveCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : (_jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, children: _jsx(PanelOnramp, { srcAmountOnRamp: srcAmount, setSrcAmountOnRamp: setSrcAmount, selectedPaymentMethod: selectedFiatPaymentMethod, setActivePanel: setActivePanel, _recipientAddress: recipientAddress, destinationToken: B3_TOKEN, destinationChainId: base.id, dstTokenSymbol: HYPE_TOKEN_DETAILS.SYMBOL, hideDstToken: true, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: PanelView.RECIPIENT_SELECTION, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(PanelView.FEE_DETAIL), customUsdInputValues: customUsdInputValues }) })), _jsx("div", { className: cn("relative -my-1 flex h-0 items-center justify-center", paymentType === "fiat" && "hidden"), children: _jsx(Button, { variant: "ghost", className: cn("swap-direction-button border-as-stroke bg-as-surface-primary z-10 h-10 w-10 cursor-default rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl"), children: _jsx("div", { className: "relative flex items-center justify-center transition-opacity", children: _jsx(ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }) }), paymentType === "crypto" && (_jsx(CryptoReceiveSection, { isDepositMode: false, isBuyMode: true, selectedRecipientAddress: selectedRecipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(PanelView.RECIPIENT_SELECTION), setRecipientAddress: setSelectedRecipientAddress, recipientAddressFromProps: recipientAddress, globalAddress: globalAddress, dstAmount: dstAmount, dstToken: B3_TOKEN, dstTokenSymbol: HYPE_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: HYPE_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: base.id, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
|
|
128
128
|
setIsSrcInputDirty(false);
|
|
129
129
|
setSrcAmount(value);
|
|
130
130
|
}, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(PanelView.FEE_DETAIL), selectedCryptoPaymentMethod: selectedCryptoPaymentMethod }))] }) }), _jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: cn("mt-4 flex w-full max-w-[460px] flex-col gap-2"), children: _jsx(ShinyButton, { accentColor: "hsl(var(--as-brand))", disabled: btnInfo.disable, onClick: onMainButtonClick, className: cn("as-main-button relative w-full", btnInfo.error ? "!bg-as-red" : btnInfo.disable ? "!bg-as-on-surface-2" : "!bg-as-brand"), textClassName: cn(btnInfo.error ? "text-white" : btnInfo.disable ? "text-as-secondary" : "text-white"), children: _jsxs("div", { className: "flex items-center justify-center gap-2", children: [btnInfo.loading && _jsx(Loader2, { className: "h-4 w-4 animate-spin" }), btnInfo.text] }) }) }), mainFooter ? mainFooter : null] }));
|
|
@@ -14,26 +14,19 @@ import { ChainTokenIcon } from "./ChainTokenIcon.js";
|
|
|
14
14
|
export function OrderTokenAmount({ disabled, inputValue, onChangeInput, context, address, chainId, setChainId, token, setToken, hideTokenSelect = false, canEditAmount = true, className, innerClassName, amountClassName, tokenSelectClassName, onTokenSelect, walletAddress, }) {
|
|
15
15
|
// Track previous token to detect changes
|
|
16
16
|
const prevTokenRef = useRef(token.address);
|
|
17
|
-
// Track if initial balance has been set
|
|
18
|
-
const initialBalanceSetRef = useRef(false);
|
|
19
17
|
// Only get token balance when context is "from" (for setting max amount)
|
|
20
18
|
const { rawBalance } = useTokenBalance({
|
|
21
19
|
token,
|
|
22
20
|
address: context === "from" && walletAddress ? walletAddress : undefined,
|
|
23
21
|
});
|
|
24
|
-
// Reset balance ref when token address or chain changes
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
initialBalanceSetRef.current = false;
|
|
27
|
-
}, [token.address, token.chainId]);
|
|
28
22
|
useEffect(() => {
|
|
29
23
|
// Only handle "from" context
|
|
30
24
|
if (context !== "from")
|
|
31
25
|
return;
|
|
32
26
|
// Check if token changed or if this is the initial load with balance
|
|
33
27
|
const isTokenChanged = prevTokenRef.current !== token.address;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.log(`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}, Initial: ${isInitialLoad}`);
|
|
28
|
+
if (isTokenChanged && rawBalance) {
|
|
29
|
+
console.log(`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}`);
|
|
37
30
|
// Calculate max amount with gas reserve for native tokens
|
|
38
31
|
let maxAmount;
|
|
39
32
|
if (isNativeToken(token.address)) {
|
|
@@ -49,7 +42,6 @@ export function OrderTokenAmount({ disabled, inputValue, onChangeInput, context,
|
|
|
49
42
|
onChangeInput(formatUnits(maxAmount, token.decimals));
|
|
50
43
|
// Update refs
|
|
51
44
|
prevTokenRef.current = token.address;
|
|
52
|
-
initialBalanceSetRef.current = true;
|
|
53
45
|
}
|
|
54
46
|
}, [token.address, token.chainId, token.decimals, chainId, context, onChangeInput, rawBalance]);
|
|
55
47
|
const handleTokenSelect = (newToken) => {
|
|
@@ -38,7 +38,7 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
38
38
|
const defaultDstToken = B3_TOKEN; // Default destination token
|
|
39
39
|
const [selectedSrcToken, setSelectedSrcToken] = useState(defaultSrcToken);
|
|
40
40
|
const [selectedDstToken, setSelectedDstToken] = useState(defaultDstToken);
|
|
41
|
-
const [srcAmount, setSrcAmount] = useState(paymentType === "fiat" ? "5" : "0
|
|
41
|
+
const [srcAmount, setSrcAmount] = useState(paymentType === "fiat" ? "5" : "0");
|
|
42
42
|
const [dstAmount, setDstAmount] = useState("");
|
|
43
43
|
const [isSrcInputDirty, setIsSrcInputDirty] = useState(true);
|
|
44
44
|
// Derive destination chain ID from token or prop (cannot change)
|
|
@@ -6,7 +6,6 @@ import invariant from "invariant";
|
|
|
6
6
|
import { useCallback, useState } from "react";
|
|
7
7
|
import { toast } from "sonner";
|
|
8
8
|
import { prepareTransaction, sendTransaction as twSendTransaction } from "thirdweb";
|
|
9
|
-
import { useActiveWallet } from "thirdweb/react";
|
|
10
9
|
import { isAddress } from "viem";
|
|
11
10
|
import { useSwitchChain } from "wagmi";
|
|
12
11
|
import { useB3 } from "../components/index.js";
|
|
@@ -19,7 +18,6 @@ invariant(partnerId, "Partner ID is required");
|
|
|
19
18
|
export function useUnifiedChainSwitchAndExecute() {
|
|
20
19
|
const { switchChainAsync } = useSwitchChain();
|
|
21
20
|
const [isSwitchingOrExecuting, setIsSwitchingOrExecuting] = useState(false);
|
|
22
|
-
const activeWallet = useActiveWallet();
|
|
23
21
|
const { isActiveSmartWallet, isActiveEOAWallet, connectedEOAWallet } = useAccountWallet();
|
|
24
22
|
const { account: aaAccount } = useB3();
|
|
25
23
|
// Handle EOA wallet chain switch and execute transaction
|
|
@@ -34,18 +32,18 @@ export function useUnifiedChainSwitchAndExecute() {
|
|
|
34
32
|
toast.error(`Chain ${targetChainId} is not supported`);
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
37
|
-
const currentChainId =
|
|
35
|
+
const currentChainId = connectedEOAWallet?.getChain()?.id;
|
|
38
36
|
const onCorrectChain = currentChainId === targetChainId;
|
|
39
37
|
// Helper function to execute the transaction
|
|
40
38
|
const executeTransaction = async () => {
|
|
41
|
-
const signer =
|
|
39
|
+
const signer = connectedEOAWallet?.getAccount();
|
|
42
40
|
if (!signer) {
|
|
43
41
|
throw new Error("No account connected");
|
|
44
42
|
}
|
|
45
43
|
// Coinbase Smart Wallet specific chain switching (different behavior from other wallets)
|
|
46
44
|
const walletChain = connectedEOAWallet.getChain();
|
|
47
45
|
if (walletChain?.id !== targetChainId) {
|
|
48
|
-
|
|
46
|
+
connectedEOAWallet?.switchChain(getThirdwebChain(targetChainId));
|
|
49
47
|
}
|
|
50
48
|
invariant(isAddress(params.to), "params.to is not a valid address");
|
|
51
49
|
const result = await signer.sendTransaction({
|
|
@@ -97,7 +95,7 @@ export function useUnifiedChainSwitchAndExecute() {
|
|
|
97
95
|
finally {
|
|
98
96
|
setIsSwitchingOrExecuting(false);
|
|
99
97
|
}
|
|
100
|
-
}, [connectedEOAWallet,
|
|
98
|
+
}, [connectedEOAWallet, switchChainAsync]);
|
|
101
99
|
// Handle AA wallet transaction (no chain switch needed for AA)
|
|
102
100
|
const handleAASendTransaction = useCallback(async (targetChainId, params) => {
|
|
103
101
|
if (!aaAccount) {
|
|
@@ -153,14 +151,8 @@ export function useUnifiedChainSwitchAndExecute() {
|
|
|
153
151
|
if (isActiveSmartWallet) {
|
|
154
152
|
return handleAASendTransaction(targetChainId, params);
|
|
155
153
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
toast.error("No wallet connected");
|
|
161
|
-
return undefined;
|
|
162
|
-
}
|
|
163
|
-
}, [isActiveSmartWallet, isActiveEOAWallet, handleAASendTransaction, handleEOASwitchChainAndSendTransaction]);
|
|
154
|
+
return handleEOASwitchChainAndSendTransaction(targetChainId, params);
|
|
155
|
+
}, [isActiveSmartWallet, handleAASendTransaction, handleEOASwitchChainAndSendTransaction]);
|
|
164
156
|
return {
|
|
165
157
|
switchChainAndExecute,
|
|
166
158
|
switchChainAndExecuteWithEOA: handleEOASwitchChainAndSendTransaction,
|
package/package.json
CHANGED
|
@@ -204,7 +204,7 @@ function AnySpendInner({
|
|
|
204
204
|
});
|
|
205
205
|
const [selectedSrcToken, setSelectedSrcToken] = useState<components["schemas"]["Token"]>(srcTokenFromUrl);
|
|
206
206
|
const { data: srcTokenMetadata } = useTokenData(selectedSrcToken?.chainId, selectedSrcToken?.address);
|
|
207
|
-
const [srcAmount, setSrcAmount] = useState<string>(searchParams.get("fromAmount") || "0
|
|
207
|
+
const [srcAmount, setSrcAmount] = useState<string>(searchParams.get("fromAmount") || "0");
|
|
208
208
|
|
|
209
209
|
// State for onramp amount
|
|
210
210
|
const [srcAmountOnRamp, setSrcAmountOnRamp] = useState<string>(searchParams.get("fromAmount") || "5");
|
|
@@ -230,7 +230,7 @@ function AnySpendCustomExactInInner({
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
if (paymentType === "crypto") {
|
|
233
|
-
if (
|
|
233
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
234
234
|
setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD);
|
|
235
235
|
return;
|
|
236
236
|
}
|
|
@@ -87,6 +87,7 @@ function AnySpendDepositHypeInner({
|
|
|
87
87
|
isSrcInputDirty,
|
|
88
88
|
setIsSrcInputDirty,
|
|
89
89
|
selectedCryptoPaymentMethod,
|
|
90
|
+
effectiveCryptoPaymentMethod,
|
|
90
91
|
setSelectedCryptoPaymentMethod,
|
|
91
92
|
selectedFiatPaymentMethod,
|
|
92
93
|
setSelectedFiatPaymentMethod,
|
|
@@ -153,7 +154,7 @@ function AnySpendDepositHypeInner({
|
|
|
153
154
|
}
|
|
154
155
|
|
|
155
156
|
if (paymentType === "crypto") {
|
|
156
|
-
if (
|
|
157
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
157
158
|
return { text: "Choose payment method", disable: false, error: false, loading: false };
|
|
158
159
|
}
|
|
159
160
|
return { text: "Continue to deposit", disable: false, error: false, loading: false };
|
|
@@ -169,6 +170,7 @@ function AnySpendDepositHypeInner({
|
|
|
169
170
|
return { text: "Continue to deposit", disable: false, error: false, loading: false };
|
|
170
171
|
}, [
|
|
171
172
|
activeInputAmountInWei,
|
|
173
|
+
effectiveCryptoPaymentMethod,
|
|
172
174
|
isLoadingAnyspendQuote,
|
|
173
175
|
isCreatingOrder,
|
|
174
176
|
isCreatingOnrampOrder,
|
|
@@ -176,7 +178,6 @@ function AnySpendDepositHypeInner({
|
|
|
176
178
|
anyspendQuote,
|
|
177
179
|
dstAmount,
|
|
178
180
|
paymentType,
|
|
179
|
-
selectedCryptoPaymentMethod,
|
|
180
181
|
selectedFiatPaymentMethod,
|
|
181
182
|
]);
|
|
182
183
|
|
|
@@ -189,7 +190,7 @@ function AnySpendDepositHypeInner({
|
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
if (paymentType === "crypto") {
|
|
192
|
-
if (
|
|
193
|
+
if (effectiveCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
193
194
|
setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD);
|
|
194
195
|
return;
|
|
195
196
|
}
|
|
@@ -227,7 +228,7 @@ function AnySpendDepositHypeInner({
|
|
|
227
228
|
setSrcAmount={setSrcAmount}
|
|
228
229
|
isSrcInputDirty={isSrcInputDirty}
|
|
229
230
|
setIsSrcInputDirty={setIsSrcInputDirty}
|
|
230
|
-
selectedCryptoPaymentMethod={
|
|
231
|
+
selectedCryptoPaymentMethod={effectiveCryptoPaymentMethod}
|
|
231
232
|
onSelectCryptoPaymentMethod={() => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD)}
|
|
232
233
|
anyspendQuote={anyspendQuote}
|
|
233
234
|
onTokenSelect={onTokenSelect}
|
|
@@ -53,8 +53,6 @@ export function OrderTokenAmount({
|
|
|
53
53
|
}) {
|
|
54
54
|
// Track previous token to detect changes
|
|
55
55
|
const prevTokenRef = useRef<string>(token.address);
|
|
56
|
-
// Track if initial balance has been set
|
|
57
|
-
const initialBalanceSetRef = useRef(false);
|
|
58
56
|
|
|
59
57
|
// Only get token balance when context is "from" (for setting max amount)
|
|
60
58
|
const { rawBalance } = useTokenBalance({
|
|
@@ -62,23 +60,15 @@ export function OrderTokenAmount({
|
|
|
62
60
|
address: context === "from" && walletAddress ? walletAddress : undefined,
|
|
63
61
|
});
|
|
64
62
|
|
|
65
|
-
// Reset balance ref when token address or chain changes
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
initialBalanceSetRef.current = false;
|
|
68
|
-
}, [token.address, token.chainId]);
|
|
69
|
-
|
|
70
63
|
useEffect(() => {
|
|
71
64
|
// Only handle "from" context
|
|
72
65
|
if (context !== "from") return;
|
|
73
66
|
|
|
74
67
|
// Check if token changed or if this is the initial load with balance
|
|
75
68
|
const isTokenChanged = prevTokenRef.current !== token.address;
|
|
76
|
-
const isInitialLoad = !initialBalanceSetRef.current && rawBalance;
|
|
77
69
|
|
|
78
|
-
if (
|
|
79
|
-
console.log(
|
|
80
|
-
`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}, Initial: ${isInitialLoad}`,
|
|
81
|
-
);
|
|
70
|
+
if (isTokenChanged && rawBalance) {
|
|
71
|
+
console.log(`Setting max balance - Token: ${token.address}, Changed: ${isTokenChanged}`);
|
|
82
72
|
|
|
83
73
|
// Calculate max amount with gas reserve for native tokens
|
|
84
74
|
let maxAmount: bigint;
|
|
@@ -97,7 +87,6 @@ export function OrderTokenAmount({
|
|
|
97
87
|
|
|
98
88
|
// Update refs
|
|
99
89
|
prevTokenRef.current = token.address;
|
|
100
|
-
initialBalanceSetRef.current = true;
|
|
101
90
|
}
|
|
102
91
|
}, [token.address, token.chainId, token.decimals, chainId, context, onChangeInput, rawBalance]);
|
|
103
92
|
|
|
@@ -86,7 +86,7 @@ export function useAnyspendFlow({
|
|
|
86
86
|
const defaultDstToken = B3_TOKEN; // Default destination token
|
|
87
87
|
const [selectedSrcToken, setSelectedSrcToken] = useState<components["schemas"]["Token"]>(defaultSrcToken);
|
|
88
88
|
const [selectedDstToken, setSelectedDstToken] = useState<components["schemas"]["Token"]>(defaultDstToken);
|
|
89
|
-
const [srcAmount, setSrcAmount] = useState<string>(paymentType === "fiat" ? "5" : "0
|
|
89
|
+
const [srcAmount, setSrcAmount] = useState<string>(paymentType === "fiat" ? "5" : "0");
|
|
90
90
|
const [dstAmount, setDstAmount] = useState<string>("");
|
|
91
91
|
const [isSrcInputDirty, setIsSrcInputDirty] = useState(true);
|
|
92
92
|
|
|
@@ -6,7 +6,6 @@ import invariant from "invariant";
|
|
|
6
6
|
import { useCallback, useState } from "react";
|
|
7
7
|
import { toast } from "sonner";
|
|
8
8
|
import { prepareTransaction, sendTransaction as twSendTransaction } from "thirdweb";
|
|
9
|
-
import { useActiveWallet } from "thirdweb/react";
|
|
10
9
|
import { isAddress } from "viem";
|
|
11
10
|
import { useSwitchChain } from "wagmi";
|
|
12
11
|
import { useB3 } from "../components";
|
|
@@ -29,7 +28,6 @@ invariant(partnerId, "Partner ID is required");
|
|
|
29
28
|
export function useUnifiedChainSwitchAndExecute() {
|
|
30
29
|
const { switchChainAsync } = useSwitchChain();
|
|
31
30
|
const [isSwitchingOrExecuting, setIsSwitchingOrExecuting] = useState(false);
|
|
32
|
-
const activeWallet = useActiveWallet();
|
|
33
31
|
|
|
34
32
|
const { isActiveSmartWallet, isActiveEOAWallet, connectedEOAWallet } = useAccountWallet();
|
|
35
33
|
const { account: aaAccount } = useB3();
|
|
@@ -49,12 +47,12 @@ export function useUnifiedChainSwitchAndExecute() {
|
|
|
49
47
|
return;
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
const currentChainId =
|
|
50
|
+
const currentChainId = connectedEOAWallet?.getChain()?.id;
|
|
53
51
|
const onCorrectChain = currentChainId === targetChainId;
|
|
54
52
|
|
|
55
53
|
// Helper function to execute the transaction
|
|
56
54
|
const executeTransaction = async (): Promise<string> => {
|
|
57
|
-
const signer =
|
|
55
|
+
const signer = connectedEOAWallet?.getAccount();
|
|
58
56
|
if (!signer) {
|
|
59
57
|
throw new Error("No account connected");
|
|
60
58
|
}
|
|
@@ -62,7 +60,7 @@ export function useUnifiedChainSwitchAndExecute() {
|
|
|
62
60
|
// Coinbase Smart Wallet specific chain switching (different behavior from other wallets)
|
|
63
61
|
const walletChain = connectedEOAWallet.getChain();
|
|
64
62
|
if (walletChain?.id !== targetChainId) {
|
|
65
|
-
|
|
63
|
+
connectedEOAWallet?.switchChain(getThirdwebChain(targetChainId));
|
|
66
64
|
}
|
|
67
65
|
|
|
68
66
|
invariant(isAddress(params.to), "params.to is not a valid address");
|
|
@@ -121,7 +119,7 @@ export function useUnifiedChainSwitchAndExecute() {
|
|
|
121
119
|
setIsSwitchingOrExecuting(false);
|
|
122
120
|
}
|
|
123
121
|
},
|
|
124
|
-
[connectedEOAWallet,
|
|
122
|
+
[connectedEOAWallet, switchChainAsync],
|
|
125
123
|
);
|
|
126
124
|
|
|
127
125
|
// Handle AA wallet transaction (no chain switch needed for AA)
|
|
@@ -186,14 +184,10 @@ export function useUnifiedChainSwitchAndExecute() {
|
|
|
186
184
|
// Check which wallet type is active
|
|
187
185
|
if (isActiveSmartWallet) {
|
|
188
186
|
return handleAASendTransaction(targetChainId, params);
|
|
189
|
-
} else if (isActiveEOAWallet) {
|
|
190
|
-
return handleEOASwitchChainAndSendTransaction(targetChainId, params);
|
|
191
|
-
} else {
|
|
192
|
-
toast.error("No wallet connected");
|
|
193
|
-
return undefined;
|
|
194
187
|
}
|
|
188
|
+
return handleEOASwitchChainAndSendTransaction(targetChainId, params);
|
|
195
189
|
},
|
|
196
|
-
[isActiveSmartWallet,
|
|
190
|
+
[isActiveSmartWallet, handleAASendTransaction, handleEOASwitchChainAndSendTransaction],
|
|
197
191
|
);
|
|
198
192
|
|
|
199
193
|
return {
|