@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
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnySpendStakeB3ExactIn = AnySpendStakeB3ExactIn;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const anyspend_1 = require("../../../anyspend");
|
|
6
|
+
const utils_1 = require("../../../anyspend/utils");
|
|
7
|
+
const react_1 = require("../../../global-account/react");
|
|
8
|
+
const constants_1 = require("../../../shared/constants");
|
|
9
|
+
const number_1 = require("../../../shared/utils/number");
|
|
10
|
+
const lucide_react_1 = require("lucide-react");
|
|
11
|
+
const react_2 = require("motion/react");
|
|
12
|
+
const react_3 = require("react");
|
|
13
|
+
const sonner_1 = require("sonner");
|
|
14
|
+
const viem_1 = require("viem");
|
|
15
|
+
const chains_1 = require("viem/chains");
|
|
16
|
+
const wagmi_1 = require("wagmi");
|
|
17
|
+
const AnySpendCustomExactIn_1 = require("./AnySpendCustomExactIn");
|
|
18
|
+
const EthIcon_1 = require("./icons/EthIcon");
|
|
19
|
+
const SolIcon_1 = require("./icons/SolIcon");
|
|
20
|
+
const USDCIcon_1 = require("./icons/USDCIcon");
|
|
21
|
+
const basePublicClient = (0, viem_1.createPublicClient)({
|
|
22
|
+
chain: chains_1.base,
|
|
23
|
+
transport: (0, viem_1.http)(constants_1.PUBLIC_BASE_RPC_URL),
|
|
24
|
+
});
|
|
25
|
+
const ERC20Staking = "0xbf04200be3cbf371467a539706393c81c470f523";
|
|
26
|
+
const STAKE_FUNCTION_ABI = JSON.stringify([
|
|
27
|
+
{
|
|
28
|
+
name: "stake",
|
|
29
|
+
type: "function",
|
|
30
|
+
stateMutability: "nonpayable",
|
|
31
|
+
inputs: [
|
|
32
|
+
{ name: "amount", type: "uint256" },
|
|
33
|
+
{ name: "beneficiary", type: "address" },
|
|
34
|
+
],
|
|
35
|
+
outputs: [],
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
function AnySpendStakeB3ExactIn({ loadOrder, mode = "modal", sourceTokenAddress, sourceTokenChainId, recipientAddress, stakeAmount, onSuccess, }) {
|
|
39
|
+
const hasMounted = (0, react_1.useHasMounted)();
|
|
40
|
+
const { setB3ModalOpen } = (0, react_1.useModalStore)();
|
|
41
|
+
// Wagmi hooks for direct staking
|
|
42
|
+
const { address } = (0, wagmi_1.useAccount)();
|
|
43
|
+
const { switchChainAndExecute, isSwitchingOrExecuting } = (0, react_1.useUnifiedChainSwitchAndExecute)();
|
|
44
|
+
// Fetch B3 token balance
|
|
45
|
+
const { data: simBalance, isLoading: isBalanceLoading } = (0, react_1.useSimBalance)(address, [chains_1.base.id]);
|
|
46
|
+
const b3RawBalanceStr = simBalance?.balances.find(b => (0, anyspend_1.eqci)(b.address, anyspend_1.B3_TOKEN.address))?.amount || "0";
|
|
47
|
+
const b3RawBalance = BigInt(b3RawBalanceStr);
|
|
48
|
+
const b3Balance = (0, number_1.formatTokenAmount)(b3RawBalance, anyspend_1.B3_TOKEN.decimals);
|
|
49
|
+
// State for direct staking flow
|
|
50
|
+
const [isStaking, setIsStaking] = (0, react_3.useState)(false);
|
|
51
|
+
const [stakingTxHash, setStakingTxHash] = (0, react_3.useState)("");
|
|
52
|
+
const [showSuccessModal, setShowSuccessModal] = (0, react_3.useState)(false);
|
|
53
|
+
// Wait for transaction confirmation
|
|
54
|
+
const { isLoading: isTxPending, isSuccess: isTxSuccess } = (0, wagmi_1.useWaitForTransactionReceipt)({
|
|
55
|
+
hash: stakingTxHash,
|
|
56
|
+
query: {
|
|
57
|
+
structuralSharing: false, // Disable to avoid BigInt serialization issues
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
// Show success modal when transaction is confirmed
|
|
61
|
+
(0, react_3.useEffect)(() => {
|
|
62
|
+
if (isTxSuccess && stakingTxHash) {
|
|
63
|
+
setShowAmountPrompt(false);
|
|
64
|
+
setShowSuccessModal(true);
|
|
65
|
+
setIsStaking(false);
|
|
66
|
+
}
|
|
67
|
+
}, [isTxSuccess, stakingTxHash]);
|
|
68
|
+
const [userStakeAmount, setUserStakeAmount] = (0, react_3.useState)(stakeAmount || "");
|
|
69
|
+
const [showAmountPrompt, setShowAmountPrompt] = (0, react_3.useState)(!stakeAmount);
|
|
70
|
+
const [isAmountValid, setIsAmountValid] = (0, react_3.useState)(!!stakeAmount);
|
|
71
|
+
const [validationError, setValidationError] = (0, react_3.useState)("");
|
|
72
|
+
// Store display amount for UI
|
|
73
|
+
const [displayAmount, setDisplayAmount] = (0, react_3.useState)("");
|
|
74
|
+
// Debounced state for balance checks and messaging
|
|
75
|
+
const [debouncedAmount, setDebouncedAmount] = (0, react_3.useState)("");
|
|
76
|
+
const [debouncedUserStakeAmount, setDebouncedUserStakeAmount] = (0, react_3.useState)("");
|
|
77
|
+
// Debounce the amount for balance checks
|
|
78
|
+
(0, react_3.useEffect)(() => {
|
|
79
|
+
const timer = setTimeout(() => {
|
|
80
|
+
setDebouncedAmount(displayAmount);
|
|
81
|
+
setDebouncedUserStakeAmount(userStakeAmount);
|
|
82
|
+
}, 500);
|
|
83
|
+
return () => clearTimeout(timer);
|
|
84
|
+
}, [displayAmount, userStakeAmount]);
|
|
85
|
+
(0, react_3.useEffect)(() => {
|
|
86
|
+
if (stakeAmount) {
|
|
87
|
+
setUserStakeAmount(stakeAmount);
|
|
88
|
+
setShowAmountPrompt(false);
|
|
89
|
+
setIsAmountValid(true);
|
|
90
|
+
}
|
|
91
|
+
}, [stakeAmount]);
|
|
92
|
+
if (!recipientAddress)
|
|
93
|
+
return null;
|
|
94
|
+
const validateAndSetAmount = (value) => {
|
|
95
|
+
// Allow decimal input by validating against a pattern
|
|
96
|
+
// This regex allows numbers with up to 18 decimal places
|
|
97
|
+
const isValidFormat = /^(\d+\.?\d{0,18}|\.\d{1,18})$/.test(value) || value === "";
|
|
98
|
+
if (!isValidFormat && value !== "") {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
setDisplayAmount(value);
|
|
102
|
+
try {
|
|
103
|
+
if (value === "" || value === ".") {
|
|
104
|
+
setUserStakeAmount("");
|
|
105
|
+
setIsAmountValid(false);
|
|
106
|
+
setValidationError("");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// For UI validation - check if it's a positive number
|
|
110
|
+
const numValue = parseFloat(value);
|
|
111
|
+
if (isNaN(numValue) || numValue <= 0) {
|
|
112
|
+
setIsAmountValid(false);
|
|
113
|
+
setUserStakeAmount("");
|
|
114
|
+
setValidationError("Please enter a valid positive number");
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// Check minimum stake amount (50 B3)
|
|
118
|
+
if (numValue < 50) {
|
|
119
|
+
setIsAmountValid(false);
|
|
120
|
+
setUserStakeAmount("");
|
|
121
|
+
setValidationError("Minimum stake amount is 50 B3");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// Convert to wei (multiply by 10^18)
|
|
125
|
+
// Handle decimal places correctly by removing the decimal point
|
|
126
|
+
let fullAmount;
|
|
127
|
+
if (value.includes(".")) {
|
|
128
|
+
const [whole, fraction = ""] = value.split(".");
|
|
129
|
+
// Pad with zeros to 18 decimal places
|
|
130
|
+
const paddedFraction = fraction.padEnd(18, "0");
|
|
131
|
+
fullAmount = whole + paddedFraction;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
fullAmount = value + "000000000000000000"; // Add 18 zeros
|
|
135
|
+
}
|
|
136
|
+
// Remove leading zeros
|
|
137
|
+
fullAmount = fullAmount.replace(/^0+/, "") || "0";
|
|
138
|
+
// Set the full amount for the actual transaction
|
|
139
|
+
setUserStakeAmount(fullAmount);
|
|
140
|
+
setIsAmountValid(true);
|
|
141
|
+
setValidationError("");
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
setIsAmountValid(false);
|
|
145
|
+
setUserStakeAmount("");
|
|
146
|
+
setValidationError("Please enter a valid amount");
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const handleDirectStaking = async () => {
|
|
150
|
+
if (!address || !basePublicClient || !userStakeAmount)
|
|
151
|
+
return;
|
|
152
|
+
try {
|
|
153
|
+
setIsStaking(true);
|
|
154
|
+
// Check current allowance
|
|
155
|
+
const allowance = await basePublicClient.readContract({
|
|
156
|
+
address: anyspend_1.B3_TOKEN.address,
|
|
157
|
+
abi: viem_1.erc20Abi,
|
|
158
|
+
functionName: "allowance",
|
|
159
|
+
args: [address, ERC20Staking],
|
|
160
|
+
});
|
|
161
|
+
// If allowance is insufficient, request approval first
|
|
162
|
+
if (allowance < BigInt(userStakeAmount)) {
|
|
163
|
+
sonner_1.toast.info("Approving B3 spending...");
|
|
164
|
+
const approvalData = (0, viem_1.encodeFunctionData)({
|
|
165
|
+
abi: viem_1.erc20Abi,
|
|
166
|
+
functionName: "approve",
|
|
167
|
+
args: [ERC20Staking, BigInt(userStakeAmount)],
|
|
168
|
+
});
|
|
169
|
+
const approvalHash = await switchChainAndExecute(chains_1.base.id, {
|
|
170
|
+
to: anyspend_1.B3_TOKEN.address,
|
|
171
|
+
data: approvalData,
|
|
172
|
+
value: BigInt(0),
|
|
173
|
+
});
|
|
174
|
+
if (!approvalHash) {
|
|
175
|
+
sonner_1.toast.error("Approval failed. Please try again.");
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const approvalReceipt = await basePublicClient.waitForTransactionReceipt({
|
|
179
|
+
hash: approvalHash,
|
|
180
|
+
confirmations: 1,
|
|
181
|
+
});
|
|
182
|
+
if (approvalReceipt?.status !== "success") {
|
|
183
|
+
sonner_1.toast.error("Approval failed. Please try again.");
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Execute the stake
|
|
188
|
+
sonner_1.toast.info("Staking B3...");
|
|
189
|
+
const stakeData = (0, viem_1.encodeFunctionData)({
|
|
190
|
+
abi: anyspend_1.ABI_ERC20_STAKING,
|
|
191
|
+
functionName: "stake",
|
|
192
|
+
args: [BigInt(userStakeAmount), recipientAddress],
|
|
193
|
+
});
|
|
194
|
+
const stakeHash = await switchChainAndExecute(chains_1.base.id, {
|
|
195
|
+
to: ERC20Staking,
|
|
196
|
+
data: stakeData,
|
|
197
|
+
value: BigInt(0),
|
|
198
|
+
});
|
|
199
|
+
if (stakeHash) {
|
|
200
|
+
setStakingTxHash(stakeHash);
|
|
201
|
+
sonner_1.toast.success("Staking transaction submitted!");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
console.error("@@b3-stake-custom-exact-in:error:", error);
|
|
206
|
+
sonner_1.toast.error("Staking failed. Please try again.");
|
|
207
|
+
setShowSuccessModal(false); // Ensure modal doesn't show on error
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
setIsStaking(false);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const confirmAmount = () => {
|
|
214
|
+
if (!isAmountValid) {
|
|
215
|
+
sonner_1.toast.error("Please enter a valid amount to stake");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
// Check if user has sufficient B3 balance for direct staking
|
|
219
|
+
const hasEnoughBalance = b3RawBalance && BigInt(userStakeAmount) <= b3RawBalance;
|
|
220
|
+
if (hasEnoughBalance) {
|
|
221
|
+
// User has enough B3, proceed with direct staking
|
|
222
|
+
handleDirectStaking();
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
// User needs more B3, proceed to AnySpend conversion flow
|
|
226
|
+
setShowAmountPrompt(false);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const header = () => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "relative mx-auto size-32", children: (0, jsx_runtime_1.jsx)("img", { alt: "b3 coin", className: "size-full", src: "https://cdn.b3.fun/b3-coin-3d.png" }) }), (0, jsx_runtime_1.jsxs)("div", { className: "from-b3-react-background to-as-on-surface-1 mt-[-60px] w-full rounded-t-lg bg-gradient-to-t", children: [(0, jsx_runtime_1.jsx)("div", { className: "h-[60px] w-full" }), (0, jsx_runtime_1.jsx)("div", { className: "mb-1 flex w-full flex-col items-center gap-2 p-5", children: (0, jsx_runtime_1.jsxs)("span", { className: "font-sf-rounded text-2xl font-semibold", children: ["Swap & Stake ", userStakeAmount ? (0, number_1.formatTokenAmount)(BigInt(userStakeAmount), 18) : "", " B3 (Exact In)"] }) })] })] }));
|
|
230
|
+
const onFocusStakeAmountInput = () => {
|
|
231
|
+
window.scrollTo(0, 0);
|
|
232
|
+
document.body.scrollTop = 0;
|
|
233
|
+
};
|
|
234
|
+
const customExactInConfig = {
|
|
235
|
+
functionAbi: STAKE_FUNCTION_ABI,
|
|
236
|
+
functionName: "stake",
|
|
237
|
+
functionArgs: ["{{amount_out}}", (0, utils_1.normalizeAddress)(recipientAddress)],
|
|
238
|
+
to: ERC20Staking,
|
|
239
|
+
spenderAddress: ERC20Staking,
|
|
240
|
+
action: "stake B3",
|
|
241
|
+
};
|
|
242
|
+
// Render amount input prompt if no stake amount is provided
|
|
243
|
+
if (showAmountPrompt) {
|
|
244
|
+
return ((0, jsx_runtime_1.jsx)(react_1.StyleRoot, { children: (0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex w-full flex-col items-center", children: [(0, jsx_runtime_1.jsxs)("div", { className: "w-full px-4", children: [(0, jsx_runtime_1.jsx)(react_2.motion.div, { initial: false, animate: {
|
|
245
|
+
opacity: hasMounted ? 1 : 0,
|
|
246
|
+
y: hasMounted ? 0 : 20,
|
|
247
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
248
|
+
}, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "relative mx-auto size-48", children: (0, jsx_runtime_1.jsx)("video", { autoPlay: true, muted: true, playsInline: true, className: "size-full", src: "https://cdn.b3.fun/b3-sphere-to-coin.mp4" }) }), (0, jsx_runtime_1.jsx)(react_2.motion.div, { initial: false, animate: {
|
|
249
|
+
opacity: hasMounted ? 1 : 0,
|
|
250
|
+
y: hasMounted ? 0 : 20,
|
|
251
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
252
|
+
}, transition: { duration: 0.3, delay: 0.1, ease: "easeInOut" }, children: (0, jsx_runtime_1.jsx)("h2", { className: "font-sf-rounded font-neue-montreal-medium mb-1 text-center text-2xl font-semibold", children: (() => {
|
|
253
|
+
const hasEnoughBalance = b3RawBalance && BigInt(debouncedUserStakeAmount || "0") <= b3RawBalance;
|
|
254
|
+
return hasEnoughBalance || !debouncedAmount ? "Stake B3" : "Swap & Stake B3";
|
|
255
|
+
})() }) })] }), (0, jsx_runtime_1.jsxs)(react_2.motion.div, { initial: false, animate: {
|
|
256
|
+
opacity: hasMounted ? 1 : 0,
|
|
257
|
+
y: hasMounted ? 0 : 20,
|
|
258
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
259
|
+
}, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: [(0, jsx_runtime_1.jsx)("div", { className: "mb-2", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("p", { className: "text-as-primary/70 text-sm font-medium", children: "I want to stake" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary/50 flex items-center gap-1 text-sm", children: ["Available: ", isBalanceLoading ? (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-3 w-3 animate-spin" }) : `${b3Balance} B3`] })] }) }), (0, jsx_runtime_1.jsxs)("div", { className: "relative", children: [(0, jsx_runtime_1.jsx)(react_1.Input, { onFocus: onFocusStakeAmountInput, type: "text", placeholder: "0.00", value: displayAmount, onChange: e => validateAndSetAmount(e.target.value), className: `h-14 px-4 text-lg ${!isAmountValid && displayAmount ? "border-as-red" : "border-b3-react-border"}` }), (0, jsx_runtime_1.jsx)("div", { className: "font-pack absolute right-4 top-1/2 -translate-y-1/2 text-lg font-medium text-blue-500/70", children: "B3" })] }), !isAmountValid && displayAmount && (0, jsx_runtime_1.jsx)("p", { className: "text-as-red mt-2 text-sm", children: validationError }), (0, jsx_runtime_1.jsx)("div", { className: "mt-4", children: (() => {
|
|
260
|
+
const hasEnoughBalance = b3RawBalance && BigInt(debouncedUserStakeAmount || "0") <= b3RawBalance;
|
|
261
|
+
if (!hasEnoughBalance || !debouncedAmount) {
|
|
262
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "bg-as-brand/10 flex flex-col items-center gap-2 rounded-lg p-4 pb-5", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-center gap-2", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary text-sm font-semibold", children: "Swap & stake from any token" }), (0, jsx_runtime_1.jsxs)(react_1.TextLoop, { children: [(0, jsx_runtime_1.jsx)(EthIcon_1.EthIcon, { className: "h-8 w-8" }), (0, jsx_runtime_1.jsx)(SolIcon_1.SolIcon, { className: "h-8 w-8" }), (0, jsx_runtime_1.jsx)(USDCIcon_1.UsdcIcon, { className: "h-8 w-8" })] }), (0, jsx_runtime_1.jsx)(lucide_react_1.ArrowRight, { className: "text-as-primary h-4 w-4" }), (0, jsx_runtime_1.jsx)("img", { src: "https://cdn.b3.fun/b3-coin-3d.png", className: "h-7 w-7", alt: "B3 Token" })] }), (0, jsx_runtime_1.jsx)("p", { className: "text-as-primary/50 text-sm font-medium", children: debouncedAmount
|
|
263
|
+
? `No problem, we'll help you swap to ${debouncedAmount} B3!`
|
|
264
|
+
: "Not enough B3? We'll help you swap from other coins." })] }));
|
|
265
|
+
}
|
|
266
|
+
})() }), (0, jsx_runtime_1.jsx)(react_1.Button, { onClick: confirmAmount, disabled: !isAmountValid || !displayAmount || isStaking || isTxPending || isSwitchingOrExecuting, className: "bg-as-brand hover:bg-as-brand/90 text-as-primary mt-4 h-14 w-full rounded-xl text-lg font-medium", children: isStaking || isSwitchingOrExecuting ? "Staking..." : isTxPending ? "Confirming..." : "Continue" })] })] }) }));
|
|
267
|
+
}
|
|
268
|
+
// Success Modal for Direct Staking
|
|
269
|
+
if (showSuccessModal) {
|
|
270
|
+
return ((0, jsx_runtime_1.jsx)(react_1.StyleRoot, { children: (0, jsx_runtime_1.jsxs)("div", { className: "bg-b3-react-background flex w-full flex-col items-center", children: [(0, jsx_runtime_1.jsxs)("div", { className: "w-full p-4", children: [(0, jsx_runtime_1.jsxs)(react_2.motion.div, { initial: false, animate: {
|
|
271
|
+
opacity: hasMounted ? 1 : 0,
|
|
272
|
+
y: hasMounted ? 0 : 20,
|
|
273
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
274
|
+
}, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "relative mx-auto mb-4 size-[120px]", children: [(0, jsx_runtime_1.jsx)("div", { className: "absolute inset-0 scale-95 rounded-[50%] bg-black/30 blur-md" }), (0, jsx_runtime_1.jsxs)(react_1.GlareCardRounded, { className: "overflow-hidden rounded-full border-none", children: [(0, jsx_runtime_1.jsx)("img", { alt: "b3 coin", loading: "lazy", width: "64", height: "64", decoding: "async", "data-nimg": "1", className: "size-full shrink-0 bg-transparent text-transparent", src: "https://cdn.b3.fun/b3-coin-3d.png" }), (0, jsx_runtime_1.jsx)("div", { className: "absolute inset-0 rounded-[50%] border border-white/10" })] })] }), (0, jsx_runtime_1.jsx)(react_2.motion.div, { initial: false, animate: {
|
|
275
|
+
opacity: hasMounted ? 1 : 0,
|
|
276
|
+
y: hasMounted ? 0 : 20,
|
|
277
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
278
|
+
}, transition: { duration: 0.3, delay: 0.1, ease: "easeInOut" }, children: (0, jsx_runtime_1.jsxs)("h2", { className: "font-sf-rounded mb-1 text-center text-2xl font-semibold", children: ["Staked ", (0, number_1.formatTokenAmount)(BigInt(userStakeAmount), 18), " B3"] }) })] }), (0, jsx_runtime_1.jsxs)(react_2.motion.div, { initial: false, animate: {
|
|
279
|
+
opacity: hasMounted ? 1 : 0,
|
|
280
|
+
y: hasMounted ? 0 : 20,
|
|
281
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
282
|
+
}, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: [(0, jsx_runtime_1.jsx)("div", { className: "mb-6", children: (0, jsx_runtime_1.jsx)("a", { href: `https://basescan.org/tx/${stakingTxHash}`, target: "_blank", rel: "noopener noreferrer", className: "text-as-primary/70 hover:text-as-primary block break-all text-center font-mono text-sm underline transition-colors", children: "View transaction" }) }), (0, jsx_runtime_1.jsx)(react_1.Button, { onClick: () => {
|
|
283
|
+
setB3ModalOpen(false);
|
|
284
|
+
onSuccess?.((0, number_1.formatTokenAmount)(BigInt(userStakeAmount), 18) ?? "");
|
|
285
|
+
}, className: "bg-as-brand hover:bg-as-brand/90 text-as-primary h-14 w-full rounded-xl text-lg font-medium", children: "Done" })] })] }) }));
|
|
286
|
+
}
|
|
287
|
+
return ((0, jsx_runtime_1.jsx)(AnySpendCustomExactIn_1.AnySpendCustomExactIn, { loadOrder: loadOrder, mode: mode, recipientAddress: recipientAddress, sourceTokenAddress: sourceTokenAddress, sourceTokenChainId: sourceTokenChainId, destinationToken: anyspend_1.B3_TOKEN, destinationChainId: chains_1.base.id, customExactInConfig: customExactInConfig, header: header, onSuccess: onSuccess }));
|
|
288
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { components } from "../../../anyspend/types/api";
|
|
2
|
+
export declare function AnySpendStakeUpsideExactIn({ loadOrder, mode, recipientAddress, sourceTokenAddress, sourceTokenChainId, stakingContractAddress, token, onSuccess, }: {
|
|
3
|
+
loadOrder?: string;
|
|
4
|
+
mode?: "modal" | "page";
|
|
5
|
+
recipientAddress: string;
|
|
6
|
+
sourceTokenAddress?: string;
|
|
7
|
+
sourceTokenChainId?: number;
|
|
8
|
+
stakingContractAddress: string;
|
|
9
|
+
token: components["schemas"]["Token"];
|
|
10
|
+
onSuccess?: (amount: string) => void;
|
|
11
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnySpendStakeUpsideExactIn = AnySpendStakeUpsideExactIn;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const utils_1 = require("../../../anyspend/utils");
|
|
6
|
+
const chains_1 = require("viem/chains");
|
|
7
|
+
const AnySpendCustomExactIn_1 = require("./AnySpendCustomExactIn");
|
|
8
|
+
const STAKE_FOR_FUNCTION_ABI = JSON.stringify([
|
|
9
|
+
{
|
|
10
|
+
name: "stakeFor",
|
|
11
|
+
type: "function",
|
|
12
|
+
stateMutability: "nonpayable",
|
|
13
|
+
inputs: [
|
|
14
|
+
{ name: "user", type: "address" },
|
|
15
|
+
{ name: "amount", type: "uint256" },
|
|
16
|
+
],
|
|
17
|
+
outputs: [],
|
|
18
|
+
},
|
|
19
|
+
]);
|
|
20
|
+
function AnySpendStakeUpsideExactIn({ loadOrder, mode = "modal", recipientAddress, sourceTokenAddress, sourceTokenChainId, stakingContractAddress, token, onSuccess, }) {
|
|
21
|
+
if (!recipientAddress)
|
|
22
|
+
return null;
|
|
23
|
+
const header = () => ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("div", { className: "from-b3-react-background to-as-on-surface-1 w-full rounded-t-lg bg-gradient-to-t", children: (0, jsx_runtime_1.jsx)("div", { className: "mb-1 flex w-full flex-col items-center gap-2", children: (0, jsx_runtime_1.jsxs)("span", { className: "font-sf-rounded text-2xl font-semibold", children: ["Swap & Stake ", token.symbol, " (Exact In)"] }) }) }) }));
|
|
24
|
+
const customExactInConfig = {
|
|
25
|
+
functionAbi: STAKE_FOR_FUNCTION_ABI,
|
|
26
|
+
functionName: "stakeFor",
|
|
27
|
+
functionArgs: [(0, utils_1.normalizeAddress)(recipientAddress), "{{amount_out}}"],
|
|
28
|
+
to: stakingContractAddress,
|
|
29
|
+
spenderAddress: stakingContractAddress,
|
|
30
|
+
action: `stake ${token.symbol}`,
|
|
31
|
+
};
|
|
32
|
+
return ((0, jsx_runtime_1.jsx)(AnySpendCustomExactIn_1.AnySpendCustomExactIn, { loadOrder: loadOrder, mode: mode, recipientAddress: recipientAddress, sourceTokenAddress: sourceTokenAddress, sourceTokenChainId: sourceTokenChainId, destinationToken: token, destinationChainId: chains_1.base.id, customExactInConfig: customExactInConfig, header: header, onSuccess: onSuccess }));
|
|
33
|
+
}
|
|
@@ -13,6 +13,7 @@ const invariant_1 = __importDefault(require("invariant"));
|
|
|
13
13
|
const react_2 = require("motion/react");
|
|
14
14
|
const react_3 = require("react");
|
|
15
15
|
const sonner_1 = require("sonner");
|
|
16
|
+
const react_4 = require("thirdweb/react");
|
|
16
17
|
const chains_1 = require("viem/chains");
|
|
17
18
|
const useAnyspendFlow_1 = require("../hooks/useAnyspendFlow");
|
|
18
19
|
const AnySpendFingerprintWrapper_1 = require("./AnySpendFingerprintWrapper");
|
|
@@ -24,10 +25,9 @@ const FiatPaymentMethod_1 = require("./common/FiatPaymentMethod");
|
|
|
24
25
|
const OrderDetails_1 = require("./common/OrderDetails");
|
|
25
26
|
const PointsDetailPanel_1 = require("./common/PointsDetailPanel");
|
|
26
27
|
const RecipientSelection_1 = require("./common/RecipientSelection");
|
|
27
|
-
const react_4 = require("thirdweb/react");
|
|
28
28
|
const lucide_react_1 = require("lucide-react");
|
|
29
|
-
const PanelOnramp_1 = require("./common/PanelOnramp");
|
|
30
29
|
const utils_1 = require("../../utils");
|
|
30
|
+
const PanelOnramp_1 = require("./common/PanelOnramp");
|
|
31
31
|
const SLIPPAGE_PERCENT = 3;
|
|
32
32
|
exports.HYPE_TOKEN_DETAILS = {
|
|
33
33
|
SYMBOL: "HYPE",
|
|
@@ -135,10 +135,10 @@ function AnySpendDepositHypeInner({ loadOrder, mode = "modal", recipientAddress,
|
|
|
135
135
|
await handleFiatOrder();
|
|
136
136
|
}
|
|
137
137
|
};
|
|
138
|
-
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: selectedCryptoPaymentMethod, 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:
|
|
138
|
+
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: selectedCryptoPaymentMethod, 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 => {
|
|
139
139
|
setIsSrcInputDirty(false);
|
|
140
140
|
setSrcAmount(value);
|
|
141
|
-
}, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(useAnyspendFlow_1.PanelView.FEE_DETAIL) }))] }) }), (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] }));
|
|
141
|
+
}, 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] }));
|
|
142
142
|
// Handle crypto order creation
|
|
143
143
|
const handleCryptoOrder = async () => {
|
|
144
144
|
try {
|
|
@@ -9,16 +9,14 @@ const number_1 = require("../../../../shared/utils/number");
|
|
|
9
9
|
const lucide_react_1 = require("lucide-react");
|
|
10
10
|
const react_2 = require("motion/react");
|
|
11
11
|
const react_3 = require("react");
|
|
12
|
+
const useConnectedWalletDisplay_1 = require("../../hooks/useConnectedWalletDisplay");
|
|
12
13
|
const CryptoPaymentMethod_1 = require("./CryptoPaymentMethod");
|
|
13
14
|
const OrderTokenAmount_1 = require("./OrderTokenAmount");
|
|
14
15
|
const TokenBalance_1 = require("./TokenBalance");
|
|
15
16
|
function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, srcAmount, setSrcAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod, anyspendQuote, onTokenSelect, onShowFeeDetail, }) {
|
|
16
|
-
const { connectedSmartWallet, connectedEOAWallet } = (0, react_1.useAccountWallet)();
|
|
17
17
|
const { data: srcTokenMetadata } = (0, react_1.useTokenData)(selectedSrcToken?.chainId, selectedSrcToken?.address);
|
|
18
|
-
//
|
|
19
|
-
const walletAddress =
|
|
20
|
-
? connectedSmartWallet?.getAccount()?.address
|
|
21
|
-
: connectedEOAWallet?.getAccount()?.address;
|
|
18
|
+
// Use custom hook to determine wallet address based on payment method
|
|
19
|
+
const { walletAddress } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(selectedCryptoPaymentMethod);
|
|
22
20
|
const { data: profileData } = (0, react_1.useProfile)({ address: walletAddress });
|
|
23
21
|
const connectedName = profileData?.displayName;
|
|
24
22
|
// Add ref to track if we've applied metadata
|
|
@@ -45,7 +43,7 @@ function CryptoPaySection({ selectedSrcChainId, setSelectedSrcChainId, selectedS
|
|
|
45
43
|
(0, react_3.useEffect)(() => {
|
|
46
44
|
appliedSrcMetadataRef.current = false;
|
|
47
45
|
}, [selectedSrcToken.address, selectedSrcToken.chainId]);
|
|
48
|
-
return ((0, jsx_runtime_1.jsxs)(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" }, className: "pay-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "text-as-primary/50 flex h-7 items-center gap-1.5 text-sm", children: ["Pay", !isSrcInputDirty && anyspendQuote?.data?.fee && onShowFeeDetail && ((0, jsx_runtime_1.jsx)("button", { onClick: onShowFeeDetail, className: "text-as-primary/40 hover:text-as-primary/60 transition-colors", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Info, { className: "h-4 w-4" }) }))] }), (0, jsx_runtime_1.jsx)("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none", onClick: onSelectCryptoPaymentMethod, children: selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [walletAddress ? ((0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-1", children: connectedName ? (0, utils_1.formatUsername)(connectedName) : (0, formatAddress_1.shortenAddress)(walletAddress || "") })) : ("Connect wallet"), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.GLOBAL_WALLET ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Global Account", (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.TRANSFER_CRYPTO ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Transfer crypto", (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Select payment method", (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) })] }), (0, jsx_runtime_1.jsx)(OrderTokenAmount_1.OrderTokenAmount, { address: walletAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
|
|
46
|
+
return ((0, jsx_runtime_1.jsxs)(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" }, className: "pay-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "text-as-primary/50 flex h-7 items-center gap-1.5 text-sm", children: ["Pay", !isSrcInputDirty && anyspendQuote?.data?.fee && onShowFeeDetail && ((0, jsx_runtime_1.jsx)("button", { onClick: onShowFeeDetail, className: "text-as-primary/40 hover:text-as-primary/60 transition-colors", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Info, { className: "h-4 w-4" }) }))] }), (0, jsx_runtime_1.jsx)("button", { className: "text-as-tertiarry flex h-7 items-center gap-2 text-sm transition-colors focus:!outline-none", onClick: onSelectCryptoPaymentMethod, children: selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [walletAddress ? ((0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-1", children: connectedName ? (0, utils_1.formatUsername)(connectedName) : (0, formatAddress_1.shortenAddress)(walletAddress || "") })) : ("Connect wallet"), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.GLOBAL_WALLET ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Global Account", (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) : selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.TRANSFER_CRYPTO ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Transfer crypto", (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Select payment method", (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] })) })] }), (0, jsx_runtime_1.jsx)(OrderTokenAmount_1.OrderTokenAmount, { address: walletAddress, walletAddress: walletAddress, context: "from", inputValue: srcAmount, onChangeInput: value => {
|
|
49
47
|
setIsSrcInputDirty(true);
|
|
50
48
|
setSrcAmount(value);
|
|
51
49
|
}, chainId: selectedSrcChainId, setChainId: setSelectedSrcChainId, token: selectedSrcToken, setToken: setSelectedSrcToken, onTokenSelect: onTokenSelect }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-primary/50 flex h-5 items-center text-sm", children: (0, number_1.formatDisplayNumber)(anyspendQuote?.data?.currencyIn?.amountUsd, {
|
|
@@ -17,6 +17,7 @@ const sonner_1 = require("sonner");
|
|
|
17
17
|
const react_4 = require("thirdweb/react");
|
|
18
18
|
const wallets_1 = require("thirdweb/wallets");
|
|
19
19
|
const wagmi_1 = require("wagmi");
|
|
20
|
+
const useConnectedWalletDisplay_1 = require("../../hooks/useConnectedWalletDisplay");
|
|
20
21
|
var CryptoPaymentMethodType;
|
|
21
22
|
(function (CryptoPaymentMethodType) {
|
|
22
23
|
CryptoPaymentMethodType["NONE"] = "none";
|
|
@@ -26,7 +27,7 @@ var CryptoPaymentMethodType;
|
|
|
26
27
|
})(CryptoPaymentMethodType || (exports.CryptoPaymentMethodType = CryptoPaymentMethodType = {}));
|
|
27
28
|
function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod, isCreatingOrder, onBack, onSelectPaymentMethod, }) {
|
|
28
29
|
const { wallet: globalWallet, connectedEOAWallet: connectedEOAWallet, connectedSmartWallet: connectedSmartWallet, } = (0, react_1.useAccountWallet)();
|
|
29
|
-
const { connector, address
|
|
30
|
+
const { connector, address } = (0, wagmi_1.useAccount)();
|
|
30
31
|
const { connect, connectors, isPending } = (0, wagmi_1.useConnect)();
|
|
31
32
|
const { disconnect } = (0, wagmi_1.useDisconnect)();
|
|
32
33
|
const { data: walletClient } = (0, wagmi_1.useWalletClient)();
|
|
@@ -37,19 +38,8 @@ function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod,
|
|
|
37
38
|
const setGlobalAccountWallet = (0, utils_1.useGlobalWalletState)(state => state.setGlobalAccountWallet);
|
|
38
39
|
const isConnected = !!connectedEOAWallet;
|
|
39
40
|
const globalAddress = connectedSmartWallet?.getAccount()?.address;
|
|
40
|
-
//
|
|
41
|
-
const
|
|
42
|
-
if (!addr1 || !addr2)
|
|
43
|
-
return false;
|
|
44
|
-
return addr1.toLowerCase() === addr2.toLowerCase();
|
|
45
|
-
};
|
|
46
|
-
// Check if connectedEOAWallet and wagmi wallet represent the same wallet
|
|
47
|
-
const connectedEOAAddress = connectedEOAWallet?.getAccount()?.address;
|
|
48
|
-
const wagmiAddress = address;
|
|
49
|
-
const isWalletDuplicated = isSameAddress(connectedEOAAddress, wagmiAddress);
|
|
50
|
-
// Determine which wallet to show (prefer connectedEOAWallet if both exist and are the same)
|
|
51
|
-
const shouldShowConnectedEOA = !!connectedEOAWallet;
|
|
52
|
-
const shouldShowWagmiWallet = wagmiWalletIsConnected && (!isWalletDuplicated || !connectedEOAWallet);
|
|
41
|
+
// Use custom hook to determine wallet display logic
|
|
42
|
+
const { shouldShowConnectedEOA, shouldShowWagmiWallet } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(selectedPaymentMethod);
|
|
53
43
|
// Map wagmi connector names to thirdweb wallet IDs
|
|
54
44
|
const getThirdwebWalletId = (connectorName) => {
|
|
55
45
|
const walletMap = {
|
|
@@ -177,9 +167,11 @@ function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod,
|
|
|
177
167
|
setSelectedPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
178
168
|
onSelectPaymentMethod(CryptoPaymentMethodType.CONNECT_WALLET);
|
|
179
169
|
setGlobalAccountWallet(activeWallet);
|
|
180
|
-
|
|
170
|
+
if (connectedEOAWallet) {
|
|
171
|
+
setActiveWallet(connectedEOAWallet);
|
|
172
|
+
}
|
|
181
173
|
sonner_1.toast.success(`Selected ${eoaWalletInfo?.name || connector?.name || "wallet"}`);
|
|
182
|
-
}, className: (0, cn_1.cn)("crypto-payment-method-connect-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
174
|
+
}, className: (0, cn_1.cn)("crypto-payment-method-connect-wallet eoa-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
183
175
|
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
184
176
|
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Wallet, { className: "h-5 w-5 text-blue-600" }) }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary font-semibold", children: eoaWalletInfo?.name || connector?.name || "Connected Wallet" }), (0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/60 text-sm", children: (0, formatAddress_1.shortenAddress)(connectedEOAWallet?.getAccount()?.address || "") })] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && ((0, jsx_runtime_1.jsx)("div", { className: "h-2 w-2 rounded-full bg-green-500" })), (0, jsx_runtime_1.jsx)("button", { onClick: e => {
|
|
185
177
|
e.stopPropagation();
|
|
@@ -199,7 +191,7 @@ function CryptoPaymentMethod({ selectedPaymentMethod, setSelectedPaymentMethod,
|
|
|
199
191
|
}
|
|
200
192
|
}
|
|
201
193
|
sonner_1.toast.success(`Selected ${connector?.name || "wallet"}`);
|
|
202
|
-
}, className: (0, cn_1.cn)("crypto-payment-method-connect-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
194
|
+
}, className: (0, cn_1.cn)("crypto-payment-method-connect-wallet wagmi-wallet w-full rounded-xl border p-4 text-left transition-all hover:shadow-md", selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET
|
|
203
195
|
? "connected-wallet border-as-brand bg-as-brand/5"
|
|
204
196
|
: "border-as-border-secondary bg-as-surface-primary hover:border-as-secondary/80"), children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-3", children: [(0, jsx_runtime_1.jsx)("div", { className: "wallet-icon flex h-10 w-10 items-center justify-center rounded-full bg-blue-100", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Wallet, { className: "h-5 w-5 text-blue-600" }) }), (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary font-semibold", children: connector?.name || "Connected Wallet" }), (0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/60 text-sm", children: (0, formatAddress_1.shortenAddress)(address || "") })] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [selectedPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET && ((0, jsx_runtime_1.jsx)("div", { className: "h-2 w-2 rounded-full bg-green-500" })), (0, jsx_runtime_1.jsx)("button", { onClick: e => {
|
|
205
197
|
e.stopPropagation();
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { components } from "../../../types/api";
|
|
2
|
+
import { CryptoPaymentMethodType } from "./CryptoPaymentMethod";
|
|
2
3
|
interface CryptoReceiveSectionProps {
|
|
3
4
|
isDepositMode?: boolean;
|
|
4
5
|
isBuyMode?: boolean;
|
|
5
6
|
selectedRecipientAddress?: string;
|
|
6
7
|
recipientName?: string;
|
|
7
8
|
onSelectRecipient: () => void;
|
|
9
|
+
setRecipientAddress?: (address: string | undefined) => void;
|
|
10
|
+
recipientAddressFromProps?: string;
|
|
11
|
+
globalAddress?: string;
|
|
8
12
|
dstAmount: string;
|
|
9
13
|
dstToken: components["schemas"]["Token"];
|
|
10
14
|
selectedDstChainId?: number;
|
|
@@ -17,6 +21,7 @@ interface CryptoReceiveSectionProps {
|
|
|
17
21
|
dstTokenLogoURI?: string;
|
|
18
22
|
onShowPointsDetail?: () => void;
|
|
19
23
|
onShowFeeDetail?: () => void;
|
|
24
|
+
selectedCryptoPaymentMethod?: CryptoPaymentMethodType;
|
|
20
25
|
}
|
|
21
|
-
export declare function CryptoReceiveSection({ isDepositMode, isBuyMode, selectedRecipientAddress, recipientName, onSelectRecipient, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, isSrcInputDirty, onChangeDstAmount, anyspendQuote, dstTokenSymbol, dstTokenLogoURI, onShowPointsDetail, onShowFeeDetail, }: CryptoReceiveSectionProps): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
export declare function CryptoReceiveSection({ isDepositMode, isBuyMode, selectedRecipientAddress, recipientName, onSelectRecipient, setRecipientAddress, recipientAddressFromProps, globalAddress, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, isSrcInputDirty, onChangeDstAmount, anyspendQuote, dstTokenSymbol, dstTokenLogoURI, onShowPointsDetail, onShowFeeDetail, selectedCryptoPaymentMethod, }: CryptoReceiveSectionProps): import("react/jsx-runtime").JSX.Element;
|
|
22
27
|
export {};
|
|
@@ -8,11 +8,21 @@ const formatAddress_1 = require("../../../../shared/utils/formatAddress");
|
|
|
8
8
|
const number_1 = require("../../../../shared/utils/number");
|
|
9
9
|
const lucide_react_1 = require("lucide-react");
|
|
10
10
|
const react_1 = require("motion/react");
|
|
11
|
+
const react_2 = require("react");
|
|
11
12
|
const FeatureFlagsContext_1 = require("../../contexts/FeatureFlagsContext");
|
|
13
|
+
const useConnectedWalletDisplay_1 = require("../../hooks/useConnectedWalletDisplay");
|
|
12
14
|
const OrderTokenAmount_1 = require("./OrderTokenAmount");
|
|
13
15
|
const PointsBadge_1 = require("./PointsBadge");
|
|
14
|
-
function CryptoReceiveSection({ isDepositMode = false, isBuyMode = false, selectedRecipientAddress, recipientName, onSelectRecipient, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, isSrcInputDirty, onChangeDstAmount, anyspendQuote, dstTokenSymbol, dstTokenLogoURI, onShowPointsDetail, onShowFeeDetail, }) {
|
|
16
|
+
function CryptoReceiveSection({ isDepositMode = false, isBuyMode = false, selectedRecipientAddress, recipientName, onSelectRecipient, setRecipientAddress, recipientAddressFromProps, globalAddress, dstAmount, dstToken, selectedDstChainId, setSelectedDstChainId, setSelectedDstToken, isSrcInputDirty, onChangeDstAmount, anyspendQuote, dstTokenSymbol, dstTokenLogoURI, onShowPointsDetail, onShowFeeDetail, selectedCryptoPaymentMethod, }) {
|
|
15
17
|
const featureFlags = (0, FeatureFlagsContext_1.useFeatureFlags)();
|
|
18
|
+
// Get wallet address based on selected payment method
|
|
19
|
+
const { walletAddress } = (0, useConnectedWalletDisplay_1.useConnectedWalletDisplay)(selectedCryptoPaymentMethod);
|
|
20
|
+
// Set default recipient address when wallet changes
|
|
21
|
+
(0, react_2.useEffect)(() => {
|
|
22
|
+
if (setRecipientAddress) {
|
|
23
|
+
setRecipientAddress(recipientAddressFromProps || walletAddress || globalAddress);
|
|
24
|
+
}
|
|
25
|
+
}, [recipientAddressFromProps, walletAddress, globalAddress, setRecipientAddress]);
|
|
16
26
|
return ((0, jsx_runtime_1.jsxs)(react_1.motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.1, ease: "easeInOut" }, className: "receive-section bg-as-surface-secondary border-as-border-secondary relative flex w-full flex-col gap-2 rounded-2xl border p-4 sm:p-6", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex w-full items-center justify-between", children: [(0, jsx_runtime_1.jsxs)("div", { className: "text-as-primary/50 flex h-7 items-center gap-1.5 text-sm", children: [isDepositMode ? "Deposit" : "Receive", isSrcInputDirty && anyspendQuote?.data?.fee && onShowFeeDetail && ((0, jsx_runtime_1.jsx)("button", { onClick: onShowFeeDetail, className: "text-as-primary/40 hover:text-as-primary/60 transition-colors", children: (0, jsx_runtime_1.jsx)(lucide_react_1.Info, { className: "h-4 w-4" }) }))] }), selectedRecipientAddress ? ((0, jsx_runtime_1.jsx)("button", { className: (0, cn_1.cn)("text-as-tertiarry flex h-7 items-center gap-2 rounded-lg"), onClick: onSelectRecipient, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-tertiarry flex items-center gap-1 text-sm", children: recipientName ? (0, utils_1.formatUsername)(recipientName) : (0, formatAddress_1.shortenAddress)(selectedRecipientAddress || "") }), (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronRight, { className: "h-4 w-4" })] }) })) : ((0, jsx_runtime_1.jsx)("button", { className: "text-as-primary/70 flex items-center gap-1 rounded-lg", onClick: onSelectRecipient, children: (0, jsx_runtime_1.jsx)("div", { className: "text-sm font-medium", children: "Select recipient" }) }))] }), isBuyMode || isDepositMode ? (
|
|
17
27
|
// Fixed destination token display for buy mode and deposit mode
|
|
18
28
|
(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-as-primary text-2xl font-bold", children: dstAmount || "0" }), (0, jsx_runtime_1.jsxs)("div", { className: "bg-as-brand/10 border-as-brand/30 flex items-center gap-3 rounded-xl border px-4 py-3", children: [(dstTokenLogoURI || dstToken.metadata?.logoURI) && ((0, jsx_runtime_1.jsx)("img", { src: dstTokenLogoURI || dstToken.metadata?.logoURI, alt: dstTokenSymbol || dstToken.symbol, className: "h-8 w-8 rounded-full" })), (0, jsx_runtime_1.jsx)("span", { className: "text-as-brand text-lg font-bold", children: dstTokenSymbol || dstToken.symbol })] })] })) : (
|