@b3dotfun/sdk 0.0.65 → 0.0.66-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 +38 -24
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +22 -9
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +44 -13
- package/dist/cjs/anyspend/react/components/AnySpendDepositUpside.d.ts +11 -0
- package/dist/cjs/anyspend/react/components/AnySpendDepositUpside.js +41 -0
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +1 -1
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +14 -251
- package/dist/cjs/anyspend/react/components/common/OrderTokenAmount.js +2 -10
- package/dist/cjs/anyspend/react/components/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/index.js +4 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +16 -10
- package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
- package/dist/cjs/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +13 -9
- package/dist/cjs/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
- package/dist/cjs/anyspend/react/hooks/useCryptoPaymentMethodState.js +51 -0
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +3 -0
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +6 -14
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +21 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +38 -24
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +22 -9
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +3 -1
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +44 -13
- package/dist/esm/anyspend/react/components/AnySpendDepositUpside.d.ts +11 -0
- package/dist/esm/anyspend/react/components/AnySpendDepositUpside.js +38 -0
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +15 -249
- package/dist/esm/anyspend/react/components/common/OrderTokenAmount.js +2 -10
- package/dist/esm/anyspend/react/components/index.d.ts +1 -0
- package/dist/esm/anyspend/react/components/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +16 -10
- package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
- package/dist/esm/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.js +13 -9
- package/dist/esm/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
- package/dist/esm/anyspend/react/hooks/useCryptoPaymentMethodState.js +48 -0
- package/dist/esm/global-account/react/components/B3DynamicModal.js +3 -0
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +6 -14
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +21 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +3 -1
- package/dist/types/anyspend/react/components/AnySpendDepositUpside.d.ts +11 -0
- package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +1 -1
- package/dist/types/anyspend/react/components/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +5 -1
- package/dist/types/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.d.ts +7 -5
- package/dist/types/anyspend/react/hooks/useCryptoPaymentMethodState.d.ts +42 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +21 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +50 -29
- package/src/anyspend/react/components/AnySpendCustom.tsx +28 -15
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +54 -13
- package/src/anyspend/react/components/AnySpendDepositUpside.tsx +81 -0
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +36 -526
- package/src/anyspend/react/components/common/OrderTokenAmount.tsx +2 -13
- package/src/anyspend/react/components/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +24 -12
- package/src/anyspend/react/hooks/useAutoSelectCryptoPaymentMethod.ts +20 -12
- package/src/anyspend/react/hooks/useCryptoPaymentMethodState.ts +71 -0
- package/src/global-account/react/components/B3DynamicModal.tsx +3 -0
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +6 -12
- package/src/global-account/react/stores/useModalStore.ts +22 -0
- package/src/styles/index.css +8 -0
|
@@ -7,11 +7,12 @@ import { useEffect, useMemo, useState } from "react";
|
|
|
7
7
|
import { toast } from "sonner";
|
|
8
8
|
import { parseUnits } from "viem";
|
|
9
9
|
import { base, mainnet } from "viem/chains";
|
|
10
|
-
import { useAccount } from "wagmi";
|
|
11
10
|
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod.js";
|
|
12
11
|
import { FiatPaymentMethod } from "../components/common/FiatPaymentMethod.js";
|
|
13
12
|
import { useAutoSelectCryptoPaymentMethod } from "./useAutoSelectCryptoPaymentMethod.js";
|
|
14
13
|
import { useAutoSetActiveWalletFromWagmi } from "./useAutoSetActiveWalletFromWagmi.js";
|
|
14
|
+
import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay.js";
|
|
15
|
+
import { useCryptoPaymentMethodState } from "./useCryptoPaymentMethodState.js";
|
|
15
16
|
export var PanelView;
|
|
16
17
|
(function (PanelView) {
|
|
17
18
|
PanelView[PanelView["MAIN"] = 0] = "MAIN";
|
|
@@ -37,17 +38,17 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
37
38
|
const defaultDstToken = B3_TOKEN; // Default destination token
|
|
38
39
|
const [selectedSrcToken, setSelectedSrcToken] = useState(defaultSrcToken);
|
|
39
40
|
const [selectedDstToken, setSelectedDstToken] = useState(defaultDstToken);
|
|
40
|
-
const [srcAmount, setSrcAmount] = useState(paymentType === "fiat" ? "5" : "0
|
|
41
|
+
const [srcAmount, setSrcAmount] = useState(paymentType === "fiat" ? "5" : "0");
|
|
41
42
|
const [dstAmount, setDstAmount] = useState("");
|
|
42
43
|
const [isSrcInputDirty, setIsSrcInputDirty] = useState(true);
|
|
43
44
|
// Derive destination chain ID from token or prop (cannot change)
|
|
44
45
|
const selectedDstChainId = destinationTokenChainId || selectedDstToken.chainId;
|
|
45
|
-
// Payment method state
|
|
46
|
-
const
|
|
46
|
+
// Payment method state with dual-state system (auto + explicit user selection)
|
|
47
|
+
const { cryptoPaymentMethod, setCryptoPaymentMethod, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, effectiveCryptoPaymentMethod, resetPaymentMethods, } = useCryptoPaymentMethodState();
|
|
47
48
|
const [selectedFiatPaymentMethod, setSelectedFiatPaymentMethod] = useState(FiatPaymentMethod.NONE);
|
|
48
49
|
// Recipient state
|
|
49
50
|
const { address: globalAddress } = useAccountWallet();
|
|
50
|
-
const {
|
|
51
|
+
const { walletAddress } = useConnectedWalletDisplay(effectiveCryptoPaymentMethod);
|
|
51
52
|
const [selectedRecipientAddress, setSelectedRecipientAddress] = useState(recipientAddress);
|
|
52
53
|
const recipientProfile = useProfile({ address: selectedRecipientAddress, fresh: true });
|
|
53
54
|
const recipientName = recipientProfile.data?.name;
|
|
@@ -62,7 +63,7 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
62
63
|
// Check token balance for crypto payments
|
|
63
64
|
const { rawBalance, isLoading: isBalanceLoading } = useTokenBalance({
|
|
64
65
|
token: selectedSrcToken,
|
|
65
|
-
address:
|
|
66
|
+
address: walletAddress,
|
|
66
67
|
});
|
|
67
68
|
// Check if user has enough balance
|
|
68
69
|
const hasEnoughBalance = useMemo(() => {
|
|
@@ -79,8 +80,9 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
79
80
|
// Auto-select crypto payment method based on available wallets and balance
|
|
80
81
|
useAutoSelectCryptoPaymentMethod({
|
|
81
82
|
paymentType,
|
|
83
|
+
cryptoPaymentMethod,
|
|
84
|
+
setCryptoPaymentMethod,
|
|
82
85
|
selectedCryptoPaymentMethod,
|
|
83
|
-
setSelectedCryptoPaymentMethod,
|
|
84
86
|
hasEnoughBalance,
|
|
85
87
|
isBalanceLoading,
|
|
86
88
|
});
|
|
@@ -180,9 +182,9 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
180
182
|
if (!disableUrlParamManagement) {
|
|
181
183
|
const params = new URLSearchParams(searchParams.toString()); // Preserve existing params
|
|
182
184
|
params.set("orderId", newOrderId);
|
|
183
|
-
if (
|
|
184
|
-
console.log("Setting cryptoPaymentMethod in URL:",
|
|
185
|
-
params.set("cryptoPaymentMethod",
|
|
185
|
+
if (effectiveCryptoPaymentMethod !== CryptoPaymentMethodType.NONE) {
|
|
186
|
+
console.log("Setting cryptoPaymentMethod in URL:", effectiveCryptoPaymentMethod);
|
|
187
|
+
params.set("cryptoPaymentMethod", effectiveCryptoPaymentMethod);
|
|
186
188
|
}
|
|
187
189
|
else {
|
|
188
190
|
console.log("Payment method is NONE, not setting in URL");
|
|
@@ -246,8 +248,12 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
|
|
|
246
248
|
isSrcInputDirty,
|
|
247
249
|
setIsSrcInputDirty,
|
|
248
250
|
// Payment methods
|
|
251
|
+
cryptoPaymentMethod,
|
|
252
|
+
setCryptoPaymentMethod,
|
|
249
253
|
selectedCryptoPaymentMethod,
|
|
250
254
|
setSelectedCryptoPaymentMethod,
|
|
255
|
+
effectiveCryptoPaymentMethod,
|
|
256
|
+
resetPaymentMethods,
|
|
251
257
|
selectedFiatPaymentMethod,
|
|
252
258
|
setSelectedFiatPaymentMethod,
|
|
253
259
|
// Recipient
|
|
@@ -2,10 +2,12 @@ import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMetho
|
|
|
2
2
|
interface UseAutoSelectCryptoPaymentMethodParams {
|
|
3
3
|
/** Current payment type (crypto or fiat) */
|
|
4
4
|
paymentType?: "crypto" | "fiat";
|
|
5
|
-
/**
|
|
5
|
+
/** Auto-selected payment method based on balance (not used in hook logic, but part of state management) */
|
|
6
|
+
cryptoPaymentMethod: CryptoPaymentMethodType;
|
|
7
|
+
/** Function to update the auto-selected payment method */
|
|
8
|
+
setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
9
|
+
/** User explicitly selected payment method (NONE means no explicit selection) */
|
|
6
10
|
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
7
|
-
/** Function to update the selected payment method */
|
|
8
|
-
setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
9
11
|
/** Whether user has enough balance to pay */
|
|
10
12
|
hasEnoughBalance: boolean;
|
|
11
13
|
/** Whether balance is still loading */
|
|
@@ -16,11 +18,11 @@ interface UseAutoSelectCryptoPaymentMethodParams {
|
|
|
16
18
|
* based on available wallets and balance.
|
|
17
19
|
*
|
|
18
20
|
* Auto-selection logic:
|
|
19
|
-
* - Only auto-selects when
|
|
21
|
+
* - Only auto-selects when selectedCryptoPaymentMethod is NONE (user hasn't explicitly chosen)
|
|
20
22
|
* - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
|
|
21
23
|
* - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
|
|
22
24
|
* - If only Global wallet available → GLOBAL_WALLET
|
|
23
25
|
* - If no wallets → remains NONE
|
|
24
26
|
*/
|
|
25
|
-
export declare function useAutoSelectCryptoPaymentMethod({ paymentType,
|
|
27
|
+
export declare function useAutoSelectCryptoPaymentMethod({ paymentType, cryptoPaymentMethod: _cryptoPaymentMethod, setCryptoPaymentMethod, selectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }: UseAutoSelectCryptoPaymentMethodParams): void;
|
|
26
28
|
export {};
|
|
@@ -6,18 +6,22 @@ import { useConnectedWalletDisplay } from "./useConnectedWalletDisplay.js";
|
|
|
6
6
|
* based on available wallets and balance.
|
|
7
7
|
*
|
|
8
8
|
* Auto-selection logic:
|
|
9
|
-
* - Only auto-selects when
|
|
9
|
+
* - Only auto-selects when selectedCryptoPaymentMethod is NONE (user hasn't explicitly chosen)
|
|
10
10
|
* - If EOA/Wagmi wallet connected + has balance → CONNECT_WALLET
|
|
11
11
|
* - If EOA/Wagmi wallet connected + insufficient balance → TRANSFER_CRYPTO
|
|
12
12
|
* - If only Global wallet available → GLOBAL_WALLET
|
|
13
13
|
* - If no wallets → remains NONE
|
|
14
14
|
*/
|
|
15
|
-
export function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto",
|
|
15
|
+
export function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto", cryptoPaymentMethod: _cryptoPaymentMethod, setCryptoPaymentMethod, selectedCryptoPaymentMethod, hasEnoughBalance, isBalanceLoading, }) {
|
|
16
16
|
// Get suggested payment method based on available wallets
|
|
17
17
|
const { suggestedPaymentMethod } = useConnectedWalletDisplay(selectedCryptoPaymentMethod);
|
|
18
18
|
useEffect(() => {
|
|
19
|
-
// Only auto-select when on crypto payment type
|
|
20
|
-
if (paymentType !== "crypto"
|
|
19
|
+
// Only auto-select when on crypto payment type
|
|
20
|
+
if (paymentType !== "crypto") {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Only auto-switch if user hasn't explicitly selected a payment method
|
|
24
|
+
if (selectedCryptoPaymentMethod !== CryptoPaymentMethodType.NONE) {
|
|
21
25
|
return;
|
|
22
26
|
}
|
|
23
27
|
// If we have a suggested payment method (wallet is connected), use it
|
|
@@ -26,28 +30,28 @@ export function useAutoSelectCryptoPaymentMethod({ paymentType = "crypto", selec
|
|
|
26
30
|
// Otherwise, default to TRANSFER_CRYPTO if balance is insufficient
|
|
27
31
|
if (!isBalanceLoading) {
|
|
28
32
|
if (hasEnoughBalance && suggestedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
29
|
-
|
|
33
|
+
setCryptoPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
30
34
|
}
|
|
31
35
|
else if (!hasEnoughBalance && suggestedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
32
36
|
// Wallet connected but insufficient balance - suggest transfer
|
|
33
|
-
|
|
37
|
+
setCryptoPaymentMethod(CryptoPaymentMethodType.TRANSFER_CRYPTO);
|
|
34
38
|
}
|
|
35
39
|
else {
|
|
36
40
|
// Use suggested method (e.g., GLOBAL_WALLET)
|
|
37
|
-
|
|
41
|
+
setCryptoPaymentMethod(suggestedPaymentMethod);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
else {
|
|
41
45
|
// Balance still loading, use suggested method
|
|
42
|
-
|
|
46
|
+
setCryptoPaymentMethod(suggestedPaymentMethod);
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
}, [
|
|
46
50
|
paymentType,
|
|
51
|
+
setCryptoPaymentMethod,
|
|
47
52
|
selectedCryptoPaymentMethod,
|
|
48
53
|
suggestedPaymentMethod,
|
|
49
54
|
hasEnoughBalance,
|
|
50
55
|
isBalanceLoading,
|
|
51
|
-
setSelectedCryptoPaymentMethod,
|
|
52
56
|
]);
|
|
53
57
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod";
|
|
2
|
+
interface UseCryptoPaymentMethodStateResult {
|
|
3
|
+
/** Auto-selected payment method based on balance */
|
|
4
|
+
cryptoPaymentMethod: CryptoPaymentMethodType;
|
|
5
|
+
/** Function to update the auto-selected payment method */
|
|
6
|
+
setCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
7
|
+
/** User explicitly selected payment method (NONE means no explicit selection) */
|
|
8
|
+
selectedCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
9
|
+
/** Function to update the user-selected payment method */
|
|
10
|
+
setSelectedCryptoPaymentMethod: (method: CryptoPaymentMethodType) => void;
|
|
11
|
+
/** Effective payment method (user selection takes priority over auto-selection) */
|
|
12
|
+
effectiveCryptoPaymentMethod: CryptoPaymentMethodType;
|
|
13
|
+
/** Reset both payment method states to NONE */
|
|
14
|
+
resetPaymentMethods: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Custom hook to manage crypto payment method state with dual-state system:
|
|
18
|
+
*
|
|
19
|
+
* - `cryptoPaymentMethod`: Auto-selected based on wallet availability and balance
|
|
20
|
+
* - `selectedCryptoPaymentMethod`: Explicitly selected by user
|
|
21
|
+
* - `effectiveCryptoPaymentMethod`: User selection takes priority over auto-selection
|
|
22
|
+
*
|
|
23
|
+
* This allows automatic payment method suggestions while respecting explicit user choices.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* const {
|
|
28
|
+
* cryptoPaymentMethod,
|
|
29
|
+
* setCryptoPaymentMethod,
|
|
30
|
+
* selectedCryptoPaymentMethod,
|
|
31
|
+
* setSelectedCryptoPaymentMethod,
|
|
32
|
+
* effectiveCryptoPaymentMethod,
|
|
33
|
+
* resetPaymentMethods
|
|
34
|
+
* } = useCryptoPaymentMethodState();
|
|
35
|
+
*
|
|
36
|
+
* // Use effectiveCryptoPaymentMethod for display
|
|
37
|
+
* // Use setSelectedCryptoPaymentMethod when user explicitly selects
|
|
38
|
+
* // Call resetPaymentMethods when switching tabs or going back
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function useCryptoPaymentMethodState(): UseCryptoPaymentMethodStateResult;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { CryptoPaymentMethodType } from "../components/common/CryptoPaymentMethod.js";
|
|
3
|
+
/**
|
|
4
|
+
* Custom hook to manage crypto payment method state with dual-state system:
|
|
5
|
+
*
|
|
6
|
+
* - `cryptoPaymentMethod`: Auto-selected based on wallet availability and balance
|
|
7
|
+
* - `selectedCryptoPaymentMethod`: Explicitly selected by user
|
|
8
|
+
* - `effectiveCryptoPaymentMethod`: User selection takes priority over auto-selection
|
|
9
|
+
*
|
|
10
|
+
* This allows automatic payment method suggestions while respecting explicit user choices.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const {
|
|
15
|
+
* cryptoPaymentMethod,
|
|
16
|
+
* setCryptoPaymentMethod,
|
|
17
|
+
* selectedCryptoPaymentMethod,
|
|
18
|
+
* setSelectedCryptoPaymentMethod,
|
|
19
|
+
* effectiveCryptoPaymentMethod,
|
|
20
|
+
* resetPaymentMethods
|
|
21
|
+
* } = useCryptoPaymentMethodState();
|
|
22
|
+
*
|
|
23
|
+
* // Use effectiveCryptoPaymentMethod for display
|
|
24
|
+
* // Use setSelectedCryptoPaymentMethod when user explicitly selects
|
|
25
|
+
* // Call resetPaymentMethods when switching tabs or going back
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function useCryptoPaymentMethodState() {
|
|
29
|
+
// cryptoPaymentMethod: auto-selected based on balance
|
|
30
|
+
const [cryptoPaymentMethod, setCryptoPaymentMethod] = useState(CryptoPaymentMethodType.NONE);
|
|
31
|
+
// selectedCryptoPaymentMethod: explicitly selected by user (NONE means no explicit selection)
|
|
32
|
+
const [selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod] = useState(CryptoPaymentMethodType.NONE);
|
|
33
|
+
// The effective payment method (user selection takes priority over auto-selection)
|
|
34
|
+
const effectiveCryptoPaymentMethod = selectedCryptoPaymentMethod !== CryptoPaymentMethodType.NONE ? selectedCryptoPaymentMethod : cryptoPaymentMethod;
|
|
35
|
+
// Helper function to reset both states
|
|
36
|
+
const resetPaymentMethods = () => {
|
|
37
|
+
setCryptoPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
38
|
+
setSelectedCryptoPaymentMethod(CryptoPaymentMethodType.NONE);
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
cryptoPaymentMethod,
|
|
42
|
+
setCryptoPaymentMethod,
|
|
43
|
+
selectedCryptoPaymentMethod,
|
|
44
|
+
setSelectedCryptoPaymentMethod,
|
|
45
|
+
effectiveCryptoPaymentMethod,
|
|
46
|
+
resetPaymentMethods,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -17,6 +17,7 @@ import { RequestPermissions } from "./RequestPermissions/RequestPermissions.js";
|
|
|
17
17
|
import { SignInWithB3Flow } from "./SignInWithB3/SignInWithB3Flow.js";
|
|
18
18
|
import { Dialog, DialogContent, DialogDescription, DialogTitle } from "./ui/dialog.js";
|
|
19
19
|
import { Drawer, DrawerContent, DrawerDescription, DrawerTitle } from "./ui/drawer.js";
|
|
20
|
+
import { AnySpendDepositUpside } from "../../../anyspend/react/components/AnySpendDepositUpside.js";
|
|
20
21
|
const debug = debugB3React("B3DynamicModal");
|
|
21
22
|
export function B3DynamicModal() {
|
|
22
23
|
const { isOpen, setB3ModalOpen, contentType, history, navigateBack } = useModalStore();
|
|
@@ -102,6 +103,8 @@ export function B3DynamicModal() {
|
|
|
102
103
|
return _jsx(AnySpendStakeUpside, { ...contentType, mode: "modal" });
|
|
103
104
|
case "anySpendStakeUpsideExactIn":
|
|
104
105
|
return _jsx(AnySpendStakeUpsideExactIn, { ...contentType, mode: "modal" });
|
|
106
|
+
case "anySpendDepositUpside":
|
|
107
|
+
return _jsx(AnySpendDepositUpside, { ...contentType, mode: "modal" });
|
|
105
108
|
case "anySpendBuySpin":
|
|
106
109
|
return _jsx(AnySpendBuySpin, { ...contentType, mode: "modal" });
|
|
107
110
|
case "anySpendSignatureMint":
|
|
@@ -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,
|
|
@@ -260,6 +260,26 @@ export interface AnySpendStakeUpsideExactInProps extends BaseModalProps {
|
|
|
260
260
|
/** Callback function called when the stake is successful */
|
|
261
261
|
onSuccess?: () => void;
|
|
262
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Props for the AnySpend Deposit Upside (Exact In) modal
|
|
265
|
+
* Handles token deposit operations using the custom exact in flow
|
|
266
|
+
*/
|
|
267
|
+
export interface AnySpendDepositUpsideProps extends BaseModalProps {
|
|
268
|
+
/** Modal type identifier */
|
|
269
|
+
type: "anySpendDepositUpside";
|
|
270
|
+
/** Source token address */
|
|
271
|
+
sourceTokenAddress?: string;
|
|
272
|
+
/** Source token address */
|
|
273
|
+
sourceTokenChainId?: number;
|
|
274
|
+
/** Recipient address to deposit tokens for */
|
|
275
|
+
recipientAddress: string;
|
|
276
|
+
/** Deposit contract address */
|
|
277
|
+
depositContractAddress: string;
|
|
278
|
+
/** Token to deposit */
|
|
279
|
+
token: components["schemas"]["Token"];
|
|
280
|
+
/** Callback function called when the deposit is successful */
|
|
281
|
+
onSuccess?: () => void;
|
|
282
|
+
}
|
|
263
283
|
/**
|
|
264
284
|
* Props for the AnySpend Buy Spin modal
|
|
265
285
|
* Handles spin wheel entry purchases
|
|
@@ -360,7 +380,7 @@ export interface ProfileEditorModalProps extends BaseModalProps {
|
|
|
360
380
|
/**
|
|
361
381
|
* Union type of all possible modal content types
|
|
362
382
|
*/
|
|
363
|
-
export type ModalContentType = SignInWithB3ModalProps | RequestPermissionsModalProps | ManageAccountModalProps | AnySpendModalProps | AnyspendOrderDetailsProps | AnySpendNftProps | AnySpendJoinTournamentProps | AnySpendFundTournamentProps | AnySpendOrderHistoryProps | AnySpendStakeB3Props | AnySpendStakeB3ExactInProps | AnySpendStakeUpsideProps | AnySpendStakeUpsideExactInProps | AnySpendBuySpinProps | AnySpendSignatureMintProps | AnySpendBondKitProps | LinkAccountModalProps | AnySpendDepositHypeProps | AvatarEditorModalProps | ProfileEditorModalProps;
|
|
383
|
+
export type ModalContentType = SignInWithB3ModalProps | RequestPermissionsModalProps | ManageAccountModalProps | AnySpendModalProps | AnyspendOrderDetailsProps | AnySpendNftProps | AnySpendJoinTournamentProps | AnySpendFundTournamentProps | AnySpendOrderHistoryProps | AnySpendStakeB3Props | AnySpendStakeB3ExactInProps | AnySpendStakeUpsideProps | AnySpendStakeUpsideExactInProps | AnySpendDepositUpsideProps | AnySpendBuySpinProps | AnySpendSignatureMintProps | AnySpendBondKitProps | LinkAccountModalProps | AnySpendDepositHypeProps | AvatarEditorModalProps | ProfileEditorModalProps;
|
|
364
384
|
/**
|
|
365
385
|
* State interface for the modal store
|
|
366
386
|
*/
|