@b3dotfun/sdk 0.0.8-alpha.1 → 0.0.8-alpha.3

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 (27) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +25 -5
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +1 -1
  3. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderAndTransactions.js +21 -6
  4. package/dist/cjs/anyspend/types/req-res/getOrderAndTransactions.d.ts +2245 -0
  5. package/dist/cjs/anyspend/types/req-res/getOrderAndTransactions.js +9 -8
  6. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +1 -1
  7. package/dist/cjs/global-account/react/components/ui/TabSystem.d.ts +2 -2
  8. package/dist/cjs/global-account/react/components/ui/TabSystem.js +5 -5
  9. package/dist/esm/anyspend/react/components/AnySpendBondKit.js +25 -5
  10. package/dist/esm/anyspend/react/components/AnySpendCustom.js +1 -1
  11. package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.js +21 -3
  12. package/dist/esm/anyspend/types/req-res/getOrderAndTransactions.d.ts +2245 -0
  13. package/dist/esm/anyspend/types/req-res/getOrderAndTransactions.js +8 -7
  14. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +1 -1
  15. package/dist/esm/global-account/react/components/ui/TabSystem.d.ts +2 -2
  16. package/dist/esm/global-account/react/components/ui/TabSystem.js +4 -4
  17. package/dist/types/anyspend/types/req-res/getOrderAndTransactions.d.ts +2245 -0
  18. package/dist/types/global-account/react/components/ui/TabSystem.d.ts +2 -2
  19. package/package.json +1 -1
  20. package/src/anyspend/react/components/AnySpend.tsx +1 -2
  21. package/src/anyspend/react/components/AnySpendBondKit.tsx +26 -5
  22. package/src/anyspend/react/components/AnySpendCustom.tsx +1 -1
  23. package/src/anyspend/react/hooks/useAnyspendOrderAndTransactions.ts +26 -4
  24. package/src/anyspend/types/req-res/getOrderAndTransactions.ts +10 -7
  25. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +1 -1
  26. package/src/global-account/react/components/StyleRoot.tsx +1 -0
  27. package/src/global-account/react/components/ui/TabSystem.tsx +36 -33
@@ -129,8 +129,10 @@ function AnySpendBondKit({ mode = "modal", recipientAddress, contractAddress, mi
129
129
  setQuote(null);
130
130
  return;
131
131
  }
132
- // Only allow numbers and one decimal point
133
- if (!/^\d*\.?\d*$/.test(value)) {
132
+ // Only allow valid number format (no leading zeros unless decimal)
133
+ if (!/^(0|[1-9]\d*)?\.?\d*$/.test(value)) {
134
+ setIsAmountValid(false);
135
+ setValidationError("Please enter a valid number");
134
136
  return;
135
137
  }
136
138
  // Prevent multiple decimal points
@@ -142,9 +144,27 @@ function AnySpendBondKit({ mode = "modal", recipientAddress, contractAddress, mi
142
144
  if (parts[1] && parts[1].length > 18) {
143
145
  return;
144
146
  }
145
- setEthAmount(value);
147
+ // Clean the input - remove leading zeros if not decimal
148
+ const cleanedValue = value.startsWith("0") && !value.startsWith("0.") ? value.replace(/^0+/, "0") : value;
149
+ setEthAmount(cleanedValue);
150
+ try {
151
+ const parsedAmount = (0, viem_1.parseEther)(cleanedValue);
152
+ if (parsedAmount <= BigInt(0)) {
153
+ setIsAmountValid(false);
154
+ setValidationError("Amount must be greater than 0");
155
+ return;
156
+ }
157
+ setIsAmountValid(true);
158
+ setValidationError("");
159
+ debouncedGetQuote(cleanedValue);
160
+ }
161
+ catch (error) {
162
+ console.error("Error validating amount:", error);
163
+ setIsAmountValid(false);
164
+ setValidationError("Please enter a valid amount");
165
+ }
146
166
  };
147
- const header = () => ((0, jsx_runtime_1.jsx)("div", { className: "w-full px-6 py-4", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex w-full flex-col items-center space-y-6", children: [(0, jsx_runtime_1.jsxs)("h2", { className: "text-[28px] font-bold", children: [tokenName, " (", tokenSymbol, ")"] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex w-full flex-col items-center space-y-2", children: [(0, jsx_runtime_1.jsxs)("span", { className: "text-[28px] font-bold", children: [ethAmount, " ETH"] }), quote && ((0, jsx_runtime_1.jsxs)("span", { className: "text-lg", children: ["\u2248 ", formatNumberWithCommas(parseFloat(quote).toFixed(4)), " ", tokenSymbol] }))] })] }) }));
167
+ const header = () => ((0, jsx_runtime_1.jsx)("div", { className: "w-full px-6 py-4", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex w-full flex-col items-center space-y-6", children: [(0, jsx_runtime_1.jsxs)("h2", { className: "text-[28px] font-bold", children: ["Buy ", tokenName, " (", tokenSymbol, ")"] }), (0, jsx_runtime_1.jsxs)("div", { className: "flex w-full flex-col items-center space-y-2", children: [(0, jsx_runtime_1.jsxs)("span", { className: "text-[28px] font-bold", children: [ethAmount, " ETH"] }), quote && ((0, jsx_runtime_1.jsxs)("span", { className: "text-lg", children: ["\u2248 ", formatNumberWithCommas(parseFloat(quote).toFixed(4)), " ", tokenSymbol] }))] })] }) }));
148
168
  // Show loading state while fetching token data
149
169
  if (isLoading) {
150
170
  return ((0, jsx_runtime_1.jsx)(react_1.StyleRoot, { children: (0, jsx_runtime_1.jsx)("div", { className: "b3-root b3-modal bg-b3-react-background flex w-full flex-col items-center p-8", children: (0, jsx_runtime_1.jsx)("p", { className: "text-as-primary/70 text-center text-sm", children: "Loading payment information..." }) }) }));
@@ -166,7 +186,7 @@ function AnySpendBondKit({ mode = "modal", recipientAddress, contractAddress, mi
166
186
  opacity: hasMounted ? 1 : 0,
167
187
  y: hasMounted ? 0 : 20,
168
188
  filter: hasMounted ? "blur(0px)" : "blur(10px)",
169
- }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: (0, jsx_runtime_1.jsxs)("div", { className: "space-y-4", children: [(0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-between", children: (0, jsx_runtime_1.jsx)("p", { className: "text-as-primary/70 text-sm font-medium", children: "Amount in ETH" }) }), (0, jsx_runtime_1.jsx)("div", { className: "relative", children: (0, jsx_runtime_1.jsx)(react_1.Input, { type: "text", inputMode: "decimal", placeholder: "0.1", value: ethAmount, onChange: e => validateAndSetAmount(e.target.value), className: `h-14 px-4 text-lg ${!isAmountValid && ethAmount ? "border-as-red" : "border-b3-react-border"}` }) }), !isAmountValid && ethAmount && (0, jsx_runtime_1.jsx)("p", { className: "text-as-red text-sm", children: validationError }), (0, jsx_runtime_1.jsxs)("div", { className: "bg-as-on-surface-2/30 rounded-lg border border-white/10 p-4 backdrop-blur-sm", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70 text-sm font-medium", children: "Total Cost:" }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary text-lg font-bold", children: [ethAmount || "0", " ETH"] }) })] }), isLoadingQuote ? ((0, jsx_runtime_1.jsx)("div", { className: "mt-2 text-center", children: (0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70 text-sm", children: "Calculating tokens..." }) })) : quote ? ((0, jsx_runtime_1.jsxs)("div", { className: "mt-2 flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70 text-sm font-medium", children: "You'll receive:" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary text-sm font-medium", children: ["\u2248 ", formatNumberWithCommas(parseFloat(quote).toFixed(4)), " ", tokenSymbol] })] })) : null] }), (0, jsx_runtime_1.jsx)(react_1.Button, { onClick: () => {
189
+ }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: (0, jsx_runtime_1.jsxs)("div", { className: "space-y-4", children: [(0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-between", children: (0, jsx_runtime_1.jsx)("p", { className: "text-as-primary/70 text-sm font-medium", children: "ETH Amount" }) }), (0, jsx_runtime_1.jsx)("div", { className: "relative", children: (0, jsx_runtime_1.jsx)(react_1.Input, { type: "text", inputMode: "decimal", placeholder: "0.1", value: ethAmount, onChange: e => validateAndSetAmount(e.target.value), className: `h-14 px-4 text-lg ${!isAmountValid && ethAmount ? "border-as-red" : "border-b3-react-border"}` }) }), !isAmountValid && ethAmount && (0, jsx_runtime_1.jsx)("p", { className: "text-as-red text-sm", children: validationError }), (0, jsx_runtime_1.jsxs)("div", { className: "bg-as-on-surface-2/30 rounded-lg border border-white/10 p-4 backdrop-blur-sm", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70 text-sm font-medium", children: "Total Cost:" }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center gap-2", children: (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary text-lg font-bold", children: [ethAmount || "0", " ETH"] }) })] }), isLoadingQuote ? ((0, jsx_runtime_1.jsx)("div", { className: "mt-2 text-center", children: (0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70 text-sm", children: "Calculating tokens..." }) })) : quote ? ((0, jsx_runtime_1.jsxs)("div", { className: "mt-2 flex items-center justify-between", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/70 text-sm font-medium", children: "You'll receive:" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-as-primary text-sm font-medium", children: ["\u2248 ", formatNumberWithCommas(parseFloat(quote).toFixed(4)), " ", tokenSymbol] })] })) : null] }), (0, jsx_runtime_1.jsx)(react_1.Button, { onClick: () => {
170
190
  if (isAmountValid && ethAmount) {
171
191
  setShowAmountPrompt(false);
172
192
  }
@@ -338,7 +338,7 @@ function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", recipient
338
338
  blockExplorers: [{ name: "B3 Explorer", url: "https://explorer.b3.fun/" }],
339
339
  testnet: undefined,
340
340
  },
341
- partnerId: String(process.env.NEXT_PUBLIC_GLOBAL_ACCOUNTS_PARTNER_ID),
341
+ partnerId: String(process.env.NEXT_PUBLIC_THIRDWEB_PARTNER_ID),
342
342
  type: "signInWithB3",
343
343
  showBackButton: false,
344
344
  });
@@ -1,13 +1,28 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useAnyspendOrderAndTransactions = useAnyspendOrderAndTransactions;
7
4
  const anyspend_1 = require("../../../anyspend/services/anyspend");
8
5
  const react_query_1 = require("@tanstack/react-query");
9
- const isEqual_js_1 = __importDefault(require("lodash/isEqual.js"));
10
6
  const react_1 = require("react");
7
+ // Custom deep equality function that handles BigInt
8
+ function customDeepEqual(oldData, newData) {
9
+ // Handle BigInt comparison
10
+ if (typeof oldData === "bigint" && typeof newData === "bigint") {
11
+ return oldData === newData;
12
+ }
13
+ // Handle arrays
14
+ if (Array.isArray(oldData) && Array.isArray(newData)) {
15
+ return oldData.length === newData.length && oldData.every((item, index) => customDeepEqual(item, newData[index]));
16
+ }
17
+ // Handle objects
18
+ if (oldData && newData && typeof oldData === "object" && typeof newData === "object") {
19
+ const keys1 = Object.keys(oldData);
20
+ const keys2 = Object.keys(newData);
21
+ return keys1.length === keys2.length && keys1.every(key => customDeepEqual(oldData[key], newData[key]));
22
+ }
23
+ // Handle primitive values
24
+ return oldData === newData;
25
+ }
11
26
  // Hook to fetch and auto-refresh order status and transaction details
12
27
  function useAnyspendOrderAndTransactions(isMainnet, orderId) {
13
28
  const selectFn = (0, react_1.useCallback)((data) => {
@@ -18,12 +33,12 @@ function useAnyspendOrderAndTransactions(isMainnet, orderId) {
18
33
  const { data, isLoading, refetch, error } = (0, react_query_1.useQuery)({
19
34
  queryKey: ["getAnyspendOrderAndTransactions", orderId],
20
35
  queryFn: () => anyspend_1.anyspendService.getOrderAndTransactions(isMainnet, orderId),
21
- enabled: Boolean(orderId),
36
+ enabled: !!orderId,
22
37
  refetchInterval: 3000,
23
38
  staleTime: 1000,
24
39
  select: selectFn,
25
40
  structuralSharing: (oldData, newData) => {
26
- if ((0, isEqual_js_1.default)(oldData, newData))
41
+ if (customDeepEqual(oldData, newData))
27
42
  return oldData;
28
43
  return newData;
29
44
  },