@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
|
@@ -19,17 +19,19 @@ const react_4 = require("react");
|
|
|
19
19
|
const sonner_1 = require("sonner");
|
|
20
20
|
const viem_1 = require("viem");
|
|
21
21
|
const chains_1 = require("viem/chains");
|
|
22
|
+
const useAutoSelectCryptoPaymentMethod_1 = require("../hooks/useAutoSelectCryptoPaymentMethod");
|
|
23
|
+
const useAutoSetActiveWalletFromWagmi_1 = require("../hooks/useAutoSetActiveWalletFromWagmi");
|
|
22
24
|
const AnySpendFingerprintWrapper_1 = require("./AnySpendFingerprintWrapper");
|
|
23
25
|
const CryptoPaymentMethod_1 = require("./common/CryptoPaymentMethod");
|
|
24
26
|
const CryptoPaySection_1 = require("./common/CryptoPaySection");
|
|
25
27
|
const CryptoReceiveSection_1 = require("./common/CryptoReceiveSection");
|
|
28
|
+
const FeeDetailPanel_1 = require("./common/FeeDetailPanel");
|
|
26
29
|
const FiatPaymentMethod_1 = require("./common/FiatPaymentMethod");
|
|
27
30
|
const OrderDetails_1 = require("./common/OrderDetails");
|
|
28
31
|
const OrderHistory_1 = require("./common/OrderHistory");
|
|
29
32
|
const PanelOnramp_1 = require("./common/PanelOnramp");
|
|
30
33
|
const PanelOnrampPayment_1 = require("./common/PanelOnrampPayment");
|
|
31
34
|
const PointsDetailPanel_1 = require("./common/PointsDetailPanel");
|
|
32
|
-
const FeeDetailPanel_1 = require("./common/FeeDetailPanel");
|
|
33
35
|
const RecipientSelection_1 = require("./common/RecipientSelection");
|
|
34
36
|
const TabSection_1 = require("./common/TabSection");
|
|
35
37
|
var PanelView;
|
|
@@ -311,13 +313,36 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
311
313
|
// );
|
|
312
314
|
// State for recipient selection
|
|
313
315
|
const [recipientAddress, setRecipientAddress] = (0, react_4.useState)();
|
|
314
|
-
const { address: globalAddress, wallet: globalWallet } = (0, react_2.useAccountWallet)();
|
|
316
|
+
const { address: globalAddress, wallet: globalWallet, connectedEOAWallet } = (0, react_2.useAccountWallet)();
|
|
315
317
|
const recipientProfile = (0, react_2.useProfile)({ address: recipientAddress, fresh: true });
|
|
316
318
|
const recipientName = recipientProfile.data?.name;
|
|
317
|
-
//
|
|
318
|
-
(0,
|
|
319
|
-
|
|
320
|
-
|
|
319
|
+
// Auto-set active wallet from wagmi
|
|
320
|
+
(0, useAutoSetActiveWalletFromWagmi_1.useAutoSetActiveWalletFromWagmi)();
|
|
321
|
+
// Check token balance for crypto payments
|
|
322
|
+
const { rawBalance, isLoading: isBalanceLoading } = (0, react_2.useTokenBalanceDirect)({
|
|
323
|
+
token: selectedSrcToken,
|
|
324
|
+
address: connectedEOAWallet?.getAccount()?.address,
|
|
325
|
+
});
|
|
326
|
+
// Check if user has enough balanceuseAutoSetActiveWalletFromWagmi
|
|
327
|
+
const hasEnoughBalance = (0, react_4.useMemo)(() => {
|
|
328
|
+
if (!rawBalance || isBalanceLoading || activeTab !== "crypto")
|
|
329
|
+
return false;
|
|
330
|
+
try {
|
|
331
|
+
const requiredAmount = (0, viem_1.parseUnits)(srcAmount.replace(/,/g, ""), selectedSrcToken.decimals);
|
|
332
|
+
return rawBalance >= requiredAmount;
|
|
333
|
+
}
|
|
334
|
+
catch {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
}, [rawBalance, srcAmount, selectedSrcToken.decimals, isBalanceLoading, activeTab]);
|
|
338
|
+
// Auto-select crypto payment method based on available wallets and balance
|
|
339
|
+
(0, useAutoSelectCryptoPaymentMethod_1.useAutoSelectCryptoPaymentMethod)({
|
|
340
|
+
paymentType: activeTab,
|
|
341
|
+
selectedCryptoPaymentMethod,
|
|
342
|
+
setSelectedCryptoPaymentMethod,
|
|
343
|
+
hasEnoughBalance,
|
|
344
|
+
isBalanceLoading,
|
|
345
|
+
});
|
|
321
346
|
// Get geo-based onramp options for fiat payments
|
|
322
347
|
const { geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support } = (0, react_1.useGeoOnrampOptions)(srcAmountOnRamp);
|
|
323
348
|
// Helper function to map payment method to onramp vendor
|
|
@@ -481,17 +506,30 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
481
506
|
return { text: "Select a different token or chain", disable: true, error: false, loading: false };
|
|
482
507
|
if (isLoadingAnyspendQuote)
|
|
483
508
|
return { text: "Loading quote...", disable: true, error: false, loading: true };
|
|
484
|
-
if (!recipientAddress)
|
|
485
|
-
return { text: "Select recipient", disable: false, error: false, loading: false };
|
|
486
509
|
if (isCreatingOrder || isCreatingOnrampOrder)
|
|
487
510
|
return { text: "Creating order...", disable: true, error: false, loading: true };
|
|
488
511
|
if (!anyspendQuote || !anyspendQuote.success)
|
|
489
512
|
return { text: "No quote found", disable: true, error: false, loading: false };
|
|
513
|
+
if (activeTab === "fiat") {
|
|
514
|
+
// For fiat: check recipient first, then payment method
|
|
515
|
+
if (!recipientAddress)
|
|
516
|
+
return { text: "Select recipient", disable: false, error: false, loading: false };
|
|
517
|
+
// If no fiat payment method selected, show "Select payment method"
|
|
518
|
+
if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.NONE) {
|
|
519
|
+
return { text: "Select payment method", disable: false, error: false, loading: false };
|
|
520
|
+
}
|
|
521
|
+
// If payment method is selected, show "Buy"
|
|
522
|
+
return { text: "Buy", disable: false, error: false, loading: false };
|
|
523
|
+
}
|
|
490
524
|
if (activeTab === "crypto") {
|
|
525
|
+
// For crypto: check payment method first, then recipient
|
|
491
526
|
// If no payment method selected, show "Choose payment method"
|
|
492
527
|
if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
493
528
|
return { text: "Choose payment method", disable: false, error: false, loading: false };
|
|
494
529
|
}
|
|
530
|
+
// Check recipient after payment method
|
|
531
|
+
if (!recipientAddress)
|
|
532
|
+
return { text: "Select recipient", disable: false, error: false, loading: false };
|
|
495
533
|
// If payment method selected, show appropriate action
|
|
496
534
|
if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET ||
|
|
497
535
|
selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.GLOBAL_WALLET) {
|
|
@@ -501,14 +539,6 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
501
539
|
return { text: "Continue to payment", disable: false, error: false, loading: false };
|
|
502
540
|
}
|
|
503
541
|
}
|
|
504
|
-
if (activeTab === "fiat") {
|
|
505
|
-
// If no fiat payment method selected, show "Select payment method"
|
|
506
|
-
if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.NONE) {
|
|
507
|
-
return { text: "Select payment method", disable: false, error: false, loading: false };
|
|
508
|
-
}
|
|
509
|
-
// If payment method is selected, show "Buy"
|
|
510
|
-
return { text: "Buy", disable: false, error: false, loading: false };
|
|
511
|
-
}
|
|
512
542
|
return { text: "Buy", disable: false, error: false, loading: false };
|
|
513
543
|
}, [
|
|
514
544
|
activeInputAmountInWei,
|
|
@@ -526,14 +556,15 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
526
556
|
const onMainButtonClick = async () => {
|
|
527
557
|
if (btnInfo.disable)
|
|
528
558
|
return;
|
|
529
|
-
if (!recipientAddress) {
|
|
530
|
-
navigateToPanel(PanelView.RECIPIENT_SELECTION, "forward");
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
559
|
try {
|
|
534
560
|
(0, invariant_1.default)(anyspendQuote, "Relay price is not found");
|
|
535
|
-
(0, invariant_1.default)(recipientAddress, "Recipient address is not found");
|
|
536
561
|
if (activeTab === "fiat") {
|
|
562
|
+
// For fiat: check recipient first
|
|
563
|
+
if (!recipientAddress) {
|
|
564
|
+
navigateToPanel(PanelView.RECIPIENT_SELECTION, "forward");
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
(0, invariant_1.default)(recipientAddress, "Recipient address is not found");
|
|
537
568
|
// If no fiat payment method selected, show payment method selection
|
|
538
569
|
if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.NONE) {
|
|
539
570
|
navigateToPanel(PanelView.FIAT_PAYMENT_METHOD, "forward");
|
|
@@ -544,12 +575,19 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
544
575
|
return;
|
|
545
576
|
}
|
|
546
577
|
if (activeTab === "crypto") {
|
|
578
|
+
// For crypto: check payment method first, then recipient
|
|
547
579
|
// If no payment method selected, show payment method selection
|
|
548
580
|
if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
549
581
|
console.log("No payment method selected, showing selection panel");
|
|
550
582
|
navigateToPanel(PanelView.CRYPTO_PAYMENT_METHOD, "forward");
|
|
551
583
|
return;
|
|
552
584
|
}
|
|
585
|
+
// Check recipient after payment method
|
|
586
|
+
if (!recipientAddress) {
|
|
587
|
+
navigateToPanel(PanelView.RECIPIENT_SELECTION, "forward");
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
(0, invariant_1.default)(recipientAddress, "Recipient address is not found");
|
|
553
591
|
// If payment method is selected, create order with payment method info
|
|
554
592
|
if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET ||
|
|
555
593
|
selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.GLOBAL_WALLET ||
|
|
@@ -762,10 +800,10 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
762
800
|
const tempDstAmount = dstAmount;
|
|
763
801
|
setSrcAmount(tempDstAmount);
|
|
764
802
|
setDstAmount(tempSrcAmount);
|
|
765
|
-
}, 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" }) }) }), activeTab === "crypto" && ((0, jsx_runtime_1.jsx)(CryptoReceiveSection_1.CryptoReceiveSection, { isDepositMode: false, isBuyMode: isBuyMode, selectedRecipientAddress: recipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => navigateToPanel(PanelView.RECIPIENT_SELECTION, "forward"), dstAmount: dstAmount, dstToken: selectedDstToken, selectedDstChainId: selectedDstChainId, setSelectedDstChainId: setSelectedDstChainId, setSelectedDstToken: setSelectedDstToken, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
|
|
803
|
+
}, 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" }) }) }), activeTab === "crypto" && ((0, jsx_runtime_1.jsx)(CryptoReceiveSection_1.CryptoReceiveSection, { isDepositMode: false, isBuyMode: isBuyMode, selectedRecipientAddress: recipientAddress, recipientName: recipientName || undefined, onSelectRecipient: () => navigateToPanel(PanelView.RECIPIENT_SELECTION, "forward"), setRecipientAddress: setRecipientAddress, recipientAddressFromProps: recipientAddressFromProps, globalAddress: globalAddress, dstAmount: dstAmount, dstToken: selectedDstToken, selectedDstChainId: selectedDstChainId, setSelectedDstChainId: setSelectedDstChainId, setSelectedDstToken: setSelectedDstToken, isSrcInputDirty: isSrcInputDirty, onChangeDstAmount: value => {
|
|
766
804
|
setIsSrcInputDirty(false);
|
|
767
805
|
setDstAmount(value);
|
|
768
|
-
}, anyspendQuote: anyspendQuote, onShowPointsDetail: () => navigateToPanel(PanelView.POINTS_DETAIL, "forward"), onShowFeeDetail: () => navigateToPanel(PanelView.FEE_DETAIL, "forward") }))] }), (0, jsx_runtime_1.jsxs)(react_3.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_2.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] }) }), !hideTransactionHistoryButton && (globalAddress || recipientAddress) ? ((0, jsx_runtime_1.jsxs)(react_2.Button, { variant: "link", onClick: onClickHistory, className: "text-as-primary/50 hover:text-as-primary flex items-center gap-1 transition-colors", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.HistoryIcon, { className: "h-4 w-4" }), " ", (0, jsx_runtime_1.jsx)("span", { className: "pr-4", children: "Transaction History" })] })) : null] })] }));
|
|
806
|
+
}, anyspendQuote: anyspendQuote, onShowPointsDetail: () => navigateToPanel(PanelView.POINTS_DETAIL, "forward"), onShowFeeDetail: () => navigateToPanel(PanelView.FEE_DETAIL, "forward"), selectedCryptoPaymentMethod: selectedCryptoPaymentMethod }))] }), (0, jsx_runtime_1.jsxs)(react_3.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_2.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] }) }), !hideTransactionHistoryButton && (globalAddress || recipientAddress) ? ((0, jsx_runtime_1.jsxs)(react_2.Button, { variant: "link", onClick: onClickHistory, className: "text-as-primary/50 hover:text-as-primary flex items-center gap-1 transition-colors", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.HistoryIcon, { className: "h-4 w-4" }), " ", (0, jsx_runtime_1.jsx)("span", { className: "pr-4", children: "Transaction History" })] })) : null] })] }));
|
|
769
807
|
const onrampPaymentView = ((0, jsx_runtime_1.jsx)(PanelOnrampPayment_1.PanelOnrampPayment, { srcAmountOnRamp: srcAmountOnRamp, recipientName: recipientName || undefined, recipientAddress: recipientAddress, isBuyMode: isBuyMode, destinationTokenChainId: destinationTokenChainId, destinationTokenAddress: destinationTokenAddress, selectedDstChainId: selectedDstChainId, selectedDstToken: selectedDstToken, orderType: "swap", anyspendQuote: anyspendQuote, globalAddress: globalAddress, onOrderCreated: orderId => {
|
|
770
808
|
setOrderId(orderId);
|
|
771
809
|
navigateToPanel(PanelView.ORDER_DETAILS, "forward");
|
|
@@ -53,6 +53,7 @@ const react_4 = __importStar(require("react"));
|
|
|
53
53
|
const sonner_1 = require("sonner");
|
|
54
54
|
const chains_1 = require("viem/chains");
|
|
55
55
|
const FeatureFlagsContext_1 = require("../contexts/FeatureFlagsContext");
|
|
56
|
+
const useAutoSetActiveWalletFromWagmi_1 = require("../hooks/useAutoSetActiveWalletFromWagmi");
|
|
56
57
|
const AnySpendFingerprintWrapper_1 = require("./AnySpendFingerprintWrapper");
|
|
57
58
|
const CryptoPaymentMethod_1 = require("./common/CryptoPaymentMethod");
|
|
58
59
|
const FeeBreakDown_1 = require("./common/FeeBreakDown");
|
|
@@ -149,6 +150,8 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
149
150
|
const featureFlags = (0, FeatureFlagsContext_1.useFeatureFlags)();
|
|
150
151
|
const searchParams = (0, react_2.useSearchParamsSSR)();
|
|
151
152
|
const router = (0, react_2.useRouter)();
|
|
153
|
+
// Auto-set active wallet from wagmi
|
|
154
|
+
(0, useAutoSetActiveWalletFromWagmi_1.useAutoSetActiveWalletFromWagmi)();
|
|
152
155
|
const [activePanel, setActivePanel] = (0, react_4.useState)(loadOrder ? PanelView.ORDER_DETAILS : PanelView.CONFIRM_ORDER);
|
|
153
156
|
const [activeTab, setActiveTab] = (0, react_4.useState)(activeTabProps);
|
|
154
157
|
// Add state for selected payment methods
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { components } from "../../../anyspend/types/api";
|
|
2
|
+
import { GetQuoteResponse } from "../../../anyspend/types/api_req_res";
|
|
3
|
+
type CustomExactInConfig = {
|
|
4
|
+
functionAbi: string;
|
|
5
|
+
functionName: string;
|
|
6
|
+
functionArgs: string[];
|
|
7
|
+
to: string;
|
|
8
|
+
spenderAddress?: string;
|
|
9
|
+
action?: string;
|
|
10
|
+
};
|
|
11
|
+
export interface AnySpendCustomExactInProps {
|
|
12
|
+
loadOrder?: string;
|
|
13
|
+
mode?: "modal" | "page";
|
|
14
|
+
recipientAddress: string;
|
|
15
|
+
paymentType?: "crypto" | "fiat";
|
|
16
|
+
sourceTokenAddress?: string;
|
|
17
|
+
sourceTokenChainId?: number;
|
|
18
|
+
destinationToken: components["schemas"]["Token"];
|
|
19
|
+
destinationChainId: number;
|
|
20
|
+
onSuccess?: (amount: string) => void;
|
|
21
|
+
mainFooter?: React.ReactNode;
|
|
22
|
+
onTokenSelect?: (token: components["schemas"]["Token"], event: {
|
|
23
|
+
preventDefault: () => void;
|
|
24
|
+
}) => void;
|
|
25
|
+
customUsdInputValues?: string[];
|
|
26
|
+
preferEoa?: boolean;
|
|
27
|
+
customExactInConfig: CustomExactInConfig;
|
|
28
|
+
header?: ({ anyspendPrice, isLoadingAnyspendPrice, }: {
|
|
29
|
+
anyspendPrice: GetQuoteResponse | undefined;
|
|
30
|
+
isLoadingAnyspendPrice: boolean;
|
|
31
|
+
}) => React.JSX.Element;
|
|
32
|
+
}
|
|
33
|
+
export declare function AnySpendCustomExactIn(props: AnySpendCustomExactInProps): import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AnySpendCustomExactIn = AnySpendCustomExactIn;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const utils_1 = require("../../../anyspend/utils");
|
|
9
|
+
const react_1 = require("../../../global-account/react");
|
|
10
|
+
const cn_1 = require("../../../shared/utils/cn");
|
|
11
|
+
const invariant_1 = __importDefault(require("invariant"));
|
|
12
|
+
const lucide_react_1 = require("lucide-react");
|
|
13
|
+
const react_2 = require("motion/react");
|
|
14
|
+
const react_3 = require("react");
|
|
15
|
+
const sonner_1 = require("sonner");
|
|
16
|
+
const react_4 = require("thirdweb/react");
|
|
17
|
+
const utils_2 = require("../../utils");
|
|
18
|
+
const useAnyspendFlow_1 = require("../hooks/useAnyspendFlow");
|
|
19
|
+
const AnySpendFingerprintWrapper_1 = require("./AnySpendFingerprintWrapper");
|
|
20
|
+
const CryptoPaySection_1 = require("./common/CryptoPaySection");
|
|
21
|
+
const CryptoPaymentMethod_1 = require("./common/CryptoPaymentMethod");
|
|
22
|
+
const CryptoReceiveSection_1 = require("./common/CryptoReceiveSection");
|
|
23
|
+
const FeeDetailPanel_1 = require("./common/FeeDetailPanel");
|
|
24
|
+
const FiatPaymentMethod_1 = require("./common/FiatPaymentMethod");
|
|
25
|
+
const OrderDetails_1 = require("./common/OrderDetails");
|
|
26
|
+
const PanelOnramp_1 = require("./common/PanelOnramp");
|
|
27
|
+
const PointsDetailPanel_1 = require("./common/PointsDetailPanel");
|
|
28
|
+
const RecipientSelection_1 = require("./common/RecipientSelection");
|
|
29
|
+
const SLIPPAGE_PERCENT = 3;
|
|
30
|
+
function AnySpendCustomExactIn(props) {
|
|
31
|
+
const fingerprintConfig = (0, AnySpendFingerprintWrapper_1.getFingerprintConfig)();
|
|
32
|
+
return ((0, jsx_runtime_1.jsx)(AnySpendFingerprintWrapper_1.AnySpendFingerprintWrapper, { fingerprint: fingerprintConfig, children: (0, jsx_runtime_1.jsx)(AnySpendCustomExactInInner, { ...props }) }));
|
|
33
|
+
}
|
|
34
|
+
function AnySpendCustomExactInInner({ loadOrder, mode = "modal", recipientAddress, paymentType = "crypto", sourceTokenAddress, sourceTokenChainId, destinationToken, destinationChainId, onSuccess, mainFooter, onTokenSelect, customUsdInputValues, preferEoa, customExactInConfig, header, }) {
|
|
35
|
+
const actionLabel = customExactInConfig.action ?? "Custom Execution";
|
|
36
|
+
const DESTINATION_TOKEN_DETAILS = {
|
|
37
|
+
SYMBOL: destinationToken.symbol ?? "TOKEN",
|
|
38
|
+
LOGO_URI: destinationToken.metadata?.logoURI ?? "",
|
|
39
|
+
};
|
|
40
|
+
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, } = (0, useAnyspendFlow_1.useAnyspendFlow)({
|
|
41
|
+
paymentType,
|
|
42
|
+
recipientAddress,
|
|
43
|
+
loadOrder,
|
|
44
|
+
isDepositMode: true,
|
|
45
|
+
onTransactionSuccess: onSuccess,
|
|
46
|
+
sourceTokenAddress,
|
|
47
|
+
sourceTokenChainId,
|
|
48
|
+
destinationTokenAddress: destinationToken.address,
|
|
49
|
+
destinationTokenChainId: destinationChainId,
|
|
50
|
+
slippage: SLIPPAGE_PERCENT,
|
|
51
|
+
disableUrlParamManagement: true,
|
|
52
|
+
orderType: "custom_exact_in",
|
|
53
|
+
});
|
|
54
|
+
const { connectedEOAWallet } = (0, react_1.useAccountWallet)();
|
|
55
|
+
const setActiveWallet = (0, react_4.useSetActiveWallet)();
|
|
56
|
+
const activeWallet = (0, react_4.useActiveWallet)();
|
|
57
|
+
const setGlobalAccountWallet = (0, utils_2.useGlobalWalletState)(state => state.setGlobalAccountWallet);
|
|
58
|
+
const appliedPreferEoa = (0, react_3.useRef)(false);
|
|
59
|
+
(0, react_3.useEffect)(() => {
|
|
60
|
+
if (preferEoa && !appliedPreferEoa.current) {
|
|
61
|
+
if (connectedEOAWallet) {
|
|
62
|
+
appliedPreferEoa.current = true;
|
|
63
|
+
setGlobalAccountWallet(activeWallet);
|
|
64
|
+
setActiveWallet(connectedEOAWallet);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, [preferEoa, connectedEOAWallet, setActiveWallet, activeWallet, setGlobalAccountWallet]);
|
|
68
|
+
const selectedRecipientOrDefault = selectedRecipientAddress ?? recipientAddress;
|
|
69
|
+
const expectedDstAmountRaw = anyspendQuote?.data?.currencyOut?.amount ?? "0";
|
|
70
|
+
const buildCustomPayload = (_recipient) => {
|
|
71
|
+
return {
|
|
72
|
+
amount: expectedDstAmountRaw,
|
|
73
|
+
expectedDstAmount: expectedDstAmountRaw,
|
|
74
|
+
functionAbi: customExactInConfig.functionAbi,
|
|
75
|
+
functionName: customExactInConfig.functionName,
|
|
76
|
+
functionArgs: customExactInConfig.functionArgs,
|
|
77
|
+
to: (0, utils_1.normalizeAddress)(customExactInConfig.to),
|
|
78
|
+
spenderAddress: customExactInConfig.spenderAddress
|
|
79
|
+
? (0, utils_1.normalizeAddress)(customExactInConfig.spenderAddress)
|
|
80
|
+
: undefined,
|
|
81
|
+
action: customExactInConfig.action,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
const btnInfo = (0, react_3.useMemo)(() => {
|
|
85
|
+
if (activeInputAmountInWei === "0")
|
|
86
|
+
return { text: "Enter an amount", disable: true, error: false, loading: false };
|
|
87
|
+
if (isLoadingAnyspendQuote)
|
|
88
|
+
return { text: "Loading quote...", disable: true, error: false, loading: true };
|
|
89
|
+
if (isCreatingOrder || isCreatingOnrampOrder)
|
|
90
|
+
return { text: "Creating order...", disable: true, error: false, loading: true };
|
|
91
|
+
if (!selectedRecipientOrDefault)
|
|
92
|
+
return { text: "Select recipient", disable: false, error: false, loading: false };
|
|
93
|
+
if (!anyspendQuote || !anyspendQuote.success)
|
|
94
|
+
return { text: "Get quote error", disable: true, error: true, loading: false };
|
|
95
|
+
if (paymentType === "crypto") {
|
|
96
|
+
if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
97
|
+
return { text: "Choose payment method", disable: false, error: false, loading: false };
|
|
98
|
+
}
|
|
99
|
+
if (!hasEnoughBalance &&
|
|
100
|
+
!isBalanceLoading &&
|
|
101
|
+
selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET) {
|
|
102
|
+
return { text: "Insufficient balance", disable: true, error: true, loading: false };
|
|
103
|
+
}
|
|
104
|
+
return { text: `Execute ${actionLabel}`, disable: false, error: false, loading: false };
|
|
105
|
+
}
|
|
106
|
+
if (paymentType === "fiat") {
|
|
107
|
+
if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.NONE) {
|
|
108
|
+
return { text: "Select payment method", disable: false, error: false, loading: false };
|
|
109
|
+
}
|
|
110
|
+
return { text: "Buy", disable: false, error: false, loading: false };
|
|
111
|
+
}
|
|
112
|
+
return { text: "Continue", disable: false, error: false, loading: false };
|
|
113
|
+
}, [
|
|
114
|
+
activeInputAmountInWei,
|
|
115
|
+
isLoadingAnyspendQuote,
|
|
116
|
+
isCreatingOrder,
|
|
117
|
+
isCreatingOnrampOrder,
|
|
118
|
+
selectedRecipientOrDefault,
|
|
119
|
+
anyspendQuote,
|
|
120
|
+
paymentType,
|
|
121
|
+
selectedCryptoPaymentMethod,
|
|
122
|
+
selectedFiatPaymentMethod,
|
|
123
|
+
hasEnoughBalance,
|
|
124
|
+
isBalanceLoading,
|
|
125
|
+
actionLabel,
|
|
126
|
+
]);
|
|
127
|
+
const onMainButtonClick = async () => {
|
|
128
|
+
if (btnInfo.disable)
|
|
129
|
+
return;
|
|
130
|
+
if (!selectedRecipientOrDefault) {
|
|
131
|
+
setActivePanel(useAnyspendFlow_1.PanelView.RECIPIENT_SELECTION);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (paymentType === "crypto") {
|
|
135
|
+
if (selectedCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE) {
|
|
136
|
+
setActivePanel(useAnyspendFlow_1.PanelView.CRYPTO_PAYMENT_METHOD);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
await handleCryptoOrder();
|
|
140
|
+
}
|
|
141
|
+
else if (paymentType === "fiat") {
|
|
142
|
+
if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.NONE) {
|
|
143
|
+
setActivePanel(useAnyspendFlow_1.PanelView.FIAT_PAYMENT_METHOD);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
await handleFiatOrder();
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const headerContent = header ? (header({ anyspendPrice: anyspendQuote, isLoadingAnyspendPrice: isLoadingAnyspendQuote })) : ((0, jsx_runtime_1.jsx)("div", { className: "mb-4 flex flex-col items-center gap-3 text-center", children: (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("h1", { className: "text-as-primary text-xl font-bold", children: actionLabel }), (0, jsx_runtime_1.jsx)("p", { className: "text-as-secondary text-sm", children: "Pay from any token to execute a custom exact-in transaction." })] }) }));
|
|
150
|
+
const mainView = ((0, jsx_runtime_1.jsxs)("div", { className: "mx-auto flex w-[460px] max-w-full flex-col items-center gap-2", children: [headerContent, (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: selectedRecipientOrDefault, destinationToken: selectedDstToken, destinationChainId: selectedDstChainId, dstTokenSymbol: DESTINATION_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: selectedRecipientOrDefault, recipientName: recipientName || undefined, onSelectRecipient: () => setActivePanel(useAnyspendFlow_1.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 => {
|
|
151
|
+
setIsSrcInputDirty(false);
|
|
152
|
+
setSrcAmount(value);
|
|
153
|
+
}, 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] }));
|
|
154
|
+
const handleCryptoOrder = async () => {
|
|
155
|
+
try {
|
|
156
|
+
(0, invariant_1.default)(anyspendQuote, "Relay price is not found");
|
|
157
|
+
(0, invariant_1.default)(selectedRecipientOrDefault, "Recipient address is not found");
|
|
158
|
+
const srcAmountBigInt = BigInt(activeInputAmountInWei);
|
|
159
|
+
const payload = buildCustomPayload(selectedRecipientOrDefault);
|
|
160
|
+
createOrder({
|
|
161
|
+
recipientAddress: selectedRecipientOrDefault,
|
|
162
|
+
orderType: "custom_exact_in",
|
|
163
|
+
srcChain: selectedSrcChainId,
|
|
164
|
+
dstChain: selectedDstChainId,
|
|
165
|
+
srcToken: selectedSrcToken,
|
|
166
|
+
dstToken: selectedDstToken,
|
|
167
|
+
srcAmount: srcAmountBigInt.toString(),
|
|
168
|
+
expectedDstAmount: expectedDstAmountRaw,
|
|
169
|
+
creatorAddress: globalAddress,
|
|
170
|
+
payload,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
console.error(err);
|
|
175
|
+
sonner_1.toast.error("Failed to create order: " + err.message);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const handleFiatOrder = async () => {
|
|
179
|
+
try {
|
|
180
|
+
(0, invariant_1.default)(anyspendQuote, "Relay price is not found");
|
|
181
|
+
(0, invariant_1.default)(selectedRecipientOrDefault, "Recipient address is not found");
|
|
182
|
+
if (!srcAmount || parseFloat(srcAmount) <= 0) {
|
|
183
|
+
sonner_1.toast.error("Please enter a valid amount");
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
let vendor;
|
|
187
|
+
let paymentMethodString = "";
|
|
188
|
+
if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.COINBASE_PAY) {
|
|
189
|
+
if (coinbaseAvailablePaymentMethods.length === 0) {
|
|
190
|
+
sonner_1.toast.error("Coinbase Pay not available");
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
vendor = "coinbase";
|
|
194
|
+
paymentMethodString = coinbaseAvailablePaymentMethods[0]?.id || "";
|
|
195
|
+
}
|
|
196
|
+
else if (selectedFiatPaymentMethod === FiatPaymentMethod_1.FiatPaymentMethod.STRIPE) {
|
|
197
|
+
if (!stripeWeb2Support || !stripeWeb2Support.isSupport) {
|
|
198
|
+
sonner_1.toast.error("Stripe not available");
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
vendor = "stripe-web2";
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
sonner_1.toast.error("Please select a payment method");
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const payload = buildCustomPayload(selectedRecipientOrDefault);
|
|
208
|
+
createOnrampOrder({
|
|
209
|
+
recipientAddress: selectedRecipientOrDefault,
|
|
210
|
+
orderType: "custom_exact_in",
|
|
211
|
+
dstChain: selectedDstChainId,
|
|
212
|
+
dstToken: selectedDstToken,
|
|
213
|
+
srcFiatAmount: srcAmount,
|
|
214
|
+
onramp: {
|
|
215
|
+
vendor,
|
|
216
|
+
paymentMethod: paymentMethodString,
|
|
217
|
+
country: geoData?.country || "US",
|
|
218
|
+
redirectUrl: window.location.origin,
|
|
219
|
+
},
|
|
220
|
+
expectedDstAmount: expectedDstAmountRaw,
|
|
221
|
+
creatorAddress: globalAddress,
|
|
222
|
+
payload,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
console.error(err);
|
|
227
|
+
sonner_1.toast.error("Failed to create order: " + err.message);
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
const orderDetailsView = ((0, jsx_runtime_1.jsx)("div", { className: "mx-auto w-[460px] max-w-full", children: (0, jsx_runtime_1.jsx)("div", { className: "relative flex flex-col gap-4", children: oat && ((0, jsx_runtime_1.jsx)(OrderDetails_1.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" ? CryptoPaymentMethod_1.CryptoPaymentMethodType.NONE : selectedCryptoPaymentMethod, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onPaymentMethodChange: setSelectedCryptoPaymentMethod, onBack: () => {
|
|
231
|
+
setOrderId(undefined);
|
|
232
|
+
setActivePanel(useAnyspendFlow_1.PanelView.MAIN);
|
|
233
|
+
}, disableUrlParamManagement: true, points: oat.data.points || undefined })) }) }));
|
|
234
|
+
const loadingView = ((0, jsx_runtime_1.jsx)("div", { className: "mx-auto flex w-full flex-col items-center gap-4 p-5", children: (0, jsx_runtime_1.jsx)("div", { className: "text-as-primary", children: "Loading order details..." }) }));
|
|
235
|
+
const recipientSelectionView = ((0, jsx_runtime_1.jsx)(RecipientSelection_1.RecipientSelection, { initialValue: selectedRecipientOrDefault || "", onBack: () => setActivePanel(useAnyspendFlow_1.PanelView.MAIN), onConfirm: address => {
|
|
236
|
+
setSelectedRecipientAddress(address);
|
|
237
|
+
setActivePanel(useAnyspendFlow_1.PanelView.MAIN);
|
|
238
|
+
} }));
|
|
239
|
+
const cryptoPaymentMethodView = ((0, jsx_runtime_1.jsx)(CryptoPaymentMethod_1.CryptoPaymentMethod, { globalAddress: globalAddress, globalWallet: undefined, selectedPaymentMethod: selectedCryptoPaymentMethod, setSelectedPaymentMethod: setSelectedCryptoPaymentMethod, isCreatingOrder: isCreatingOrder, onBack: () => setActivePanel(useAnyspendFlow_1.PanelView.MAIN), onSelectPaymentMethod: (method) => {
|
|
240
|
+
setSelectedCryptoPaymentMethod(method);
|
|
241
|
+
setActivePanel(useAnyspendFlow_1.PanelView.MAIN);
|
|
242
|
+
} }));
|
|
243
|
+
const fiatPaymentMethodView = ((0, jsx_runtime_1.jsx)(FiatPaymentMethod_1.FiatPaymentMethodComponent, { selectedPaymentMethod: selectedFiatPaymentMethod, setSelectedPaymentMethod: setSelectedFiatPaymentMethod, onBack: () => setActivePanel(useAnyspendFlow_1.PanelView.MAIN), onSelectPaymentMethod: (method) => {
|
|
244
|
+
setSelectedFiatPaymentMethod(method);
|
|
245
|
+
setActivePanel(useAnyspendFlow_1.PanelView.MAIN);
|
|
246
|
+
}, srcAmountOnRamp: srcAmount }));
|
|
247
|
+
const pointsDetailView = ((0, jsx_runtime_1.jsx)(PointsDetailPanel_1.PointsDetailPanel, { pointsAmount: anyspendQuote?.data?.pointsAmount || 0, onBack: () => setActivePanel(useAnyspendFlow_1.PanelView.MAIN) }));
|
|
248
|
+
const feeDetailView = anyspendQuote?.data?.fee ? ((0, jsx_runtime_1.jsx)(FeeDetailPanel_1.FeeDetailPanel, { fee: anyspendQuote.data.fee, transactionAmountUsd: paymentType === "fiat"
|
|
249
|
+
? parseFloat(srcAmount)
|
|
250
|
+
: anyspendQuote.data.currencyIn?.amountUsd
|
|
251
|
+
? Number(anyspendQuote.data.currencyIn.amountUsd)
|
|
252
|
+
: undefined, onBack: () => setActivePanel(useAnyspendFlow_1.PanelView.MAIN) })) : null;
|
|
253
|
+
return ((0, jsx_runtime_1.jsx)(react_1.StyleRoot, { children: (0, jsx_runtime_1.jsx)("div", { className: (0, cn_1.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: (0, jsx_runtime_1.jsx)(react_1.TransitionPanel, { activeIndex: orderId
|
|
254
|
+
? oat
|
|
255
|
+
? useAnyspendFlow_1.PanelView.ORDER_DETAILS
|
|
256
|
+
: useAnyspendFlow_1.PanelView.LOADING
|
|
257
|
+
: activePanel === useAnyspendFlow_1.PanelView.ORDER_DETAILS
|
|
258
|
+
? useAnyspendFlow_1.PanelView.MAIN
|
|
259
|
+
: activePanel, className: (0, cn_1.cn)("rounded-2xl", {
|
|
260
|
+
"mt-0": mode === "modal",
|
|
261
|
+
}), variants: {
|
|
262
|
+
enter: { x: 300, opacity: 0 },
|
|
263
|
+
center: { x: 0, opacity: 1 },
|
|
264
|
+
exit: { x: -300, opacity: 0 },
|
|
265
|
+
}, transition: { type: "spring", stiffness: 300, damping: 30 }, children: [
|
|
266
|
+
(0, jsx_runtime_1.jsx)("div", { children: mainView }, "main-view"),
|
|
267
|
+
(0, jsx_runtime_1.jsx)("div", { children: cryptoPaymentMethodView }, "crypto-payment-method-view"),
|
|
268
|
+
(0, jsx_runtime_1.jsx)("div", { children: fiatPaymentMethodView }, "fiat-payment-method-view"),
|
|
269
|
+
(0, jsx_runtime_1.jsx)("div", { children: recipientSelectionView }, "recipient-selection-view"),
|
|
270
|
+
(0, jsx_runtime_1.jsx)("div", { children: orderDetailsView }, "order-details-view"),
|
|
271
|
+
(0, jsx_runtime_1.jsx)("div", { children: loadingView }, "loading-view"),
|
|
272
|
+
(0, jsx_runtime_1.jsx)("div", { children: pointsDetailView }, "points-detail-view"),
|
|
273
|
+
(0, jsx_runtime_1.jsx)("div", { children: feeDetailView }, "fee-detail-view"),
|
|
274
|
+
] }) }) }));
|
|
275
|
+
}
|
|
@@ -38,13 +38,14 @@ function generateEncodedDataForStakingB3(amount, beneficiary) {
|
|
|
38
38
|
function AnySpendStakeB3({ loadOrder, mode = "modal", recipientAddress, stakeAmount, onSuccess, }) {
|
|
39
39
|
const hasMounted = (0, react_1.useHasMounted)();
|
|
40
40
|
const { setB3ModalOpen } = (0, react_1.useModalStore)();
|
|
41
|
-
// Fetch B3 token balance
|
|
42
|
-
const { formattedBalance: b3Balance, isLoading: isBalanceLoading, rawBalance: b3RawBalance, } = (0, react_1.useTokenBalance)({
|
|
43
|
-
token: anyspend_1.B3_TOKEN,
|
|
44
|
-
});
|
|
45
41
|
// Wagmi hooks for direct staking
|
|
46
42
|
const { address } = (0, wagmi_1.useAccount)();
|
|
47
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);
|
|
48
49
|
// State for direct staking flow
|
|
49
50
|
const [isStaking, setIsStaking] = (0, react_3.useState)(false);
|
|
50
51
|
const [stakingTxHash, setStakingTxHash] = (0, react_3.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;
|