@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.
- package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +25 -5
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +1 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendOrderAndTransactions.js +21 -6
- package/dist/cjs/anyspend/types/req-res/getOrderAndTransactions.d.ts +2245 -0
- package/dist/cjs/anyspend/types/req-res/getOrderAndTransactions.js +9 -8
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +1 -1
- package/dist/cjs/global-account/react/components/ui/TabSystem.d.ts +2 -2
- package/dist/cjs/global-account/react/components/ui/TabSystem.js +5 -5
- package/dist/esm/anyspend/react/components/AnySpendBondKit.js +25 -5
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +1 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.js +21 -3
- package/dist/esm/anyspend/types/req-res/getOrderAndTransactions.d.ts +2245 -0
- package/dist/esm/anyspend/types/req-res/getOrderAndTransactions.js +8 -7
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +1 -1
- package/dist/esm/global-account/react/components/ui/TabSystem.d.ts +2 -2
- package/dist/esm/global-account/react/components/ui/TabSystem.js +4 -4
- package/dist/types/anyspend/types/req-res/getOrderAndTransactions.d.ts +2245 -0
- package/dist/types/global-account/react/components/ui/TabSystem.d.ts +2 -2
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +1 -2
- package/src/anyspend/react/components/AnySpendBondKit.tsx +26 -5
- package/src/anyspend/react/components/AnySpendCustom.tsx +1 -1
- package/src/anyspend/react/hooks/useAnyspendOrderAndTransactions.ts +26 -4
- package/src/anyspend/types/req-res/getOrderAndTransactions.ts +10 -7
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +1 -1
- package/src/global-account/react/components/StyleRoot.tsx +1 -0
- package/src/global-account/react/components/ui/TabSystem.tsx +36 -33
|
@@ -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
|
|
21
|
+
export declare const TabTrigger: React.ForwardRefExoticComponent<TabTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
22
22
|
interface TabsContentProps {
|
|
23
23
|
value: string;
|
|
24
24
|
children: ReactNode;
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ import { ArrowDown, ChevronRightCircle, ChevronsUpDown, CircleAlert, ClipboardIc
|
|
|
27
27
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
28
28
|
import { toast } from "sonner";
|
|
29
29
|
import { parseUnits } from "viem";
|
|
30
|
-
import {
|
|
30
|
+
import { b3Sepolia, base, mainnet, sepolia } from "viem/chains";
|
|
31
31
|
import { OrderDetails, OrderDetailsLoadingView } from "./common/OrderDetails";
|
|
32
32
|
import { OrderHistory } from "./common/OrderHistory";
|
|
33
33
|
import { OrderStatus } from "./common/OrderStatus";
|
|
@@ -35,7 +35,6 @@ import { OrderTokenAmount } from "./common/OrderTokenAmount";
|
|
|
35
35
|
import { PanelOnramp } from "./common/PanelOnramp";
|
|
36
36
|
import { PanelOnrampPayment } from "./common/PanelOnrampPayment";
|
|
37
37
|
import { TokenBalance } from "./common/TokenBalance";
|
|
38
|
-
import { Warning } from "./common/Warning";
|
|
39
38
|
import { EnterRecipientModal } from "./modals/EnterRecipientModal";
|
|
40
39
|
|
|
41
40
|
export interface RecipientOption {
|
|
@@ -155,8 +155,10 @@ export function AnySpendBondKit({
|
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
// Only allow
|
|
159
|
-
if (
|
|
158
|
+
// Only allow valid number format (no leading zeros unless decimal)
|
|
159
|
+
if (!/^(0|[1-9]\d*)?\.?\d*$/.test(value)) {
|
|
160
|
+
setIsAmountValid(false);
|
|
161
|
+
setValidationError("Please enter a valid number");
|
|
160
162
|
return;
|
|
161
163
|
}
|
|
162
164
|
|
|
@@ -171,14 +173,33 @@ export function AnySpendBondKit({
|
|
|
171
173
|
return;
|
|
172
174
|
}
|
|
173
175
|
|
|
174
|
-
|
|
176
|
+
// Clean the input - remove leading zeros if not decimal
|
|
177
|
+
const cleanedValue = value.startsWith("0") && !value.startsWith("0.") ? value.replace(/^0+/, "0") : value;
|
|
178
|
+
setEthAmount(cleanedValue);
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
const parsedAmount = parseEther(cleanedValue);
|
|
182
|
+
if (parsedAmount <= BigInt(0)) {
|
|
183
|
+
setIsAmountValid(false);
|
|
184
|
+
setValidationError("Amount must be greater than 0");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
setIsAmountValid(true);
|
|
189
|
+
setValidationError("");
|
|
190
|
+
debouncedGetQuote(cleanedValue);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error("Error validating amount:", error);
|
|
193
|
+
setIsAmountValid(false);
|
|
194
|
+
setValidationError("Please enter a valid amount");
|
|
195
|
+
}
|
|
175
196
|
};
|
|
176
197
|
|
|
177
198
|
const header = () => (
|
|
178
199
|
<div className="w-full px-6 py-4">
|
|
179
200
|
<div className="flex w-full flex-col items-center space-y-6">
|
|
180
201
|
<h2 className="text-[28px] font-bold">
|
|
181
|
-
{tokenName} ({tokenSymbol})
|
|
202
|
+
Buy {tokenName} ({tokenSymbol})
|
|
182
203
|
</h2>
|
|
183
204
|
<div className="flex w-full flex-col items-center space-y-2">
|
|
184
205
|
<span className="text-[28px] font-bold">{ethAmount} ETH</span>
|
|
@@ -267,7 +288,7 @@ export function AnySpendBondKit({
|
|
|
267
288
|
>
|
|
268
289
|
<div className="space-y-4">
|
|
269
290
|
<div className="flex items-center justify-between">
|
|
270
|
-
<p className="text-as-primary/70 text-sm font-medium">Amount
|
|
291
|
+
<p className="text-as-primary/70 text-sm font-medium">ETH Amount</p>
|
|
271
292
|
</div>
|
|
272
293
|
|
|
273
294
|
<div className="relative">
|
|
@@ -488,7 +488,7 @@ export function AnySpendCustom({
|
|
|
488
488
|
blockExplorers: [{ name: "B3 Explorer", url: "https://explorer.b3.fun/" }],
|
|
489
489
|
testnet: undefined,
|
|
490
490
|
},
|
|
491
|
-
partnerId: String(process.env.
|
|
491
|
+
partnerId: String(process.env.NEXT_PUBLIC_THIRDWEB_PARTNER_ID),
|
|
492
492
|
type: "signInWithB3",
|
|
493
493
|
showBackButton: false,
|
|
494
494
|
});
|
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import { anyspendService } from "@b3dotfun/sdk/anyspend/services/anyspend";
|
|
2
2
|
import { GetOrderAndTxsResponse } from "@b3dotfun/sdk/anyspend/types";
|
|
3
3
|
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
import isEqual from "lodash/isEqual.js";
|
|
5
4
|
import { useCallback, useMemo } from "react";
|
|
6
5
|
|
|
6
|
+
// Custom deep equality function that handles BigInt
|
|
7
|
+
function customDeepEqual(oldData: any, newData: any): boolean {
|
|
8
|
+
// Handle BigInt comparison
|
|
9
|
+
if (typeof oldData === "bigint" && typeof newData === "bigint") {
|
|
10
|
+
return oldData === newData;
|
|
11
|
+
}
|
|
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
|
+
|
|
18
|
+
// Handle objects
|
|
19
|
+
if (oldData && newData && typeof oldData === "object" && typeof newData === "object") {
|
|
20
|
+
const keys1 = Object.keys(oldData);
|
|
21
|
+
const keys2 = Object.keys(newData);
|
|
22
|
+
return keys1.length === keys2.length && keys1.every(key => customDeepEqual(oldData[key], newData[key]));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Handle primitive values
|
|
26
|
+
return oldData === newData;
|
|
27
|
+
}
|
|
28
|
+
|
|
7
29
|
// Hook to fetch and auto-refresh order status and transaction details
|
|
8
30
|
export function useAnyspendOrderAndTransactions(isMainnet: boolean, orderId: string | undefined) {
|
|
9
31
|
const selectFn = useCallback((data: any) => {
|
|
@@ -13,13 +35,13 @@ export function useAnyspendOrderAndTransactions(isMainnet: boolean, orderId: str
|
|
|
13
35
|
|
|
14
36
|
const { data, isLoading, refetch, error } = useQuery<GetOrderAndTxsResponse>({
|
|
15
37
|
queryKey: ["getAnyspendOrderAndTransactions", orderId],
|
|
16
|
-
queryFn: () => anyspendService.getOrderAndTransactions(isMainnet, orderId),
|
|
17
|
-
enabled:
|
|
38
|
+
queryFn: () => anyspendService.getOrderAndTransactions(isMainnet, orderId!),
|
|
39
|
+
enabled: !!orderId,
|
|
18
40
|
refetchInterval: 3000,
|
|
19
41
|
staleTime: 1000,
|
|
20
42
|
select: selectFn,
|
|
21
43
|
structuralSharing: (oldData, newData) => {
|
|
22
|
-
if (
|
|
44
|
+
if (customDeepEqual(oldData, newData)) return oldData;
|
|
23
45
|
return newData;
|
|
24
46
|
},
|
|
25
47
|
});
|
|
@@ -8,16 +8,19 @@ export const zGetOrderAndTransactionsRequest = z.object({
|
|
|
8
8
|
}),
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
+
export const zGetOrderAndTxsResponseData = z.object({
|
|
12
|
+
order: zOrder,
|
|
13
|
+
depositTxs: z.array(zDepositTransaction).nullable(),
|
|
14
|
+
relayTx: zRelayTransaction.nullable(),
|
|
15
|
+
executeTx: zExecuteTransaction.nullable(),
|
|
16
|
+
refundTxs: z.array(zRefundTransaction).nullable(),
|
|
17
|
+
});
|
|
18
|
+
export type GetOrderAndTxsResponseData = z.infer<typeof zGetOrderAndTxsResponseData>;
|
|
19
|
+
|
|
11
20
|
export const zGetOrderAndTxsResponse = z.object({
|
|
12
21
|
success: z.boolean(),
|
|
13
22
|
message: z.string(),
|
|
14
|
-
data:
|
|
15
|
-
order: zOrder,
|
|
16
|
-
depositTxs: z.array(zDepositTransaction).nullable(),
|
|
17
|
-
relayTx: zRelayTransaction.nullable(),
|
|
18
|
-
executeTx: zExecuteTransaction.nullable(),
|
|
19
|
-
refundTxs: z.array(zRefundTransaction).nullable(),
|
|
20
|
-
}),
|
|
23
|
+
data: zGetOrderAndTxsResponseData,
|
|
21
24
|
statusCode: z.number(),
|
|
22
25
|
});
|
|
23
26
|
export type GetOrderAndTxsResponse = z.infer<typeof zGetOrderAndTxsResponse>;
|
|
@@ -43,7 +43,7 @@ export function SignIn(props: SignInWithB3Props) {
|
|
|
43
43
|
} = useAccountWallet();
|
|
44
44
|
|
|
45
45
|
const isMobile = useIsMobile();
|
|
46
|
-
const { logout } = useAuthentication(String(process.env.
|
|
46
|
+
const { logout } = useAuthentication(String(process.env.NEXT_PUBLIC_THIRDWEB_PARTNER_ID));
|
|
47
47
|
const onDisconnect = async () => {
|
|
48
48
|
await logout();
|
|
49
49
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { cn } from "@b3dotfun/sdk/shared/utils/cn";
|
|
4
3
|
import { TransitionPanel } from "@b3dotfun/sdk/global-account/react";
|
|
4
|
+
import { cn } from "@b3dotfun/sdk/shared/utils/cn";
|
|
5
5
|
import { AnimatePresence, motion } from "framer-motion";
|
|
6
6
|
import React, { ReactNode, createContext, useContext } from "react";
|
|
7
7
|
|
|
@@ -67,39 +67,42 @@ interface TabTriggerProps {
|
|
|
67
67
|
disabled?: boolean;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
export
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
className={`${isSelected ? "opacity-100" : "opacity-50"} relative z-10 flex items-center gap-2 font-semibold uppercase`}
|
|
70
|
+
export const TabTrigger = React.forwardRef<HTMLButtonElement, TabTriggerProps>(
|
|
71
|
+
({ value, children, icon, disabled = false }, ref) => {
|
|
72
|
+
const context = useContext(TabsContext);
|
|
73
|
+
if (!context) throw new Error("TabTrigger must be used within Tabs");
|
|
74
|
+
|
|
75
|
+
const { selectedTab, onTabChange } = context;
|
|
76
|
+
const isSelected = selectedTab === value;
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<button
|
|
80
|
+
ref={ref}
|
|
81
|
+
role="tab"
|
|
82
|
+
aria-selected={isSelected}
|
|
83
|
+
aria-controls={`panel-${value}`}
|
|
84
|
+
id={`tab-${value}`}
|
|
85
|
+
onClick={() => onTabChange(value)}
|
|
86
|
+
className={`relative rounded-full px-4 py-2 text-sm text-white transition-all duration-200 hover:text-white focus:outline-none`}
|
|
87
|
+
disabled={disabled}
|
|
89
88
|
>
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
89
|
+
<span
|
|
90
|
+
className={`${isSelected ? "opacity-100" : "opacity-50"} relative z-10 flex items-center gap-2 font-semibold uppercase`}
|
|
91
|
+
>
|
|
92
|
+
{children}
|
|
93
|
+
{icon}
|
|
94
|
+
</span>
|
|
95
|
+
{isSelected && (
|
|
96
|
+
<motion.span
|
|
97
|
+
layoutId="activeTab"
|
|
98
|
+
transition={{ type: "spring", duration: 0.4 }}
|
|
99
|
+
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"
|
|
100
|
+
/>
|
|
101
|
+
)}
|
|
102
|
+
</button>
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
);
|
|
103
106
|
|
|
104
107
|
interface TabsContentProps {
|
|
105
108
|
value: string;
|