@b3dotfun/sdk 0.1.64 → 0.1.65-alpha.1
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/AnySpend.js +3 -14
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -50
- package/dist/cjs/anyspend/react/components/QRDeposit.js +2 -12
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +1 -1
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
- package/dist/cjs/anyspend/react/hooks/useOnOrderSuccess.js +27 -0
- package/dist/cjs/anyspend/types/api.d.ts +10 -287
- package/dist/esm/anyspend/react/components/AnySpend.js +3 -14
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +4 -17
- package/dist/esm/anyspend/react/components/QRDeposit.js +2 -12
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +1 -1
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
- package/dist/esm/anyspend/react/hooks/useOnOrderSuccess.js +24 -0
- package/dist/esm/anyspend/types/api.d.ts +10 -287
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
- package/dist/types/anyspend/types/api.d.ts +10 -287
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +3 -16
- package/src/anyspend/react/components/AnySpendCustom.tsx +3 -18
- package/src/anyspend/react/components/QRDeposit.tsx +2 -13
- package/src/anyspend/react/components/common/OrderDetails.tsx +1 -1
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useOnOrderSuccess.ts +36 -0
- package/src/anyspend/types/api.ts +10 -287
package/package.json
CHANGED
|
@@ -52,6 +52,7 @@ import { useAutoSelectCryptoPaymentMethod } from "../hooks/useAutoSelectCryptoPa
|
|
|
52
52
|
import { useConnectedWalletDisplay } from "../hooks/useConnectedWalletDisplay";
|
|
53
53
|
import { useCryptoPaymentMethodState } from "../hooks/useCryptoPaymentMethodState";
|
|
54
54
|
import { useDirectTransfer } from "../hooks/useDirectTransfer";
|
|
55
|
+
import { useOnOrderSuccess } from "../hooks/useOnOrderSuccess";
|
|
55
56
|
import { useRecipientAddressState } from "../hooks/useRecipientAddressState";
|
|
56
57
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper";
|
|
57
58
|
import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod";
|
|
@@ -208,9 +209,6 @@ function AnySpendInner({
|
|
|
208
209
|
toAmount?: string;
|
|
209
210
|
} | null>(null);
|
|
210
211
|
|
|
211
|
-
// Track if onSuccess has been called for the current order
|
|
212
|
-
const onSuccessCalled = useRef(false);
|
|
213
|
-
|
|
214
212
|
// Track animation direction for TransitionPanel
|
|
215
213
|
const animationDirection = useRef<"forward" | "back" | null>(null);
|
|
216
214
|
// Track previous panel for proper back navigation
|
|
@@ -704,19 +702,8 @@ function AnySpendInner({
|
|
|
704
702
|
}
|
|
705
703
|
}, [anyspendQuote, isSrcInputDirty, destinationTokenAmount]);
|
|
706
704
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
console.log("Calling onSuccess");
|
|
710
|
-
const txHash = oat?.data?.executeTx?.txHash;
|
|
711
|
-
onSuccess?.(txHash);
|
|
712
|
-
onSuccessCalled.current = true;
|
|
713
|
-
}
|
|
714
|
-
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
715
|
-
|
|
716
|
-
// Reset flag when orderId changes
|
|
717
|
-
useEffect(() => {
|
|
718
|
-
onSuccessCalled.current = false;
|
|
719
|
-
}, [orderId]);
|
|
705
|
+
// Call onSuccess when order is executed
|
|
706
|
+
useOnOrderSuccess({ orderData: oat, orderId, onSuccess });
|
|
720
707
|
|
|
721
708
|
const { createOrder, isCreatingOrder } = useAnyspendCreateOrder({
|
|
722
709
|
onSuccess: data => {
|
|
@@ -45,6 +45,7 @@ import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
|
45
45
|
|
|
46
46
|
import { base } from "viem/chains";
|
|
47
47
|
import { useCryptoPaymentMethodState } from "../hooks/useCryptoPaymentMethodState";
|
|
48
|
+
import { useOnOrderSuccess } from "../hooks/useOnOrderSuccess";
|
|
48
49
|
import { useRecipientAddressState } from "../hooks/useRecipientAddressState";
|
|
49
50
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper";
|
|
50
51
|
import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod";
|
|
@@ -274,9 +275,6 @@ function AnySpendCustomInner({
|
|
|
274
275
|
|
|
275
276
|
const [orderId, setOrderId] = useState<string | undefined>(loadOrder);
|
|
276
277
|
|
|
277
|
-
// Track if onSuccess has been called for the current order
|
|
278
|
-
const onSuccessCalled = React.useRef(false);
|
|
279
|
-
|
|
280
278
|
const [srcChainId, setSrcChainId] = useState<number>(base.id);
|
|
281
279
|
|
|
282
280
|
// Get token list for token balance check
|
|
@@ -433,21 +431,8 @@ function AnySpendCustomInner({
|
|
|
433
431
|
const { geoData, isOnrampSupported, coinbaseAvailablePaymentMethods, stripeOnrampSupport, stripeWeb2Support } =
|
|
434
432
|
useGeoOnrampOptions(srcFiatAmountForGeoCheck);
|
|
435
433
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
console.log("Calling onSuccess");
|
|
439
|
-
const relayTxs = oat?.data?.relayTxs;
|
|
440
|
-
const lastRelayTxHash = relayTxs?.[relayTxs.length - 1]?.txHash;
|
|
441
|
-
const txHash = oat?.data?.executeTx?.txHash || lastRelayTxHash;
|
|
442
|
-
onSuccess?.(txHash);
|
|
443
|
-
onSuccessCalled.current = true;
|
|
444
|
-
}
|
|
445
|
-
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, oat?.data?.relayTxs, onSuccess]);
|
|
446
|
-
|
|
447
|
-
// Reset flag when orderId changes
|
|
448
|
-
useEffect(() => {
|
|
449
|
-
onSuccessCalled.current = false;
|
|
450
|
-
}, [orderId]);
|
|
434
|
+
// Call onSuccess when order is executed
|
|
435
|
+
useOnOrderSuccess({ orderData: oat, orderId, onSuccess });
|
|
451
436
|
|
|
452
437
|
const { createOrder: createRegularOrder, isCreatingOrder: isCreatingRegularOrder } = useAnyspendCreateOrder({
|
|
453
438
|
onSuccess: data => {
|
|
@@ -8,6 +8,7 @@ import { QRCodeSVG } from "qrcode.react";
|
|
|
8
8
|
import { useEffect, useRef, useState } from "react";
|
|
9
9
|
import { useAnyspendOrderAndTransactions } from "../hooks/useAnyspendOrderAndTransactions";
|
|
10
10
|
import { useCreateDepositFirstOrder } from "../hooks/useCreateDepositFirstOrder";
|
|
11
|
+
import { useOnOrderSuccess } from "../hooks/useOnOrderSuccess";
|
|
11
12
|
import { TransferResult, useWatchTransfer } from "../hooks/useWatchTransfer";
|
|
12
13
|
import { DepositContractConfig } from "./AnySpendDeposit";
|
|
13
14
|
import { ChainTokenIcon } from "./common/ChainTokenIcon";
|
|
@@ -90,7 +91,6 @@ export function QRDeposit({
|
|
|
90
91
|
const [orderId, setOrderId] = useState<string | undefined>();
|
|
91
92
|
const [globalAddress, setGlobalAddress] = useState<string | undefined>();
|
|
92
93
|
const orderCreatedRef = useRef(false);
|
|
93
|
-
const onSuccessCalled = useRef(false);
|
|
94
94
|
const [transferResult, setTransferResult] = useState<TransferResult | null>(null);
|
|
95
95
|
|
|
96
96
|
// Source token/chain as state (can be changed by user)
|
|
@@ -189,18 +189,7 @@ export function QRDeposit({
|
|
|
189
189
|
]);
|
|
190
190
|
|
|
191
191
|
// Call onSuccess when order is executed
|
|
192
|
-
|
|
193
|
-
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
194
|
-
const txHash = oat?.data?.executeTx?.txHash;
|
|
195
|
-
onSuccess?.(txHash);
|
|
196
|
-
onSuccessCalled.current = true;
|
|
197
|
-
}
|
|
198
|
-
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
199
|
-
|
|
200
|
-
// Reset onSuccess flag when orderId changes
|
|
201
|
-
useEffect(() => {
|
|
202
|
-
onSuccessCalled.current = false;
|
|
203
|
-
}, [orderId]);
|
|
192
|
+
useOnOrderSuccess({ orderData: oat, orderId, onSuccess });
|
|
204
193
|
|
|
205
194
|
// For pure transfers, always use recipient address; for orders, use global address
|
|
206
195
|
const displayAddress = isPureTransfer ? recipientAddress : globalAddress || recipientAddress;
|
|
@@ -959,7 +959,7 @@ export const OrderDetails = memo(function OrderDetails({
|
|
|
959
959
|
<OrderStatus order={order} selectedCryptoPaymentMethod={effectiveCryptoPaymentMethod} />
|
|
960
960
|
{statusDisplay === "processing" && (
|
|
961
961
|
<>
|
|
962
|
-
{order.onrampMetadata ? (
|
|
962
|
+
{order.onrampMetadata && order.onrampMetadata.vendor !== "none" ? (
|
|
963
963
|
<PaymentVendorUI order={order} dstTokenSymbol={dstToken.symbol} />
|
|
964
964
|
) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ||
|
|
965
965
|
effectiveCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ? (
|
|
@@ -12,6 +12,7 @@ export * from "./useGasPrice";
|
|
|
12
12
|
export * from "./useGeoOnrampOptions";
|
|
13
13
|
export * from "./useGetGeo";
|
|
14
14
|
export * from "./useHyperliquidTransfer";
|
|
15
|
+
export * from "./useOnOrderSuccess";
|
|
15
16
|
export * from "./useRecipientAddressState";
|
|
16
17
|
export * from "./useSigMint";
|
|
17
18
|
export * from "./useStripeClientSecret";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { GetOrderAndTxsResponse } from "../../types/api_req_res";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hook to call onSuccess callback when an order is executed.
|
|
6
|
+
* Handles fallback to relayTxs when executeTx is null.
|
|
7
|
+
*/
|
|
8
|
+
export function useOnOrderSuccess({
|
|
9
|
+
orderData,
|
|
10
|
+
orderId,
|
|
11
|
+
onSuccess,
|
|
12
|
+
}: {
|
|
13
|
+
orderData: GetOrderAndTxsResponse | undefined;
|
|
14
|
+
orderId: string | undefined;
|
|
15
|
+
onSuccess?: (txHash?: string) => void;
|
|
16
|
+
}) {
|
|
17
|
+
const onSuccessCalled = useRef(false);
|
|
18
|
+
const prevOrderId = useRef(orderId);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
// Reset flag when orderId changes
|
|
22
|
+
if (prevOrderId.current !== orderId) {
|
|
23
|
+
onSuccessCalled.current = false;
|
|
24
|
+
prevOrderId.current = orderId;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Call onSuccess when order is executed
|
|
28
|
+
if (orderData?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
29
|
+
const relayTxs = orderData?.data?.relayTxs;
|
|
30
|
+
const lastSuccessfulRelayTx = relayTxs?.filter(tx => tx.status === "success").pop();
|
|
31
|
+
const txHash = orderData?.data?.executeTx?.txHash || lastSuccessfulRelayTx?.txHash;
|
|
32
|
+
onSuccess?.(txHash);
|
|
33
|
+
onSuccessCalled.current = true;
|
|
34
|
+
}
|
|
35
|
+
}, [orderData, orderId, onSuccess]);
|
|
36
|
+
}
|