@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
|
@@ -18,6 +18,7 @@ import { useAutoSelectCryptoPaymentMethod } from "../hooks/useAutoSelectCryptoPa
|
|
|
18
18
|
import { useConnectedWalletDisplay } from "../hooks/useConnectedWalletDisplay.js";
|
|
19
19
|
import { useCryptoPaymentMethodState } from "../hooks/useCryptoPaymentMethodState.js";
|
|
20
20
|
import { useDirectTransfer } from "../hooks/useDirectTransfer.js";
|
|
21
|
+
import { useOnOrderSuccess } from "../hooks/useOnOrderSuccess.js";
|
|
21
22
|
import { useRecipientAddressState } from "../hooks/useRecipientAddressState.js";
|
|
22
23
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
|
|
23
24
|
import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod.js";
|
|
@@ -65,8 +66,6 @@ function AnySpendInner({ sourceChainId, destinationTokenAddress, destinationToke
|
|
|
65
66
|
// Add refs to track URL state
|
|
66
67
|
const initialUrlProcessed = useRef(false);
|
|
67
68
|
const lastUrlUpdate = useRef(null);
|
|
68
|
-
// Track if onSuccess has been called for the current order
|
|
69
|
-
const onSuccessCalled = useRef(false);
|
|
70
69
|
// Track animation direction for TransitionPanel
|
|
71
70
|
const animationDirection = useRef(null);
|
|
72
71
|
// Track previous panel for proper back navigation
|
|
@@ -486,18 +485,8 @@ function AnySpendInner({ sourceChainId, destinationTokenAddress, destinationToke
|
|
|
486
485
|
}
|
|
487
486
|
}
|
|
488
487
|
}, [anyspendQuote, isSrcInputDirty, destinationTokenAmount]);
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
console.log("Calling onSuccess");
|
|
492
|
-
const txHash = oat?.data?.executeTx?.txHash;
|
|
493
|
-
onSuccess?.(txHash);
|
|
494
|
-
onSuccessCalled.current = true;
|
|
495
|
-
}
|
|
496
|
-
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
497
|
-
// Reset flag when orderId changes
|
|
498
|
-
useEffect(() => {
|
|
499
|
-
onSuccessCalled.current = false;
|
|
500
|
-
}, [orderId]);
|
|
488
|
+
// Call onSuccess when order is executed
|
|
489
|
+
useOnOrderSuccess({ orderData: oat, orderId, onSuccess });
|
|
501
490
|
const { createOrder, isCreatingOrder } = useAnyspendCreateOrder({
|
|
502
491
|
onSuccess: data => {
|
|
503
492
|
const orderId = data.data.id;
|
|
@@ -11,9 +11,10 @@ import { simpleHashChainToChainName } from "../../../shared/utils/simplehash.js"
|
|
|
11
11
|
import invariant from "invariant";
|
|
12
12
|
import { ChevronRight, ChevronRightCircle, Info, Loader2 } from "lucide-react";
|
|
13
13
|
import { motion } from "motion/react";
|
|
14
|
-
import
|
|
14
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
15
15
|
import { base } from "viem/chains";
|
|
16
16
|
import { useCryptoPaymentMethodState } from "../hooks/useCryptoPaymentMethodState.js";
|
|
17
|
+
import { useOnOrderSuccess } from "../hooks/useOnOrderSuccess.js";
|
|
17
18
|
import { useRecipientAddressState } from "../hooks/useRecipientAddressState.js";
|
|
18
19
|
import { AnySpendFingerprintWrapper, getFingerprintConfig } from "./AnySpendFingerprintWrapper.js";
|
|
19
20
|
import { CryptoPaymentMethod, CryptoPaymentMethodType } from "./common/CryptoPaymentMethod.js";
|
|
@@ -126,8 +127,6 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
126
127
|
globalAddress: currentWallet.address,
|
|
127
128
|
});
|
|
128
129
|
const [orderId, setOrderId] = useState(loadOrder);
|
|
129
|
-
// Track if onSuccess has been called for the current order
|
|
130
|
-
const onSuccessCalled = React.useRef(false);
|
|
131
130
|
const [srcChainId, setSrcChainId] = useState(base.id);
|
|
132
131
|
// Get token list for token balance check
|
|
133
132
|
const chainName = useMemo(() => simpleHashChainToChainName(srcChainId), [srcChainId]);
|
|
@@ -265,20 +264,8 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
265
264
|
}, [activeTab, srcFiatAmountForGeoCheck]);
|
|
266
265
|
// Get geo data and onramp options (use srcFiatAmountForGeoCheck to check availability regardless of activeTab)
|
|
267
266
|
const { geoData, isOnrampSupported, coinbaseAvailablePaymentMethods, stripeOnrampSupport, stripeWeb2Support } = useGeoOnrampOptions(srcFiatAmountForGeoCheck);
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
console.log("Calling onSuccess");
|
|
271
|
-
const relayTxs = oat?.data?.relayTxs;
|
|
272
|
-
const lastRelayTxHash = relayTxs?.[relayTxs.length - 1]?.txHash;
|
|
273
|
-
const txHash = oat?.data?.executeTx?.txHash || lastRelayTxHash;
|
|
274
|
-
onSuccess?.(txHash);
|
|
275
|
-
onSuccessCalled.current = true;
|
|
276
|
-
}
|
|
277
|
-
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, oat?.data?.relayTxs, onSuccess]);
|
|
278
|
-
// Reset flag when orderId changes
|
|
279
|
-
useEffect(() => {
|
|
280
|
-
onSuccessCalled.current = false;
|
|
281
|
-
}, [orderId]);
|
|
267
|
+
// Call onSuccess when order is executed
|
|
268
|
+
useOnOrderSuccess({ orderData: oat, orderId, onSuccess });
|
|
282
269
|
const { createOrder: createRegularOrder, isCreatingOrder: isCreatingRegularOrder } = useAnyspendCreateOrder({
|
|
283
270
|
onSuccess: data => {
|
|
284
271
|
setOrderId(data.data.id);
|
|
@@ -8,6 +8,7 @@ import { QRCodeSVG } from "qrcode.react";
|
|
|
8
8
|
import { useEffect, useRef, useState } from "react";
|
|
9
9
|
import { useAnyspendOrderAndTransactions } from "../hooks/useAnyspendOrderAndTransactions.js";
|
|
10
10
|
import { useCreateDepositFirstOrder } from "../hooks/useCreateDepositFirstOrder.js";
|
|
11
|
+
import { useOnOrderSuccess } from "../hooks/useOnOrderSuccess.js";
|
|
11
12
|
import { useWatchTransfer } from "../hooks/useWatchTransfer.js";
|
|
12
13
|
import { ChainTokenIcon } from "./common/ChainTokenIcon.js";
|
|
13
14
|
import { OrderDetails } from "./common/OrderDetails.js";
|
|
@@ -43,7 +44,6 @@ export function QRDeposit({ mode = "modal", recipientAddress, sourceToken: sourc
|
|
|
43
44
|
const [orderId, setOrderId] = useState();
|
|
44
45
|
const [globalAddress, setGlobalAddress] = useState();
|
|
45
46
|
const orderCreatedRef = useRef(false);
|
|
46
|
-
const onSuccessCalled = useRef(false);
|
|
47
47
|
const [transferResult, setTransferResult] = useState(null);
|
|
48
48
|
// Source token/chain as state (can be changed by user)
|
|
49
49
|
const [sourceChainId, setSourceChainId] = useState(sourceChainIdProp ?? 8453);
|
|
@@ -125,17 +125,7 @@ export function QRDeposit({ mode = "modal", recipientAddress, sourceToken: sourc
|
|
|
125
125
|
isPureTransfer,
|
|
126
126
|
]);
|
|
127
127
|
// Call onSuccess when order is executed
|
|
128
|
-
|
|
129
|
-
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
130
|
-
const txHash = oat?.data?.executeTx?.txHash;
|
|
131
|
-
onSuccess?.(txHash);
|
|
132
|
-
onSuccessCalled.current = true;
|
|
133
|
-
}
|
|
134
|
-
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
135
|
-
// Reset onSuccess flag when orderId changes
|
|
136
|
-
useEffect(() => {
|
|
137
|
-
onSuccessCalled.current = false;
|
|
138
|
-
}, [orderId]);
|
|
128
|
+
useOnOrderSuccess({ orderData: oat, orderId, onSuccess });
|
|
139
129
|
// For pure transfers, always use recipient address; for orders, use global address
|
|
140
130
|
const displayAddress = isPureTransfer ? recipientAddress : globalAddress || recipientAddress;
|
|
141
131
|
const handleCopyAddress = async () => {
|
|
@@ -450,7 +450,7 @@ export const OrderDetails = memo(function OrderDetails({ mode = "modal", order,
|
|
|
450
450
|
: `Waiting for deposit ${formattedDepositDeficit} ${srcToken.symbol}`, chainId: order.srcChain, tx: null, isProcessing: true, delay: 0.5 }))] }) })] }) }), depositTxs?.length > 0 && !depositEnoughAmount && order.status === "scanning_deposit_transaction" && (_jsx(InsufficientDepositPayment, { order: order, srcToken: srcToken, depositDeficit: depositDeficit, phantomWalletAddress: phantomWalletAddress, txLoading: txLoading, isSwitchingOrExecuting: isSwitchingOrExecuting, onPayment: handlePayment })), _jsxs("button", { className: classes?.backButton ||
|
|
451
451
|
"text-b3-primary-blue hover:text-b3-primary-blue/50 order-details-cancel-btn flex w-full items-center justify-center gap-2 underline", onClick: handleBack, children: [_jsx(RefreshCcw, { className: "ml-2 h-4 w-4" }), " Cancel and start over"] })] }));
|
|
452
452
|
}
|
|
453
|
-
return (_jsxs(_Fragment, { children: [_jsx(OrderStatus, { order: order, selectedCryptoPaymentMethod: effectiveCryptoPaymentMethod }), statusDisplay === "processing" && (_jsx(_Fragment, { children: order.onrampMetadata ? (_jsx(PaymentVendorUI, { order: order, dstTokenSymbol: dstToken.symbol })) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ||
|
|
453
|
+
return (_jsxs(_Fragment, { children: [_jsx(OrderStatus, { order: order, selectedCryptoPaymentMethod: effectiveCryptoPaymentMethod }), statusDisplay === "processing" && (_jsx(_Fragment, { children: order.onrampMetadata && order.onrampMetadata.vendor !== "none" ? (_jsx(PaymentVendorUI, { order: order, dstTokenSymbol: dstToken.symbol })) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.CONNECT_WALLET ||
|
|
454
454
|
effectiveCryptoPaymentMethod === CryptoPaymentMethodType.GLOBAL_WALLET ? (_jsx(ConnectWalletPayment, { order: order, onPayment: handlePayment, onCancel: handleBack, txLoading: txLoading, isSwitchingOrExecuting: isSwitchingOrExecuting, phantomWalletAddress: phantomWalletAddress, tournament: tournament, nft: nft, cryptoPaymentMethod: effectiveCryptoPaymentMethod, onPaymentMethodChange: onPaymentMethodChange })) : effectiveCryptoPaymentMethod === CryptoPaymentMethodType.TRANSFER_CRYPTO ? (
|
|
455
455
|
// Transfer Crypto Payment Method - Show new card-based UI
|
|
456
456
|
_jsx(TransferCryptoDetails, { order: order, recipientName: recipientName, srcToken: srcToken, dstToken: dstToken, tournament: tournament, nft: nft, onBack: handleBack, onPaymentMethodChange: onPaymentMethodChange })) : (_jsxs("div", { className: "order-details-payment-section relative flex w-full flex-1 flex-col", children: [_jsxs("div", { className: "order-details-amount-section flex flex-col gap-1", children: [_jsx("span", { className: "text-as-primary/50 order-details-amount-label", children: "Please send" }), _jsxs("div", { className: "order-details-amount-container flex w-full flex-wrap items-center gap-6 sm:justify-between sm:gap-0", children: [_jsx(CopyToClipboard, { text: roundedUpSrcAmount, onCopy: () => {
|
|
@@ -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";
|
|
@@ -12,6 +12,7 @@ export * from "./useGasPrice.js";
|
|
|
12
12
|
export * from "./useGeoOnrampOptions.js";
|
|
13
13
|
export * from "./useGetGeo.js";
|
|
14
14
|
export * from "./useHyperliquidTransfer.js";
|
|
15
|
+
export * from "./useOnOrderSuccess.js";
|
|
15
16
|
export * from "./useRecipientAddressState.js";
|
|
16
17
|
export * from "./useSigMint.js";
|
|
17
18
|
export * from "./useStripeClientSecret.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GetOrderAndTxsResponse } from "../../types/api_req_res";
|
|
2
|
+
/**
|
|
3
|
+
* Hook to call onSuccess callback when an order is executed.
|
|
4
|
+
* Handles fallback to relayTxs when executeTx is null.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useOnOrderSuccess({ orderData, orderId, onSuccess, }: {
|
|
7
|
+
orderData: GetOrderAndTxsResponse | undefined;
|
|
8
|
+
orderId: string | undefined;
|
|
9
|
+
onSuccess?: (txHash?: string) => void;
|
|
10
|
+
}): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Hook to call onSuccess callback when an order is executed.
|
|
4
|
+
* Handles fallback to relayTxs when executeTx is null.
|
|
5
|
+
*/
|
|
6
|
+
export function useOnOrderSuccess({ orderData, orderId, onSuccess, }) {
|
|
7
|
+
const onSuccessCalled = useRef(false);
|
|
8
|
+
const prevOrderId = useRef(orderId);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
// Reset flag when orderId changes
|
|
11
|
+
if (prevOrderId.current !== orderId) {
|
|
12
|
+
onSuccessCalled.current = false;
|
|
13
|
+
prevOrderId.current = orderId;
|
|
14
|
+
}
|
|
15
|
+
// Call onSuccess when order is executed
|
|
16
|
+
if (orderData?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
17
|
+
const relayTxs = orderData?.data?.relayTxs;
|
|
18
|
+
const lastSuccessfulRelayTx = relayTxs?.filter(tx => tx.status === "success").pop();
|
|
19
|
+
const txHash = orderData?.data?.executeTx?.txHash || lastSuccessfulRelayTx?.txHash;
|
|
20
|
+
onSuccess?.(txHash);
|
|
21
|
+
onSuccessCalled.current = true;
|
|
22
|
+
}
|
|
23
|
+
}, [orderData, orderId, onSuccess]);
|
|
24
|
+
}
|