@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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zGetOrderAndTxsResponse = exports.zGetOrderAndTransactionsRequest = void 0;
3
+ exports.zGetOrderAndTxsResponse = exports.zGetOrderAndTxsResponseData = exports.zGetOrderAndTransactionsRequest = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const order_1 = require("../order");
6
6
  const transaction_1 = require("../transaction");
@@ -9,15 +9,16 @@ exports.zGetOrderAndTransactionsRequest = zod_1.z.object({
9
9
  orderId: zod_1.z.string(),
10
10
  }),
11
11
  });
12
+ exports.zGetOrderAndTxsResponseData = zod_1.z.object({
13
+ order: order_1.zOrder,
14
+ depositTxs: zod_1.z.array(transaction_1.zDepositTransaction).nullable(),
15
+ relayTx: transaction_1.zRelayTransaction.nullable(),
16
+ executeTx: transaction_1.zExecuteTransaction.nullable(),
17
+ refundTxs: zod_1.z.array(transaction_1.zRefundTransaction).nullable(),
18
+ });
12
19
  exports.zGetOrderAndTxsResponse = zod_1.z.object({
13
20
  success: zod_1.z.boolean(),
14
21
  message: zod_1.z.string(),
15
- data: zod_1.z.object({
16
- order: order_1.zOrder,
17
- depositTxs: zod_1.z.array(transaction_1.zDepositTransaction).nullable(),
18
- relayTx: transaction_1.zRelayTransaction.nullable(),
19
- executeTx: transaction_1.zExecuteTransaction.nullable(),
20
- refundTxs: zod_1.z.array(transaction_1.zRefundTransaction).nullable(),
21
- }),
22
+ data: exports.zGetOrderAndTxsResponseData,
22
23
  statusCode: zod_1.z.number(),
23
24
  });
@@ -18,7 +18,7 @@ function SignIn(props) {
18
18
  const { automaticallySetFirstEoa } = (0, react_1.useB3)();
19
19
  const { wallet, address: globalAddress, ensName, connectedSmartWallet, connectedEOAWallet, isActiveSmartWallet, isActiveEOAWallet, smartWalletIcon, eoaWalletIcon, } = (0, react_1.useAccountWallet)();
20
20
  const isMobile = (0, react_1.useIsMobile)();
21
- const { logout } = (0, react_1.useAuthentication)(String(process.env.NEXT_PUBLIC_GLOBAL_ACCOUNTS_PARTNER_ID));
21
+ const { logout } = (0, react_1.useAuthentication)(String(process.env.NEXT_PUBLIC_THIRDWEB_PARTNER_ID));
22
22
  const onDisconnect = async () => {
23
23
  await logout();
24
24
  };
@@ -1,4 +1,4 @@
1
- import { ReactNode } from "react";
1
+ import React, { ReactNode } from "react";
2
2
  interface TabsRootProps {
3
3
  value: string;
4
4
  onValueChange: (value: string) => void;
@@ -18,7 +18,7 @@ interface TabTriggerProps {
18
18
  icon?: ReactNode;
19
19
  disabled?: boolean;
20
20
  }
21
- export declare function TabTrigger({ value, children, icon, disabled }: TabTriggerProps): import("react/jsx-runtime").JSX.Element;
21
+ export declare const TabTrigger: React.ForwardRefExoticComponent<TabTriggerProps & React.RefAttributes<HTMLButtonElement>>;
22
22
  interface TabsContentProps {
23
23
  value: string;
24
24
  children: ReactNode;
@@ -34,14 +34,14 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  };
35
35
  })();
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.TabTrigger = void 0;
37
38
  exports.Tabs = Tabs;
38
39
  exports.TabsList = TabsList;
39
- exports.TabTrigger = TabTrigger;
40
40
  exports.TabsContent = TabsContent;
41
41
  exports.TabsTransitionWrapper = TabsTransitionWrapper;
42
42
  const jsx_runtime_1 = require("react/jsx-runtime");
43
- const cn_1 = require("../../../../shared/utils/cn");
44
43
  const react_1 = require("../../../../global-account/react");
44
+ const cn_1 = require("../../../../shared/utils/cn");
45
45
  const framer_motion_1 = require("framer-motion");
46
46
  const react_2 = __importStar(require("react"));
47
47
  const TabsContext = (0, react_2.createContext)(undefined);
@@ -51,14 +51,14 @@ function Tabs({ value, onValueChange, children, className = "" }) {
51
51
  function TabsList({ children, className = "", hideGradient = false }) {
52
52
  return ((0, jsx_runtime_1.jsxs)("div", { className: "relative w-full", children: [(0, jsx_runtime_1.jsx)("div", { role: "tablist", className: (0, cn_1.cn)("no-scrollbar relative mb-4 flex items-center gap-2 whitespace-nowrap", className), children: children }), (0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { mode: "wait", children: !hideGradient && ((0, jsx_runtime_1.jsxs)(framer_motion_1.motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.2, delay: 0.2 }, children: [(0, jsx_runtime_1.jsx)("div", { className: "pointer-events-none absolute bottom-0 left-0 top-0 z-10 w-8 bg-gradient-to-r from-[#15121c] to-transparent md:hidden" }), (0, jsx_runtime_1.jsx)("div", { className: "pointer-events-none absolute bottom-0 right-0 top-0 z-10 w-8 bg-gradient-to-l from-[#15121c] to-transparent md:hidden" })] }, "gradients-container")) })] }));
53
53
  }
54
- function TabTrigger({ value, children, icon, disabled = false }) {
54
+ exports.TabTrigger = react_2.default.forwardRef(({ value, children, icon, disabled = false }, ref) => {
55
55
  const context = (0, react_2.useContext)(TabsContext);
56
56
  if (!context)
57
57
  throw new Error("TabTrigger must be used within Tabs");
58
58
  const { selectedTab, onTabChange } = context;
59
59
  const isSelected = selectedTab === value;
60
- return ((0, jsx_runtime_1.jsxs)("button", { role: "tab", "aria-selected": isSelected, "aria-controls": `panel-${value}`, id: `tab-${value}`, onClick: () => onTabChange(value), className: `relative rounded-full px-4 py-2 text-sm text-white transition-all duration-200 hover:text-white focus:outline-none`, disabled: disabled, children: [(0, jsx_runtime_1.jsxs)("span", { className: `${isSelected ? "opacity-100" : "opacity-50"} relative z-10 flex items-center gap-2 font-semibold uppercase`, children: [children, icon] }), isSelected && ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.span, { layoutId: "activeTab", transition: { type: "spring", duration: 0.4 }, className: "from-as-light-brand to-as-brand/10 border-as-brand/30 absolute inset-0 z-0 rounded-full border border-t-white/15 bg-gradient-to-b shadow-lg" }))] }));
61
- }
60
+ return ((0, jsx_runtime_1.jsxs)("button", { ref: ref, role: "tab", "aria-selected": isSelected, "aria-controls": `panel-${value}`, id: `tab-${value}`, onClick: () => onTabChange(value), className: `relative rounded-full px-4 py-2 text-sm text-white transition-all duration-200 hover:text-white focus:outline-none`, disabled: disabled, children: [(0, jsx_runtime_1.jsxs)("span", { className: `${isSelected ? "opacity-100" : "opacity-50"} relative z-10 flex items-center gap-2 font-semibold uppercase`, children: [children, icon] }), isSelected && ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.span, { layoutId: "activeTab", transition: { type: "spring", duration: 0.4 }, className: "from-as-light-brand to-as-brand/10 border-as-brand/30 absolute inset-0 z-0 rounded-full border border-t-white/15 bg-gradient-to-b shadow-lg" }))] }));
61
+ });
62
62
  function TabsContent({ value, children }) {
63
63
  const context = (0, react_2.useContext)(TabsContext);
64
64
  if (!context)
@@ -126,8 +126,10 @@ export function AnySpendBondKit({ mode = "modal", recipientAddress, contractAddr
126
126
  setQuote(null);
127
127
  return;
128
128
  }
129
- // Only allow numbers and one decimal point
130
- if (!/^\d*\.?\d*$/.test(value)) {
129
+ // Only allow valid number format (no leading zeros unless decimal)
130
+ if (!/^(0|[1-9]\d*)?\.?\d*$/.test(value)) {
131
+ setIsAmountValid(false);
132
+ setValidationError("Please enter a valid number");
131
133
  return;
132
134
  }
133
135
  // Prevent multiple decimal points
@@ -139,9 +141,27 @@ export function AnySpendBondKit({ mode = "modal", recipientAddress, contractAddr
139
141
  if (parts[1] && parts[1].length > 18) {
140
142
  return;
141
143
  }
142
- setEthAmount(value);
144
+ // Clean the input - remove leading zeros if not decimal
145
+ const cleanedValue = value.startsWith("0") && !value.startsWith("0.") ? value.replace(/^0+/, "0") : value;
146
+ setEthAmount(cleanedValue);
147
+ try {
148
+ const parsedAmount = parseEther(cleanedValue);
149
+ if (parsedAmount <= BigInt(0)) {
150
+ setIsAmountValid(false);
151
+ setValidationError("Amount must be greater than 0");
152
+ return;
153
+ }
154
+ setIsAmountValid(true);
155
+ setValidationError("");
156
+ debouncedGetQuote(cleanedValue);
157
+ }
158
+ catch (error) {
159
+ console.error("Error validating amount:", error);
160
+ setIsAmountValid(false);
161
+ setValidationError("Please enter a valid amount");
162
+ }
143
163
  };
144
- const header = () => (_jsx("div", { className: "w-full px-6 py-4", children: _jsxs("div", { className: "flex w-full flex-col items-center space-y-6", children: [_jsxs("h2", { className: "text-[28px] font-bold", children: [tokenName, " (", tokenSymbol, ")"] }), _jsxs("div", { className: "flex w-full flex-col items-center space-y-2", children: [_jsxs("span", { className: "text-[28px] font-bold", children: [ethAmount, " ETH"] }), quote && (_jsxs("span", { className: "text-lg", children: ["\u2248 ", formatNumberWithCommas(parseFloat(quote).toFixed(4)), " ", tokenSymbol] }))] })] }) }));
164
+ const header = () => (_jsx("div", { className: "w-full px-6 py-4", children: _jsxs("div", { className: "flex w-full flex-col items-center space-y-6", children: [_jsxs("h2", { className: "text-[28px] font-bold", children: ["Buy ", tokenName, " (", tokenSymbol, ")"] }), _jsxs("div", { className: "flex w-full flex-col items-center space-y-2", children: [_jsxs("span", { className: "text-[28px] font-bold", children: [ethAmount, " ETH"] }), quote && (_jsxs("span", { className: "text-lg", children: ["\u2248 ", formatNumberWithCommas(parseFloat(quote).toFixed(4)), " ", tokenSymbol] }))] })] }) }));
145
165
  // Show loading state while fetching token data
146
166
  if (isLoading) {
147
167
  return (_jsx(StyleRoot, { children: _jsx("div", { className: "b3-root b3-modal bg-b3-react-background flex w-full flex-col items-center p-8", children: _jsx("p", { className: "text-as-primary/70 text-center text-sm", children: "Loading payment information..." }) }) }));
@@ -163,7 +183,7 @@ export function AnySpendBondKit({ mode = "modal", recipientAddress, contractAddr
163
183
  opacity: hasMounted ? 1 : 0,
164
184
  y: hasMounted ? 0 : 20,
165
185
  filter: hasMounted ? "blur(0px)" : "blur(10px)",
166
- }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: _jsxs("div", { className: "space-y-4", children: [_jsx("div", { className: "flex items-center justify-between", children: _jsx("p", { className: "text-as-primary/70 text-sm font-medium", children: "Amount in ETH" }) }), _jsx("div", { className: "relative", children: _jsx(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 && _jsx("p", { className: "text-as-red text-sm", children: validationError }), _jsxs("div", { className: "bg-as-on-surface-2/30 rounded-lg border border-white/10 p-4 backdrop-blur-sm", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("span", { className: "text-as-primary/70 text-sm font-medium", children: "Total Cost:" }), _jsx("div", { className: "flex items-center gap-2", children: _jsxs("span", { className: "text-as-primary text-lg font-bold", children: [ethAmount || "0", " ETH"] }) })] }), isLoadingQuote ? (_jsx("div", { className: "mt-2 text-center", children: _jsx("span", { className: "text-as-primary/70 text-sm", children: "Calculating tokens..." }) })) : quote ? (_jsxs("div", { className: "mt-2 flex items-center justify-between", children: [_jsx("span", { className: "text-as-primary/70 text-sm font-medium", children: "You'll receive:" }), _jsxs("span", { className: "text-as-primary text-sm font-medium", children: ["\u2248 ", formatNumberWithCommas(parseFloat(quote).toFixed(4)), " ", tokenSymbol] })] })) : null] }), _jsx(Button, { onClick: () => {
186
+ }, transition: { duration: 0.3, delay: 0.2, ease: "easeInOut" }, className: "bg-b3-react-background w-full p-6", children: _jsxs("div", { className: "space-y-4", children: [_jsx("div", { className: "flex items-center justify-between", children: _jsx("p", { className: "text-as-primary/70 text-sm font-medium", children: "ETH Amount" }) }), _jsx("div", { className: "relative", children: _jsx(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 && _jsx("p", { className: "text-as-red text-sm", children: validationError }), _jsxs("div", { className: "bg-as-on-surface-2/30 rounded-lg border border-white/10 p-4 backdrop-blur-sm", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("span", { className: "text-as-primary/70 text-sm font-medium", children: "Total Cost:" }), _jsx("div", { className: "flex items-center gap-2", children: _jsxs("span", { className: "text-as-primary text-lg font-bold", children: [ethAmount || "0", " ETH"] }) })] }), isLoadingQuote ? (_jsx("div", { className: "mt-2 text-center", children: _jsx("span", { className: "text-as-primary/70 text-sm", children: "Calculating tokens..." }) })) : quote ? (_jsxs("div", { className: "mt-2 flex items-center justify-between", children: [_jsx("span", { className: "text-as-primary/70 text-sm font-medium", children: "You'll receive:" }), _jsxs("span", { className: "text-as-primary text-sm font-medium", children: ["\u2248 ", formatNumberWithCommas(parseFloat(quote).toFixed(4)), " ", tokenSymbol] })] })) : null] }), _jsx(Button, { onClick: () => {
167
187
  if (isAmountValid && ethAmount) {
168
188
  setShowAmountPrompt(false);
169
189
  }
@@ -332,7 +332,7 @@ export function AnySpendCustom({ isMainnet = true, loadOrder, mode = "modal", re
332
332
  blockExplorers: [{ name: "B3 Explorer", url: "https://explorer.b3.fun/" }],
333
333
  testnet: undefined,
334
334
  },
335
- partnerId: String(process.env.NEXT_PUBLIC_GLOBAL_ACCOUNTS_PARTNER_ID),
335
+ partnerId: String(process.env.NEXT_PUBLIC_THIRDWEB_PARTNER_ID),
336
336
  type: "signInWithB3",
337
337
  showBackButton: false,
338
338
  });
@@ -1,7 +1,25 @@
1
1
  import { anyspendService } from "../../../anyspend/services/anyspend.js";
2
2
  import { useQuery } from "@tanstack/react-query";
3
- import isEqual from "lodash/isEqual.js";
4
3
  import { useCallback, useMemo } from "react";
4
+ // Custom deep equality function that handles BigInt
5
+ function customDeepEqual(oldData, newData) {
6
+ // Handle BigInt comparison
7
+ if (typeof oldData === "bigint" && typeof newData === "bigint") {
8
+ return oldData === newData;
9
+ }
10
+ // Handle arrays
11
+ if (Array.isArray(oldData) && Array.isArray(newData)) {
12
+ return oldData.length === newData.length && oldData.every((item, index) => customDeepEqual(item, newData[index]));
13
+ }
14
+ // Handle objects
15
+ if (oldData && newData && typeof oldData === "object" && typeof newData === "object") {
16
+ const keys1 = Object.keys(oldData);
17
+ const keys2 = Object.keys(newData);
18
+ return keys1.length === keys2.length && keys1.every(key => customDeepEqual(oldData[key], newData[key]));
19
+ }
20
+ // Handle primitive values
21
+ return oldData === newData;
22
+ }
5
23
  // Hook to fetch and auto-refresh order status and transaction details
6
24
  export function useAnyspendOrderAndTransactions(isMainnet, orderId) {
7
25
  const selectFn = useCallback((data) => {
@@ -12,12 +30,12 @@ export function useAnyspendOrderAndTransactions(isMainnet, orderId) {
12
30
  const { data, isLoading, refetch, error } = useQuery({
13
31
  queryKey: ["getAnyspendOrderAndTransactions", orderId],
14
32
  queryFn: () => anyspendService.getOrderAndTransactions(isMainnet, orderId),
15
- enabled: Boolean(orderId),
33
+ enabled: !!orderId,
16
34
  refetchInterval: 3000,
17
35
  staleTime: 1000,
18
36
  select: selectFn,
19
37
  structuralSharing: (oldData, newData) => {
20
- if (isEqual(oldData, newData))
38
+ if (customDeepEqual(oldData, newData))
21
39
  return oldData;
22
40
  return newData;
23
41
  },