@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.
Files changed (29) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +3 -14
  2. package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -50
  3. package/dist/cjs/anyspend/react/components/QRDeposit.js +2 -12
  4. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +1 -1
  5. package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
  6. package/dist/cjs/anyspend/react/hooks/index.js +1 -0
  7. package/dist/cjs/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
  8. package/dist/cjs/anyspend/react/hooks/useOnOrderSuccess.js +27 -0
  9. package/dist/cjs/anyspend/types/api.d.ts +10 -287
  10. package/dist/esm/anyspend/react/components/AnySpend.js +3 -14
  11. package/dist/esm/anyspend/react/components/AnySpendCustom.js +4 -17
  12. package/dist/esm/anyspend/react/components/QRDeposit.js +2 -12
  13. package/dist/esm/anyspend/react/components/common/OrderDetails.js +1 -1
  14. package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
  15. package/dist/esm/anyspend/react/hooks/index.js +1 -0
  16. package/dist/esm/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
  17. package/dist/esm/anyspend/react/hooks/useOnOrderSuccess.js +24 -0
  18. package/dist/esm/anyspend/types/api.d.ts +10 -287
  19. package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
  20. package/dist/types/anyspend/react/hooks/useOnOrderSuccess.d.ts +10 -0
  21. package/dist/types/anyspend/types/api.d.ts +10 -287
  22. package/package.json +1 -1
  23. package/src/anyspend/react/components/AnySpend.tsx +3 -16
  24. package/src/anyspend/react/components/AnySpendCustom.tsx +3 -18
  25. package/src/anyspend/react/components/QRDeposit.tsx +2 -13
  26. package/src/anyspend/react/components/common/OrderDetails.tsx +1 -1
  27. package/src/anyspend/react/hooks/index.ts +1 -0
  28. package/src/anyspend/react/hooks/useOnOrderSuccess.ts +36 -0
  29. package/src/anyspend/types/api.ts +10 -287
@@ -25,6 +25,7 @@ const useAutoSelectCryptoPaymentMethod_1 = require("../hooks/useAutoSelectCrypto
25
25
  const useConnectedWalletDisplay_1 = require("../hooks/useConnectedWalletDisplay");
26
26
  const useCryptoPaymentMethodState_1 = require("../hooks/useCryptoPaymentMethodState");
27
27
  const useDirectTransfer_1 = require("../hooks/useDirectTransfer");
28
+ const useOnOrderSuccess_1 = require("../hooks/useOnOrderSuccess");
28
29
  const useRecipientAddressState_1 = require("../hooks/useRecipientAddressState");
29
30
  const AnySpendFingerprintWrapper_1 = require("./AnySpendFingerprintWrapper");
30
31
  const CryptoPaymentMethod_1 = require("./common/CryptoPaymentMethod");
@@ -72,8 +73,6 @@ function AnySpendInner({ sourceChainId, destinationTokenAddress, destinationToke
72
73
  // Add refs to track URL state
73
74
  const initialUrlProcessed = (0, react_4.useRef)(false);
74
75
  const lastUrlUpdate = (0, react_4.useRef)(null);
75
- // Track if onSuccess has been called for the current order
76
- const onSuccessCalled = (0, react_4.useRef)(false);
77
76
  // Track animation direction for TransitionPanel
78
77
  const animationDirection = (0, react_4.useRef)(null);
79
78
  // Track previous panel for proper back navigation
@@ -493,18 +492,8 @@ function AnySpendInner({ sourceChainId, destinationTokenAddress, destinationToke
493
492
  }
494
493
  }
495
494
  }, [anyspendQuote, isSrcInputDirty, destinationTokenAmount]);
496
- (0, react_4.useEffect)(() => {
497
- if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
498
- console.log("Calling onSuccess");
499
- const txHash = oat?.data?.executeTx?.txHash;
500
- onSuccess?.(txHash);
501
- onSuccessCalled.current = true;
502
- }
503
- }, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
504
- // Reset flag when orderId changes
505
- (0, react_4.useEffect)(() => {
506
- onSuccessCalled.current = false;
507
- }, [orderId]);
495
+ // Call onSuccess when order is executed
496
+ (0, useOnOrderSuccess_1.useOnOrderSuccess)({ orderData: oat, orderId, onSuccess });
508
497
  const { createOrder, isCreatingOrder } = (0, react_1.useAnyspendCreateOrder)({
509
498
  onSuccess: data => {
510
499
  const orderId = data.data.id;
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
@@ -50,9 +17,10 @@ const simplehash_1 = require("../../../shared/utils/simplehash");
50
17
  const invariant_1 = __importDefault(require("invariant"));
51
18
  const lucide_react_1 = require("lucide-react");
52
19
  const react_4 = require("motion/react");
53
- const react_5 = __importStar(require("react"));
20
+ const react_5 = require("react");
54
21
  const chains_1 = require("viem/chains");
55
22
  const useCryptoPaymentMethodState_1 = require("../hooks/useCryptoPaymentMethodState");
23
+ const useOnOrderSuccess_1 = require("../hooks/useOnOrderSuccess");
56
24
  const useRecipientAddressState_1 = require("../hooks/useRecipientAddressState");
57
25
  const AnySpendFingerprintWrapper_1 = require("./AnySpendFingerprintWrapper");
58
26
  const CryptoPaymentMethod_1 = require("./common/CryptoPaymentMethod");
@@ -165,8 +133,6 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
165
133
  globalAddress: currentWallet.address,
166
134
  });
167
135
  const [orderId, setOrderId] = (0, react_5.useState)(loadOrder);
168
- // Track if onSuccess has been called for the current order
169
- const onSuccessCalled = react_5.default.useRef(false);
170
136
  const [srcChainId, setSrcChainId] = (0, react_5.useState)(chains_1.base.id);
171
137
  // Get token list for token balance check
172
138
  const chainName = (0, react_5.useMemo)(() => (0, simplehash_1.simpleHashChainToChainName)(srcChainId), [srcChainId]);
@@ -304,20 +270,8 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
304
270
  }, [activeTab, srcFiatAmountForGeoCheck]);
305
271
  // Get geo data and onramp options (use srcFiatAmountForGeoCheck to check availability regardless of activeTab)
306
272
  const { geoData, isOnrampSupported, coinbaseAvailablePaymentMethods, stripeOnrampSupport, stripeWeb2Support } = (0, react_1.useGeoOnrampOptions)(srcFiatAmountForGeoCheck);
307
- (0, react_5.useEffect)(() => {
308
- if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
309
- console.log("Calling onSuccess");
310
- const relayTxs = oat?.data?.relayTxs;
311
- const lastRelayTxHash = relayTxs?.[relayTxs.length - 1]?.txHash;
312
- const txHash = oat?.data?.executeTx?.txHash || lastRelayTxHash;
313
- onSuccess?.(txHash);
314
- onSuccessCalled.current = true;
315
- }
316
- }, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, oat?.data?.relayTxs, onSuccess]);
317
- // Reset flag when orderId changes
318
- (0, react_5.useEffect)(() => {
319
- onSuccessCalled.current = false;
320
- }, [orderId]);
273
+ // Call onSuccess when order is executed
274
+ (0, useOnOrderSuccess_1.useOnOrderSuccess)({ orderData: oat, orderId, onSuccess });
321
275
  const { createOrder: createRegularOrder, isCreatingOrder: isCreatingRegularOrder } = (0, react_1.useAnyspendCreateOrder)({
322
276
  onSuccess: data => {
323
277
  setOrderId(data.data.id);
@@ -11,6 +11,7 @@ const qrcode_react_1 = require("qrcode.react");
11
11
  const react_2 = require("react");
12
12
  const useAnyspendOrderAndTransactions_1 = require("../hooks/useAnyspendOrderAndTransactions");
13
13
  const useCreateDepositFirstOrder_1 = require("../hooks/useCreateDepositFirstOrder");
14
+ const useOnOrderSuccess_1 = require("../hooks/useOnOrderSuccess");
14
15
  const useWatchTransfer_1 = require("../hooks/useWatchTransfer");
15
16
  const ChainTokenIcon_1 = require("./common/ChainTokenIcon");
16
17
  const OrderDetails_1 = require("./common/OrderDetails");
@@ -46,7 +47,6 @@ function QRDeposit({ mode = "modal", recipientAddress, sourceToken: sourceTokenP
46
47
  const [orderId, setOrderId] = (0, react_2.useState)();
47
48
  const [globalAddress, setGlobalAddress] = (0, react_2.useState)();
48
49
  const orderCreatedRef = (0, react_2.useRef)(false);
49
- const onSuccessCalled = (0, react_2.useRef)(false);
50
50
  const [transferResult, setTransferResult] = (0, react_2.useState)(null);
51
51
  // Source token/chain as state (can be changed by user)
52
52
  const [sourceChainId, setSourceChainId] = (0, react_2.useState)(sourceChainIdProp ?? 8453);
@@ -128,17 +128,7 @@ function QRDeposit({ mode = "modal", recipientAddress, sourceToken: sourceTokenP
128
128
  isPureTransfer,
129
129
  ]);
130
130
  // Call onSuccess when order is executed
131
- (0, react_2.useEffect)(() => {
132
- if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
133
- const txHash = oat?.data?.executeTx?.txHash;
134
- onSuccess?.(txHash);
135
- onSuccessCalled.current = true;
136
- }
137
- }, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
138
- // Reset onSuccess flag when orderId changes
139
- (0, react_2.useEffect)(() => {
140
- onSuccessCalled.current = false;
141
- }, [orderId]);
131
+ (0, useOnOrderSuccess_1.useOnOrderSuccess)({ orderData: oat, orderId, onSuccess });
142
132
  // For pure transfers, always use recipient address; for orders, use global address
143
133
  const displayAddress = isPureTransfer ? recipientAddress : globalAddress || recipientAddress;
144
134
  const handleCopyAddress = async () => {
@@ -456,7 +456,7 @@ exports.OrderDetails = (0, react_5.memo)(function OrderDetails({ mode = "modal",
456
456
  : `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" && ((0, jsx_runtime_1.jsx)(InsufficientDepositPayment_1.InsufficientDepositPayment, { order: order, srcToken: srcToken, depositDeficit: depositDeficit, phantomWalletAddress: phantomWalletAddress, txLoading: txLoading, isSwitchingOrExecuting: isSwitchingOrExecuting, onPayment: handlePayment })), (0, jsx_runtime_1.jsxs)("button", { className: classes?.backButton ||
457
457
  "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: [(0, jsx_runtime_1.jsx)(lucide_react_1.RefreshCcw, { className: "ml-2 h-4 w-4" }), " Cancel and start over"] })] }));
458
458
  }
459
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(OrderStatus_1.OrderStatus, { order: order, selectedCryptoPaymentMethod: effectiveCryptoPaymentMethod }), statusDisplay === "processing" && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: order.onrampMetadata ? ((0, jsx_runtime_1.jsx)(PaymentVendorUI_1.default, { order: order, dstTokenSymbol: dstToken.symbol })) : effectiveCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET ||
459
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(OrderStatus_1.OrderStatus, { order: order, selectedCryptoPaymentMethod: effectiveCryptoPaymentMethod }), statusDisplay === "processing" && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: order.onrampMetadata && order.onrampMetadata.vendor !== "none" ? ((0, jsx_runtime_1.jsx)(PaymentVendorUI_1.default, { order: order, dstTokenSymbol: dstToken.symbol })) : effectiveCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.CONNECT_WALLET ||
460
460
  effectiveCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.GLOBAL_WALLET ? ((0, jsx_runtime_1.jsx)(ConnectWalletPayment_1.default, { order: order, onPayment: handlePayment, onCancel: handleBack, txLoading: txLoading, isSwitchingOrExecuting: isSwitchingOrExecuting, phantomWalletAddress: phantomWalletAddress, tournament: tournament, nft: nft, cryptoPaymentMethod: effectiveCryptoPaymentMethod, onPaymentMethodChange: onPaymentMethodChange })) : effectiveCryptoPaymentMethod === CryptoPaymentMethod_1.CryptoPaymentMethodType.TRANSFER_CRYPTO ? (
461
461
  // Transfer Crypto Payment Method - Show new card-based UI
462
462
  (0, jsx_runtime_1.jsx)(TransferCryptoDetails_1.TransferCryptoDetails, { order: order, recipientName: recipientName, srcToken: srcToken, dstToken: dstToken, tournament: tournament, nft: nft, onBack: handleBack, onPaymentMethodChange: onPaymentMethodChange })) : ((0, jsx_runtime_1.jsxs)("div", { className: "order-details-payment-section relative flex w-full flex-1 flex-col", children: [(0, jsx_runtime_1.jsxs)("div", { className: "order-details-amount-section flex flex-col gap-1", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-as-primary/50 order-details-amount-label", children: "Please send" }), (0, jsx_runtime_1.jsxs)("div", { className: "order-details-amount-container flex w-full flex-wrap items-center gap-6 sm:justify-between sm:gap-0", children: [(0, jsx_runtime_1.jsx)(react_1.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";
@@ -28,6 +28,7 @@ __exportStar(require("./useGasPrice"), exports);
28
28
  __exportStar(require("./useGeoOnrampOptions"), exports);
29
29
  __exportStar(require("./useGetGeo"), exports);
30
30
  __exportStar(require("./useHyperliquidTransfer"), exports);
31
+ __exportStar(require("./useOnOrderSuccess"), exports);
31
32
  __exportStar(require("./useRecipientAddressState"), exports);
32
33
  __exportStar(require("./useSigMint"), exports);
33
34
  __exportStar(require("./useStripeClientSecret"), exports);
@@ -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,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useOnOrderSuccess = useOnOrderSuccess;
4
+ const react_1 = require("react");
5
+ /**
6
+ * Hook to call onSuccess callback when an order is executed.
7
+ * Handles fallback to relayTxs when executeTx is null.
8
+ */
9
+ function useOnOrderSuccess({ orderData, orderId, onSuccess, }) {
10
+ const onSuccessCalled = (0, react_1.useRef)(false);
11
+ const prevOrderId = (0, react_1.useRef)(orderId);
12
+ (0, react_1.useEffect)(() => {
13
+ // Reset flag when orderId changes
14
+ if (prevOrderId.current !== orderId) {
15
+ onSuccessCalled.current = false;
16
+ prevOrderId.current = orderId;
17
+ }
18
+ // Call onSuccess when order is executed
19
+ if (orderData?.data?.order.status === "executed" && !onSuccessCalled.current) {
20
+ const relayTxs = orderData?.data?.relayTxs;
21
+ const lastSuccessfulRelayTx = relayTxs?.filter(tx => tx.status === "success").pop();
22
+ const txHash = orderData?.data?.executeTx?.txHash || lastSuccessfulRelayTx?.txHash;
23
+ onSuccess?.(txHash);
24
+ onSuccessCalled.current = true;
25
+ }
26
+ }, [orderData, orderId, onSuccess]);
27
+ }