@b3dotfun/sdk 0.0.70-alpha.0 → 0.0.70-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 (81) hide show
  1. package/dist/cjs/anyspend/index.d.ts +1 -0
  2. package/dist/cjs/anyspend/index.js +1 -0
  3. package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +57 -0
  4. package/dist/cjs/anyspend/react/components/AnySpendCollectorClubPurchase.js +82 -0
  5. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +3 -1
  6. package/dist/cjs/anyspend/react/components/index.d.ts +1 -0
  7. package/dist/cjs/anyspend/react/components/index.js +3 -1
  8. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +4 -0
  9. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.js +4 -0
  10. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +16 -0
  11. package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +1 -1
  12. package/dist/cjs/anyspend/react/hooks/useValidatedClientReferenceId.d.ts +5 -0
  13. package/dist/cjs/anyspend/react/hooks/useValidatedClientReferenceId.js +35 -0
  14. package/dist/cjs/anyspend/services/anyspend.d.ts +2 -1
  15. package/dist/cjs/anyspend/services/anyspend.js +2 -1
  16. package/dist/cjs/anyspend/types/api.d.ts +295 -0
  17. package/dist/cjs/anyspend/utils/validation.d.ts +67 -0
  18. package/dist/cjs/anyspend/utils/validation.js +157 -0
  19. package/dist/cjs/global-account/react/components/B3DynamicModal.js +2 -0
  20. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
  21. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +4 -3
  22. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +1 -0
  23. package/dist/cjs/global-account/react/components/B3Provider/types.js +1 -0
  24. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +1 -1
  25. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
  26. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +27 -1
  27. package/dist/esm/anyspend/index.d.ts +1 -0
  28. package/dist/esm/anyspend/index.js +1 -0
  29. package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +57 -0
  30. package/dist/esm/anyspend/react/components/AnySpendCollectorClubPurchase.js +79 -0
  31. package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -1
  32. package/dist/esm/anyspend/react/components/index.d.ts +1 -0
  33. package/dist/esm/anyspend/react/components/index.js +1 -0
  34. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +4 -0
  35. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.js +4 -0
  36. package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +16 -0
  37. package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +1 -1
  38. package/dist/esm/anyspend/react/hooks/useValidatedClientReferenceId.d.ts +5 -0
  39. package/dist/esm/anyspend/react/hooks/useValidatedClientReferenceId.js +32 -0
  40. package/dist/esm/anyspend/services/anyspend.d.ts +2 -1
  41. package/dist/esm/anyspend/services/anyspend.js +2 -1
  42. package/dist/esm/anyspend/types/api.d.ts +295 -0
  43. package/dist/esm/anyspend/utils/validation.d.ts +67 -0
  44. package/dist/esm/anyspend/utils/validation.js +153 -0
  45. package/dist/esm/global-account/react/components/B3DynamicModal.js +3 -1
  46. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
  47. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +4 -3
  48. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +1 -0
  49. package/dist/esm/global-account/react/components/B3Provider/types.js +1 -0
  50. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +1 -1
  51. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
  52. package/dist/esm/global-account/react/stores/useModalStore.d.ts +27 -1
  53. package/dist/types/anyspend/index.d.ts +1 -0
  54. package/dist/types/anyspend/react/components/AnySpendCollectorClubPurchase.d.ts +57 -0
  55. package/dist/types/anyspend/react/components/index.d.ts +1 -0
  56. package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +16 -0
  57. package/dist/types/anyspend/react/hooks/useSigMint.d.ts +1 -1
  58. package/dist/types/anyspend/react/hooks/useValidatedClientReferenceId.d.ts +5 -0
  59. package/dist/types/anyspend/services/anyspend.d.ts +2 -1
  60. package/dist/types/anyspend/types/api.d.ts +295 -0
  61. package/dist/types/anyspend/utils/validation.d.ts +67 -0
  62. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
  63. package/dist/types/global-account/react/components/B3Provider/types.d.ts +1 -0
  64. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +1 -1
  65. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
  66. package/dist/types/global-account/react/stores/useModalStore.d.ts +27 -1
  67. package/package.json +1 -1
  68. package/src/anyspend/index.ts +1 -0
  69. package/src/anyspend/react/components/AnySpendCollectorClubPurchase.tsx +178 -0
  70. package/src/anyspend/react/components/AnySpendCustom.tsx +3 -1
  71. package/src/anyspend/react/components/index.ts +1 -0
  72. package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +5 -0
  73. package/src/anyspend/react/hooks/useAnyspendCreateOrder.ts +5 -0
  74. package/src/anyspend/react/hooks/useValidatedClientReferenceId.ts +40 -0
  75. package/src/anyspend/services/anyspend.ts +3 -0
  76. package/src/anyspend/types/api.ts +295 -0
  77. package/src/anyspend/utils/validation.ts +209 -0
  78. package/src/global-account/react/components/B3DynamicModal.tsx +3 -0
  79. package/src/global-account/react/components/B3Provider/B3Provider.tsx +6 -0
  80. package/src/global-account/react/components/B3Provider/types.ts +2 -0
  81. package/src/global-account/react/stores/useModalStore.ts +29 -1
@@ -0,0 +1,67 @@
1
+ export interface ValidationResult {
2
+ isValid: boolean;
3
+ error?: string;
4
+ cleaned?: string;
5
+ }
6
+ export interface StringValidationOptions {
7
+ required?: boolean;
8
+ defaultValue?: () => string;
9
+ minLength?: number;
10
+ maxLength?: number;
11
+ pattern?: RegExp;
12
+ patternErrorMessage?: string;
13
+ trim?: boolean;
14
+ toLowerCase?: boolean;
15
+ toUpperCase?: boolean;
16
+ customValidator?: (value: string) => {
17
+ valid: boolean;
18
+ error?: string;
19
+ };
20
+ }
21
+ /**
22
+ * Generic string validator with configurable rules
23
+ */
24
+ export declare function validateString(value: string | undefined, options: StringValidationOptions): ValidationResult;
25
+ /**
26
+ * Common validation patterns
27
+ */
28
+ export declare const ValidationPatterns: {
29
+ readonly ALPHANUMERIC: RegExp;
30
+ readonly ALPHANUMERIC_WITH_DASH_UNDERSCORE: RegExp;
31
+ readonly ALPHANUMERIC_WITH_SAFE_CHARS: RegExp;
32
+ readonly SAFE_IDENTIFIER: RegExp;
33
+ readonly NO_CONTROL_CHARS: RegExp;
34
+ readonly URL_SAFE: RegExp;
35
+ readonly NUMERIC: RegExp;
36
+ readonly HEX: RegExp;
37
+ };
38
+ /**
39
+ * Pre-configured validators for common use cases
40
+ */
41
+ export declare const Validators: {
42
+ /**
43
+ * Validates client reference IDs (alphanumeric + safe chars)
44
+ * Returns undefined if not provided
45
+ */
46
+ clientReferenceId: (value?: string) => ValidationResult;
47
+ /**
48
+ * Validates alphanumeric strings (letters and numbers only)
49
+ */
50
+ alphanumeric: (value?: string, required?: boolean) => ValidationResult;
51
+ /**
52
+ * Validates wallet addresses (hex format)
53
+ */
54
+ walletAddress: (value?: string, required?: boolean) => ValidationResult;
55
+ /**
56
+ * Validates order IDs (UUID format)
57
+ */
58
+ orderId: (value?: string) => ValidationResult;
59
+ /**
60
+ * Validates URL-safe strings
61
+ */
62
+ urlSafe: (value?: string, maxLength?: number) => ValidationResult;
63
+ /**
64
+ * Validates safe identifiers (no injection risks)
65
+ */
66
+ safeIdentifier: (value?: string, required?: boolean) => ValidationResult;
67
+ };
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Validators = exports.ValidationPatterns = void 0;
4
+ exports.validateString = validateString;
5
+ /**
6
+ * Generic string validator with configurable rules
7
+ */
8
+ function validateString(value, options) {
9
+ const { required = false, defaultValue, minLength, maxLength, pattern, patternErrorMessage, trim = true, toLowerCase = false, toUpperCase = false, customValidator, } = options;
10
+ // Handle empty/undefined
11
+ if (!value || (trim && value.trim() === "")) {
12
+ if (required && !defaultValue) {
13
+ return { isValid: false, error: "This field is required" };
14
+ }
15
+ if (defaultValue) {
16
+ return { isValid: true, cleaned: defaultValue() };
17
+ }
18
+ return { isValid: true, cleaned: undefined };
19
+ }
20
+ // Pre-processing
21
+ let cleaned = value;
22
+ if (trim)
23
+ cleaned = cleaned.trim();
24
+ if (toLowerCase)
25
+ cleaned = cleaned.toLowerCase();
26
+ if (toUpperCase)
27
+ cleaned = cleaned.toUpperCase();
28
+ // Length validation
29
+ if (minLength !== undefined && cleaned.length < minLength) {
30
+ return {
31
+ isValid: false,
32
+ error: `Minimum length is ${minLength} characters`,
33
+ };
34
+ }
35
+ if (maxLength !== undefined && cleaned.length > maxLength) {
36
+ return {
37
+ isValid: false,
38
+ error: `Maximum length is ${maxLength} characters`,
39
+ };
40
+ }
41
+ // Pattern validation
42
+ if (pattern && !pattern.test(cleaned)) {
43
+ return {
44
+ isValid: false,
45
+ error: patternErrorMessage || "Invalid format",
46
+ };
47
+ }
48
+ // Custom validation
49
+ if (customValidator) {
50
+ const customResult = customValidator(cleaned);
51
+ if (!customResult.valid) {
52
+ return { isValid: false, error: customResult.error };
53
+ }
54
+ }
55
+ return { isValid: true, cleaned };
56
+ }
57
+ /**
58
+ * Common validation patterns
59
+ */
60
+ exports.ValidationPatterns = {
61
+ ALPHANUMERIC: /^[a-zA-Z0-9]+$/,
62
+ ALPHANUMERIC_WITH_DASH_UNDERSCORE: /^[a-zA-Z0-9_-]+$/,
63
+ ALPHANUMERIC_WITH_SAFE_CHARS: /^[a-zA-Z0-9_.\-]+$/,
64
+ SAFE_IDENTIFIER: /^[a-zA-Z0-9_.\-]+$/, // For IDs, references
65
+ NO_CONTROL_CHARS: /^[^\x00-\x1F\x7F]+$/,
66
+ URL_SAFE: /^[a-zA-Z0-9_.\-~]+$/,
67
+ NUMERIC: /^\d+$/,
68
+ HEX: /^[0-9a-fA-F]+$/,
69
+ };
70
+ /**
71
+ * Pre-configured validators for common use cases
72
+ */
73
+ exports.Validators = {
74
+ /**
75
+ * Validates client reference IDs (alphanumeric + safe chars)
76
+ * Returns undefined if not provided
77
+ */
78
+ clientReferenceId: (value) => validateString(value, {
79
+ required: false,
80
+ maxLength: 255,
81
+ pattern: exports.ValidationPatterns.SAFE_IDENTIFIER,
82
+ patternErrorMessage: "Only letters, numbers, hyphens, underscores, and dots allowed",
83
+ trim: true,
84
+ customValidator: val => {
85
+ // Additional security checks
86
+ const dangerous = /('|"|;|--|\/\*|\*\/|<|>|script)/i;
87
+ if (dangerous.test(val)) {
88
+ return {
89
+ valid: false,
90
+ error: "Contains potentially dangerous characters",
91
+ };
92
+ }
93
+ return { valid: true };
94
+ },
95
+ }),
96
+ /**
97
+ * Validates alphanumeric strings (letters and numbers only)
98
+ */
99
+ alphanumeric: (value, required = false) => validateString(value, {
100
+ required,
101
+ pattern: exports.ValidationPatterns.ALPHANUMERIC,
102
+ patternErrorMessage: "Only letters and numbers allowed",
103
+ trim: true,
104
+ }),
105
+ /**
106
+ * Validates wallet addresses (hex format)
107
+ */
108
+ walletAddress: (value, required = true) => validateString(value, {
109
+ required,
110
+ minLength: 42,
111
+ maxLength: 42,
112
+ pattern: /^0x[a-fA-F0-9]{40}$/,
113
+ patternErrorMessage: "Invalid wallet address format",
114
+ trim: true,
115
+ toLowerCase: true,
116
+ }),
117
+ /**
118
+ * Validates order IDs (UUID format)
119
+ */
120
+ orderId: (value) => validateString(value, {
121
+ required: false,
122
+ pattern: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
123
+ patternErrorMessage: "Invalid order ID format",
124
+ trim: true,
125
+ toLowerCase: true,
126
+ }),
127
+ /**
128
+ * Validates URL-safe strings
129
+ */
130
+ urlSafe: (value, maxLength = 255) => validateString(value, {
131
+ maxLength,
132
+ pattern: exports.ValidationPatterns.URL_SAFE,
133
+ patternErrorMessage: "Contains invalid URL characters",
134
+ trim: true,
135
+ }),
136
+ /**
137
+ * Validates safe identifiers (no injection risks)
138
+ */
139
+ safeIdentifier: (value, required = false) => validateString(value, {
140
+ required,
141
+ maxLength: 255,
142
+ pattern: exports.ValidationPatterns.SAFE_IDENTIFIER,
143
+ patternErrorMessage: "Invalid identifier format",
144
+ customValidator: val => {
145
+ // Additional security checks
146
+ const dangerous = /('|"|;|--|\/\*|\*\/|<|>|script)/i;
147
+ if (dangerous.test(val)) {
148
+ return {
149
+ valid: false,
150
+ error: "Contains potentially dangerous characters",
151
+ };
152
+ }
153
+ return { valid: true };
154
+ },
155
+ trim: true,
156
+ }),
157
+ };
@@ -118,6 +118,8 @@ function B3DynamicModal() {
118
118
  return (0, jsx_runtime_1.jsx)(LinkAccount_1.LinkAccount, { ...contentType });
119
119
  case "anySpendDepositHype":
120
120
  return (0, jsx_runtime_1.jsx)(AnyspendDepositHype_1.AnySpendDepositHype, { ...contentType, mode: "modal" });
121
+ case "anySpendCollectorClubPurchase":
122
+ return (0, jsx_runtime_1.jsx)(react_1.AnySpendCollectorClubPurchase, { ...contentType, mode: "modal" });
121
123
  case "avatarEditor":
122
124
  return (0, jsx_runtime_1.jsx)(AvatarEditor_1.AvatarEditor, { onSetAvatar: contentType.onSuccess });
123
125
  case "profileEditor":
@@ -7,7 +7,7 @@ import { B3ContextType } from "./types";
7
7
  /**
8
8
  * Main B3Provider component
9
9
  */
10
- export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, onConnect, connectors, overrideDefaultConnectors, }: {
10
+ export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType, rpcUrls, partnerId, onConnect, connectors, overrideDefaultConnectors, createClientReferenceId, }: {
11
11
  theme: "light" | "dark";
12
12
  children: React.ReactNode;
13
13
  accountOverride?: Account;
@@ -24,11 +24,12 @@ export declare function B3Provider({ theme, children, accountOverride, environme
24
24
  onConnect?: (wallet: Wallet, b3Jwt: string) => void | Promise<void>;
25
25
  connectors?: CreateConnectorFn[];
26
26
  overrideDefaultConnectors?: boolean;
27
+ createClientReferenceId?: () => string;
27
28
  }): import("react/jsx-runtime").JSX.Element;
28
29
  /**
29
30
  * Inner provider component that provides the actual B3Context
30
31
  */
31
- export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, partnerId, }: {
32
+ export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, partnerId, createClientReferenceId, }: {
32
33
  children: React.ReactNode;
33
34
  accountOverride?: Account;
34
35
  environment: B3ContextType["environment"];
@@ -37,4 +38,5 @@ export declare function InnerProvider({ children, accountOverride, environment,
37
38
  theme: "light" | "dark";
38
39
  clientType?: ClientType;
39
40
  partnerId: string;
41
+ createClientReferenceId?: () => string;
40
42
  }): import("react/jsx-runtime").JSX.Element;
@@ -32,7 +32,7 @@ const queryClient = new react_query_1.QueryClient();
32
32
  /**
33
33
  * Main B3Provider component
34
34
  */
35
- function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", rpcUrls, partnerId, onConnect, connectors, overrideDefaultConnectors = false, }) {
35
+ function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster, clientType = "rest", rpcUrls, partnerId, onConnect, connectors, overrideDefaultConnectors = false, createClientReferenceId, }) {
36
36
  // Initialize Google Analytics on mount
37
37
  (0, react_2.useEffect)(() => {
38
38
  (0, analytics_1.loadGA4Script)();
@@ -42,12 +42,12 @@ function B3Provider({ theme = "light", children, accountOverride, environment, a
42
42
  (0, client_manager_1.setClientType)(clientType);
43
43
  }, [clientType]);
44
44
  const wagmiConfig = (0, createWagmiConfig_1.createWagmiConfig)({ partnerId, rpcUrls, connectors, overrideDefaultConnectors });
45
- return ((0, jsx_runtime_1.jsx)(react_3.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(wagmi_1.WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(react_1.TooltipProvider, { children: (0, jsx_runtime_1.jsx)(LocalSDKProvider_1.LocalSDKProvider, { onConnectCallback: onConnect, children: (0, jsx_runtime_1.jsx)(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, partnerId: partnerId, children: (0, jsx_runtime_1.jsxs)(react_1.RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, (0, jsx_runtime_1.jsx)(StyleRoot_1.StyleRoot, { id: "b3-root" }), (0, jsx_runtime_1.jsx)(sonner_1.Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }) }));
45
+ return ((0, jsx_runtime_1.jsx)(react_3.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(wagmi_1.WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(react_1.TooltipProvider, { children: (0, jsx_runtime_1.jsx)(LocalSDKProvider_1.LocalSDKProvider, { onConnectCallback: onConnect, children: (0, jsx_runtime_1.jsx)(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, partnerId: partnerId, createClientReferenceId: createClientReferenceId, children: (0, jsx_runtime_1.jsxs)(react_1.RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, (0, jsx_runtime_1.jsx)(StyleRoot_1.StyleRoot, { id: "b3-root" }), (0, jsx_runtime_1.jsx)(sonner_1.Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }) }));
46
46
  }
47
47
  /**
48
48
  * Inner provider component that provides the actual B3Context
49
49
  */
50
- function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", clientType = "socket", partnerId, }) {
50
+ function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", clientType = "socket", partnerId, createClientReferenceId, }) {
51
51
  const activeAccount = (0, react_3.useActiveAccount)();
52
52
  const [manuallySelectedWallet, setManuallySelectedWallet] = (0, react_2.useState)(undefined);
53
53
  const wallets = (0, react_3.useConnectedWallets)();
@@ -101,6 +101,7 @@ function InnerProvider({ children, accountOverride, environment, defaultPermissi
101
101
  theme,
102
102
  clientType,
103
103
  partnerId: partnerId,
104
+ createClientReferenceId,
104
105
  }, children: (0, jsx_runtime_1.jsx)(InnerProvider2, { children: children }) }));
105
106
  }
106
107
  const InnerProvider2 = ({ children }) => {
@@ -20,6 +20,7 @@ export interface B3ContextType {
20
20
  theme: "light" | "dark";
21
21
  clientType: ClientType;
22
22
  partnerId: string;
23
+ createClientReferenceId?: () => string;
23
24
  }
24
25
  /**
25
26
  * Context for B3 provider
@@ -19,4 +19,5 @@ exports.B3Context = (0, react_1.createContext)({
19
19
  theme: "light",
20
20
  clientType: "rest",
21
21
  partnerId: "",
22
+ createClientReferenceId: undefined,
22
23
  });
@@ -13,8 +13,8 @@ export declare function useAuthentication(partnerId: string): {
13
13
  onConnect: (_walleAutoConnectedWith: Wallet, allConnectedWallets: Wallet[]) => Promise<void>;
14
14
  user: {
15
15
  email?: string | undefined;
16
- username?: string | undefined;
17
16
  telNumber?: string | undefined;
17
+ username?: string | undefined;
18
18
  ens?: string | undefined;
19
19
  avatar?: string | undefined;
20
20
  preferences?: {} | undefined;
@@ -8,8 +8,8 @@ import { Users } from "@b3dotfun/b3-api";
8
8
  export declare function useUserQuery(): {
9
9
  user: {
10
10
  email?: string | undefined;
11
- username?: string | undefined;
12
11
  telNumber?: string | undefined;
12
+ username?: string | undefined;
13
13
  ens?: string | undefined;
14
14
  avatar?: string | undefined;
15
15
  preferences?: {} | undefined;
@@ -122,6 +122,8 @@ export interface AnySpendModalProps extends BaseModalProps {
122
122
  destinationTokenChainId?: number;
123
123
  /** Custom USD input values for quick amount buttons in fiat onramp */
124
124
  customUsdInputValues?: string[];
125
+ /** Client-provided reference ID for tracking orders */
126
+ clientReferenceId?: string;
125
127
  }
126
128
  /**
127
129
  * Props for the AnySpend NFT modal
@@ -136,6 +138,8 @@ export interface AnySpendNftProps extends BaseModalProps {
136
138
  recipientAddress?: string;
137
139
  /** Callback function called when the NFT is successfully transferred */
138
140
  onSuccess?: (txHash?: string) => void;
141
+ /** Client-provided reference ID for tracking orders */
142
+ clientReferenceId?: string;
139
143
  }
140
144
  /**
141
145
  * Props for the AnySpend tournament modal
@@ -377,10 +381,32 @@ export interface ProfileEditorModalProps extends BaseModalProps {
377
381
  /** Callback function called when profile is successfully updated */
378
382
  onSuccess?: () => void;
379
383
  }
384
+ /**
385
+ * Props for the AnySpend Collector Club Purchase modal
386
+ * Handles Collector Club pack purchases
387
+ */
388
+ export interface AnySpendCollectorClubPurchaseProps extends BaseModalProps {
389
+ /** Modal type identifier */
390
+ type: "anySpendCollectorClubPurchase";
391
+ /** The pack ID to purchase */
392
+ packId: number;
393
+ /** The number of packs to purchase */
394
+ packAmount: number;
395
+ /** Price per pack in wei (e.g., "10000" for 0.01 USDC with 6 decimals) */
396
+ pricePerPack: string;
397
+ /** Recipient address to receive the packs */
398
+ recipientAddress: string;
399
+ /** Payment type - crypto or fiat */
400
+ paymentType?: "crypto" | "fiat";
401
+ /** Callback function called when the purchase is successful */
402
+ onSuccess?: (txHash?: string) => void;
403
+ /** Client-provided reference ID for tracking orders */
404
+ clientReferenceId?: string;
405
+ }
380
406
  /**
381
407
  * Union type of all possible modal content types
382
408
  */
383
- export type ModalContentType = SignInWithB3ModalProps | RequestPermissionsModalProps | ManageAccountModalProps | AnySpendModalProps | AnyspendOrderDetailsProps | AnySpendNftProps | AnySpendJoinTournamentProps | AnySpendFundTournamentProps | AnySpendOrderHistoryProps | AnySpendStakeB3Props | AnySpendStakeB3ExactInProps | AnySpendStakeUpsideProps | AnySpendStakeUpsideExactInProps | AnySpendDepositUpsideProps | AnySpendBuySpinProps | AnySpendSignatureMintProps | AnySpendBondKitProps | LinkAccountModalProps | AnySpendDepositHypeProps | AvatarEditorModalProps | ProfileEditorModalProps;
409
+ export type ModalContentType = SignInWithB3ModalProps | RequestPermissionsModalProps | ManageAccountModalProps | AnySpendModalProps | AnyspendOrderDetailsProps | AnySpendNftProps | AnySpendJoinTournamentProps | AnySpendFundTournamentProps | AnySpendOrderHistoryProps | AnySpendStakeB3Props | AnySpendStakeB3ExactInProps | AnySpendStakeUpsideProps | AnySpendStakeUpsideExactInProps | AnySpendDepositUpsideProps | AnySpendBuySpinProps | AnySpendSignatureMintProps | AnySpendBondKitProps | LinkAccountModalProps | AnySpendDepositHypeProps | AvatarEditorModalProps | ProfileEditorModalProps | AnySpendCollectorClubPurchaseProps;
384
410
  /**
385
411
  * State interface for the modal store
386
412
  */
@@ -6,6 +6,7 @@ export * from "./utils/json";
6
6
  export * from "./utils/number";
7
7
  export * from "./utils/string";
8
8
  export * from "./utils/token";
9
+ export * from "./utils/validation";
9
10
  export * from "./constants";
10
11
  export * from "./abis/abiUsdcBase";
11
12
  export * from "./abis/erc20Staking";
@@ -8,6 +8,7 @@ export * from "./utils/json.js";
8
8
  export * from "./utils/number.js";
9
9
  export * from "./utils/string.js";
10
10
  export * from "./utils/token.js";
11
+ export * from "./utils/validation.js";
11
12
  // Constants
12
13
  export * from "./constants/index.js";
13
14
  // Abis
@@ -0,0 +1,57 @@
1
+ import { components } from "../../../anyspend/types/api";
2
+ import { GetQuoteResponse } from "../../../anyspend/types/api_req_res";
3
+ import React from "react";
4
+ export interface AnySpendCollectorClubPurchaseProps {
5
+ /**
6
+ * Optional order ID to load existing order
7
+ */
8
+ loadOrder?: string;
9
+ /**
10
+ * Display mode
11
+ */
12
+ mode?: "modal" | "page";
13
+ /**
14
+ * Active tab (crypto or fiat payment)
15
+ */
16
+ activeTab?: "crypto" | "fiat";
17
+ /**
18
+ * The pack ID to purchase
19
+ */
20
+ packId: number;
21
+ /**
22
+ * The number of packs to purchase
23
+ */
24
+ packAmount: number;
25
+ /**
26
+ * Price per pack in wei (e.g., "10000" for 0.01 USDC with 6 decimals)
27
+ */
28
+ pricePerPack: string;
29
+ /**
30
+ * The payment token (defaults to USDC on Base)
31
+ */
32
+ paymentToken?: components["schemas"]["Token"];
33
+ /**
34
+ * Address that will receive the packs
35
+ */
36
+ recipientAddress: string;
37
+ /**
38
+ * Optional spender address (defaults to contract address)
39
+ */
40
+ spenderAddress?: string;
41
+ /**
42
+ * Success callback
43
+ */
44
+ onSuccess?: (txHash?: string) => void;
45
+ /**
46
+ * Optional custom header component
47
+ */
48
+ header?: (props: {
49
+ anyspendPrice: GetQuoteResponse | undefined;
50
+ isLoadingAnyspendPrice: boolean;
51
+ }) => React.JSX.Element;
52
+ /**
53
+ * Show recipient selection (default: true)
54
+ */
55
+ showRecipient?: boolean;
56
+ }
57
+ export declare function AnySpendCollectorClubPurchase({ loadOrder, mode, activeTab, packId, packAmount, pricePerPack, paymentToken, recipientAddress, spenderAddress, onSuccess, header, showRecipient, }: AnySpendCollectorClubPurchaseProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,79 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * AnySpend component for Collector Club pack purchases
4
+ *
5
+ * This component enables users to purchase Collector Club packs using any token via AnySpend.
6
+ * It calls the `buyPacksFor` function on the Collector Club Shop contract on Base.
7
+ * Uses exact-out flow to ensure the contract receives exactly the required USDC amount.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import { AnySpendCollectorClubPurchase } from "../../..";
12
+ * import { USDC_BASE } from "../../../anyspend/constants/index.js";
13
+ *
14
+ * function MyComponent() {
15
+ * return (
16
+ * <AnySpendCollectorClubPurchase
17
+ * packId={1}
18
+ * packAmount={5}
19
+ * pricePerPack="10000" // 0.01 USDC in wei (6 decimals)
20
+ * paymentToken={USDC_BASE}
21
+ * recipientAddress="0x123..."
22
+ * onSuccess={(txHash) => console.log("Purchase successful!", txHash)}
23
+ * />
24
+ * );
25
+ * }
26
+ * ```
27
+ */
28
+ import { USDC_BASE } from "../../../anyspend/constants/index.js";
29
+ import { useMemo } from "react";
30
+ import { encodeFunctionData } from "viem";
31
+ import { AnySpendCustom } from "./AnySpendCustom.js";
32
+ // Collector Club Shop contract on Base
33
+ const CC_SHOP_ADDRESS = "0x68B32D594E3c7E5B8cd8046BD66AfB0DB5b9BF9c";
34
+ const BASE_CHAIN_ID = 8453;
35
+ // ABI for buyPacksFor function only
36
+ const BUY_PACKS_FOR_ABI = {
37
+ inputs: [
38
+ { internalType: "address", name: "user", type: "address" },
39
+ { internalType: "uint256", name: "packId", type: "uint256" },
40
+ { internalType: "uint256", name: "amount", type: "uint256" },
41
+ ],
42
+ name: "buyPacksFor",
43
+ outputs: [],
44
+ stateMutability: "nonpayable",
45
+ type: "function",
46
+ };
47
+ export function AnySpendCollectorClubPurchase({ loadOrder, mode = "modal", activeTab = "crypto", packId, packAmount, pricePerPack, paymentToken = USDC_BASE, recipientAddress, spenderAddress = CC_SHOP_ADDRESS, onSuccess, header, showRecipient = true, }) {
48
+ // Calculate total amount needed (pricePerPack * packAmount)
49
+ const totalAmount = useMemo(() => {
50
+ try {
51
+ return (BigInt(pricePerPack) * BigInt(packAmount)).toString();
52
+ }
53
+ catch (error) {
54
+ console.error("Failed to calculate total amount from props", { pricePerPack, packAmount, error });
55
+ return "0";
56
+ }
57
+ }, [pricePerPack, packAmount]);
58
+ // Encode the buyPacksFor function call
59
+ const encodedData = useMemo(() => {
60
+ try {
61
+ return encodeFunctionData({
62
+ abi: [BUY_PACKS_FOR_ABI],
63
+ functionName: "buyPacksFor",
64
+ args: [recipientAddress, BigInt(packId), BigInt(packAmount)],
65
+ });
66
+ }
67
+ catch (error) {
68
+ console.error("Failed to encode function data", { recipientAddress, packId, packAmount, error });
69
+ return "0x";
70
+ }
71
+ }, [recipientAddress, packId, packAmount]);
72
+ // Default header if not provided
73
+ const defaultHeader = () => (_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: "Buy Collector Club Packs" }), _jsxs("p", { className: "text-as-secondary text-sm", children: ["Purchase ", packAmount, " pack", packAmount !== 1 ? "s" : "", " using any token"] })] }) }));
74
+ return (_jsx(AnySpendCustom, { loadOrder: loadOrder, mode: mode, activeTab: activeTab, recipientAddress: recipientAddress, spenderAddress: spenderAddress, orderType: "custom", dstChainId: BASE_CHAIN_ID, dstToken: paymentToken, dstAmount: totalAmount, contractAddress: CC_SHOP_ADDRESS, encodedData: encodedData, metadata: {
75
+ packId,
76
+ packAmount,
77
+ pricePerPack,
78
+ }, header: header || defaultHeader, onSuccess: onSuccess, showRecipient: showRecipient }));
79
+ }
@@ -354,7 +354,9 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
354
354
  });
355
355
  }
356
356
  else {
357
- void createRegularOrder(createOrderParams);
357
+ void createRegularOrder({
358
+ ...createOrderParams,
359
+ });
358
360
  }
359
361
  }
360
362
  catch (err) {
@@ -1,6 +1,7 @@
1
1
  export { AnySpend } from "./AnySpend";
2
2
  export { AnySpendBondKit } from "./AnySpendBondKit";
3
3
  export { AnySpendBuySpin } from "./AnySpendBuySpin";
4
+ export { AnySpendCollectorClubPurchase } from "./AnySpendCollectorClubPurchase";
4
5
  export { AnySpendCustom } from "./AnySpendCustom";
5
6
  export { AnySpendCustomExactIn } from "./AnySpendCustomExactIn";
6
7
  export { AnySpendDepositHype, HYPE_TOKEN_DETAILS } from "./AnyspendDepositHype";
@@ -2,6 +2,7 @@
2
2
  export { AnySpend } from "./AnySpend.js";
3
3
  export { AnySpendBondKit } from "./AnySpendBondKit.js";
4
4
  export { AnySpendBuySpin } from "./AnySpendBuySpin.js";
5
+ export { AnySpendCollectorClubPurchase } from "./AnySpendCollectorClubPurchase.js";
5
6
  export { AnySpendCustom } from "./AnySpendCustom.js";
6
7
  export { AnySpendCustomExactIn } from "./AnySpendCustomExactIn.js";
7
8
  export { AnySpendDepositHype, HYPE_TOKEN_DETAILS } from "./AnyspendDepositHype.js";
@@ -6,11 +6,14 @@ import { useMutation } from "@tanstack/react-query";
6
6
  import { useMemo } from "react";
7
7
  import { parseUnits } from "viem";
8
8
  import { base } from "viem/chains";
9
+ import { useValidatedClientReferenceId } from "./useValidatedClientReferenceId.js";
9
10
  /**
10
11
  * Hook for creating onramp orders in the Anyspend protocol
11
12
  * Specifically handles orders that involve fiat-to-crypto onramp functionality
12
13
  */
13
14
  export function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
15
+ // Get validated client reference ID from B3 context
16
+ const validatedClientReferenceId = useValidatedClientReferenceId();
14
17
  // Get fingerprint data
15
18
  const { data: fpData } = useVisitorData({ extendedResult: true }, { immediate: true });
16
19
  const visitorData = fpData && {
@@ -62,6 +65,7 @@ export function useAnyspendCreateOnrampOrder({ onSuccess, onError } = {}) {
62
65
  }),
63
66
  creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined,
64
67
  partnerId,
68
+ clientReferenceId: validatedClientReferenceId,
65
69
  visitorData,
66
70
  });
67
71
  }
@@ -3,12 +3,15 @@ import { buildMetadata, buildPayload, normalizeAddress } from "../../../anyspend
3
3
  import { useVisitorData } from "@fingerprintjs/fingerprintjs-pro-react";
4
4
  import { useMutation } from "@tanstack/react-query";
5
5
  import { useMemo } from "react";
6
+ import { useValidatedClientReferenceId } from "./useValidatedClientReferenceId.js";
6
7
  /**
7
8
  * Hook for creating orders in the Anyspend protocol
8
9
  * Handles regular order creation for swaps, NFT minting, tournament participation, etc.
9
10
  * For onramp orders, use useAnyspendCreateOnrampOrder instead.
10
11
  */
11
12
  export function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
13
+ // Get validated client reference ID from B3 context
14
+ const validatedClientReferenceId = useValidatedClientReferenceId();
12
15
  // Get fingerprint data
13
16
  const { data: fpData } = useVisitorData({ extendedResult: true }, { immediate: true });
14
17
  const visitorData = fpData && {
@@ -50,6 +53,7 @@ export function useAnyspendCreateOrder({ onSuccess, onError } = {}) {
50
53
  },
51
54
  }),
52
55
  creatorAddress: creatorAddress ? normalizeAddress(creatorAddress) : undefined,
56
+ clientReferenceId: validatedClientReferenceId,
53
57
  visitorData,
54
58
  });
55
59
  }