@b3dotfun/sdk 0.0.63-test.0 → 0.0.63-test.0-alpha.0
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/AnySpendCustomExactIn.d.ts +34 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +275 -0
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.js +288 -0
- package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
- package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.js +33 -0
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +10 -2
- package/dist/cjs/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -3
- package/dist/cjs/anyspend/react/components/index.d.ts +5 -1
- package/dist/cjs/anyspend/react/components/index.js +11 -3
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
- package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +30 -8
- package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendQuote.js +1 -1
- package/dist/cjs/anyspend/types/api.d.ts +665 -3
- package/dist/cjs/anyspend/utils/orderPayload.js +4 -0
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +10 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +7 -2
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +31 -1
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +269 -0
- package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
- package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.js +285 -0
- package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
- package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.js +30 -0
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +10 -2
- package/dist/esm/anyspend/react/components/common/OrderDetailsCollapsible.js +2 -3
- package/dist/esm/anyspend/react/components/index.d.ts +5 -1
- package/dist/esm/anyspend/react/components/index.js +5 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
- package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +30 -8
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendQuote.js +1 -1
- package/dist/esm/anyspend/types/api.d.ts +665 -3
- package/dist/esm/anyspend/utils/orderPayload.js +4 -0
- package/dist/esm/global-account/react/components/B3DynamicModal.js +11 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +7 -2
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +31 -1
- package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +34 -0
- package/dist/types/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +9 -0
- package/dist/types/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +11 -0
- package/dist/types/anyspend/react/components/index.d.ts +5 -1
- package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +25 -3
- package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +116 -0
- package/dist/types/anyspend/types/api.d.ts +665 -3
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -2
- package/dist/types/global-account/react/stores/useModalStore.d.ts +31 -1
- package/package.json +3 -3
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +595 -0
- package/src/anyspend/react/components/AnySpendStakeB3ExactIn.tsx +522 -0
- package/src/anyspend/react/components/AnySpendStakeUpsideExactIn.tsx +73 -0
- package/src/anyspend/react/components/common/OrderDetails.tsx +10 -2
- package/src/anyspend/react/components/common/OrderDetailsCollapsible.tsx +2 -3
- package/src/anyspend/react/components/index.ts +5 -1
- package/src/anyspend/react/hooks/useAnyspendFlow.ts +38 -8
- package/src/anyspend/react/hooks/useAnyspendQuote.ts +1 -1
- package/src/anyspend/types/api.ts +669 -1
- package/src/anyspend/utils/orderPayload.ts +5 -1
- package/src/global-account/react/components/B3DynamicModal.tsx +11 -1
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +2 -2
- package/src/global-account/react/hooks/useAuthentication.ts +10 -2
- package/src/global-account/react/stores/useModalStore.ts +34 -0
|
@@ -43,13 +43,17 @@ interface UseAnyspendFlowProps {
|
|
|
43
43
|
loadOrder?: string;
|
|
44
44
|
isDepositMode?: boolean;
|
|
45
45
|
onOrderSuccess?: (orderId: string) => void;
|
|
46
|
-
onTransactionSuccess?: (amount
|
|
46
|
+
onTransactionSuccess?: (amount: string) => void;
|
|
47
47
|
sourceTokenAddress?: string;
|
|
48
48
|
sourceTokenChainId?: number;
|
|
49
|
+
destinationTokenAddress?: string;
|
|
50
|
+
destinationTokenChainId?: number;
|
|
49
51
|
slippage?: number;
|
|
50
52
|
disableUrlParamManagement?: boolean;
|
|
53
|
+
orderType?: "hype_duel" | "custom_exact_in";
|
|
51
54
|
}
|
|
52
55
|
|
|
56
|
+
// This hook serves for order hype_duel and custom_exact_in
|
|
53
57
|
export function useAnyspendFlow({
|
|
54
58
|
paymentType = "crypto",
|
|
55
59
|
recipientAddress,
|
|
@@ -59,8 +63,11 @@ export function useAnyspendFlow({
|
|
|
59
63
|
onTransactionSuccess,
|
|
60
64
|
sourceTokenAddress,
|
|
61
65
|
sourceTokenChainId,
|
|
66
|
+
destinationTokenAddress,
|
|
67
|
+
destinationTokenChainId,
|
|
62
68
|
slippage = 0,
|
|
63
69
|
disableUrlParamManagement = false,
|
|
70
|
+
orderType = "hype_duel",
|
|
64
71
|
}: UseAnyspendFlowProps) {
|
|
65
72
|
const searchParams = useSearchParamsSSR();
|
|
66
73
|
const router = useRouter();
|
|
@@ -70,17 +77,21 @@ export function useAnyspendFlow({
|
|
|
70
77
|
const [orderId, setOrderId] = useState<string | undefined>(loadOrder);
|
|
71
78
|
const { orderAndTransactions: oat } = useAnyspendOrderAndTransactions(orderId);
|
|
72
79
|
|
|
73
|
-
// Token selection state - use provided sourceTokenChainId if available
|
|
80
|
+
// Token selection state - use provided sourceTokenChainId and destinationTokenChainId if available
|
|
74
81
|
const [selectedSrcChainId, setSelectedSrcChainId] = useState<number>(
|
|
75
82
|
sourceTokenChainId || (paymentType === "fiat" ? base.id : mainnet.id),
|
|
76
83
|
);
|
|
77
|
-
const [selectedDstChainId, setSelectedDstChainId] = useState<number>(base.id); // Default to Base for cross-chain swaps
|
|
78
84
|
const defaultSrcToken = paymentType === "fiat" ? USDC_BASE : getDefaultToken(selectedSrcChainId);
|
|
85
|
+
const defaultDstToken = B3_TOKEN; // Default destination token
|
|
79
86
|
const [selectedSrcToken, setSelectedSrcToken] = useState<components["schemas"]["Token"]>(defaultSrcToken);
|
|
87
|
+
const [selectedDstToken, setSelectedDstToken] = useState<components["schemas"]["Token"]>(defaultDstToken);
|
|
80
88
|
const [srcAmount, setSrcAmount] = useState<string>(paymentType === "fiat" ? "5" : "0.1");
|
|
81
89
|
const [dstAmount, setDstAmount] = useState<string>("");
|
|
82
90
|
const [isSrcInputDirty, setIsSrcInputDirty] = useState(true);
|
|
83
91
|
|
|
92
|
+
// Derive destination chain ID from token or prop (cannot change)
|
|
93
|
+
const selectedDstChainId = destinationTokenChainId || selectedDstToken.chainId;
|
|
94
|
+
|
|
84
95
|
// Payment method state
|
|
85
96
|
const [selectedCryptoPaymentMethod, setSelectedCryptoPaymentMethod] = useState<CryptoPaymentMethodType>(
|
|
86
97
|
CryptoPaymentMethodType.NONE,
|
|
@@ -148,6 +159,24 @@ export function useAnyspendFlow({
|
|
|
148
159
|
fetchSourceToken();
|
|
149
160
|
}, [sourceTokenAddress, sourceTokenChainId]);
|
|
150
161
|
|
|
162
|
+
// Fetch specific token when destinationTokenAddress and destinationTokenChainId are provided
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
const fetchDestinationToken = async () => {
|
|
165
|
+
if (destinationTokenAddress && destinationTokenChainId) {
|
|
166
|
+
try {
|
|
167
|
+
const token = await anyspendService.getToken(destinationTokenChainId, destinationTokenAddress);
|
|
168
|
+
setSelectedDstToken(token);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
console.error("Failed to fetch destination token:", error);
|
|
171
|
+
toast.error(`Failed to load token ${destinationTokenAddress} on chain ${destinationTokenChainId}`);
|
|
172
|
+
// Keep the default token on error
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
fetchDestinationToken();
|
|
178
|
+
}, [destinationTokenAddress, destinationTokenChainId]);
|
|
179
|
+
|
|
151
180
|
// Helper function for onramp vendor mapping
|
|
152
181
|
const getOnrampVendor = (paymentMethod: FiatPaymentMethod): "coinbase" | "stripe" | "stripe-web2" | undefined => {
|
|
153
182
|
switch (paymentMethod) {
|
|
@@ -168,8 +197,8 @@ export function useAnyspendFlow({
|
|
|
168
197
|
srcChain: paymentType === "fiat" ? base.id : selectedSrcChainId,
|
|
169
198
|
dstChain: isDepositMode ? base.id : selectedDstChainId, // For deposits, always Base; for swaps, use selected destination
|
|
170
199
|
srcTokenAddress: paymentType === "fiat" ? USDC_BASE.address : selectedSrcToken.address,
|
|
171
|
-
dstTokenAddress:
|
|
172
|
-
type:
|
|
200
|
+
dstTokenAddress: selectedDstToken.address,
|
|
201
|
+
type: orderType,
|
|
173
202
|
amount: activeInputAmountInWei,
|
|
174
203
|
recipientAddress: selectedRecipientAddress,
|
|
175
204
|
onrampVendor: paymentType === "fiat" ? getOnrampVendor(selectedFiatPaymentMethod) : undefined,
|
|
@@ -256,7 +285,7 @@ export function useAnyspendFlow({
|
|
|
256
285
|
const formattedActualDstAmount = amount
|
|
257
286
|
? formatTokenAmount(BigInt(amount), oat.data.order.metadata.dstToken.decimals)
|
|
258
287
|
: undefined;
|
|
259
|
-
onTransactionSuccess?.(formattedActualDstAmount);
|
|
288
|
+
onTransactionSuccess?.(formattedActualDstAmount ?? "");
|
|
260
289
|
}
|
|
261
290
|
}, [
|
|
262
291
|
oat?.data?.order.status,
|
|
@@ -275,10 +304,11 @@ export function useAnyspendFlow({
|
|
|
275
304
|
// Token state
|
|
276
305
|
selectedSrcChainId,
|
|
277
306
|
setSelectedSrcChainId,
|
|
278
|
-
selectedDstChainId,
|
|
279
|
-
setSelectedDstChainId,
|
|
307
|
+
selectedDstChainId, // Derived, not stateful
|
|
280
308
|
selectedSrcToken,
|
|
281
309
|
setSelectedSrcToken,
|
|
310
|
+
selectedDstToken,
|
|
311
|
+
setSelectedDstToken,
|
|
282
312
|
srcAmount,
|
|
283
313
|
setSrcAmount,
|
|
284
314
|
dstAmount,
|
|
@@ -27,7 +27,7 @@ export function useAnyspendQuote(req: GetQuoteRequest): UseAnyspendQuoteResult {
|
|
|
27
27
|
req.srcTokenAddress &&
|
|
28
28
|
req.dstTokenAddress &&
|
|
29
29
|
BigInt(
|
|
30
|
-
req.type === "swap" || req.type === "hype_duel"
|
|
30
|
+
req.type === "swap" || req.type === "hype_duel" || req.type === "x402_swap" || req.type === "custom_exact_in"
|
|
31
31
|
? req.amount
|
|
32
32
|
: req.type === "mint_nft"
|
|
33
33
|
? req.price
|