@b3dotfun/sdk 0.0.62 → 0.0.63-test.0-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,269 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { normalizeAddress } from "../../../anyspend/utils/index.js";
|
|
3
|
+
import { Button, ShinyButton, StyleRoot, TransitionPanel, useAccountWallet } from "../../../global-account/react/index.js";
|
|
4
|
+
import { cn } from "../../../shared/utils/cn.js";
|
|
5
|
+
import invariant from "invariant";
|
|
6
|
+
import { ArrowDown, Loader2 } from "lucide-react";
|
|
7
|
+
import { motion } from "motion/react";
|
|
8
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
9
|
+
import { toast } from "sonner";
|
|
10
|
+
import { useActiveWallet, useSetActiveWallet } from "thirdweb/react";
|
|
11
|
+
import { useGlobalWalletState } from "../../utils/index.js";
|
|
12
|
+
import { PanelView, useAnyspendFlow } from "../hooks/useAnyspendFlow.js";
|
|
13
|
+
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
|
|
14
|
+
import { CryptoPaySection } from "./common/CryptoPaySection.js";
|
|
15
|
+
import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod.js";
|
|
16
|
+
import { CryptoReceiveSection } from "./common/CryptoReceiveSection.js";
|
|
17
|
+
import { FeeDetailPanel } from "./common/FeeDetailPanel.js";
|
|
18
|
+
import { FiatPaymentMethod, FiatPaymentMethodComponent } from "./common/FiatPaymentMethod.js";
|
|
19
|
+
import { OrderDetails } from "./common/OrderDetails.js";
|
|
20
|
+
import { PanelOnramp } from "./common/PanelOnramp.js";
|
|
21
|
+
import { PointsDetailPanel } from "./common/PointsDetailPanel.js";
|
|
22
|
+
import { RecipientSelection } from "./common/RecipientSelection.js";
|
|
23
|
+
const SLIPPAGE_PERCENT = 3;
|
|
24
|
+
export function AnySpendCustomExactIn(props) {
|
|
25
|
+
const fingerprintConfig = getFingerprintConfig();
|
|
26
|
+
return (_jsx(AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: _jsx(AnySpendCustomExactInInner, { ...props }) }));
|
|
27
|
+
}
|
|
28
|
+
function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, destinationToken, destinationChainId, onSuccess, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, customExactInConfig, header, }) {
|
|
29
|
+
const actionLabel = customExactInConfig.action ?? "Custom Execution";
|
|
30
|
+
const DESTINATION_TOKEN_DETAILS = {
|
|
31
|
+
SYMBOL: destinationToken.symbol ?? "TOKEN",
|
|
32
|
+
LOGO_URI: destinationToken.metadata?.logoURI ?? "",
|
|
33
|
+
};
|
|
34
|
+
const { activePanel, setActivePanel, orderId, setOrderId, oat, selectedSrcChainId, setSelectedSrcChainId, selectedSrcToken, setSelectedSrcToken, selectedDstToken, selectedDstChainId, srcAmount, setSrcAmount, dstAmount, isSrcInputDirty, setIsSrcInputDirty, selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod, selectedFiatPaymentMethod, setSelectedFiatPaymentMethod, selectedRecipientAddress, setSelectedRecipientAddress, recipientName, globalAddress, hasEnoughBalance, isBalanceLoading, anyspendQuote, isLoadingAnyspendQuote, activeInputAmountInWei, geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support, createOrder, isCreatingOrder, createOnrampOrder, isCreatingOnrampOrder, } = useAnyspendFlow({
|
|
35
|
+
paymentType,
|
|
36
|
+
recipientAddress,
|
|
37
|
+
loadOrder,
|
|
38
|
+
isDepositMode: true,
|
|
39
|
+
onTransactionSuccess: onSuccess,
|
|
40
|
+
sourceTokenAddress,
|
|
41
|
+
sourceTokenChainId,
|
|
42
|
+
destinationTokenAddress: destinationToken.address,
|
|
43
|
+
destinationTokenChainId: destinationChainId,
|
|
44
|
+
slippage: SLIPPAGE_PERCENT,
|
|
45
|
+
disableUrlParamManagement: true,
|
|
46
|
+
orderType: "custom_exact_in",
|
|
47
|
+
});
|
|
48
|
+
const { connectedEOAWallet } = useAccountWallet();
|
|
49
|
+
const setActiveWallet = useSetActiveWallet();
|
|
50
|
+
const activeWallet = useActiveWallet();
|
|
51
|
+
const setGlobalAccountWallet = useGlobalWalletState(state => state.setGlobalAccountWallet);
|
|
52
|
+
const appliedPreferEoa = useRef(false);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (preferEoa && !appliedPreferEoa.current) {
|
|
55
|
+
if (connectedEOAWallet) {
|
|
56
|
+
appliedPreferEoa.current = true;
|
|
57
|
+
setGlobalAccountWallet(activeWallet);
|
|
58
|
+
setActiveWallet(connectedEOAWallet);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}, [preferEoa, connectedEOAWallet, setActiveWallet, activeWallet, setGlobalAccountWallet]);
|
|
62
|
+
const selectedRecipientOrDefault = selectedRecipientAddress ?? recipientAddress;
|
|
63
|
+
const expectedDstAmountRaw = anyspendQuote?.data?.currencyOut?.amount ?? "0";
|
|
64
|
+
const buildCustomPayload = (_recipient) => {
|
|
65
|
+
return {
|
|
66
|
+
amount: expectedDstAmountRaw,
|
|
67
|
+
expectedDstAmount: expectedDstAmountRaw,
|
|
68
|
+
functionAbi: customExactInConfig.functionAbi,
|
|
69
|
+
functionName: customExactInConfig.functionName,
|
|
70
|
+
functionArgs: customExactInConfig.functionArgs,
|
|
71
|
+
to: normalizeAddress(customExactInConfig.to),
|
|
72
|
+
spenderAddress: customExactInConfig.spenderAddress
|
|
73
|
+
? normalizeAddress(customExactInConfig.spenderAddress)
|
|
74
|
+
: undefined,
|
|
75
|
+
action: customExactInConfig.action,
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const btnInfo = useMemo(() => {
|
|
79
|
+
if (activeInputAmountInWei === "0")
|
|
80
|
+
return { text: "Enter an amount", disable: true, error: false, loading: false };
|
|
81
|
+
if (isLoadingAnyspendQuote)
|
|
82
|
+
return { text: "Loading quote...", disable: true, error: false, loading: true };
|
|
83
|
+
if (isCreatingOrder || isCreatingOnrampOrder)
|
|
84
|
+
return { text: "Creating order...", disable: true, error: false, loading: true };
|
|
85
|
+
if (!selectedRecipientOrDefault)
|
|
86
|
+
return { text: "Select recipient", disable: false, error: false, loading: false };
|
|
87
|
+
if (!anyspendQuote || !anyspendQuote.success)
|
|
88
|
+
return { text: "Get quote error", disable: true, error: true, loading: false };
|
|
89
|
+
if (paymentType === "crypto") {
|
|
90
|
+
if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
91
|
+
return { text: "Choose payment method", disable: false, error: false, loading: false };
|
|
92
|
+
}
|
|
93
|
+
if (!hasEnoughBalance &&
|
|
94
|
+
!isBalanceLoading &&
|
|
95
|
+
selectedCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
96
|
+
return { text: "Insufficient balance", disable: true, error: true, loading: false };
|
|
97
|
+
}
|
|
98
|
+
return { text: `Execute ${actionLabel}`, disable: false, error: false, loading: false };
|
|
99
|
+
}
|
|
100
|
+
if (paymentType === "fiat") {
|
|
101
|
+
if (selectedFiatPaymentMethod === FiatPaymentMethod.NONE) {
|
|
102
|
+
return { text: "Select payment method", disable: false, error: false, loading: false };
|
|
103
|
+
}
|
|
104
|
+
return { text: "Buy", disable: false, error: false, loading: false };
|
|
105
|
+
}
|
|
106
|
+
return { text: "Continue", disable: false, error: false, loading: false };
|
|
107
|
+
}, [
|
|
108
|
+
activeInputAmountInWei,
|
|
109
|
+
isLoadingAnyspendQuote,
|
|
110
|
+
isCreatingOrder,
|
|
111
|
+
isCreatingOnrampOrder,
|
|
112
|
+
selectedRecipientOrDefault,
|
|
113
|
+
anyspendQuote,
|
|
114
|
+
paymentType,
|
|
115
|
+
selectedCryptoPaymentMethod,
|
|
116
|
+
selectedFiatPaymentMethod,
|
|
117
|
+
hasEnoughBalance,
|
|
118
|
+
isBalanceLoading,
|
|
119
|
+
actionLabel,
|
|
120
|
+
]);
|
|
121
|
+
const onMainButtonClick = async () => {
|
|
122
|
+
if (btnInfo.disable)
|
|
123
|
+
return;
|
|
124
|
+
if (!selectedRecipientOrDefault) {
|
|
125
|
+
setActivePanel(PanelView.RECIPIENT_SELECTION);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (paymentType === "crypto") {
|
|
129
|
+
if (selectedCryptoPaymentMethod === CryptoPaymentMethodType.NONE) {
|
|
130
|
+
setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
await handleCryptoOrder();
|
|
134
|
+
}
|
|
135
|
+
else if (paymentType === "fiat") {
|
|
136
|
+
if (selectedFiatPaymentMethod === FiatPaymentMethod.NONE) {
|
|
137
|
+
setActivePanel(PanelView.FIAT_PAYMENT_METHOD);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
await handleFiatOrder();
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const headerContent = header ? (header({ anyspendPrice: anyspendQuote, isLoadingAnyspendPrice: isLoadingAnyspendQuote })) : (_jsx("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: _jsxs("div", { children: [_jsx("h1", { className: "text-as-primary text-xl font-bold", children: actionLabel }), _jsx("p", { className: "text-as-secondary text-sm", children: "Pay from any token to execute a custom exact-in transaction." })] }) }));
|
|
144
|
+
const mainView = (_jsxs("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [headerContent, _jsx("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: _jsxs("div", { className: "relative flex w-full max-w-[calc(100vw-32px)] flex-col gap-2", children: [paymentType === "crypto" ? (_jsx(CryptoPaySection, { selectedSrcChainId: selectedSrcChainId, setSelectedSrcChainId: setSelectedSrcChainId, selectedSrcToken: selectedSrcToken, setSelectedSrcToken: setSelectedSrcToken, srcAmount: srcAmount, setSrcAmount: setSrcAmount, isSrcInputDirty: isSrcInputDirty, setIsSrcInputDirty: setIsSrcInputDirty, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onSelectCryptoPaymentMethod: () => setActivePanel(PanelView.CRYPTO_PAYMENT_METHOD), anyspendQuote: anyspendQuote, onTokenSelect: onTokenSelect })) : (_jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, children: _jsx(PanelOnramp, { srcAmountOnRamp: srcAmount, setSrcAmountOnRamp: setSrcAmount, selectedPaymentMethod: selectedFiatPaymentMethod, setActivePanel: setActivePanel, _recipientAddress: selectedRecipientOrDefault, destinationToken: selectedDstToken, destinationChainId: selectedDstChainId, dstTokenSymbol: DESTINATION_TOKEN_DETAILS.SYMBOL, hideDstToken: true, destinationAmount: dstAmount, onDestinationTokenChange: () => { }, onDestinationChainChange: () => { }, fiatPaymentMethodIndex: PanelView.FIAT_PAYMENT_METHOD, recipientSelectionPanelIndex: PanelView.RECIPIENT_SELECTION, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(PanelView.FEE_DETAIL), customUsdInputValues: customUsdInputValues }) })), _jsx("div", { className: cn("relative -my-1 flex h-0 items-center justify-center", paymentType === "fiat" && "hidden"), children: _jsx(Button, { variant: "ghost", className: cn("swap-direction-button border-as-stroke bg-as-surface-primary z-10 h-10 w-10 cursor-default rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl"), children: _jsx("div", { className: "relative flex items-center justify-center transition-opacity", children: _jsx(ArrowDown, { className: "text-as-primary/50 h-5 w-5" }) }) }) }), paymentType === "crypto" && (_jsx(CryptoReceiveSection, { isDepositMode: false, isBuyMode: true, selectedRecipientAddress: selectedRecipientOrDefault, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(PanelView.RECIPIENT_SELECTION), dstAmount: dstAmount, dstToken: selectedDstToken, dstTokenSymbol: DESTINATION_TOKEN_DETAILS.SYMBOL, dstTokenLogoURI: DESTINATION_TOKEN_DETAILS.LOGO_URI, selectedDstChainId: selectedDstChainId, setSelectedDstChainId: () => { }, setSelectedDstToken: () => { }, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
|
|
145
|
+
setIsSrcInputDirty(false);
|
|
146
|
+
setSrcAmount(value);
|
|
147
|
+
}, anyspendQuote: anyspendQuote, onShowPointsDetail: () => setActivePanel(PanelView.POINTS_DETAIL), onShowFeeDetail: () => setActivePanel(PanelView.FEE_DETAIL) }))] }) }), _jsx(motion.div, { initial: { opacity: 0, y: 20, filter: "blur(10px)" }, animate: { opacity: 1, y: 0, filter: "blur(0px)" }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: cn("mt-4 flex w-full max-w-[460px] flex-col gap-2"), children: _jsx(ShinyButton, { accentColor: "hsl(var(--as-brand))", disabled: btnInfo.disable, onClick: onMainButtonClick, className: cn("as-main-button relative w-full", btnInfo.error ? "!bg-as-red" : btnInfo.disable ? "!bg-as-on-surface-2" : "!bg-as-brand"), textClassName: cn(btnInfo.error ? "text-white" : btnInfo.disable ? "text-as-secondary" : "text-white"), children: _jsxs("div", { className: "flex items-center justify-center gap-2", children: [btnInfo.loading && _jsx(Loader2, { className: "h-4 w-4 animate-spin" }), btnInfo.text] }) }) }), mainFooter ? mainFooter : null] }));
|
|
148
|
+
const handleCryptoOrder = async () => {
|
|
149
|
+
try {
|
|
150
|
+
invariant(anyspendQuote, "Relay price is not found");
|
|
151
|
+
invariant(selectedRecipientOrDefault, "Recipient address is not found");
|
|
152
|
+
const srcAmountBigInt = BigInt(activeInputAmountInWei);
|
|
153
|
+
const payload = buildCustomPayload(selectedRecipientOrDefault);
|
|
154
|
+
createOrder({
|
|
155
|
+
recipientAddress: selectedRecipientOrDefault,
|
|
156
|
+
orderType: "custom_exact_in",
|
|
157
|
+
srcChain: selectedSrcChainId,
|
|
158
|
+
dstChain: selectedDstChainId,
|
|
159
|
+
srcToken: selectedSrcToken,
|
|
160
|
+
dstToken: selectedDstToken,
|
|
161
|
+
srcAmount: srcAmountBigInt.toString(),
|
|
162
|
+
expectedDstAmount: expectedDstAmountRaw,
|
|
163
|
+
creatorAddress: globalAddress,
|
|
164
|
+
payload,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
console.error(err);
|
|
169
|
+
toast.error("Failed to create order: " + err.message);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const handleFiatOrder = async () => {
|
|
173
|
+
try {
|
|
174
|
+
invariant(anyspendQuote, "Relay price is not found");
|
|
175
|
+
invariant(selectedRecipientOrDefault, "Recipient address is not found");
|
|
176
|
+
if (!srcAmount || parseFloat(srcAmount) <= 0) {
|
|
177
|
+
toast.error("Please enter a valid amount");
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
let vendor;
|
|
181
|
+
let paymentMethodString = "";
|
|
182
|
+
if (selectedFiatPaymentMethod === FiatPaymentMethod.COINBASE_PAY) {
|
|
183
|
+
if (coinbaseAvailablePaymentMethods.length === 0) {
|
|
184
|
+
toast.error("Coinbase Pay not available");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
vendor = "coinbase";
|
|
188
|
+
paymentMethodString = coinbaseAvailablePaymentMethods[0]?.id || "";
|
|
189
|
+
}
|
|
190
|
+
else if (selectedFiatPaymentMethod === FiatPaymentMethod.STRIPE) {
|
|
191
|
+
if (!stripeWeb2Support || !stripeWeb2Support.isSupport) {
|
|
192
|
+
toast.error("Stripe not available");
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
vendor = "stripe-web2";
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
toast.error("Please select a payment method");
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const payload = buildCustomPayload(selectedRecipientOrDefault);
|
|
202
|
+
createOnrampOrder({
|
|
203
|
+
recipientAddress: selectedRecipientOrDefault,
|
|
204
|
+
orderType: "custom_exact_in",
|
|
205
|
+
dstChain: selectedDstChainId,
|
|
206
|
+
dstToken: selectedDstToken,
|
|
207
|
+
srcFiatAmount: srcAmount,
|
|
208
|
+
onramp: {
|
|
209
|
+
vendor,
|
|
210
|
+
paymentMethod: paymentMethodString,
|
|
211
|
+
country: geoData?.country || "US",
|
|
212
|
+
redirectUrl: window.location.origin,
|
|
213
|
+
},
|
|
214
|
+
expectedDstAmount: expectedDstAmountRaw,
|
|
215
|
+
creatorAddress: globalAddress,
|
|
216
|
+
payload,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
console.error(err);
|
|
221
|
+
toast.error("Failed to create order: " + err.message);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
const orderDetailsView = (_jsx("div", { className: "mx-auto w-[460px] max-w-full", children: _jsx("div", { className: "relative flex flex-col gap-4", children: oat && (_jsx(OrderDetails, { mode: mode, order: oat.data.order, depositTxs: oat.data.depositTxs, relayTxs: oat.data.relayTxs, executeTx: oat.data.executeTx, refundTxs: oat.data.refundTxs, cryptoPaymentMethod: paymentType === "fiat" ? CryptoPaymentMethodType.NONE : selectedCryptoPaymentMethod, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onPaymentMethodChange: setSelectedCryptoPaymentMethod, onBack: () => {
|
|
225
|
+
setOrderId(undefined);
|
|
226
|
+
setActivePanel(PanelView.MAIN);
|
|
227
|
+
}, disableUrlParamManagement: true, points: oat.data.points || undefined })) }) }));
|
|
228
|
+
const loadingView = (_jsx("div", { className: "mx-auto flex w-full flex-col items-center gap-4 p-5", children: _jsx("div", { className: "text-as-primary", children: "Loading order details..." }) }));
|
|
229
|
+
const recipientSelectionView = (_jsx(RecipientSelection, { initialValue: selectedRecipientOrDefault || "", onBack: () => setActivePanel(PanelView.MAIN), onConfirm: address => {
|
|
230
|
+
setSelectedRecipientAddress(address);
|
|
231
|
+
setActivePanel(PanelView.MAIN);
|
|
232
|
+
} }));
|
|
233
|
+
const cryptoPaymentMethodView = (_jsx(CryptoPaymentMethod, { globalAddress: globalAddress, globalWallet: undefined, selectedPaymentMethod: selectedCryptoPaymentMethod, setSelectedPaymentMethod: setSelectedCryptoPaymentMethod, isCreatingOrder: isCreatingOrder, onBack: () => setActivePanel(PanelView.MAIN), onSelectPaymentMethod: (method) => {
|
|
234
|
+
setSelectedCryptoPaymentMethod(method);
|
|
235
|
+
setActivePanel(PanelView.MAIN);
|
|
236
|
+
} }));
|
|
237
|
+
const fiatPaymentMethodView = (_jsx(FiatPaymentMethodComponent, { selectedPaymentMethod: selectedFiatPaymentMethod, setSelectedPaymentMethod: setSelectedFiatPaymentMethod, onBack: () => setActivePanel(PanelView.MAIN), onSelectPaymentMethod: (method) => {
|
|
238
|
+
setSelectedFiatPaymentMethod(method);
|
|
239
|
+
setActivePanel(PanelView.MAIN);
|
|
240
|
+
}, srcAmountOnRamp: srcAmount }));
|
|
241
|
+
const pointsDetailView = (_jsx(PointsDetailPanel, { pointsAmount: anyspendQuote?.data?.pointsAmount || 0, onBack: () => setActivePanel(PanelView.MAIN) }));
|
|
242
|
+
const feeDetailView = anyspendQuote?.data?.fee ? (_jsx(FeeDetailPanel, { fee: anyspendQuote.data.fee, transactionAmountUsd: paymentType === "fiat"
|
|
243
|
+
? parseFloat(srcAmount)
|
|
244
|
+
: anyspendQuote.data.currencyIn?.amountUsd
|
|
245
|
+
? Number(anyspendQuote.data.currencyIn.amountUsd)
|
|
246
|
+
: undefined, onBack: () => setActivePanel(PanelView.MAIN) })) : null;
|
|
247
|
+
return (_jsx(StyleRoot, { children: _jsx("div", { className: cn("anyspend-container font-inter bg-as-surface-primary mx-auto w-full max-w-[460px] p-6", mode === "page" && "border-as-border-secondary overflow-hidden rounded-2xl border shadow-xl"), children: _jsx(TransitionPanel, { activeIndex: orderId
|
|
248
|
+
? oat
|
|
249
|
+
? PanelView.ORDER_DETAILS
|
|
250
|
+
: PanelView.LOADING
|
|
251
|
+
: activePanel === PanelView.ORDER_DETAILS
|
|
252
|
+
? PanelView.MAIN
|
|
253
|
+
: activePanel, className: cn("rounded-2xl", {
|
|
254
|
+
"mt-0": mode === "modal",
|
|
255
|
+
}), variants: {
|
|
256
|
+
enter: { x: 300, opacity: 0 },
|
|
257
|
+
center: { x: 0, opacity: 1 },
|
|
258
|
+
exit: { x: -300, opacity: 0 },
|
|
259
|
+
}, transition: { type: "spring", stiffness: 300, damping: 30 }, children: [
|
|
260
|
+
_jsx("div", { children: mainView }, "main-view"),
|
|
261
|
+
_jsx("div", { children: cryptoPaymentMethodView }, "crypto-payment-method-view"),
|
|
262
|
+
_jsx("div", { children: fiatPaymentMethodView }, "fiat-payment-method-view"),
|
|
263
|
+
_jsx("div", { children: recipientSelectionView }, "recipient-selection-view"),
|
|
264
|
+
_jsx("div", { children: orderDetailsView }, "order-details-view"),
|
|
265
|
+
_jsx("div", { children: loadingView }, "loading-view"),
|
|
266
|
+
_jsx("div", { children: pointsDetailView }, "points-detail-view"),
|
|
267
|
+
_jsx("div", { children: feeDetailView }, "fee-detail-view"),
|
|
268
|
+
] }) }) }));
|
|
269
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { ABI_ERC20_STAKING, B3_TOKEN } from "../../../anyspend/index.js";
|
|
3
|
-
import { Button, GlareCardRounded, Input, StyleRoot, TextLoop, useHasMounted, useModalStore,
|
|
2
|
+
import { ABI_ERC20_STAKING, B3_TOKEN, eqci } from "../../../anyspend/index.js";
|
|
3
|
+
import { Button, GlareCardRounded, Input, StyleRoot, TextLoop, useHasMounted, useModalStore, useSimBalance, useUnifiedChainSwitchAndExecute, } from "../../../global-account/react/index.js";
|
|
4
4
|
import { PUBLIC_BASE_RPC_URL } from "../../../shared/constants/index.js";
|
|
5
5
|
import { formatTokenAmount } from "../../../shared/utils/number.js";
|
|
6
6
|
import invariant from "invariant";
|
|
@@ -32,13 +32,14 @@ function generateEncodedDataForStakingB3(amount, beneficiary) {
|
|
|
32
32
|
export function AnySpendStakeB3({ loadOrder, mode = "modal", recipientAddress, stakeAmount, onSuccess, }) {
|
|
33
33
|
const hasMounted = useHasMounted();
|
|
34
34
|
const { setB3ModalOpen } = useModalStore();
|
|
35
|
-
// Fetch B3 token balance
|
|
36
|
-
const { formattedBalance: b3Balance, isLoading: isBalanceLoading, rawBalance: b3RawBalance, } = useTokenBalance({
|
|
37
|
-
token: B3_TOKEN,
|
|
38
|
-
});
|
|
39
35
|
// Wagmi hooks for direct staking
|
|
40
36
|
const { address } = useAccount();
|
|
41
37
|
const { switchChainAndExecute, isSwitchingOrExecuting } = useUnifiedChainSwitchAndExecute();
|
|
38
|
+
// Fetch B3 token balance
|
|
39
|
+
const { data: simBalance, isLoading: isBalanceLoading } = useSimBalance(address, [base.id]);
|
|
40
|
+
const b3RawBalanceStr = simBalance?.balances.find(b => eqci(b.address, B3_TOKEN.address))?.amount || "0";
|
|
41
|
+
const b3RawBalance = BigInt(b3RawBalanceStr);
|
|
42
|
+
const b3Balance = formatTokenAmount(b3RawBalance, B3_TOKEN.decimals);
|
|
42
43
|
// State for direct staking flow
|
|
43
44
|
const [isStaking, setIsStaking] = useState(false);
|
|
44
45
|
const [stakingTxHash, setStakingTxHash] = useState("");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function AnySpendStakeB3ExactIn({ loadOrder, mode, sourceTokenAddress, sourceTokenChainId, recipientAddress, stakeAmount, onSuccess, }: {
|
|
2
|
+
loadOrder?: string;
|
|
3
|
+
mode?: "modal" | "page";
|
|
4
|
+
sourceTokenAddress?: string;
|
|
5
|
+
sourceTokenChainId?: number;
|
|
6
|
+
recipientAddress: string;
|
|
7
|
+
stakeAmount?: string;
|
|
8
|
+
onSuccess?: (amount: string) => void;
|
|
9
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { ABI_ERC20_STAKING, B3_TOKEN, eqci } from "../../../anyspend/index.js";
|
|
3
|
+
import { normalizeAddress } from "../../../anyspend/utils/index.js";
|
|
4
|
+
import { Button, GlareCardRounded, Input, StyleRoot, TextLoop, useHasMounted, useModalStore, useSimBalance, useUnifiedChainSwitchAndExecute, } from "../../../global-account/react/index.js";
|
|
5
|
+
import { PUBLIC_BASE_RPC_URL } from "../../../shared/constants/index.js";
|
|
6
|
+
import { formatTokenAmount } from "../../../shared/utils/number.js";
|
|
7
|
+
import { ArrowRight, Loader2 } from "lucide-react";
|
|
8
|
+
import { motion } from "motion/react";
|
|
9
|
+
import { useEffect, useState } from "react";
|
|
10
|
+
import { toast } from "sonner";
|
|
11
|
+
import { createPublicClient, encodeFunctionData, erc20Abi, http } from "viem";
|
|
12
|
+
import { base } from "viem/chains";
|
|
13
|
+
import { useAccount, useWaitForTransactionReceipt } from "wagmi";
|
|
14
|
+
import { AnySpendCustomExactIn } from "./AnySpendCustomExactIn.js";
|
|
15
|
+
import { EthIcon } from "./icons/EthIcon.js";
|
|
16
|
+
import { SolIcon } from "./icons/SolIcon.js";
|
|
17
|
+
import { UsdcIcon } from "./icons/USDCIcon.js";
|
|
18
|
+
const basePublicClient = createPublicClient({
|
|
19
|
+
chain: base,
|
|
20
|
+
transport: http(PUBLIC_BASE_RPC_URL),
|
|
21
|
+
});
|
|
22
|
+
const ERC20Staking = "0xbf04200be3cbf371467a539706393c81c470f523";
|
|
23
|
+
const STAKE_FUNCTION_ABI = JSON.stringify([
|
|
24
|
+
{
|
|
25
|
+
name: "stake",
|
|
26
|
+
type: "function",
|
|
27
|
+
stateMutability: "nonpayable",
|
|
28
|
+
inputs: [
|
|
29
|
+
{ name: "amount", type: "uint256" },
|
|
30
|
+
{ name: "beneficiary", type: "address" },
|
|
31
|
+
],
|
|
32
|
+
outputs: [],
|
|
33
|
+
},
|
|
34
|
+
]);
|
|
35
|
+
export function AnySpendStakeB3ExactIn({ loadOrder, mode = "modal", sourceTokenAddress, sourceTokenChainId, recipientAddress, stakeAmount, onSuccess, }) {
|
|
36
|
+
const hasMounted = useHasMounted();
|
|
37
|
+
const { setB3ModalOpen } = useModalStore();
|
|
38
|
+
// Wagmi hooks for direct staking
|
|
39
|
+
const { address } = useAccount();
|
|
40
|
+
const { switchChainAndExecute, isSwitchingOrExecuting } = useUnifiedChainSwitchAndExecute();
|
|
41
|
+
// Fetch B3 token balance
|
|
42
|
+
const { data: simBalance, isLoading: isBalanceLoading } = useSimBalance(address, [base.id]);
|
|
43
|
+
const b3RawBalanceStr = simBalance?.balances.find(b => eqci(b.address, B3_TOKEN.address))?.amount || "0";
|
|
44
|
+
const b3RawBalance = BigInt(b3RawBalanceStr);
|
|
45
|
+
const b3Balance = formatTokenAmount(b3RawBalance, B3_TOKEN.decimals);
|
|
46
|
+
// State for direct staking flow
|
|
47
|
+
const [isStaking, setIsStaking] = useState(false);
|
|
48
|
+
const [stakingTxHash, setStakingTxHash] = useState("");
|
|
49
|
+
const [showSuccessModal, setShowSuccessModal] = useState(false);
|
|
50
|
+
// Wait for transaction confirmation
|
|
51
|
+
const { isLoading: isTxPending, isSuccess: isTxSuccess } = useWaitForTransactionReceipt({
|
|
52
|
+
hash: stakingTxHash,
|
|
53
|
+
query: {
|
|
54
|
+
structuralSharing: false, // Disable to avoid BigInt serialization issues
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
// Show success modal when transaction is confirmed
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (isTxSuccess && stakingTxHash) {
|
|
60
|
+
setShowAmountPrompt(false);
|
|
61
|
+
setShowSuccessModal(true);
|
|
62
|
+
setIsStaking(false);
|
|
63
|
+
}
|
|
64
|
+
}, [isTxSuccess, stakingTxHash]);
|
|
65
|
+
const [userStakeAmount, setUserStakeAmount] = useState(stakeAmount || "");
|
|
66
|
+
const [showAmountPrompt, setShowAmountPrompt] = useState(!stakeAmount);
|
|
67
|
+
const [isAmountValid, setIsAmountValid] = useState(!!stakeAmount);
|
|
68
|
+
const [validationError, setValidationError] = useState("");
|
|
69
|
+
// Store display amount for UI
|
|
70
|
+
const [displayAmount, setDisplayAmount] = useState("");
|
|
71
|
+
// Debounced state for balance checks and messaging
|
|
72
|
+
const [debouncedAmount, setDebouncedAmount] = useState("");
|
|
73
|
+
const [debouncedUserStakeAmount, setDebouncedUserStakeAmount] = useState("");
|
|
74
|
+
// Debounce the amount for balance checks
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const timer = setTimeout(() => {
|
|
77
|
+
setDebouncedAmount(displayAmount);
|
|
78
|
+
setDebouncedUserStakeAmount(userStakeAmount);
|
|
79
|
+
}, 500);
|
|
80
|
+
return () => clearTimeout(timer);
|
|
81
|
+
}, [displayAmount, userStakeAmount]);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (stakeAmount) {
|
|
84
|
+
setUserStakeAmount(stakeAmount);
|
|
85
|
+
setShowAmountPrompt(false);
|
|
86
|
+
setIsAmountValid(true);
|
|
87
|
+
}
|
|
88
|
+
}, [stakeAmount]);
|
|
89
|
+
if (!recipientAddress)
|
|
90
|
+
return null;
|
|
91
|
+
const validateAndSetAmount = (value) => {
|
|
92
|
+
// Allow decimal input by validating against a pattern
|
|
93
|
+
// This regex allows numbers with up to 18 decimal places
|
|
94
|
+
const isValidFormat = /^(\d+\.?\d{0,18}|\.\d{1,18})$/.test(value) || value === "";
|
|
95
|
+
if (!isValidFormat && value !== "") {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
setDisplayAmount(value);
|
|
99
|
+
try {
|
|
100
|
+
if (value === "" || value === ".") {
|
|
101
|
+
setUserStakeAmount("");
|
|
102
|
+
setIsAmountValid(false);
|
|
103
|
+
setValidationError("");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// For UI validation - check if it's a positive number
|
|
107
|
+
const numValue = parseFloat(value);
|
|
108
|
+
if (isNaN(numValue) || numValue <= 0) {
|
|
109
|
+
setIsAmountValid(false);
|
|
110
|
+
setUserStakeAmount("");
|
|
111
|
+
setValidationError("Please enter a valid positive number");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// Check minimum stake amount (50 B3)
|
|
115
|
+
if (numValue < 50) {
|
|
116
|
+
setIsAmountValid(false);
|
|
117
|
+
setUserStakeAmount("");
|
|
118
|
+
setValidationError("Minimum stake amount is 50 B3");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// Convert to wei (multiply by 10^18)
|
|
122
|
+
// Handle decimal places correctly by removing the decimal point
|
|
123
|
+
let fullAmount;
|
|
124
|
+
if (value.includes(".")) {
|
|
125
|
+
const [whole, fraction = ""] = value.split(".");
|
|
126
|
+
// Pad with zeros to 18 decimal places
|
|
127
|
+
const paddedFraction = fraction.padEnd(18, "0");
|
|
128
|
+
fullAmount = whole + paddedFraction;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
fullAmount = value + "000000000000000000"; // Add 18 zeros
|
|
132
|
+
}
|
|
133
|
+
// Remove leading zeros
|
|
134
|
+
fullAmount = fullAmount.replace(/^0+/, "") || "0";
|
|
135
|
+
// Set the full amount for the actual transaction
|
|
136
|
+
setUserStakeAmount(fullAmount);
|
|
137
|
+
setIsAmountValid(true);
|
|
138
|
+
setValidationError("");
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
setIsAmountValid(false);
|
|
142
|
+
setUserStakeAmount("");
|
|
143
|
+
setValidationError("Please enter a valid amount");
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const handleDirectStaking = async () => {
|
|
147
|
+
if (!address || !basePublicClient || !userStakeAmount)
|
|
148
|
+
return;
|
|
149
|
+
try {
|
|
150
|
+
setIsStaking(true);
|
|
151
|
+
// Check current allowance
|
|
152
|
+
const allowance = await basePublicClient.readContract({
|
|
153
|
+
address: B3_TOKEN.address,
|
|
154
|
+
abi: erc20Abi,
|
|
155
|
+
functionName: "allowance",
|
|
156
|
+
args: [address, ERC20Staking],
|
|
157
|
+
});
|
|
158
|
+
// If allowance is insufficient, request approval first
|
|
159
|
+
if (allowance < BigInt(userStakeAmount)) {
|
|
160
|
+
toast.info("Approving B3 spending...");
|
|
161
|
+
const approvalData = encodeFunctionData({
|
|
162
|
+
abi: erc20Abi,
|
|
163
|
+
functionName: "approve",
|
|
164
|
+
args: [ERC20Staking, BigInt(userStakeAmount)],
|
|
165
|
+
});
|
|
166
|
+
const approvalHash = await switchChainAndExecute(base.id, {
|
|
167
|
+
to: B3_TOKEN.address,
|
|
168
|
+
data: approvalData,
|
|
169
|
+
value: BigInt(0),
|
|
170
|
+
});
|
|
171
|
+
if (!approvalHash) {
|
|
172
|
+
toast.error("Approval failed. Please try again.");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const approvalReceipt = await basePublicClient.waitForTransactionReceipt({
|
|
176
|
+
hash: approvalHash,
|
|
177
|
+
confirmations: 1,
|
|
178
|
+
});
|
|
179
|
+
if (approvalReceipt?.status !== "success") {
|
|
180
|
+
toast.error("Approval failed. Please try again.");
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Execute the stake
|
|
185
|
+
toast.info("Staking B3...");
|
|
186
|
+
const stakeData = encodeFunctionData({
|
|
187
|
+
abi: ABI_ERC20_STAKING,
|
|
188
|
+
functionName: "stake",
|
|
189
|
+
args: [BigInt(userStakeAmount), recipientAddress],
|
|
190
|
+
});
|
|
191
|
+
const stakeHash = await switchChainAndExecute(base.id, {
|
|
192
|
+
to: ERC20Staking,
|
|
193
|
+
data: stakeData,
|
|
194
|
+
value: BigInt(0),
|
|
195
|
+
});
|
|
196
|
+
if (stakeHash) {
|
|
197
|
+
setStakingTxHash(stakeHash);
|
|
198
|
+
toast.success("Staking transaction submitted!");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
console.error("@@b3-stake-custom-exact-in:error:", error);
|
|
203
|
+
toast.error("Staking failed. Please try again.");
|
|
204
|
+
setShowSuccessModal(false); // Ensure modal doesn't show on error
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
setIsStaking(false);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const confirmAmount = () => {
|
|
211
|
+
if (!isAmountValid) {
|
|
212
|
+
toast.error("Please enter a valid amount to stake");
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
// Check if user has sufficient B3 balance for direct staking
|
|
216
|
+
const hasEnoughBalance = b3RawBalance && BigInt(userStakeAmount) <= b3RawBalance;
|
|
217
|
+
if (hasEnoughBalance) {
|
|
218
|
+
// User has enough B3, proceed with direct staking
|
|
219
|
+
handleDirectStaking();
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
// User needs more B3, proceed to AnySpend conversion flow
|
|
223
|
+
setShowAmountPrompt(false);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const header = () => (_jsxs(_Fragment, { children: [_jsx("div", { className: "relative mx-auto size-32", children: _jsx("img", { alt: "b3 coin", className: "size-full", src: "https://cdn.b3.fun/b3-coin-3d.png" }) }), _jsxs("div", { className: "from-b3-react-background to-as-on-surface-1 mt-[-60px] w-full rounded-t-lg bg-gradient-to-t", children: [_jsx("div", { className: "h-[60px] w-full" }), _jsx("div", { className: "mb-1 flex w-full flex-col items-center gap-2 p-5", children: _jsxs("span", { className: "font-sf-rounded text-2xl font-semibold", children: ["Swap & Stake ", userStakeAmount ? formatTokenAmount(BigInt(userStakeAmount), 18) : "", " B3 (Exact In)"] }) })] })] }));
|
|
227
|
+
const onFocusStakeAmountInput = () => {
|
|
228
|
+
window.scrollTo(0, 0);
|
|
229
|
+
document.body.scrollTop = 0;
|
|
230
|
+
};
|
|
231
|
+
const customExactInConfig = {
|
|
232
|
+
functionAbi: STAKE_FUNCTION_ABI,
|
|
233
|
+
functionName: "stake",
|
|
234
|
+
functionArgs: ["{{amount_out}}", normalizeAddress(recipientAddress)],
|
|
235
|
+
to: ERC20Staking,
|
|
236
|
+
spenderAddress: ERC20Staking,
|
|
237
|
+
action: "stake B3",
|
|
238
|
+
};
|
|
239
|
+
// Render amount input prompt if no stake amount is provided
|
|
240
|
+
if (showAmountPrompt) {
|
|
241
|
+
return (_jsx(StyleRoot, { children: _jsxs("div", { className: "bg-b3-react-background flex w-full flex-col items-center", children: [_jsxs("div", { className: "w-full px-4", children: [_jsx(motion.div, { initial: false, animate: {
|
|
242
|
+
opacity: hasMounted ? 1 : 0,
|
|
243
|
+
y: hasMounted ? 0 : 20,
|
|
244
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
245
|
+
}, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "relative mx-auto size-48", children: _jsx("video", { autoPlay: true, muted: true, playsInline: true, className: "size-full", src: "https://cdn.b3.fun/b3-sphere-to-coin.mp4" }) }), _jsx(motion.div, { initial: false, animate: {
|
|
246
|
+
opacity: hasMounted ? 1 : 0,
|
|
247
|
+
y: hasMounted ? 0 : 20,
|
|
248
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
249
|
+
}, transition: { duration: 0.3, delay: 0.1, ease: "easeInOut" }, children: _jsx("h2", { className: "font-sf-rounded font-neue-montreal-medium mb-1 text-center text-2xl font-semibold", children: (() => {
|
|
250
|
+
const hasEnoughBalance = b3RawBalance && BigInt(debouncedUserStakeAmount || "0") <= b3RawBalance;
|
|
251
|
+
return hasEnoughBalance || !debouncedAmount ? "Stake B3" : "Swap & Stake B3";
|
|
252
|
+
})() }) })] }), _jsxs(motion.div, { initial: false, animate: {
|
|
253
|
+
opacity: hasMounted ? 1 : 0,
|
|
254
|
+
y: hasMounted ? 0 : 20,
|
|
255
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
256
|
+
}, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: [_jsx("div", { className: "mb-2", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsx("p", { className: "text-as-primary/70 text-sm font-medium", children: "I want to stake" }), _jsxs("span", { className: "text-as-primary/50 flex items-center gap-1 text-sm", children: ["Available: ", isBalanceLoading ? _jsx(Loader2, { className: "h-3 w-3 animate-spin" }) : `${b3Balance} B3`] })] }) }), _jsxs("div", { className: "relative", children: [_jsx(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"}` }), _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 && _jsx("p", { className: "text-as-red mt-2 text-sm", children: validationError }), _jsx("div", { className: "mt-4", children: (() => {
|
|
257
|
+
const hasEnoughBalance = b3RawBalance && BigInt(debouncedUserStakeAmount || "0") <= b3RawBalance;
|
|
258
|
+
if (!hasEnoughBalance || !debouncedAmount) {
|
|
259
|
+
return (_jsxs("div", { className: "bg-as-brand/10 flex flex-col items-center gap-2 rounded-lg p-4 pb-5", children: [_jsxs("div", { className: "flex items-center justify-center gap-2", children: [_jsx("span", { className: "text-as-primary text-sm font-semibold", children: "Swap & stake from any token" }), _jsxs(TextLoop, { children: [_jsx(EthIcon, { className: "h-8 w-8" }), _jsx(SolIcon, { className: "h-8 w-8" }), _jsx(UsdcIcon, { className: "h-8 w-8" })] }), _jsx(ArrowRight, { className: "text-as-primary h-4 w-4" }), _jsx("img", { src: "https://cdn.b3.fun/b3-coin-3d.png", className: "h-7 w-7", alt: "B3 Token" })] }), _jsx("p", { className: "text-as-primary/50 text-sm font-medium", children: debouncedAmount
|
|
260
|
+
? `No problem, we'll help you swap to ${debouncedAmount} B3!`
|
|
261
|
+
: "Not enough B3? We'll help you swap from other coins." })] }));
|
|
262
|
+
}
|
|
263
|
+
})() }), _jsx(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" })] })] }) }));
|
|
264
|
+
}
|
|
265
|
+
// Success Modal for Direct Staking
|
|
266
|
+
if (showSuccessModal) {
|
|
267
|
+
return (_jsx(StyleRoot, { children: _jsxs("div", { className: "bg-b3-react-background flex w-full flex-col items-center", children: [_jsxs("div", { className: "w-full p-4", children: [_jsxs(motion.div, { initial: false, animate: {
|
|
268
|
+
opacity: hasMounted ? 1 : 0,
|
|
269
|
+
y: hasMounted ? 0 : 20,
|
|
270
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
271
|
+
}, transition: { duration: 0.3, delay: 0, ease: "easeInOut" }, className: "relative mx-auto mb-4 size-[120px]", children: [_jsx("div", { className: "absolute inset-0 scale-95 rounded-[50%] bg-black/30 blur-md" }), _jsxs(GlareCardRounded, { className: "overflow-hidden rounded-full border-none", children: [_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" }), _jsx("div", { className: "absolute inset-0 rounded-[50%] border border-white/10" })] })] }), _jsx(motion.div, { initial: false, animate: {
|
|
272
|
+
opacity: hasMounted ? 1 : 0,
|
|
273
|
+
y: hasMounted ? 0 : 20,
|
|
274
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
275
|
+
}, transition: { duration: 0.3, delay: 0.1, ease: "easeInOut" }, children: _jsxs("h2", { className: "font-sf-rounded mb-1 text-center text-2xl font-semibold", children: ["Staked ", formatTokenAmount(BigInt(userStakeAmount), 18), " B3"] }) })] }), _jsxs(motion.div, { initial: false, animate: {
|
|
276
|
+
opacity: hasMounted ? 1 : 0,
|
|
277
|
+
y: hasMounted ? 0 : 20,
|
|
278
|
+
filter: hasMounted ? "blur(0px)" : "blur(10px)",
|
|
279
|
+
}, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: [_jsx("div", { className: "mb-6", children: _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" }) }), _jsx(Button, { onClick: () => {
|
|
280
|
+
setB3ModalOpen(false);
|
|
281
|
+
onSuccess?.(formatTokenAmount(BigInt(userStakeAmount), 18) ?? "");
|
|
282
|
+
}, className: "bg-as-brand hover:bg-as-brand/90 text-as-primary h-14 w-full rounded-xl text-lg font-medium", children: "Done" })] })] }) }));
|
|
283
|
+
}
|
|
284
|
+
return (_jsx(AnySpendCustomExactIn, { loadOrder: loadOrder, mode: mode, recipientAddress: recipientAddress, sourceTokenAddress: sourceTokenAddress, sourceTokenChainId: sourceTokenChainId, destinationToken: B3_TOKEN, destinationChainId: base.id, customExactInConfig: customExactInConfig, header: header, onSuccess: onSuccess }));
|
|
285
|
+
}
|
|
@@ -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,30 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { normalizeAddress } from "../../../anyspend/utils/index.js";
|
|
3
|
+
import { base } from "viem/chains";
|
|
4
|
+
import { AnySpendCustomExactIn } from "./AnySpendCustomExactIn.js";
|
|
5
|
+
const STAKE_FOR_FUNCTION_ABI = JSON.stringify([
|
|
6
|
+
{
|
|
7
|
+
name: "stakeFor",
|
|
8
|
+
type: "function",
|
|
9
|
+
stateMutability: "nonpayable",
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: "user", type: "address" },
|
|
12
|
+
{ name: "amount", type: "uint256" },
|
|
13
|
+
],
|
|
14
|
+
outputs: [],
|
|
15
|
+
},
|
|
16
|
+
]);
|
|
17
|
+
export function AnySpendStakeUpsideExactIn({ loadOrder, mode = "modal", recipientAddress, sourceTokenAddress, sourceTokenChainId, stakingContractAddress, token, onSuccess, }) {
|
|
18
|
+
if (!recipientAddress)
|
|
19
|
+
return null;
|
|
20
|
+
const header = () => (_jsx(_Fragment, { children: _jsx("div", { className: "from-b3-react-background to-as-on-surface-1 w-full rounded-t-lg bg-gradient-to-t", children: _jsx("div", { className: "mb-1 flex w-full flex-col items-center gap-2", children: _jsxs("span", { className: "font-sf-rounded text-2xl font-semibold", children: ["Swap & Stake ", token.symbol, " (Exact In)"] }) }) }) }));
|
|
21
|
+
const customExactInConfig = {
|
|
22
|
+
functionAbi: STAKE_FOR_FUNCTION_ABI,
|
|
23
|
+
functionName: "stakeFor",
|
|
24
|
+
functionArgs: [normalizeAddress(recipientAddress), "{{amount_out}}"],
|
|
25
|
+
to: stakingContractAddress,
|
|
26
|
+
spenderAddress: stakingContractAddress,
|
|
27
|
+
action: `stake ${token.symbol}`,
|
|
28
|
+
};
|
|
29
|
+
return (_jsx(AnySpendCustomExactIn, { loadOrder: loadOrder, mode: mode, recipientAddress: recipientAddress, sourceTokenAddress: sourceTokenAddress, sourceTokenChainId: sourceTokenChainId, destinationToken: token, destinationChainId: base.id, customExactInConfig: customExactInConfig, header: header, onSuccess: onSuccess }));
|
|
30
|
+
}
|