@b3dotfun/sdk 0.0.87-alpha.0 → 0.0.87-alpha.2

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 (90) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.d.ts +5 -0
  2. package/dist/cjs/anyspend/react/components/AnySpend.js +77 -73
  3. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -1
  4. package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +1 -2
  5. package/dist/cjs/anyspend/react/components/AnySpendDeposit.d.ts +122 -0
  6. package/dist/cjs/anyspend/react/components/AnySpendDeposit.js +190 -0
  7. package/dist/cjs/anyspend/react/components/QRDeposit.d.ts +43 -0
  8. package/dist/cjs/anyspend/react/components/QRDeposit.js +146 -0
  9. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +17 -12
  10. package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
  11. package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +12 -5
  12. package/dist/cjs/anyspend/react/components/common/OrderStatus.js +2 -2
  13. package/dist/cjs/anyspend/react/components/common/WarningText.d.ts +32 -0
  14. package/dist/cjs/anyspend/react/components/common/WarningText.js +36 -0
  15. package/dist/cjs/anyspend/react/components/icons/CreditCardIcon.d.ts +6 -0
  16. package/dist/cjs/anyspend/react/components/icons/CreditCardIcon.js +6 -0
  17. package/dist/cjs/anyspend/react/components/icons/QrCodeIcon.d.ts +6 -0
  18. package/dist/cjs/anyspend/react/components/icons/QrCodeIcon.js +6 -0
  19. package/dist/cjs/anyspend/react/components/index.d.ts +2 -0
  20. package/dist/cjs/anyspend/react/components/index.js +3 -1
  21. package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
  22. package/dist/cjs/anyspend/react/hooks/index.js +1 -0
  23. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -2
  24. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +35 -11
  25. package/dist/cjs/anyspend/react/hooks/useCreateDepositFirstOrder.d.ts +24 -0
  26. package/dist/cjs/anyspend/react/hooks/useCreateDepositFirstOrder.js +86 -0
  27. package/dist/cjs/anyspend/utils/format.js +28 -5
  28. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +4 -0
  29. package/dist/esm/anyspend/react/components/AnySpend.d.ts +5 -0
  30. package/dist/esm/anyspend/react/components/AnySpend.js +77 -73
  31. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -1
  32. package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +1 -2
  33. package/dist/esm/anyspend/react/components/AnySpendDeposit.d.ts +122 -0
  34. package/dist/esm/anyspend/react/components/AnySpendDeposit.js +187 -0
  35. package/dist/esm/anyspend/react/components/QRDeposit.d.ts +43 -0
  36. package/dist/esm/anyspend/react/components/QRDeposit.js +143 -0
  37. package/dist/esm/anyspend/react/components/common/OrderDetails.js +17 -12
  38. package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
  39. package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +12 -5
  40. package/dist/esm/anyspend/react/components/common/OrderStatus.js +2 -2
  41. package/dist/esm/anyspend/react/components/common/WarningText.d.ts +32 -0
  42. package/dist/esm/anyspend/react/components/common/WarningText.js +32 -0
  43. package/dist/esm/anyspend/react/components/icons/CreditCardIcon.d.ts +6 -0
  44. package/dist/esm/anyspend/react/components/icons/CreditCardIcon.js +2 -0
  45. package/dist/esm/anyspend/react/components/icons/QrCodeIcon.d.ts +6 -0
  46. package/dist/esm/anyspend/react/components/icons/QrCodeIcon.js +2 -0
  47. package/dist/esm/anyspend/react/components/index.d.ts +2 -0
  48. package/dist/esm/anyspend/react/components/index.js +1 -0
  49. package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
  50. package/dist/esm/anyspend/react/hooks/index.js +1 -0
  51. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -2
  52. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +35 -11
  53. package/dist/esm/anyspend/react/hooks/useCreateDepositFirstOrder.d.ts +24 -0
  54. package/dist/esm/anyspend/react/hooks/useCreateDepositFirstOrder.js +83 -0
  55. package/dist/esm/anyspend/utils/format.js +28 -5
  56. package/dist/esm/global-account/react/stores/useModalStore.d.ts +4 -0
  57. package/dist/styles/index.css +1 -1
  58. package/dist/types/anyspend/react/components/AnySpend.d.ts +5 -0
  59. package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -1
  60. package/dist/types/anyspend/react/components/AnySpendDeposit.d.ts +122 -0
  61. package/dist/types/anyspend/react/components/QRDeposit.d.ts +43 -0
  62. package/dist/types/anyspend/react/components/common/OrderDetailsCollapsible.d.ts +2 -0
  63. package/dist/types/anyspend/react/components/common/WarningText.d.ts +32 -0
  64. package/dist/types/anyspend/react/components/icons/CreditCardIcon.d.ts +6 -0
  65. package/dist/types/anyspend/react/components/icons/QrCodeIcon.d.ts +6 -0
  66. package/dist/types/anyspend/react/components/index.d.ts +2 -0
  67. package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
  68. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +2 -2
  69. package/dist/types/anyspend/react/hooks/useCreateDepositFirstOrder.d.ts +24 -0
  70. package/dist/types/global-account/react/stores/useModalStore.d.ts +4 -0
  71. package/package.json +1 -1
  72. package/src/anyspend/react/components/AnySpend.tsx +105 -85
  73. package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +2 -3
  74. package/src/anyspend/react/components/AnySpendDeposit.tsx +578 -0
  75. package/src/anyspend/react/components/QRDeposit.tsx +348 -0
  76. package/src/anyspend/react/components/common/OrderDetails.tsx +26 -8
  77. package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +20 -8
  78. package/src/anyspend/react/components/common/OrderStatus.tsx +2 -2
  79. package/src/anyspend/react/components/common/WarningText.tsx +52 -0
  80. package/src/anyspend/react/components/icons/CreditCardIcon.tsx +25 -0
  81. package/src/anyspend/react/components/icons/QrCodeIcon.tsx +25 -0
  82. package/src/anyspend/react/components/icons/credit-card.svg +5 -0
  83. package/src/anyspend/react/components/icons/qr-code.svg +5 -0
  84. package/src/anyspend/react/components/index.ts +2 -0
  85. package/src/anyspend/react/hooks/index.ts +1 -0
  86. package/src/anyspend/react/hooks/useAnyspendFlow.ts +37 -12
  87. package/src/anyspend/react/hooks/useCreateDepositFirstOrder.ts +110 -0
  88. package/src/anyspend/utils/format.ts +33 -5
  89. package/src/global-account/react/stores/useModalStore.ts +4 -0
  90. package/src/styles/index.css +2 -0
@@ -24,7 +24,7 @@ export var PanelView;
24
24
  PanelView[PanelView["FEE_DETAIL"] = 7] = "FEE_DETAIL";
25
25
  })(PanelView || (PanelView = {}));
26
26
  // This hook serves for order hype_duel and custom_exact_in
27
- export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, isDepositMode = false, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, destinationTokenAddress, destinationTokenChainId, slippage = 0, disableUrlParamManagement = false, orderType = "hype_duel", }) {
27
+ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, loadOrder, onOrderSuccess, onTransactionSuccess, sourceTokenAddress, sourceTokenChainId, destinationTokenAddress, destinationTokenChainId, slippage = 0, disableUrlParamManagement = false, orderType = "hype_duel", }) {
28
28
  const searchParams = useSearchParamsSSR();
29
29
  const router = useRouter();
30
30
  // Panel and order state
@@ -131,16 +131,40 @@ export function useAnyspendFlow({ paymentType = "crypto", recipientAddress, load
131
131
  // For fiat payments, always use USDC decimals (6) regardless of selectedSrcToken
132
132
  const effectiveDecimals = paymentType === "fiat" ? USDC_BASE.decimals : selectedSrcToken.decimals;
133
133
  const activeInputAmountInWei = parseUnits(srcAmount.replace(/,/g, ""), effectiveDecimals).toString();
134
- const { anyspendQuote, isLoadingAnyspendQuote, getAnyspendQuoteError } = useAnyspendQuote({
135
- srcChain: paymentType === "fiat" ? base.id : selectedSrcChainId,
136
- dstChain: isDepositMode ? base.id : selectedDstChainId, // For deposits, always Base; for swaps, use selected destination
137
- srcTokenAddress: paymentType === "fiat" ? USDC_BASE.address : selectedSrcToken.address,
138
- dstTokenAddress: selectedDstToken.address,
139
- type: orderType,
140
- amount: activeInputAmountInWei,
141
- recipientAddress: effectiveRecipientAddress,
142
- onrampVendor: paymentType === "fiat" ? getOnrampVendor(selectedFiatPaymentMethod) : undefined,
143
- });
134
+ // Build quote request based on order type
135
+ const quoteRequest = (() => {
136
+ const baseParams = {
137
+ srcChain: paymentType === "fiat" ? base.id : selectedSrcChainId,
138
+ dstChain: selectedDstChainId ?? base.id,
139
+ srcTokenAddress: paymentType === "fiat" ? USDC_BASE.address : selectedSrcToken.address,
140
+ dstTokenAddress: selectedDstToken.address,
141
+ recipientAddress: effectiveRecipientAddress,
142
+ onrampVendor: paymentType === "fiat" ? getOnrampVendor(selectedFiatPaymentMethod) : undefined,
143
+ };
144
+ if (orderType === "swap") {
145
+ return {
146
+ ...baseParams,
147
+ type: "swap",
148
+ tradeType: "EXACT_INPUT",
149
+ amount: activeInputAmountInWei,
150
+ };
151
+ }
152
+ else if (orderType === "hype_duel") {
153
+ return {
154
+ ...baseParams,
155
+ type: "hype_duel",
156
+ amount: activeInputAmountInWei,
157
+ };
158
+ }
159
+ else {
160
+ return {
161
+ ...baseParams,
162
+ type: "custom_exact_in",
163
+ amount: activeInputAmountInWei,
164
+ };
165
+ }
166
+ })();
167
+ const { anyspendQuote, isLoadingAnyspendQuote, getAnyspendQuoteError } = useAnyspendQuote(quoteRequest);
144
168
  // Get geo options for fiat
145
169
  const { geoData, coinbaseAvailablePaymentMethods, stripeWeb2Support } = useGeoOnrampOptions(paymentType === "fiat" ? formatUnits(activeInputAmountInWei, USDC_BASE.decimals) : "0");
146
170
  // Update destination amount when quote changes
@@ -0,0 +1,24 @@
1
+ import { components } from "../../../anyspend/types/api";
2
+ import { DepositContractConfig } from "../components/AnySpendDeposit";
3
+ export type CreateDepositFirstOrderParams = {
4
+ recipientAddress: string;
5
+ srcChain: number;
6
+ dstChain: number;
7
+ srcToken: components["schemas"]["Token"];
8
+ dstToken: components["schemas"]["Token"];
9
+ creatorAddress?: string;
10
+ /** Optional contract config for custom execution after deposit */
11
+ contractConfig?: DepositContractConfig;
12
+ };
13
+ export type UseCreateDepositFirstOrderProps = {
14
+ onSuccess?: (data: any) => void;
15
+ onError?: (error: Error) => void;
16
+ };
17
+ /**
18
+ * Hook for creating deposit_first orders in the Anyspend protocol.
19
+ * This order type doesn't require srcAmount - the user deposits tokens after the order is created.
20
+ */
21
+ export declare function useCreateDepositFirstOrder({ onSuccess, onError }?: UseCreateDepositFirstOrderProps): {
22
+ createOrder: import("@tanstack/react-query").UseMutateFunction<any, Error, CreateDepositFirstOrderParams, unknown>;
23
+ isCreatingOrder: boolean;
24
+ };
@@ -0,0 +1,83 @@
1
+ import { anyspendService } from "../../../anyspend/services/anyspend.js";
2
+ import { normalizeAddress } from "../../../anyspend/utils/index.js";
3
+ import { useB3 } from "../../../global-account/react/index.js";
4
+ import { useVisitorData } from "@fingerprintjs/fingerprintjs-pro-react";
5
+ import { useMutation } from "@tanstack/react-query";
6
+ import { useMemo } from "react";
7
+ /**
8
+ * Hook for creating deposit_first orders in the Anyspend protocol.
9
+ * This order type doesn't require srcAmount - the user deposits tokens after the order is created.
10
+ */
11
+ export function useCreateDepositFirstOrder({ onSuccess, onError } = {}) {
12
+ const { partnerId } = useB3();
13
+ const { data: fpData } = useVisitorData({ extendedResult: true }, { immediate: true });
14
+ const visitorData = fpData && {
15
+ requestId: fpData.requestId,
16
+ visitorId: fpData.visitorId,
17
+ };
18
+ const { mutate: createOrder, isPending } = useMutation({
19
+ mutationFn: async (params) => {
20
+ const { recipientAddress, srcChain, dstChain, srcToken, dstToken, creatorAddress, contractConfig } = params;
21
+ // Build payload based on whether we have a contract config
22
+ const payload = contractConfig
23
+ ? {
24
+ functionAbi: contractConfig.functionAbi,
25
+ functionName: contractConfig.functionName,
26
+ functionArgs: contractConfig.functionArgs,
27
+ to: normalizeAddress(contractConfig.to),
28
+ spenderAddress: contractConfig.spenderAddress ? normalizeAddress(contractConfig.spenderAddress) : undefined,
29
+ action: contractConfig.action,
30
+ }
31
+ : {};
32
+ try {
33
+ return await anyspendService.createOrder({
34
+ recipientAddress: normalizeAddress(recipientAddress),
35
+ type: "deposit_first",
36
+ srcChain,
37
+ dstChain,
38
+ srcTokenAddress: normalizeAddress(srcToken.address),
39
+ dstTokenAddress: normalizeAddress(dstToken.address),
40
+ srcAmount: "", // Not required for deposit_first
41
+ payload,
42
+ metadata: {
43
+ srcToken: {
44
+ chainId: srcToken.chainId,
45
+ address: srcToken.address,
46
+ symbol: srcToken.symbol,
47
+ name: srcToken.name,
48
+ decimals: srcToken.decimals,
49
+ metadata: srcToken.metadata || {},
50
+ },
51
+ dstToken: {
52
+ chainId: dstToken.chainId,
53
+ address: dstToken.address,
54
+ symbol: dstToken.symbol,
55
+ name: dstToken.name,
56
+ decimals: dstToken.decimals,
57
+ metadata: dstToken.metadata || {},
58
+ },
59
+ },
60
+ creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined,
61
+ partnerId,
62
+ visitorData,
63
+ });
64
+ }
65
+ catch (error) {
66
+ if (error?.data) {
67
+ throw error.data;
68
+ }
69
+ throw error;
70
+ }
71
+ },
72
+ onSuccess: (data) => {
73
+ onSuccess?.(data);
74
+ },
75
+ onError: (error) => {
76
+ onError?.(error);
77
+ },
78
+ });
79
+ return useMemo(() => ({
80
+ createOrder,
81
+ isCreatingOrder: isPending,
82
+ }), [createOrder, isPending]);
83
+ }
@@ -1,10 +1,22 @@
1
+ import { formatTokenAmount } from "../../shared/utils/number.js";
1
2
  export const getStatusDisplay = (order) => {
3
+ const srcToken = order.metadata?.srcToken;
4
+ const dstToken = order.metadata?.dstToken;
5
+ const formattedSrcAmount = srcToken ? formatTokenAmount(BigInt(order.srcAmount), srcToken.decimals) : undefined;
6
+ const actualDstAmount = order.settlement?.actualDstAmount;
7
+ const formattedActualDstAmount = actualDstAmount && dstToken ? formatTokenAmount(BigInt(actualDstAmount), dstToken.decimals) : undefined;
2
8
  switch (order.status) {
3
- case "scanning_deposit_transaction":
9
+ case "scanning_deposit_transaction": {
10
+ const depositText = formattedSrcAmount && srcToken
11
+ ? `Awaiting ${formattedSrcAmount} ${srcToken.symbol}`
12
+ : order.onrampMetadata
13
+ ? "Awaiting Payment"
14
+ : "Awaiting Deposit";
4
15
  return {
5
- text: order.onrampMetadata ? "Awaiting Payment" : "Awaiting Deposit",
16
+ text: depositText,
6
17
  status: "processing",
7
18
  };
19
+ }
8
20
  case "waiting_stripe_payment":
9
21
  return {
10
22
  text: "Awaiting Payment",
@@ -27,15 +39,16 @@ export const getStatusDisplay = (order) => {
27
39
  description: "It will take approximately one minute to complete.",
28
40
  };
29
41
  case "executed": {
42
+ const receivedText = formattedActualDstAmount && dstToken ? `Received ${formattedActualDstAmount} ${dstToken.symbol}` : undefined;
30
43
  const { text, description } = order.type === "swap"
31
- ? { text: "Swap Complete", description: "Your swap has been completed successfully." }
44
+ ? { text: receivedText || "Swap Complete", description: "Your swap has been completed successfully." }
32
45
  : order.type === "mint_nft"
33
46
  ? { text: "NFT Minted", description: "Your NFT has been minted" }
34
47
  : order.type === "join_tournament"
35
48
  ? { text: "Tournament Joined", description: "You have joined the tournament" }
36
49
  : order.type === "fund_tournament"
37
50
  ? { text: "Tournament Funded", description: "You have funded the tournament" }
38
- : { text: "Order Complete", description: "Your order has been completed" };
51
+ : { text: receivedText || "Order Complete", description: "Your order has been completed" };
39
52
  return { text, status: "success", description };
40
53
  }
41
54
  case "refunding":
@@ -48,8 +61,18 @@ export const getStatusDisplay = (order) => {
48
61
  status: "failure",
49
62
  description: "This order has failed. Please try again or contact support.",
50
63
  };
64
+ case "quoting_after_deposit": {
65
+ return {
66
+ text: "Quoting After Deposit",
67
+ status: "processing",
68
+ description: "Getting quote for the order",
69
+ };
70
+ }
51
71
  default:
52
- throw new Error("Invalid order status");
72
+ return {
73
+ text: order.status,
74
+ status: "processing",
75
+ };
53
76
  }
54
77
  };
55
78
  export const getErrorDisplay = (errorDetails) => {
@@ -144,6 +144,10 @@ export interface AnySpendModalProps extends BaseModalProps {
144
144
  customUsdInputValues?: string[];
145
145
  /** Client-provided reference ID for tracking orders */
146
146
  clientReferenceId?: string;
147
+ /** Whether to hide the header */
148
+ hideHeader?: boolean;
149
+ /** When true, disables URL parameter management for swap configuration */
150
+ disableUrlParamManagement?: boolean;
147
151
  }
148
152
  /**
149
153
  * Props for the AnySpend NFT modal