@b3dotfun/sdk 0.0.63-test.0 → 0.0.63

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.
Files changed (66) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
  2. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +275 -0
  3. package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
  4. package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.js +288 -0
  5. package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
  6. package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.js +33 -0
  7. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +10 -2
  8. package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -3
  9. package/dist/cjs/anyspend/react/components/index.d.ts +5 -1
  10. package/dist/cjs/anyspend/react/components/index.js +11 -3
  11. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
  12. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +30 -8
  13. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
  14. package/dist/cjs/anyspend/react/hooks/useAnyspendQuote.js +1 -1
  15. package/dist/cjs/anyspend/types/api.d.ts +665 -3
  16. package/dist/cjs/anyspend/utils/orderPayload.js +4 -0
  17. package/dist/cjs/global-account/react/components/B3DynamicModal.js +10 -1
  18. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
  19. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
  20. package/dist/cjs/global-account/react/hooks/useAuthentication.js +7 -2
  21. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +31 -1
  22. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
  23. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +269 -0
  24. package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
  25. package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.js +285 -0
  26. package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
  27. package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.js +30 -0
  28. package/dist/esm/anyspend/react/components/common/OrderDetails.js +10 -2
  29. package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -3
  30. package/dist/esm/anyspend/react/components/index.d.ts +5 -1
  31. package/dist/esm/anyspend/react/components/index.js +5 -1
  32. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
  33. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +30 -8
  34. package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
  35. package/dist/esm/anyspend/react/hooks/useAnyspendQuote.js +1 -1
  36. package/dist/esm/anyspend/types/api.d.ts +665 -3
  37. package/dist/esm/anyspend/utils/orderPayload.js +4 -0
  38. package/dist/esm/global-account/react/components/B3DynamicModal.js +11 -2
  39. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
  40. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
  41. package/dist/esm/global-account/react/hooks/useAuthentication.js +7 -2
  42. package/dist/esm/global-account/react/stores/useModalStore.d.ts +31 -1
  43. package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
  44. package/dist/types/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
  45. package/dist/types/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
  46. package/dist/types/anyspend/react/components/index.d.ts +5 -1
  47. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
  48. package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
  49. package/dist/types/anyspend/types/api.d.ts +665 -3
  50. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
  51. package/dist/types/global-account/react/stores/useModalStore.d.ts +31 -1
  52. package/package.json +3 -3
  53. package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +595 -0
  54. package/src/anyspend/react/components/AnySpendStakeB3ExactIn.tsx +522 -0
  55. package/src/anyspend/react/components/AnySpendStakeUpsideExactIn.tsx +73 -0
  56. package/src/anyspend/react/components/common/OrderDetails.tsx +10 -2
  57. package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +2 -3
  58. package/src/anyspend/react/components/index.ts +5 -1
  59. package/src/anyspend/react/hooks/useAnyspendFlow.ts +38 -8
  60. package/src/anyspend/react/hooks/useAnyspendQuote.ts +1 -1
  61. package/src/anyspend/types/api.ts +669 -1
  62. package/src/anyspend/utils/orderPayload.ts +5 -1
  63. package/src/global-account/react/components/B3DynamicModal.tsx +11 -1
  64. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +2 -2
  65. package/src/global-account/react/hooks/useAuthentication.ts +10 -2
  66. package/src/global-account/react/stores/useModalStore.ts +34 -0
@@ -41,6 +41,8 @@ const buildPayload = (orderType, params) => {
41
41
  };
42
42
  case "custom":
43
43
  return { ...payload };
44
+ case "custom_exact_in":
45
+ return { ...payload, expectedDstAmount };
44
46
  case "hype_duel":
45
47
  return {
46
48
  expectedDstAmount,
@@ -66,6 +68,8 @@ const buildMetadata = (orderType, params) => {
66
68
  return { ...baseMetadata, tournament };
67
69
  case "custom":
68
70
  return { ...baseMetadata, action: payload.action };
71
+ case "custom_exact_in":
72
+ return { ...baseMetadata, action: payload.action };
69
73
  case "hype_duel":
70
74
  return { ...baseMetadata };
71
75
  default:
@@ -5,11 +5,13 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("../../../anyspend/react");
6
6
  const AnyspendDepositHype_1 = require("../../../anyspend/react/components/AnyspendDepositHype");
7
7
  const AnySpendStakeUpside_1 = require("../../../anyspend/react/components/AnySpendStakeUpside");
8
+ const AnySpendStakeUpsideExactIn_1 = require("../../../anyspend/react/components/AnySpendStakeUpsideExactIn");
8
9
  const utils_1 = require("../../../anyspend/utils");
9
10
  const react_2 = require("../../../global-account/react");
10
11
  const cn_1 = require("../../../shared/utils/cn");
11
12
  const debug_1 = require("../../../shared/utils/debug");
12
13
  const react_3 = require("react");
14
+ const react_4 = require("thirdweb/react");
13
15
  const AvatarEditor_1 = require("./AvatarEditor/AvatarEditor");
14
16
  const useB3_1 = require("./B3Provider/useB3");
15
17
  const LinkAccount_1 = require("./LinkAccount/LinkAccount");
@@ -18,7 +20,6 @@ const RequestPermissions_1 = require("./RequestPermissions/RequestPermissions");
18
20
  const SignInWithB3Flow_1 = require("./SignInWithB3/SignInWithB3Flow");
19
21
  const dialog_1 = require("./ui/dialog");
20
22
  const drawer_1 = require("./ui/drawer");
21
- const react_4 = require("thirdweb/react");
22
23
  const debug = (0, debug_1.debugB3React)("B3DynamicModal");
23
24
  function B3DynamicModal() {
24
25
  const { isOpen, setB3ModalOpen, contentType, history, navigateBack } = (0, react_2.useModalStore)();
@@ -45,7 +46,9 @@ function B3DynamicModal() {
45
46
  "anySpendJoinTournament",
46
47
  "anySpendFundTournament",
47
48
  "anySpendStakeB3",
49
+ "anySpendStakeB3ExactIn",
48
50
  "anySpendStakeUpside",
51
+ "anySpendStakeUpsideExactIn",
49
52
  "anySpendBuySpin",
50
53
  "anySpendOrderHistory",
51
54
  "signInWithB3",
@@ -59,7 +62,9 @@ function B3DynamicModal() {
59
62
  "anySpendJoinTournament",
60
63
  "anySpendFundTournament",
61
64
  "anySpendStakeB3",
65
+ "anySpendStakeB3ExactIn",
62
66
  "anySpendStakeUpside",
67
+ "anySpendStakeUpsideExactIn",
63
68
  "anySpendBuySpin",
64
69
  "anySpendSignatureMint",
65
70
  "anySpendBondKit",
@@ -95,8 +100,12 @@ function B3DynamicModal() {
95
100
  return (0, jsx_runtime_1.jsx)(react_1.OrderHistory, { onBack: () => { }, mode: "modal" });
96
101
  case "anySpendStakeB3":
97
102
  return (0, jsx_runtime_1.jsx)(react_1.AnySpendStakeB3, { ...contentType, mode: "modal" });
103
+ case "anySpendStakeB3ExactIn":
104
+ return (0, jsx_runtime_1.jsx)(react_1.AnySpendStakeB3ExactIn, { ...contentType, mode: "modal" });
98
105
  case "anySpendStakeUpside":
99
106
  return (0, jsx_runtime_1.jsx)(AnySpendStakeUpside_1.AnySpendStakeUpside, { ...contentType, mode: "modal" });
107
+ case "anySpendStakeUpsideExactIn":
108
+ return (0, jsx_runtime_1.jsx)(AnySpendStakeUpsideExactIn_1.AnySpendStakeUpsideExactIn, { ...contentType, mode: "modal" });
100
109
  case "anySpendBuySpin":
101
110
  return (0, jsx_runtime_1.jsx)(react_1.AnySpendBuySpin, { ...contentType, mode: "modal" });
102
111
  case "anySpendSignatureMint":
@@ -41,8 +41,8 @@ function LoginStep({ onSuccess, chain }) {
41
41
  }, header: {
42
42
  title: "Sign in with B3",
43
43
  titleIcon: "https://cdn.b3.fun/b3_logo.svg",
44
- }, className: "b3-login-step", onConnect: async (wallet) => {
45
- await onConnect(wallet);
44
+ }, className: "b3-login-step", onConnect: async (wallet, allConnectedWallets) => {
45
+ await onConnect(wallet, allConnectedWallets);
46
46
  const account = wallet.getAccount();
47
47
  if (!account)
48
48
  throw new Error("No account found");
@@ -8,9 +8,9 @@ export declare function useAuthentication(partnerId: string): {
8
8
  isConnected: boolean;
9
9
  wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
10
10
  preAuthenticate: typeof preAuthenticate;
11
- connect: (wallet: Wallet) => Promise<void>;
11
+ connect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
12
12
  isAuthenticating: boolean;
13
- onConnect: (wallet: Wallet) => Promise<void>;
13
+ onConnect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
14
14
  user: {
15
15
  email?: string | undefined;
16
16
  username?: string | undefined;
@@ -142,7 +142,12 @@ function useAuthentication(partnerId) {
142
142
  return userAuth;
143
143
  }
144
144
  }, [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
145
- const onConnect = (0, react_2.useCallback)(async (wallet) => {
145
+ const onConnect = (0, react_2.useCallback)(async (_walleAutoConnectedWith, allConnectedWallets) => {
146
+ debug("@@useAuthentication:onConnect", { _walleAutoConnectedWith, allConnectedWallets });
147
+ const wallet = allConnectedWallets.find(wallet => wallet.id.startsWith("ecosystem."));
148
+ if (!wallet) {
149
+ throw new Error("No smart wallet found during auto-connect");
150
+ }
146
151
  debug("@@useAuthentication:onConnect", { wallet });
147
152
  try {
148
153
  setHasStartedConnecting(true);
@@ -209,7 +214,7 @@ function useAuthentication(partnerId) {
209
214
  const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
210
215
  client: thirdweb_1.client,
211
216
  wallets: [wallet],
212
- onConnect: onConnect,
217
+ onConnect,
213
218
  });
214
219
  /**
215
220
  * useAutoConnectLoading starts as false
@@ -210,6 +210,20 @@ export interface AnySpendStakeB3Props extends BaseModalProps {
210
210
  /** Callback function called when the stake is successful */
211
211
  onSuccess?: () => void;
212
212
  }
213
+ /**
214
+ * Props for the AnySpend Stake B3 (Custom Exact In) modal
215
+ * Handles B3 token staking operations using the custom exact in flow
216
+ */
217
+ export interface AnySpendStakeB3ExactInProps extends BaseModalProps {
218
+ /** Modal type identifier */
219
+ type: "anySpendStakeB3ExactIn";
220
+ /** Recipient address to stake B3 for */
221
+ recipientAddress: string;
222
+ /** Stake amount */
223
+ stakeAmount?: string;
224
+ /** Callback function called when the stake is successful */
225
+ onSuccess?: () => void;
226
+ }
213
227
  /**
214
228
  * Props for the AnySpend Stake Contract modal
215
229
  * Handles token staking operations to a given contract
@@ -230,6 +244,22 @@ export interface AnySpendStakeUpsideProps extends BaseModalProps {
230
244
  /** Callback function called when the stake is successful */
231
245
  onSuccess?: () => void;
232
246
  }
247
+ /**
248
+ * Props for the AnySpend Stake Upside (Exact In) modal
249
+ * Handles token staking operations using the custom exact in flow
250
+ */
251
+ export interface AnySpendStakeUpsideExactInProps extends BaseModalProps {
252
+ /** Modal type identifier */
253
+ type: "anySpendStakeUpsideExactIn";
254
+ /** Recipient address to stake tokens for */
255
+ recipientAddress: string;
256
+ /** Staking contract address */
257
+ stakingContractAddress: string;
258
+ /** Token to stake */
259
+ token: components["schemas"]["Token"];
260
+ /** Callback function called when the stake is successful */
261
+ onSuccess?: () => void;
262
+ }
233
263
  /**
234
264
  * Props for the AnySpend Buy Spin modal
235
265
  * Handles spin wheel entry purchases
@@ -324,7 +354,7 @@ export interface AvatarEditorModalProps extends BaseModalProps {
324
354
  /**
325
355
  * Union type of all possible modal content types
326
356
  */
327
- export type ModalContentType = SignInWithB3ModalProps | RequestPermissionsModalProps | ManageAccountModalProps | AnySpendModalProps | AnyspendOrderDetailsProps | AnySpendNftProps | AnySpendJoinTournamentProps | AnySpendFundTournamentProps | AnySpendOrderHistoryProps | AnySpendStakeB3Props | AnySpendStakeUpsideProps | AnySpendBuySpinProps | AnySpendSignatureMintProps | AnySpendBondKitProps | LinkAccountModalProps | AnySpendDepositHypeProps | AvatarEditorModalProps;
357
+ export type ModalContentType = SignInWithB3ModalProps | RequestPermissionsModalProps | ManageAccountModalProps | AnySpendModalProps | AnyspendOrderDetailsProps | AnySpendNftProps | AnySpendJoinTournamentProps | AnySpendFundTournamentProps | AnySpendOrderHistoryProps | AnySpendStakeB3Props | AnySpendStakeB3ExactInProps | AnySpendStakeUpsideProps | AnySpendStakeUpsideExactInProps | AnySpendBuySpinProps | AnySpendSignatureMintProps | AnySpendBondKitProps | LinkAccountModalProps | AnySpendDepositHypeProps | AvatarEditorModalProps;
328
358
  /**
329
359
  * State interface for the modal store
330
360
  */
@@ -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,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
+ }
@@ -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;