@b3dotfun/sdk 0.0.5 → 0.0.6-alpha.1

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 (93) hide show
  1. package/dist/cjs/anyspend/constants/index.js +2 -2
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +2 -2
  3. package/dist/cjs/anyspend/react/components/index.d.ts +7 -5
  4. package/dist/cjs/anyspend/react/components/index.js +15 -11
  5. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampOrderStatus.d.ts +6 -0
  6. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampOrderStatus.js +37 -0
  7. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +12 -0
  8. package/dist/cjs/anyspend/react/components/webview/WebviewOnrampPayment.js +173 -0
  9. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +1 -0
  10. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +4 -3
  11. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +10 -0
  12. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +10 -0
  13. package/dist/cjs/anyspend/services/anyspend.d.ts +7 -1
  14. package/dist/cjs/anyspend/services/anyspend.js +3 -2
  15. package/dist/cjs/anyspend/types/order.d.ts +18 -0
  16. package/dist/cjs/anyspend/types/order.js +1 -0
  17. package/dist/cjs/anyspend/types/req-res/createOrder.d.ts +50 -0
  18. package/dist/cjs/anyspend/types/req-res/createOrder.js +1 -0
  19. package/dist/cjs/anyspend/types/req-res/getOrderAndTransactions.d.ts +35 -0
  20. package/dist/cjs/anyspend/types/req-res/getOrderHistory.d.ts +25 -0
  21. package/dist/cjs/global-account/react/hooks/index.d.ts +2 -1
  22. package/dist/cjs/global-account/react/hooks/index.js +3 -1
  23. package/dist/cjs/global-account/react/hooks/useB3EnsName.d.ts +9 -0
  24. package/dist/cjs/global-account/react/hooks/useB3EnsName.js +39 -0
  25. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.d.ts +5 -1
  26. package/dist/cjs/global-account/react/hooks/useTokenFromUrl.js +74 -13
  27. package/dist/cjs/shared/constants/chains/supported.d.ts +13 -3
  28. package/dist/cjs/shared/constants/chains/supported.js +15 -9
  29. package/dist/cjs/shared/generated/coingecko-chains.json +1072 -0
  30. package/dist/esm/anyspend/constants/index.js +2 -2
  31. package/dist/esm/anyspend/react/components/AnySpend.js +2 -2
  32. package/dist/esm/anyspend/react/components/index.d.ts +7 -5
  33. package/dist/esm/anyspend/react/components/index.js +7 -5
  34. package/dist/esm/anyspend/react/components/webview/WebviewOnrampOrderStatus.d.ts +6 -0
  35. package/dist/esm/anyspend/react/components/webview/WebviewOnrampOrderStatus.js +31 -0
  36. package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +12 -0
  37. package/dist/esm/anyspend/react/components/webview/WebviewOnrampPayment.js +167 -0
  38. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +1 -0
  39. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +5 -4
  40. package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +10 -0
  41. package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +10 -0
  42. package/dist/esm/anyspend/services/anyspend.d.ts +7 -1
  43. package/dist/esm/anyspend/services/anyspend.js +3 -2
  44. package/dist/esm/anyspend/types/order.d.ts +18 -0
  45. package/dist/esm/anyspend/types/order.js +1 -0
  46. package/dist/esm/anyspend/types/req-res/createOrder.d.ts +50 -0
  47. package/dist/esm/anyspend/types/req-res/createOrder.js +1 -0
  48. package/dist/esm/anyspend/types/req-res/getOrderAndTransactions.d.ts +35 -0
  49. package/dist/esm/anyspend/types/req-res/getOrderHistory.d.ts +25 -0
  50. package/dist/esm/global-account/react/hooks/index.d.ts +2 -1
  51. package/dist/esm/global-account/react/hooks/index.js +1 -0
  52. package/dist/esm/global-account/react/hooks/useB3EnsName.d.ts +9 -0
  53. package/dist/esm/global-account/react/hooks/useB3EnsName.js +32 -0
  54. package/dist/esm/global-account/react/hooks/useTokenFromUrl.d.ts +5 -1
  55. package/dist/esm/global-account/react/hooks/useTokenFromUrl.js +73 -13
  56. package/dist/esm/shared/constants/chains/supported.d.ts +13 -3
  57. package/dist/esm/shared/constants/chains/supported.js +13 -8
  58. package/dist/esm/shared/generated/coingecko-chains.json +1072 -0
  59. package/dist/styles/index.css +1 -1
  60. package/dist/types/anyspend/react/components/index.d.ts +7 -5
  61. package/dist/types/anyspend/react/components/webview/WebviewOnrampOrderStatus.d.ts +6 -0
  62. package/dist/types/anyspend/react/components/webview/WebviewOnrampPayment.d.ts +12 -0
  63. package/dist/types/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +1 -0
  64. package/dist/types/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +10 -0
  65. package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +10 -0
  66. package/dist/types/anyspend/services/anyspend.d.ts +7 -1
  67. package/dist/types/anyspend/types/order.d.ts +18 -0
  68. package/dist/types/anyspend/types/req-res/createOrder.d.ts +50 -0
  69. package/dist/types/anyspend/types/req-res/getOrderAndTransactions.d.ts +35 -0
  70. package/dist/types/anyspend/types/req-res/getOrderHistory.d.ts +25 -0
  71. package/dist/types/global-account/react/hooks/index.d.ts +2 -1
  72. package/dist/types/global-account/react/hooks/useB3EnsName.d.ts +9 -0
  73. package/dist/types/global-account/react/hooks/useTokenFromUrl.d.ts +5 -1
  74. package/dist/types/shared/constants/chains/supported.d.ts +13 -3
  75. package/package.json +3 -3
  76. package/src/anyspend/README.md +626 -0
  77. package/src/anyspend/constants/index.ts +2 -4
  78. package/src/anyspend/react/components/AnySpend.tsx +2 -2
  79. package/src/anyspend/react/components/index.ts +7 -5
  80. package/src/anyspend/react/components/webview/WebviewOnrampOrderStatus.tsx +120 -0
  81. package/src/anyspend/react/components/webview/WebviewOnrampPayment.tsx +369 -0
  82. package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +7 -4
  83. package/src/anyspend/services/anyspend.ts +5 -2
  84. package/src/anyspend/types/order.ts +1 -0
  85. package/src/anyspend/types/req-res/createOrder.ts +1 -0
  86. package/src/global-account/react/hooks/index.ts +2 -1
  87. package/src/global-account/react/hooks/useB3EnsName.ts +49 -0
  88. package/src/global-account/react/hooks/useTokenFromUrl.tsx +95 -13
  89. package/src/shared/constants/chains/supported.ts +23 -8
  90. package/src/shared/generated/coingecko-chains.json +1072 -0
  91. /package/dist/cjs/{generated → shared/generated}/chain-networks.json +0 -0
  92. /package/dist/esm/{generated → shared/generated}/chain-networks.json +0 -0
  93. /package/src/{generated → shared/generated}/chain-networks.json +0 -0
@@ -1,6 +1,6 @@
1
1
  import { base } from "viem/chains";
2
- export const ANYSPEND_MAINNET_BASE_URL = process.env.NEXT_PUBLIC_ANYSPEND_BASE_URL || "https://anyspend-mainnet.up.railway.app";
3
- export const ANYSPEND_TESTNET_BASE_URL = process.env.NEXT_PUBLIC_ANYSPEND_BASE_URL || "https://anyspend-testnet.up.railway.app";
2
+ export const ANYSPEND_MAINNET_BASE_URL = process.env.NEXT_PUBLIC_ANYSPEND_BASE_URL || "https://mainnet.anyspend.com";
3
+ export const ANYSPEND_TESTNET_BASE_URL = process.env.NEXT_PUBLIC_ANYSPEND_BASE_URL || "https://testnet.anyspend.com";
4
4
  export const RELAY_ETH_ADDRESS = "0x0000000000000000000000000000000000000000";
5
5
  export const RELAY_SOL_ADDRESS = "11111111111111111111111111111111";
6
6
  export const RELAY_SOLANA_MAINNET_CHAIN_ID = 792703809;
@@ -96,7 +96,7 @@ export function AnySpend({ destinationTokenAddress, destinationTokenChainId, isM
96
96
  name: srcTokenMetadata.name || selectedSrcToken.name,
97
97
  metadata: {
98
98
  ...selectedSrcToken.metadata,
99
- logoURI: srcTokenMetadata.logoURI || selectedSrcToken.metadata?.logoURI
99
+ logoURI: srcTokenMetadata?.logoURI || selectedSrcToken.metadata.logoURI
100
100
  }
101
101
  };
102
102
  setSelectedSrcToken(enhancedToken);
@@ -118,7 +118,7 @@ export function AnySpend({ destinationTokenAddress, destinationTokenChainId, isM
118
118
  name: dstTokenMetadata.name || selectedDstToken.name,
119
119
  metadata: {
120
120
  ...selectedDstToken.metadata,
121
- logoURI: dstTokenMetadata.logoURI || selectedDstToken.metadata?.logoURI
121
+ logoURI: dstTokenMetadata?.logoURI || selectedDstToken.metadata.logoURI
122
122
  }
123
123
  };
124
124
  setSelectedDstToken(enhancedToken);
@@ -1,14 +1,16 @@
1
1
  export { AnySpend } from "./AnySpend";
2
+ export { AnySpendBuySpin } from "./AnySpendBuySpin";
2
3
  export { AnySpendCustom } from "./AnySpendCustom";
3
4
  export { AnySpendNFT } from "./AnySpendNFT";
4
5
  export { AnySpendNFTButton } from "./AnySpendNFTButton";
5
- export { AnySpendTournament } from "./AnySpendTournament";
6
6
  export { AnySpendStakeB3 } from "./AnySpendStakeB3";
7
- export { AnySpendBuySpin } from "./AnySpendBuySpin";
8
- export { OrderHistoryItem } from "./common/OrderHistoryItem";
9
- export { OrderHistory } from "./common/OrderHistory";
7
+ export { AnySpendTournament } from "./AnySpendTournament";
10
8
  export { OrderDetails } from "./common/OrderDetails";
9
+ export { OrderHistory } from "./common/OrderHistory";
10
+ export { OrderHistoryItem } from "./common/OrderHistoryItem";
11
+ export { OrderStatus } from "./common/OrderStatus";
11
12
  export { OrderToken } from "./common/OrderToken";
12
13
  export { OrderTokenAmount } from "./common/OrderTokenAmount";
13
- export { OrderStatus } from "./common/OrderStatus";
14
14
  export { TokenBalance } from "./common/TokenBalance";
15
+ export { WebviewOnrampOrderStatus } from "./webview/WebviewOnrampOrderStatus";
16
+ export { WebviewOnrampPayment } from "./webview/WebviewOnrampPayment";
@@ -1,16 +1,18 @@
1
1
  // Components
2
2
  export { AnySpend } from "./AnySpend.js";
3
+ export { AnySpendBuySpin } from "./AnySpendBuySpin.js";
3
4
  export { AnySpendCustom } from "./AnySpendCustom.js";
4
5
  export { AnySpendNFT } from "./AnySpendNFT.js";
5
6
  export { AnySpendNFTButton } from "./AnySpendNFTButton.js";
6
- export { AnySpendTournament } from "./AnySpendTournament.js";
7
7
  export { AnySpendStakeB3 } from "./AnySpendStakeB3.js";
8
- export { AnySpendBuySpin } from "./AnySpendBuySpin.js";
8
+ export { AnySpendTournament } from "./AnySpendTournament.js";
9
9
  // Common Components
10
- export { OrderHistoryItem } from "./common/OrderHistoryItem.js";
11
- export { OrderHistory } from "./common/OrderHistory.js";
12
10
  export { OrderDetails } from "./common/OrderDetails.js";
11
+ export { OrderHistory } from "./common/OrderHistory.js";
12
+ export { OrderHistoryItem } from "./common/OrderHistoryItem.js";
13
+ export { OrderStatus } from "./common/OrderStatus.js";
13
14
  export { OrderToken } from "./common/OrderToken.js";
14
15
  export { OrderTokenAmount } from "./common/OrderTokenAmount.js";
15
- export { OrderStatus } from "./common/OrderStatus.js";
16
16
  export { TokenBalance } from "./common/TokenBalance.js";
17
+ export { WebviewOnrampOrderStatus } from "./webview/WebviewOnrampOrderStatus.js";
18
+ export { WebviewOnrampPayment } from "./webview/WebviewOnrampPayment.js";
@@ -0,0 +1,6 @@
1
+ import { Order } from "../../../../anyspend";
2
+ interface WebviewOnrampOrderStatusProps {
3
+ order: Order;
4
+ }
5
+ export declare function WebviewOnrampOrderStatus({ order }: WebviewOnrampOrderStatusProps): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { getChainName, OrderStatus, OrderType } from "../../../../anyspend/index.js";
3
+ import { Badge, useTokenData } from "../../../../global-account/react/index.js";
4
+ import centerTruncate from "../../../../shared/utils/centerTruncate.js";
5
+ import { CheckIcon, Copy, ExternalLink, Loader2 } from "lucide-react";
6
+ import { toast } from "sonner";
7
+ import { formatUnits } from "viem";
8
+ export function WebviewOnrampOrderStatus({ order }) {
9
+ console.log(order.status);
10
+ const isPending = order.status === OrderStatus.WaitingStripePayment ||
11
+ order.status === OrderStatus.ScanningDepositTransaction ||
12
+ order.status === OrderStatus.SendingTokenFromVault ||
13
+ order.status === OrderStatus.ObtainToken ||
14
+ order.status === OrderStatus.Relay;
15
+ const isExecuted = order.status === OrderStatus.Executed;
16
+ const isFailed = order.status === OrderStatus.Failure;
17
+ const isRefunded = order.status === OrderStatus.Refunded;
18
+ // Get token metadata
19
+ const { data: tokenMetadata } = useTokenData(order.metadata.dstToken.chainId, order.metadata.dstToken.address);
20
+ // Only show expected amount for swap orders
21
+ const expectedAmount = order.type === OrderType.Swap
22
+ ? Number(formatUnits(BigInt(order.payload.expectedDstAmount), order.metadata.dstToken.decimals)).toFixed(2)
23
+ : null;
24
+ // Use token metadata logo if available
25
+ const tokenLogoUrl = tokenMetadata?.logoURI || order.metadata.dstToken.metadata?.logoURI;
26
+ const handleCopy = (text, label) => {
27
+ navigator.clipboard.writeText(text);
28
+ toast.success(`${label} copied to clipboard`);
29
+ };
30
+ return (_jsxs("div", { className: "mx-auto flex w-full max-w-[460px] flex-col gap-6", children: [_jsx("div", { className: "flex justify-center", children: _jsxs(Badge, { variant: "default", className: "flex items-center gap-3 px-4 py-2 text-base", children: [isPending && _jsx(Loader2, { className: "h-4 w-4 animate-spin" }), isExecuted && _jsx(CheckIcon, { className: "h-4 w-4 text-green-500" }), isFailed && _jsx(ExternalLink, { className: "h-4 w-4 text-red-500" }), _jsxs("span", { children: [isPending && "Processing Payment...", isExecuted && "Payment Complete", isFailed && "Payment Failed", isRefunded && "Payment Refunded"] })] }) }), _jsx("div", { className: "overflow-hidden rounded-xl bg-white", children: _jsxs("div", { className: "px-6 py-4", children: [_jsx("h2", { className: "mb-4 text-lg font-semibold", children: "Order Summary" }), _jsxs("div", { className: "flex flex-col divide-y", children: [_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Amount Paid" }), _jsxs("span", { className: "text-lg font-semibold", children: ["$", Number(formatUnits(BigInt(order.srcAmount), order.metadata.srcToken.decimals)).toFixed(2)] })] }), order.type === OrderType.Swap && expectedAmount && (_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Est Token Amount" }), _jsxs("div", { className: "flex items-center gap-2", children: [tokenLogoUrl && (_jsx("img", { src: tokenLogoUrl, alt: order.metadata.dstToken.symbol, className: "h-5 w-5 rounded-full" })), _jsxs("span", { className: "font-medium", children: [expectedAmount, " ", order.metadata.dstToken.symbol] })] })] })), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Network" }), _jsx("span", { className: "font-medium", children: getChainName(order.dstChain) })] }), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Recipient" }), _jsxs("button", { onClick: () => handleCopy(order.recipientAddress, "Recipient address"), className: "flex items-center gap-2 font-medium transition-colors hover:text-blue-600", children: [centerTruncate(order.recipientAddress, 8), _jsx(Copy, { className: "h-4 w-4" })] })] }), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Order ID" }), _jsxs("button", { onClick: () => handleCopy(order.id, "Order ID"), className: "flex items-center gap-2 font-medium transition-colors hover:text-blue-600", children: [centerTruncate(order.id, 8), _jsx(Copy, { className: "h-4 w-4" })] })] })] })] }) })] }));
31
+ }
@@ -0,0 +1,12 @@
1
+ import { GetQuoteResponse, Token } from "../../../../anyspend";
2
+ interface WebviewOnrampPaymentProps {
3
+ srcAmountOnRamp: string;
4
+ recipientAddress?: string;
5
+ destinationToken: Token;
6
+ partnerId?: string;
7
+ anyspendQuote: GetQuoteResponse | undefined;
8
+ onPaymentSuccess: (orderId: string) => void;
9
+ userId?: string;
10
+ }
11
+ export declare function WebviewOnrampPayment({ srcAmountOnRamp, recipientAddress, destinationToken, anyspendQuote, onPaymentSuccess, userId, partnerId }: WebviewOnrampPaymentProps): import("react/jsx-runtime").JSX.Element;
12
+ export {};
@@ -0,0 +1,167 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { getChainName, OnrampVendor, OrderType, STRIPE_CONFIG, useAnyspendCreateOnrampOrder, useGeoOnrampOptions, useStripeClientSecret } from "../../../../anyspend/index.js";
3
+ import centerTruncate from "../../../../shared/utils/centerTruncate.js";
4
+ import { Elements, PaymentElement, useElements, useStripe } from "@stripe/react-stripe-js";
5
+ import { loadStripe } from "@stripe/stripe-js";
6
+ import { motion } from "framer-motion";
7
+ import { Loader2 } from "lucide-react";
8
+ import { useEffect, useRef, useState } from "react";
9
+ import { toast } from "sonner";
10
+ import { formatUnits } from "viem";
11
+ const stripePromise = loadStripe(STRIPE_CONFIG.publishableKey);
12
+ // Stripe Payment Form Component
13
+ function StripePaymentForm({ order, onPaymentSuccess }) {
14
+ const stripe = useStripe();
15
+ const elements = useElements();
16
+ const [isProcessing, setIsProcessing] = useState(false);
17
+ const [error, setError] = useState(null);
18
+ const handleSubmit = async (e) => {
19
+ e.preventDefault();
20
+ if (!stripe || !elements) {
21
+ return;
22
+ }
23
+ setIsProcessing(true);
24
+ setError(null);
25
+ try {
26
+ const { error: submitError } = await stripe.confirmPayment({
27
+ elements,
28
+ redirect: "if_required"
29
+ });
30
+ if (submitError) {
31
+ setError(submitError.message || "An error occurred");
32
+ console.error("Payment error:", submitError);
33
+ }
34
+ else {
35
+ console.log("Payment successful");
36
+ onPaymentSuccess(order.id);
37
+ }
38
+ }
39
+ catch (err) {
40
+ setError(err.message || "An error occurred");
41
+ console.error("Payment error:", err);
42
+ }
43
+ finally {
44
+ setIsProcessing(false);
45
+ }
46
+ };
47
+ const stripeElementOptions = {
48
+ layout: "tabs",
49
+ defaultValues: {
50
+ billingDetails: {
51
+ name: "",
52
+ email: ""
53
+ }
54
+ }
55
+ };
56
+ return (_jsx("form", { onSubmit: handleSubmit, className: "w-full", children: _jsx("div", { className: "overflow-hidden rounded-xl bg-white", children: _jsxs("div", { className: "px-6 py-4", children: [_jsx("h2", { className: "mb-4 text-lg font-semibold", children: "Payment Details" }), _jsx(PaymentElement, { options: stripeElementOptions }), error && (_jsx("div", { className: "mt-4 rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-600", children: error })), _jsx("button", { type: "submit", disabled: !stripe || isProcessing, className: "mt-6 w-full rounded-xl bg-blue-600 px-4 py-3 font-medium text-white hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50", children: isProcessing ? (_jsxs("div", { className: "flex items-center justify-center gap-2", children: [_jsx(Loader2, { className: "h-5 w-5 animate-spin" }), _jsx("span", { children: "Processing..." })] })) : (_jsx("span", { children: "Complete Payment" })) })] }) }) }));
57
+ }
58
+ export function WebviewOnrampPayment({ srcAmountOnRamp, recipientAddress, destinationToken, anyspendQuote, onPaymentSuccess, userId, partnerId }) {
59
+ const [stableAmountForGeo, setStableAmountForGeo] = useState(srcAmountOnRamp);
60
+ const hasInitialized = useRef(false);
61
+ const [createdOrder, setCreatedOrder] = useState(null);
62
+ const orderCreationAttempted = useRef(false);
63
+ // Only update the stable amount on first render or when explicitly needed
64
+ useEffect(() => {
65
+ if (!hasInitialized.current && srcAmountOnRamp) {
66
+ setStableAmountForGeo(srcAmountOnRamp);
67
+ hasInitialized.current = true;
68
+ }
69
+ }, [srcAmountOnRamp]);
70
+ const { geoData, isStripeWeb2Supported, isLoading: isLoadingGeoOnramp } = useGeoOnrampOptions(true, stableAmountForGeo);
71
+ const { createOrder, isCreatingOrder } = useAnyspendCreateOnrampOrder({
72
+ onSuccess: data => {
73
+ const orderId = data.data.id;
74
+ setCreatedOrder(data.data);
75
+ },
76
+ onError: error => {
77
+ console.error(error);
78
+ toast.error("Failed to create order: " + error.message);
79
+ }
80
+ });
81
+ const { clientSecret, isLoadingStripeClientSecret } = useStripeClientSecret(true, createdOrder?.stripePaymentIntentId || "");
82
+ // Create order when component mounts and all required data is available
83
+ useEffect(() => {
84
+ const createOrderIfPossible = async () => {
85
+ if (!orderCreationAttempted.current &&
86
+ recipientAddress &&
87
+ srcAmountOnRamp &&
88
+ parseFloat(srcAmountOnRamp) > 0 &&
89
+ isStripeWeb2Supported &&
90
+ anyspendQuote &&
91
+ geoData) {
92
+ orderCreationAttempted.current = true;
93
+ try {
94
+ const getDstToken = () => {
95
+ return {
96
+ ...destinationToken,
97
+ chainId: destinationToken.chainId,
98
+ address: destinationToken.address
99
+ };
100
+ };
101
+ createOrder({
102
+ isMainnet: true,
103
+ recipientAddress,
104
+ orderType: OrderType.Swap,
105
+ dstChain: getDstToken().chainId,
106
+ dstToken: getDstToken(),
107
+ srcFiatAmount: srcAmountOnRamp,
108
+ onramp: {
109
+ vendor: OnrampVendor.StripeWeb2,
110
+ paymentMethod: "",
111
+ country: geoData.country || "US",
112
+ ipAddress: geoData.ip,
113
+ redirectUrl: `${window.location.origin}${userId ? `?userId=${userId}` : ""}`
114
+ },
115
+ expectedDstAmount: anyspendQuote.data?.currencyOut?.amount?.toString() || "0",
116
+ partnerId
117
+ });
118
+ }
119
+ catch (err) {
120
+ console.error(err);
121
+ toast.error("Failed to create order: " + err.message);
122
+ }
123
+ }
124
+ };
125
+ createOrderIfPossible();
126
+ }, [
127
+ recipientAddress,
128
+ srcAmountOnRamp,
129
+ isStripeWeb2Supported,
130
+ anyspendQuote,
131
+ geoData,
132
+ createOrder,
133
+ destinationToken,
134
+ userId,
135
+ partnerId
136
+ ]);
137
+ // Check if all required data is loaded
138
+ const isLoading = isLoadingGeoOnramp || !anyspendQuote || !destinationToken.metadata?.logoURI;
139
+ // Show loading state while data is being fetched or order is being created
140
+ if (isLoading || isCreatingOrder || isLoadingStripeClientSecret) {
141
+ return (_jsxs("div", { className: "mx-auto flex w-full max-w-[460px] flex-col items-center justify-center gap-3 py-12", children: [_jsx(Loader2, { className: "text-as-brand h-8 w-8 animate-spin" }), _jsx("span", { className: "text-as-primary/70", children: isCreatingOrder
142
+ ? "Creating payment session..."
143
+ : isLoadingStripeClientSecret
144
+ ? "Loading payment form..."
145
+ : "Loading payment details..." })] }));
146
+ }
147
+ // If we have a created order and client secret, show the payment form
148
+ if (createdOrder && clientSecret) {
149
+ return (_jsxs("div", { className: "mx-auto flex w-full max-w-[460px] flex-col gap-6", children: [_jsx("div", { className: "overflow-hidden rounded-xl bg-white", children: _jsxs("div", { className: "px-6 py-4", children: [_jsx("h2", { className: "mb-4 text-lg font-semibold", children: "Order summary" }), _jsxs("div", { className: "flex flex-col divide-y", children: [_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Receiving" }), _jsxs("div", { className: "flex items-center gap-2", children: [destinationToken.metadata?.logoURI && (_jsx("img", { src: destinationToken.metadata.logoURI, alt: destinationToken.symbol, className: "h-5 w-5 rounded-full" })), _jsxs("span", { className: "font-medium", children: [anyspendQuote?.data?.currencyOut?.amount
150
+ ? Number(formatUnits(BigInt(anyspendQuote.data.currencyOut.amount), destinationToken.decimals)).toFixed(4)
151
+ : "0", " ", destinationToken.symbol] })] })] }), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Network" }), _jsx("span", { className: "font-medium", children: getChainName(destinationToken.chainId) })] }), recipientAddress && (_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Recipient" }), _jsx("span", { className: "font-medium", children: centerTruncate(recipientAddress) })] })), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "You Pay" }), _jsxs("span", { className: "text-lg font-semibold", children: ["$", parseFloat(srcAmountOnRamp).toFixed(2)] })] })] })] }) }), _jsx(Elements, { stripe: stripePromise, options: {
152
+ clientSecret,
153
+ appearance: {
154
+ theme: "flat",
155
+ variables: {
156
+ colorPrimary: "#2563eb",
157
+ colorBackground: "#ffffff",
158
+ borderRadius: "12px"
159
+ }
160
+ }
161
+ }, children: _jsx(StripePaymentForm, { order: createdOrder, onPaymentSuccess: onPaymentSuccess }) })] }));
162
+ }
163
+ // Show initial order summary while waiting for order creation
164
+ return (_jsx(motion.div, { initial: { opacity: 0, y: 20 }, animate: { opacity: 1, y: 0 }, transition: { duration: 0.3 }, className: "mx-auto w-full max-w-[460px]", children: _jsx("div", { className: "overflow-hidden rounded-xl bg-white", children: _jsxs("div", { className: "px-6 py-4", children: [_jsx("h2", { className: "mb-4 text-lg font-semibold", children: "Order summary" }), _jsxs("div", { className: "flex flex-col divide-y", children: [_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Receiving" }), _jsxs("div", { className: "flex items-center gap-2", children: [destinationToken.metadata?.logoURI && (_jsx("img", { src: destinationToken.metadata.logoURI, alt: destinationToken.symbol, className: "h-5 w-5 rounded-full" })), _jsxs("span", { className: "font-medium", children: [anyspendQuote?.data?.currencyOut?.amount
165
+ ? Number(formatUnits(BigInt(anyspendQuote.data.currencyOut.amount), destinationToken.decimals)).toFixed(4)
166
+ : "0", " ", destinationToken.symbol] })] })] }), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Network" }), _jsx("span", { className: "font-medium", children: getChainName(destinationToken.chainId) })] }), recipientAddress && (_jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "Recipient" }), _jsx("span", { className: "font-medium", children: centerTruncate(recipientAddress) })] })), _jsxs("div", { className: "flex items-center justify-between py-3", children: [_jsx("span", { className: "text-gray-600", children: "You Pay" }), _jsxs("span", { className: "text-lg font-semibold", children: ["$", parseFloat(srcAmountOnRamp).toFixed(2)] })] })] })] }) }) }));
167
+ }
@@ -14,6 +14,7 @@ export type CreateOnrampOrderParams = {
14
14
  dstToken: Token;
15
15
  srcFiatAmount: string;
16
16
  onramp: OnrampOptions;
17
+ partnerId?: string;
17
18
  expectedDstAmount: string;
18
19
  creatorAddress?: string;
19
20
  nft?: Nft & {
@@ -1,10 +1,10 @@
1
+ import { USDC_BASE } from "../../../anyspend/constants/index.js";
1
2
  import { anyspendService } from "../../../anyspend/services/anyspend.js";
2
- import { normalizeAddress, buildMetadata, buildPayload } from "../../../anyspend/utils/index.js";
3
+ import { buildMetadata, buildPayload, normalizeAddress } from "../../../anyspend/utils/index.js";
3
4
  import { useMutation } from "@tanstack/react-query";
4
5
  import { useMemo } from "react";
5
6
  import { parseUnits } from "viem";
6
7
  import { base } from "viem/chains";
7
- import { USDC_BASE } from "../../../anyspend/constants/index.js";
8
8
  /**
9
9
  * Hook for creating onramp orders in the Anyspend protocol
10
10
  * Specifically handles orders that involve fiat-to-crypto onramp functionality
@@ -12,7 +12,7 @@ import { USDC_BASE } from "../../../anyspend/constants/index.js";
12
12
  export function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
13
13
  const { mutate: createOrder, isPending } = useMutation({
14
14
  mutationFn: async (params) => {
15
- const { isMainnet, recipientAddress, orderType, dstChain, dstToken, srcFiatAmount, onramp, creatorAddress, expectedDstAmount, nft, tournament, payload } = params;
15
+ const { isMainnet, recipientAddress, orderType, dstChain, dstToken, srcFiatAmount, onramp, creatorAddress, expectedDstAmount, nft, tournament, payload, partnerId } = params;
16
16
  try {
17
17
  // Validate Stripe onramp options
18
18
  if (onramp.vendor === "stripe" && !onramp.ipAddress) {
@@ -54,7 +54,8 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
54
54
  tournament,
55
55
  payload
56
56
  }),
57
- creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined
57
+ creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined,
58
+ partnerId
58
59
  });
59
60
  }
60
61
  catch (error) {
@@ -46,6 +46,7 @@ export declare function useAnyspendOrderAndTransactions(isMainnet: boolean, orde
46
46
  ipAddress?: string | undefined;
47
47
  } | null;
48
48
  creatorAddress: string | null;
49
+ partnerId: string | null;
49
50
  oneClickBuyUrl: string | null;
50
51
  stripePaymentIntentId: string | null;
51
52
  permit: {
@@ -117,6 +118,7 @@ export declare function useAnyspendOrderAndTransactions(isMainnet: boolean, orde
117
118
  ipAddress?: string | undefined;
118
119
  } | null;
119
120
  creatorAddress: string | null;
121
+ partnerId: string | null;
120
122
  oneClickBuyUrl: string | null;
121
123
  stripePaymentIntentId: string | null;
122
124
  permit: {
@@ -180,6 +182,7 @@ export declare function useAnyspendOrderAndTransactions(isMainnet: boolean, orde
180
182
  ipAddress?: string | undefined;
181
183
  } | null;
182
184
  creatorAddress: string | null;
185
+ partnerId: string | null;
183
186
  oneClickBuyUrl: string | null;
184
187
  stripePaymentIntentId: string | null;
185
188
  permit: {
@@ -243,6 +246,7 @@ export declare function useAnyspendOrderAndTransactions(isMainnet: boolean, orde
243
246
  ipAddress?: string | undefined;
244
247
  } | null;
245
248
  creatorAddress: string | null;
249
+ partnerId: string | null;
246
250
  oneClickBuyUrl: string | null;
247
251
  stripePaymentIntentId: string | null;
248
252
  permit: {
@@ -301,6 +305,7 @@ export declare function useAnyspendOrderAndTransactions(isMainnet: boolean, orde
301
305
  ipAddress?: string | undefined;
302
306
  } | null;
303
307
  creatorAddress: string | null;
308
+ partnerId: string | null;
304
309
  oneClickBuyUrl: string | null;
305
310
  stripePaymentIntentId: string | null;
306
311
  permit: {
@@ -399,6 +404,7 @@ export declare function useAnyspendOrderAndTransactions(isMainnet: boolean, orde
399
404
  ipAddress?: string | undefined;
400
405
  } | null;
401
406
  creatorAddress: string | null;
407
+ partnerId: string | null;
402
408
  oneClickBuyUrl: string | null;
403
409
  stripePaymentIntentId: string | null;
404
410
  permit: {
@@ -470,6 +476,7 @@ export declare function useAnyspendOrderAndTransactions(isMainnet: boolean, orde
470
476
  ipAddress?: string | undefined;
471
477
  } | null;
472
478
  creatorAddress: string | null;
479
+ partnerId: string | null;
473
480
  oneClickBuyUrl: string | null;
474
481
  stripePaymentIntentId: string | null;
475
482
  permit: {
@@ -533,6 +540,7 @@ export declare function useAnyspendOrderAndTransactions(isMainnet: boolean, orde
533
540
  ipAddress?: string | undefined;
534
541
  } | null;
535
542
  creatorAddress: string | null;
543
+ partnerId: string | null;
536
544
  oneClickBuyUrl: string | null;
537
545
  stripePaymentIntentId: string | null;
538
546
  permit: {
@@ -596,6 +604,7 @@ export declare function useAnyspendOrderAndTransactions(isMainnet: boolean, orde
596
604
  ipAddress?: string | undefined;
597
605
  } | null;
598
606
  creatorAddress: string | null;
607
+ partnerId: string | null;
599
608
  oneClickBuyUrl: string | null;
600
609
  stripePaymentIntentId: string | null;
601
610
  permit: {
@@ -654,6 +663,7 @@ export declare function useAnyspendOrderAndTransactions(isMainnet: boolean, orde
654
663
  ipAddress?: string | undefined;
655
664
  } | null;
656
665
  creatorAddress: string | null;
666
+ partnerId: string | null;
657
667
  oneClickBuyUrl: string | null;
658
668
  stripePaymentIntentId: string | null;
659
669
  permit: {
@@ -43,6 +43,7 @@ export declare function useAnyspendOrderHistory(isMainnet: boolean, creatorAddre
43
43
  ipAddress?: string | undefined;
44
44
  } | null;
45
45
  creatorAddress: string | null;
46
+ partnerId: string | null;
46
47
  oneClickBuyUrl: string | null;
47
48
  stripePaymentIntentId: string | null;
48
49
  permit: {
@@ -114,6 +115,7 @@ export declare function useAnyspendOrderHistory(isMainnet: boolean, creatorAddre
114
115
  ipAddress?: string | undefined;
115
116
  } | null;
116
117
  creatorAddress: string | null;
118
+ partnerId: string | null;
117
119
  oneClickBuyUrl: string | null;
118
120
  stripePaymentIntentId: string | null;
119
121
  permit: {
@@ -177,6 +179,7 @@ export declare function useAnyspendOrderHistory(isMainnet: boolean, creatorAddre
177
179
  ipAddress?: string | undefined;
178
180
  } | null;
179
181
  creatorAddress: string | null;
182
+ partnerId: string | null;
180
183
  oneClickBuyUrl: string | null;
181
184
  stripePaymentIntentId: string | null;
182
185
  permit: {
@@ -240,6 +243,7 @@ export declare function useAnyspendOrderHistory(isMainnet: boolean, creatorAddre
240
243
  ipAddress?: string | undefined;
241
244
  } | null;
242
245
  creatorAddress: string | null;
246
+ partnerId: string | null;
243
247
  oneClickBuyUrl: string | null;
244
248
  stripePaymentIntentId: string | null;
245
249
  permit: {
@@ -298,6 +302,7 @@ export declare function useAnyspendOrderHistory(isMainnet: boolean, creatorAddre
298
302
  ipAddress?: string | undefined;
299
303
  } | null;
300
304
  creatorAddress: string | null;
305
+ partnerId: string | null;
301
306
  oneClickBuyUrl: string | null;
302
307
  stripePaymentIntentId: string | null;
303
308
  permit: {
@@ -360,6 +365,7 @@ export declare function useAnyspendOrderHistory(isMainnet: boolean, creatorAddre
360
365
  ipAddress?: string | undefined;
361
366
  } | null;
362
367
  creatorAddress: string | null;
368
+ partnerId: string | null;
363
369
  oneClickBuyUrl: string | null;
364
370
  stripePaymentIntentId: string | null;
365
371
  permit: {
@@ -431,6 +437,7 @@ export declare function useAnyspendOrderHistory(isMainnet: boolean, creatorAddre
431
437
  ipAddress?: string | undefined;
432
438
  } | null;
433
439
  creatorAddress: string | null;
440
+ partnerId: string | null;
434
441
  oneClickBuyUrl: string | null;
435
442
  stripePaymentIntentId: string | null;
436
443
  permit: {
@@ -494,6 +501,7 @@ export declare function useAnyspendOrderHistory(isMainnet: boolean, creatorAddre
494
501
  ipAddress?: string | undefined;
495
502
  } | null;
496
503
  creatorAddress: string | null;
504
+ partnerId: string | null;
497
505
  oneClickBuyUrl: string | null;
498
506
  stripePaymentIntentId: string | null;
499
507
  permit: {
@@ -557,6 +565,7 @@ export declare function useAnyspendOrderHistory(isMainnet: boolean, creatorAddre
557
565
  ipAddress?: string | undefined;
558
566
  } | null;
559
567
  creatorAddress: string | null;
568
+ partnerId: string | null;
560
569
  oneClickBuyUrl: string | null;
561
570
  stripePaymentIntentId: string | null;
562
571
  permit: {
@@ -615,6 +624,7 @@ export declare function useAnyspendOrderHistory(isMainnet: boolean, creatorAddre
615
624
  ipAddress?: string | undefined;
616
625
  } | null;
617
626
  creatorAddress: string | null;
627
+ partnerId: string | null;
618
628
  oneClickBuyUrl: string | null;
619
629
  stripePaymentIntentId: string | null;
620
630
  permit: {
@@ -4,7 +4,7 @@ export declare const anyspendService: {
4
4
  getTokenList: (isMainnet: boolean, chainId: number, query: string) => Promise<Token[]>;
5
5
  getToken: (isMainnet: boolean, chainId: number, tokenAddress: string) => Promise<Token>;
6
6
  getQuote: (isMainnet: boolean, req: GetQuoteRequest) => Promise<GetQuoteResponse>;
7
- createOrder: ({ isMainnet, recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress }: {
7
+ createOrder: ({ isMainnet, recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId }: {
8
8
  isMainnet: boolean;
9
9
  recipientAddress: string;
10
10
  type: string;
@@ -17,6 +17,7 @@ export declare const anyspendService: {
17
17
  onramp?: OnrampOptions;
18
18
  metadata: Record<string, any>;
19
19
  creatorAddress?: string;
20
+ partnerId?: string;
20
21
  }) => Promise<any>;
21
22
  getOrderAndTransactions: (isMainnet: boolean, orderId: string | undefined) => Promise<GetOrderAndTxsResponse>;
22
23
  getOrderHistory: (isMainnet: boolean, creatorAddress: string | undefined, limit?: number, offset?: number) => Promise<{
@@ -65,6 +66,7 @@ export declare const anyspendService: {
65
66
  ipAddress?: string | undefined;
66
67
  } | null;
67
68
  creatorAddress: string | null;
69
+ partnerId: string | null;
68
70
  oneClickBuyUrl: string | null;
69
71
  stripePaymentIntentId: string | null;
70
72
  permit: {
@@ -136,6 +138,7 @@ export declare const anyspendService: {
136
138
  ipAddress?: string | undefined;
137
139
  } | null;
138
140
  creatorAddress: string | null;
141
+ partnerId: string | null;
139
142
  oneClickBuyUrl: string | null;
140
143
  stripePaymentIntentId: string | null;
141
144
  permit: {
@@ -199,6 +202,7 @@ export declare const anyspendService: {
199
202
  ipAddress?: string | undefined;
200
203
  } | null;
201
204
  creatorAddress: string | null;
205
+ partnerId: string | null;
202
206
  oneClickBuyUrl: string | null;
203
207
  stripePaymentIntentId: string | null;
204
208
  permit: {
@@ -262,6 +266,7 @@ export declare const anyspendService: {
262
266
  ipAddress?: string | undefined;
263
267
  } | null;
264
268
  creatorAddress: string | null;
269
+ partnerId: string | null;
265
270
  oneClickBuyUrl: string | null;
266
271
  stripePaymentIntentId: string | null;
267
272
  permit: {
@@ -320,6 +325,7 @@ export declare const anyspendService: {
320
325
  ipAddress?: string | undefined;
321
326
  } | null;
322
327
  creatorAddress: string | null;
328
+ partnerId: string | null;
323
329
  oneClickBuyUrl: string | null;
324
330
  stripePaymentIntentId: string | null;
325
331
  permit: {
@@ -37,7 +37,7 @@ export const anyspendService = {
37
37
  return data;
38
38
  },
39
39
  // Order related
40
- createOrder: async ({ isMainnet, recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress }) => {
40
+ createOrder: async ({ isMainnet, recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId }) => {
41
41
  const response = await fetch(`${isMainnet ? ANYSPEND_MAINNET_BASE_URL : ANYSPEND_TESTNET_BASE_URL}/orders`, {
42
42
  method: "POST",
43
43
  headers: {
@@ -54,7 +54,8 @@ export const anyspendService = {
54
54
  payload,
55
55
  onramp,
56
56
  metadata,
57
- creatorAddress
57
+ creatorAddress,
58
+ partnerId
58
59
  })
59
60
  });
60
61
  const data = await response.json();