@b3dotfun/sdk 0.0.62 → 0.0.63-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/react/components/AnySpend.js +61 -23
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +3 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +275 -0
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +5 -4
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.js +288 -0
- package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
- package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.js +33 -0
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +4 -4
- package/dist/cjs/anyspend/react/components/common/CryptoPaySection.js +4 -6
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +9 -17
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
- package/dist/cjs/anyspend/react/components/common/CryptoReceiveSection.js +11 -1
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +66 -147
- package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -3
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +39 -15
- package/dist/cjs/anyspend/react/components/common/PaySection.js +1 -1
- package/dist/cjs/anyspend/react/components/common/TokenBalance.js +1 -1
- package/dist/cjs/anyspend/react/components/index.d.ts +5 -1
- package/dist/cjs/anyspend/react/components/index.js +11 -3
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +42 -19
- package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendQuote.js +1 -1
- package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
- package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +56 -0
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
- package/dist/cjs/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +73 -0
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
- package/dist/cjs/anyspend/react/hooks/useConnectedWalletDisplay.js +57 -0
- package/dist/cjs/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
- package/dist/cjs/anyspend/react/hooks/usePhantomTransfer.js +211 -0
- package/dist/cjs/anyspend/types/api.d.ts +665 -3
- package/dist/cjs/anyspend/utils/orderPayload.js +4 -0
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +10 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +3 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
- package/dist/cjs/global-account/react/hooks/index.d.ts +2 -1
- package/dist/cjs/global-account/react/hooks/index.js +5 -3
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +7 -2
- package/dist/cjs/global-account/react/hooks/useSimBalance.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useSimBalance.js +6 -5
- package/dist/cjs/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
- package/dist/cjs/global-account/react/hooks/useTokenBalanceDirect.js +62 -0
- package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +4 -3
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +31 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +62 -24
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -0
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +269 -0
- package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +7 -6
- package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
- package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.js +285 -0
- package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
- package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.js +30 -0
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +4 -4
- package/dist/esm/anyspend/react/components/common/CryptoPaySection.js +5 -7
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +9 -17
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
- package/dist/esm/anyspend/react/components/common/CryptoReceiveSection.js +11 -1
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +67 -148
- package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -3
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +40 -16
- package/dist/esm/anyspend/react/components/common/PaySection.js +1 -1
- package/dist/esm/anyspend/react/components/common/TokenBalance.js +2 -2
- package/dist/esm/anyspend/react/components/index.d.ts +5 -1
- package/dist/esm/anyspend/react/components/index.js +5 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +42 -19
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendQuote.js +1 -1
- package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
- package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +53 -0
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
- package/dist/esm/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.js +70 -0
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
- package/dist/esm/anyspend/react/hooks/useConnectedWalletDisplay.js +54 -0
- package/dist/esm/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
- package/dist/esm/anyspend/react/hooks/usePhantomTransfer.js +208 -0
- package/dist/esm/anyspend/types/api.d.ts +665 -3
- package/dist/esm/anyspend/utils/orderPayload.js +4 -0
- package/dist/esm/global-account/react/components/B3DynamicModal.js +11 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +3 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
- package/dist/esm/global-account/react/hooks/index.d.ts +2 -1
- package/dist/esm/global-account/react/hooks/index.js +2 -1
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +7 -2
- package/dist/esm/global-account/react/hooks/useSimBalance.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useSimBalance.js +6 -5
- package/dist/esm/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
- package/dist/esm/global-account/react/hooks/useTokenBalanceDirect.js +59 -0
- package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +4 -3
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +31 -1
- package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
- package/dist/types/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
- package/dist/types/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
- package/dist/types/anyspend/react/components/common/CryptoReceiveSection.d.ts +6 -1
- package/dist/types/anyspend/react/components/common/OrderTokenAmount.d.ts +2 -1
- package/dist/types/anyspend/react/components/index.d.ts +5 -1
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
- package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
- package/dist/types/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +26 -0
- package/dist/types/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.d.ts +10 -0
- package/dist/types/anyspend/react/hooks/useConnectedWalletDisplay.d.ts +14 -0
- package/dist/types/anyspend/react/hooks/usePhantomTransfer.d.ts +36 -0
- package/dist/types/anyspend/types/api.d.ts +665 -3
- package/dist/types/global-account/react/hooks/index.d.ts +2 -1
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/types/global-account/react/hooks/useSimBalance.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useTokenBalanceDirect.d.ts +12 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +31 -1
- package/package.json +3 -2
- package/src/anyspend/react/components/AnySpend.tsx +73 -22
- package/src/anyspend/react/components/AnySpendCustom.tsx +4 -0
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +595 -0
- package/src/anyspend/react/components/AnySpendStakeB3.tsx +8 -11
- package/src/anyspend/react/components/AnySpendStakeB3ExactIn.tsx +522 -0
- package/src/anyspend/react/components/AnySpendStakeUpsideExactIn.tsx +73 -0
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +7 -3
- package/src/anyspend/react/components/common/CryptoPaySection.tsx +5 -7
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +9 -18
- package/src/anyspend/react/components/common/CryptoReceiveSection.tsx +22 -0
- package/src/anyspend/react/components/common/OrderDetails.tsx +76 -190
- package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +2 -3
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +48 -17
- package/src/anyspend/react/components/common/PaySection.tsx +1 -0
- package/src/anyspend/react/components/common/TokenBalance.tsx +2 -2
- package/src/anyspend/react/components/index.ts +5 -1
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +51 -18
- package/src/anyspend/react/hooks/useAnyspendQuote.ts +1 -1
- package/src/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.ts +72 -0
- package/src/anyspend/react/hooks/useAutoSetActiveWalletFromWagmi.ts +80 -0
- package/src/anyspend/react/hooks/useConnectedWalletDisplay.ts +69 -0
- package/src/anyspend/react/hooks/usePhantomTransfer.ts +301 -0
- package/src/anyspend/types/api.ts +669 -1
- package/src/anyspend/utils/orderPayload.ts +5 -1
- package/src/global-account/react/components/B3DynamicModal.tsx +11 -1
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +3 -1
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +2 -2
- package/src/global-account/react/hooks/index.ts +2 -1
- package/src/global-account/react/hooks/useAuthentication.ts +10 -2
- package/src/global-account/react/hooks/useSimBalance.ts +6 -5
- package/src/global-account/react/hooks/useTokenBalanceDirect.tsx +84 -0
- package/src/global-account/react/hooks/useTokenFromUrl.tsx +6 -5
- package/src/global-account/react/stores/useModalStore.ts +34 -0
|
@@ -14,6 +14,8 @@ const chains_1 = require("viem/chains");
|
|
|
14
14
|
const wagmi_1 = require("wagmi");
|
|
15
15
|
const CryptoPaymentMethod_1 = require("../components/common/CryptoPaymentMethod");
|
|
16
16
|
const FiatPaymentMethod_1 = require("../components/common/FiatPaymentMethod");
|
|
17
|
+
const useAutoSelectCryptoPaymentMethod_1 = require("./useAutoSelectCryptoPaymentMethod");
|
|
18
|
+
const useAutoSetActiveWalletFromWagmi_1 = require("./useAutoSetActiveWalletFromWagmi");
|
|
17
19
|
var PanelView;
|
|
18
20
|
(function (PanelView) {
|
|
19
21
|
PanelView[PanelView["MAIN"] = 0] = "MAIN";
|
|
@@ -25,21 +27,25 @@ var PanelView;
|
|
|
25
27
|
PanelView[PanelView["POINTS_DETAIL"] = 6] = "POINTS_DETAIL";
|
|
26
28
|
PanelView[PanelView["FEE_DETAIL"] = 7] = "FEE_DETAIL";
|
|
27
29
|
})(PanelView || (exports.PanelView = PanelView = {}));
|
|
28
|
-
|
|
30
|
+
// This hook serves for order hype_duel and custom_exact_in
|
|
31
|
+
function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, isDepositMode = false, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, destinationTokenAddress, destinationTokenChainId, slippage = 0, disableUrlParamManagement = false, orderType = "hype_duel", }) {
|
|
29
32
|
const searchParams = (0, react_2.useSearchParamsSSR)();
|
|
30
33
|
const router = (0, react_2.useRouter)();
|
|
31
34
|
// Panel and order state
|
|
32
35
|
const [activePanel, setActivePanel] = (0, react_3.useState)(loadOrder ? PanelView.ORDER_DETAILS : PanelView.MAIN);
|
|
33
36
|
const [orderId, setOrderId] = (0, react_3.useState)(loadOrder);
|
|
34
37
|
const { orderAndTransactions: oat } = (0, react_1.useAnyspendOrderAndTransactions)(orderId);
|
|
35
|
-
// Token selection state - use provided sourceTokenChainId if available
|
|
38
|
+
// Token selection state - use provided sourceTokenChainId and destinationTokenChainId if available
|
|
36
39
|
const [selectedSrcChainId, setSelectedSrcChainId] = (0, react_3.useState)(sourceTokenChainId || (paymentType === "fiat" ? chains_1.base.id : chains_1.mainnet.id));
|
|
37
|
-
const [selectedDstChainId, setSelectedDstChainId] = (0, react_3.useState)(chains_1.base.id); // Default to Base for cross-chain swaps
|
|
38
40
|
const defaultSrcToken = paymentType === "fiat" ? anyspend_1.USDC_BASE : (0, anyspend_1.getDefaultToken)(selectedSrcChainId);
|
|
41
|
+
const defaultDstToken = anyspend_1.B3_TOKEN; // Default destination token
|
|
39
42
|
const [selectedSrcToken, setSelectedSrcToken] = (0, react_3.useState)(defaultSrcToken);
|
|
43
|
+
const [selectedDstToken, setSelectedDstToken] = (0, react_3.useState)(defaultDstToken);
|
|
40
44
|
const [srcAmount, setSrcAmount] = (0, react_3.useState)(paymentType === "fiat" ? "5" : "0.1");
|
|
41
45
|
const [dstAmount, setDstAmount] = (0, react_3.useState)("");
|
|
42
46
|
const [isSrcInputDirty, setIsSrcInputDirty] = (0, react_3.useState)(true);
|
|
47
|
+
// Derive destination chain ID from token or prop (cannot change)
|
|
48
|
+
const selectedDstChainId = destinationTokenChainId || selectedDstToken.chainId;
|
|
43
49
|
// Payment method state
|
|
44
50
|
const [selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod] = (0, react_3.useState)(CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE);
|
|
45
51
|
const [selectedFiatPaymentMethod, setSelectedFiatPaymentMethod] = (0, react_3.useState)(FiatPaymentMethod_1.FiatPaymentMethod.NONE);
|
|
@@ -49,6 +55,8 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
49
55
|
const [selectedRecipientAddress, setSelectedRecipientAddress] = (0, react_3.useState)(recipientAddress);
|
|
50
56
|
const recipientProfile = (0, react_2.useProfile)({ address: selectedRecipientAddress, fresh: true });
|
|
51
57
|
const recipientName = recipientProfile.data?.name;
|
|
58
|
+
// Auto-set active wallet from wagmi
|
|
59
|
+
(0, useAutoSetActiveWalletFromWagmi_1.useAutoSetActiveWalletFromWagmi)();
|
|
52
60
|
// Set default recipient address when wallet changes
|
|
53
61
|
(0, react_3.useEffect)(() => {
|
|
54
62
|
if (!selectedRecipientAddress && globalAddress) {
|
|
@@ -72,17 +80,14 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
72
80
|
return false;
|
|
73
81
|
}
|
|
74
82
|
}, [rawBalance, srcAmount, selectedSrcToken.decimals, isBalanceLoading, paymentType]);
|
|
75
|
-
// Auto-
|
|
76
|
-
(0,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}, [paymentType, hasEnoughBalance, isBalanceLoading]);
|
|
83
|
+
// Auto-select crypto payment method based on available wallets and balance
|
|
84
|
+
(0, useAutoSelectCryptoPaymentMethod_1.useAutoSelectCryptoPaymentMethod)({
|
|
85
|
+
paymentType,
|
|
86
|
+
selectedCryptoPaymentMethod,
|
|
87
|
+
setSelectedCryptoPaymentMethod,
|
|
88
|
+
hasEnoughBalance,
|
|
89
|
+
isBalanceLoading,
|
|
90
|
+
});
|
|
86
91
|
// Fetch specific token when sourceTokenAddress and sourceTokenChainId are provided
|
|
87
92
|
(0, react_3.useEffect)(() => {
|
|
88
93
|
const fetchSourceToken = async () => {
|
|
@@ -100,6 +105,23 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
100
105
|
};
|
|
101
106
|
fetchSourceToken();
|
|
102
107
|
}, [sourceTokenAddress, sourceTokenChainId]);
|
|
108
|
+
// Fetch specific token when destinationTokenAddress and destinationTokenChainId are provided
|
|
109
|
+
(0, react_3.useEffect)(() => {
|
|
110
|
+
const fetchDestinationToken = async () => {
|
|
111
|
+
if (destinationTokenAddress && destinationTokenChainId) {
|
|
112
|
+
try {
|
|
113
|
+
const token = await anyspend_2.anyspendService.getToken(destinationTokenChainId, destinationTokenAddress);
|
|
114
|
+
setSelectedDstToken(token);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error("Failed to fetch destination token:", error);
|
|
118
|
+
sonner_1.toast.error(`Failed to load token ${destinationTokenAddress} on chain ${destinationTokenChainId}`);
|
|
119
|
+
// Keep the default token on error
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
fetchDestinationToken();
|
|
124
|
+
}, [destinationTokenAddress, destinationTokenChainId]);
|
|
103
125
|
// Helper function for onramp vendor mapping
|
|
104
126
|
const getOnrampVendor = (paymentMethod) => {
|
|
105
127
|
switch (paymentMethod) {
|
|
@@ -119,8 +141,8 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
119
141
|
srcChain: paymentType === "fiat" ? chains_1.base.id : selectedSrcChainId,
|
|
120
142
|
dstChain: isDepositMode ? chains_1.base.id : selectedDstChainId, // For deposits, always Base; for swaps, use selected destination
|
|
121
143
|
srcTokenAddress: paymentType === "fiat" ? anyspend_1.USDC_BASE.address : selectedSrcToken.address,
|
|
122
|
-
dstTokenAddress:
|
|
123
|
-
type:
|
|
144
|
+
dstTokenAddress: selectedDstToken.address,
|
|
145
|
+
type: orderType,
|
|
124
146
|
amount: activeInputAmountInWei,
|
|
125
147
|
recipientAddress: selectedRecipientAddress,
|
|
126
148
|
onrampVendor: paymentType === "fiat" ? getOnrampVendor(selectedFiatPaymentMethod) : undefined,
|
|
@@ -198,7 +220,7 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
198
220
|
const formattedActualDstAmount = amount
|
|
199
221
|
? (0, number_1.formatTokenAmount)(BigInt(amount), oat.data.order.metadata.dstToken.decimals)
|
|
200
222
|
: undefined;
|
|
201
|
-
onTransactionSuccess?.(formattedActualDstAmount);
|
|
223
|
+
onTransactionSuccess?.(formattedActualDstAmount ?? "");
|
|
202
224
|
}
|
|
203
225
|
}, [
|
|
204
226
|
oat?.data?.order.status,
|
|
@@ -216,10 +238,11 @@ function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder,
|
|
|
216
238
|
// Token state
|
|
217
239
|
selectedSrcChainId,
|
|
218
240
|
setSelectedSrcChainId,
|
|
219
|
-
selectedDstChainId,
|
|
220
|
-
setSelectedDstChainId,
|
|
241
|
+
selectedDstChainId, // Derived, not stateful
|
|
221
242
|
selectedSrcToken,
|
|
222
243
|
setSelectedSrcToken,
|
|
244
|
+
selectedDstToken,
|
|
245
|
+
setSelectedDstToken,
|
|
223
246
|
srcAmount,
|
|
224
247
|
setSrcAmount,
|
|
225
248
|
dstAmount,
|
|
@@ -53,6 +53,35 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
53
53
|
relay?: Record<string, never>;
|
|
54
54
|
} | null;
|
|
55
55
|
fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
|
|
56
|
+
} & {
|
|
57
|
+
type: "x402_swap";
|
|
58
|
+
payload: import("../..").components["schemas"]["X402SwapPayload"];
|
|
59
|
+
metadata: import("../..").components["schemas"]["X402SwapMetadata"];
|
|
60
|
+
}) | ({
|
|
61
|
+
id: string;
|
|
62
|
+
recipientAddress: string;
|
|
63
|
+
globalAddress: string;
|
|
64
|
+
srcChain: number;
|
|
65
|
+
dstChain: number;
|
|
66
|
+
srcTokenAddress: string;
|
|
67
|
+
dstTokenAddress: string;
|
|
68
|
+
srcAmount: string;
|
|
69
|
+
status: "scanning_deposit_transaction" | "waiting_stripe_payment" | "expired" | "sending_token_from_vault" | "relay" | "executing" | "executed" | "refunding" | "refunded" | "failure";
|
|
70
|
+
errorDetails: string | null;
|
|
71
|
+
createdAt: number;
|
|
72
|
+
expiredAt: number;
|
|
73
|
+
filledAt: number | null;
|
|
74
|
+
receivedDepositAt: number | null;
|
|
75
|
+
creatorAddress: string | null;
|
|
76
|
+
partnerId: string | null;
|
|
77
|
+
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
78
|
+
oneClickBuyUrl: string | null;
|
|
79
|
+
stripePaymentIntentId: string | null;
|
|
80
|
+
settlement: {
|
|
81
|
+
actualDstAmount?: string;
|
|
82
|
+
relay?: Record<string, never>;
|
|
83
|
+
} | null;
|
|
84
|
+
fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
|
|
56
85
|
} & {
|
|
57
86
|
type: "hype_duel";
|
|
58
87
|
payload: import("../..").components["schemas"]["HypeDuelPayload"];
|
|
@@ -111,6 +140,35 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
111
140
|
relay?: Record<string, never>;
|
|
112
141
|
} | null;
|
|
113
142
|
fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
|
|
143
|
+
} & {
|
|
144
|
+
type: "custom_exact_in";
|
|
145
|
+
payload: import("../..").components["schemas"]["CustomExactInPayload"];
|
|
146
|
+
metadata: import("../..").components["schemas"]["CustomMetadata"];
|
|
147
|
+
}) | ({
|
|
148
|
+
id: string;
|
|
149
|
+
recipientAddress: string;
|
|
150
|
+
globalAddress: string;
|
|
151
|
+
srcChain: number;
|
|
152
|
+
dstChain: number;
|
|
153
|
+
srcTokenAddress: string;
|
|
154
|
+
dstTokenAddress: string;
|
|
155
|
+
srcAmount: string;
|
|
156
|
+
status: "scanning_deposit_transaction" | "waiting_stripe_payment" | "expired" | "sending_token_from_vault" | "relay" | "executing" | "executed" | "refunding" | "refunded" | "failure";
|
|
157
|
+
errorDetails: string | null;
|
|
158
|
+
createdAt: number;
|
|
159
|
+
expiredAt: number;
|
|
160
|
+
filledAt: number | null;
|
|
161
|
+
receivedDepositAt: number | null;
|
|
162
|
+
creatorAddress: string | null;
|
|
163
|
+
partnerId: string | null;
|
|
164
|
+
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
165
|
+
oneClickBuyUrl: string | null;
|
|
166
|
+
stripePaymentIntentId: string | null;
|
|
167
|
+
settlement: {
|
|
168
|
+
actualDstAmount?: string;
|
|
169
|
+
relay?: Record<string, never>;
|
|
170
|
+
} | null;
|
|
171
|
+
fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
|
|
114
172
|
} & {
|
|
115
173
|
type: "mint_nft";
|
|
116
174
|
payload: import("../..").components["schemas"]["MintNftPayload"];
|
|
@@ -230,6 +288,35 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
230
288
|
relay?: Record<string, never>;
|
|
231
289
|
} | null;
|
|
232
290
|
fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
|
|
291
|
+
} & {
|
|
292
|
+
type: "x402_swap";
|
|
293
|
+
payload: import("../..").components["schemas"]["X402SwapPayload"];
|
|
294
|
+
metadata: import("../..").components["schemas"]["X402SwapMetadata"];
|
|
295
|
+
}) | ({
|
|
296
|
+
id: string;
|
|
297
|
+
recipientAddress: string;
|
|
298
|
+
globalAddress: string;
|
|
299
|
+
srcChain: number;
|
|
300
|
+
dstChain: number;
|
|
301
|
+
srcTokenAddress: string;
|
|
302
|
+
dstTokenAddress: string;
|
|
303
|
+
srcAmount: string;
|
|
304
|
+
status: "scanning_deposit_transaction" | "waiting_stripe_payment" | "expired" | "sending_token_from_vault" | "relay" | "executing" | "executed" | "refunding" | "refunded" | "failure";
|
|
305
|
+
errorDetails: string | null;
|
|
306
|
+
createdAt: number;
|
|
307
|
+
expiredAt: number;
|
|
308
|
+
filledAt: number | null;
|
|
309
|
+
receivedDepositAt: number | null;
|
|
310
|
+
creatorAddress: string | null;
|
|
311
|
+
partnerId: string | null;
|
|
312
|
+
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
313
|
+
oneClickBuyUrl: string | null;
|
|
314
|
+
stripePaymentIntentId: string | null;
|
|
315
|
+
settlement: {
|
|
316
|
+
actualDstAmount?: string;
|
|
317
|
+
relay?: Record<string, never>;
|
|
318
|
+
} | null;
|
|
319
|
+
fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
|
|
233
320
|
} & {
|
|
234
321
|
type: "hype_duel";
|
|
235
322
|
payload: import("../..").components["schemas"]["HypeDuelPayload"];
|
|
@@ -288,6 +375,35 @@ export declare function useAnyspendOrderHistory(creatorAddress: string | undefin
|
|
|
288
375
|
relay?: Record<string, never>;
|
|
289
376
|
} | null;
|
|
290
377
|
fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
|
|
378
|
+
} & {
|
|
379
|
+
type: "custom_exact_in";
|
|
380
|
+
payload: import("../..").components["schemas"]["CustomExactInPayload"];
|
|
381
|
+
metadata: import("../..").components["schemas"]["CustomMetadata"];
|
|
382
|
+
}) | ({
|
|
383
|
+
id: string;
|
|
384
|
+
recipientAddress: string;
|
|
385
|
+
globalAddress: string;
|
|
386
|
+
srcChain: number;
|
|
387
|
+
dstChain: number;
|
|
388
|
+
srcTokenAddress: string;
|
|
389
|
+
dstTokenAddress: string;
|
|
390
|
+
srcAmount: string;
|
|
391
|
+
status: "scanning_deposit_transaction" | "waiting_stripe_payment" | "expired" | "sending_token_from_vault" | "relay" | "executing" | "executed" | "refunding" | "refunded" | "failure";
|
|
392
|
+
errorDetails: string | null;
|
|
393
|
+
createdAt: number;
|
|
394
|
+
expiredAt: number;
|
|
395
|
+
filledAt: number | null;
|
|
396
|
+
receivedDepositAt: number | null;
|
|
397
|
+
creatorAddress: string | null;
|
|
398
|
+
partnerId: string | null;
|
|
399
|
+
onrampMetadata: import("../..").components["schemas"]["OnrampMetadata"] | null;
|
|
400
|
+
oneClickBuyUrl: string | null;
|
|
401
|
+
stripePaymentIntentId: string | null;
|
|
402
|
+
settlement: {
|
|
403
|
+
actualDstAmount?: string;
|
|
404
|
+
relay?: Record<string, never>;
|
|
405
|
+
} | null;
|
|
406
|
+
fee?: Omit<import("../..").components["schemas"]["Fee"], "type"> | null;
|
|
291
407
|
} & {
|
|
292
408
|
type: "mint_nft";
|
|
293
409
|
payload: import("../..").components["schemas"]["MintNftPayload"];
|
|
@@ -14,7 +14,7 @@ function useAnyspendQuote(req) {
|
|
|
14
14
|
req.dstChain &&
|
|
15
15
|
req.srcTokenAddress &&
|
|
16
16
|
req.dstTokenAddress &&
|
|
17
|
-
BigInt(req.type === "swap" || req.type === "hype_duel"
|
|
17
|
+
BigInt(req.type === "swap" || req.type === "hype_duel" || req.type === "x402_swap" || req.type === "custom_exact_in"
|
|
18
18
|
? req.amount
|
|
19
19
|
: req.type === "mint_nft"
|
|
20
20
|
? req.price
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
2
|
+
interface UseAutoSelectCryptoPaymentMethodParams {
|
|
3
|
+
/** Current payment type (crypto or fiat) */
|
|
4
|
+
paymentType?: "crypto" | "fiat";
|
|
5
|
+
/** Currently selected payment method */
|
|
6
|
+
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
7
|
+
/** Function to update the selected payment method */
|
|
8
|
+
setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
9
|
+
/** Whether user has enough balance to pay */
|
|
10
|
+
hasEnoughBalance: boolean;
|
|
11
|
+
/** Whether balance is still loading */
|
|
12
|
+
isBalanceLoading: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Custom hook to automatically select appropriate crypto payment method
|
|
16
|
+
* based on available wallets and balance.
|
|
17
|
+
*
|
|
18
|
+
* Auto-selection logic:
|
|
19
|
+
* - Only auto-selects when payment method is NONE (doesn't override user choices)
|
|
20
|
+
* - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
|
|
21
|
+
* - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
|
|
22
|
+
* - If only Global wallet available → GLOBAL_WALLET
|
|
23
|
+
* - If no wallets → remains NONE
|
|
24
|
+
*/
|
|
25
|
+
export declare function useAutoSelectCryptoPaymentMethod({ paymentType, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }: UseAutoSelectCryptoPaymentMethodParams): void;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAutoSelectCryptoPaymentMethod = useAutoSelectCryptoPaymentMethod;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const CryptoPaymentMethod_1 = require("../components/common/CryptoPaymentMethod");
|
|
6
|
+
const useConnectedWalletDisplay_1 = require("./useConnectedWalletDisplay");
|
|
7
|
+
/**
|
|
8
|
+
* Custom hook to automatically select appropriate crypto payment method
|
|
9
|
+
* based on available wallets and balance.
|
|
10
|
+
*
|
|
11
|
+
* Auto-selection logic:
|
|
12
|
+
* - Only auto-selects when payment method is NONE (doesn't override user choices)
|
|
13
|
+
* - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
|
|
14
|
+
* - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
|
|
15
|
+
* - If only Global wallet available → GLOBAL_WALLET
|
|
16
|
+
* - If no wallets → remains NONE
|
|
17
|
+
*/
|
|
18
|
+
function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto", selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }) {
|
|
19
|
+
// Get suggested payment method based on available wallets
|
|
20
|
+
const { suggestedPaymentMethod } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(selectedCryptoPaymentMethod);
|
|
21
|
+
(0, react_1.useEffect)(() => {
|
|
22
|
+
// Only auto-select when on crypto payment type and payment method is NONE
|
|
23
|
+
if (paymentType !== "crypto" || selectedCryptoPaymentMethod !== CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// If we have a suggested payment method (wallet is connected), use it
|
|
27
|
+
if (suggestedPaymentMethod !== CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
28
|
+
// If we have balance info and enough balance, use CONNECT_WALLET
|
|
29
|
+
// Otherwise, default to TRANSFER_CRYPTO if balance is insufficient
|
|
30
|
+
if (!isBalanceLoading) {
|
|
31
|
+
if (hasEnoughBalance && suggestedPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
32
|
+
setSelectedCryptoPaymentMethod(CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET);
|
|
33
|
+
}
|
|
34
|
+
else if (!hasEnoughBalance && suggestedPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
35
|
+
// Wallet connected but insufficient balance - suggest transfer
|
|
36
|
+
setSelectedCryptoPaymentMethod(CryptoPaymentMethod_1.CryptoPaymentMethodType.TRANSFER_CRYPTO);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Use suggested method (e.g., GLOBAL_WALLET)
|
|
40
|
+
setSelectedCryptoPaymentMethod(suggestedPaymentMethod);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// Balance still loading, use suggested method
|
|
45
|
+
setSelectedCryptoPaymentMethod(suggestedPaymentMethod);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, [
|
|
49
|
+
paymentType,
|
|
50
|
+
selectedCryptoPaymentMethod,
|
|
51
|
+
suggestedPaymentMethod,
|
|
52
|
+
hasEnoughBalance,
|
|
53
|
+
isBalanceLoading,
|
|
54
|
+
setSelectedCryptoPaymentMethod,
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAutoSetActiveWalletFromWagmi = useAutoSetActiveWalletFromWagmi;
|
|
4
|
+
const thirdweb_1 = require("../../../shared/utils/thirdweb");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_2 = require("thirdweb/react");
|
|
7
|
+
const wallets_1 = require("thirdweb/wallets");
|
|
8
|
+
const wagmi_1 = require("wagmi");
|
|
9
|
+
/**
|
|
10
|
+
* Hook that automatically sets the active thirdweb wallet when a wagmi wallet connects.
|
|
11
|
+
*
|
|
12
|
+
* This is useful for syncing wagmi wallet connections with thirdweb's wallet system,
|
|
13
|
+
* ensuring that when users connect via wagmi, the active wallet is properly set.
|
|
14
|
+
*
|
|
15
|
+
* Place this hook in components that stay mounted throughout the user flow
|
|
16
|
+
* (not in components that unmount during navigation).
|
|
17
|
+
*/
|
|
18
|
+
function useAutoSetActiveWalletFromWagmi() {
|
|
19
|
+
const { address: wagmiAddress, connector: wagmiConnector } = (0, wagmi_1.useAccount)();
|
|
20
|
+
const setActiveWallet = (0, react_2.useSetActiveWallet)();
|
|
21
|
+
const prevWagmiAddress = (0, react_1.useRef)(undefined);
|
|
22
|
+
// Map wagmi connector names to thirdweb wallet IDs
|
|
23
|
+
const getThirdwebWalletId = (0, react_1.useCallback)((connectorName) => {
|
|
24
|
+
const walletMap = {
|
|
25
|
+
MetaMask: "io.metamask",
|
|
26
|
+
"Coinbase Wallet": "com.coinbase.wallet",
|
|
27
|
+
Rainbow: "me.rainbow",
|
|
28
|
+
WalletConnect: "walletConnect",
|
|
29
|
+
Phantom: "app.phantom",
|
|
30
|
+
};
|
|
31
|
+
return walletMap[connectorName] || null;
|
|
32
|
+
}, []);
|
|
33
|
+
// Create thirdweb wallet from wagmi connector
|
|
34
|
+
const createThirdwebWalletFromConnector = (0, react_1.useCallback)(async (connectorName) => {
|
|
35
|
+
const walletId = getThirdwebWalletId(connectorName);
|
|
36
|
+
if (!walletId) {
|
|
37
|
+
console.warn(`No thirdweb wallet ID found for connector: ${connectorName}`);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const thirdwebWallet = (0, wallets_1.createWallet)(walletId);
|
|
42
|
+
await thirdwebWallet.connect({ client: thirdweb_1.client });
|
|
43
|
+
return thirdwebWallet;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error(`Failed to create thirdweb wallet for ${connectorName}:`, error);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}, [getThirdwebWalletId]);
|
|
50
|
+
// Listen for wagmi wallet connections and automatically set active wallet
|
|
51
|
+
(0, react_1.useEffect)(() => {
|
|
52
|
+
const isNewConnection = wagmiAddress && wagmiAddress !== prevWagmiAddress.current;
|
|
53
|
+
if (isNewConnection && wagmiConnector?.name) {
|
|
54
|
+
prevWagmiAddress.current = wagmiAddress;
|
|
55
|
+
const setupThirdwebWallet = async () => {
|
|
56
|
+
try {
|
|
57
|
+
const thirdwebWallet = await createThirdwebWalletFromConnector(wagmiConnector.name);
|
|
58
|
+
if (thirdwebWallet) {
|
|
59
|
+
setActiveWallet(thirdwebWallet);
|
|
60
|
+
console.log(`Auto-set active wallet for ${wagmiConnector.name}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error("Failed to auto-set active wallet:", error);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
setupThirdwebWallet();
|
|
68
|
+
}
|
|
69
|
+
if (!wagmiAddress) {
|
|
70
|
+
prevWagmiAddress.current = undefined;
|
|
71
|
+
}
|
|
72
|
+
}, [wagmiAddress, wagmiConnector?.name, setActiveWallet, createThirdwebWalletFromConnector]);
|
|
73
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
2
|
+
interface UseConnectedWalletDisplayResult {
|
|
3
|
+
walletAddress: string | undefined;
|
|
4
|
+
shouldShowConnectedEOA: boolean;
|
|
5
|
+
shouldShowWagmiWallet: boolean;
|
|
6
|
+
isWalletDuplicated: boolean;
|
|
7
|
+
suggestedPaymentMethod: CryptoPaymentMethodType;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Custom hook to determine which wallet to display and its address
|
|
11
|
+
* Handles logic for showing EOA wallet, wagmi wallet, or global wallet based on payment method
|
|
12
|
+
*/
|
|
13
|
+
export declare function useConnectedWalletDisplay(selectedCryptoPaymentMethod?: CryptoPaymentMethodType): UseConnectedWalletDisplayResult;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useConnectedWalletDisplay = useConnectedWalletDisplay;
|
|
4
|
+
const react_1 = require("../../../global-account/react");
|
|
5
|
+
const wagmi_1 = require("wagmi");
|
|
6
|
+
const CryptoPaymentMethod_1 = require("../components/common/CryptoPaymentMethod");
|
|
7
|
+
/**
|
|
8
|
+
* Custom hook to determine which wallet to display and its address
|
|
9
|
+
* Handles logic for showing EOA wallet, wagmi wallet, or global wallet based on payment method
|
|
10
|
+
*/
|
|
11
|
+
function useConnectedWalletDisplay(selectedCryptoPaymentMethod) {
|
|
12
|
+
const { connectedEOAWallet, connectedSmartWallet } = (0, react_1.useAccountWallet)();
|
|
13
|
+
const { address: wagmiAddress, isConnected: wagmiWalletIsConnected } = (0, wagmi_1.useAccount)();
|
|
14
|
+
// Helper function to check if two addresses are the same
|
|
15
|
+
const isSameAddress = (addr1, addr2) => {
|
|
16
|
+
if (!addr1 || !addr2)
|
|
17
|
+
return false;
|
|
18
|
+
return addr1.toLowerCase() === addr2.toLowerCase();
|
|
19
|
+
};
|
|
20
|
+
// Check if connectedEOAWallet and wagmi wallet represent the same wallet
|
|
21
|
+
const connectedEOAAddress = connectedEOAWallet?.getAccount()?.address;
|
|
22
|
+
const isWalletDuplicated = isSameAddress(connectedEOAAddress, wagmiAddress);
|
|
23
|
+
// Determine which wallet to show (prefer connectedEOAWallet if both exist and are the same)
|
|
24
|
+
const shouldShowConnectedEOA = !!connectedEOAWallet;
|
|
25
|
+
const shouldShowWagmiWallet = wagmiWalletIsConnected && (!isWalletDuplicated || !connectedEOAWallet);
|
|
26
|
+
// Determine which address to use based on payment method
|
|
27
|
+
let walletAddress;
|
|
28
|
+
if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
29
|
+
walletAddress = connectedSmartWallet?.getAccount()?.address;
|
|
30
|
+
}
|
|
31
|
+
else if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
32
|
+
// Prefer connectedEOAWallet, fallback to wagmi wallet
|
|
33
|
+
walletAddress = connectedEOAAddress || wagmiAddress;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Default behavior: use connectedEOAWallet if available, otherwise wagmi
|
|
37
|
+
walletAddress = connectedEOAAddress || wagmiAddress;
|
|
38
|
+
}
|
|
39
|
+
// Suggest a payment method based on available wallets
|
|
40
|
+
// Priority: Connected EOA/Wagmi wallet > Global wallet > None
|
|
41
|
+
let suggestedPaymentMethod = CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE;
|
|
42
|
+
if (connectedEOAAddress || wagmiAddress) {
|
|
43
|
+
// If there's a connected EOA or wagmi wallet, suggest CONNECT_WALLET
|
|
44
|
+
suggestedPaymentMethod = CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET;
|
|
45
|
+
}
|
|
46
|
+
else if (connectedSmartWallet?.getAccount()?.address) {
|
|
47
|
+
// If only global wallet is available, suggest that
|
|
48
|
+
suggestedPaymentMethod = CryptoPaymentMethod_1.CryptoPaymentMethodType.GLOBAL_WALLET;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
walletAddress,
|
|
52
|
+
shouldShowConnectedEOA,
|
|
53
|
+
shouldShowWagmiWallet,
|
|
54
|
+
isWalletDuplicated,
|
|
55
|
+
suggestedPaymentMethod,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
interface UsePhantomTransferParams {
|
|
2
|
+
/** RPC endpoint URL for Solana network */
|
|
3
|
+
rpcEndpoint?: string;
|
|
4
|
+
}
|
|
5
|
+
interface PhantomTransferParams {
|
|
6
|
+
/** Amount in lamports (for SOL) or smallest token unit (for SPL tokens) */
|
|
7
|
+
amountLamports: string;
|
|
8
|
+
/** Token address (use "11111111111111111111111111111111" for native SOL) */
|
|
9
|
+
tokenAddress: string;
|
|
10
|
+
/** Recipient address */
|
|
11
|
+
recipientAddress: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Custom hook for handling Phantom wallet transfers on Solana.
|
|
15
|
+
* Supports both native SOL and SPL token transfers with automatic priority fee calculation.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const { initiateTransfer, isPhantomAvailable } = usePhantomTransfer();
|
|
20
|
+
*
|
|
21
|
+
* await initiateTransfer({
|
|
22
|
+
* amountLamports: "1000000000", // 1 SOL
|
|
23
|
+
* tokenAddress: "11111111111111111111111111111111",
|
|
24
|
+
* recipientAddress: "..."
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function usePhantomTransfer({ rpcEndpoint }?: UsePhantomTransferParams): {
|
|
29
|
+
/** Function to initiate a transfer */
|
|
30
|
+
initiateTransfer: ({ amountLamports, tokenAddress, recipientAddress }: PhantomTransferParams) => Promise<void>;
|
|
31
|
+
/** Whether Phantom wallet is available (installed) */
|
|
32
|
+
isPhantomAvailable: any;
|
|
33
|
+
/** Get the currently connected Phantom wallet address */
|
|
34
|
+
getConnectedAddress: () => any;
|
|
35
|
+
};
|
|
36
|
+
export {};
|