@b3dotfun/sdk 0.0.42-alpha.0 → 0.0.42-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 +9 -2
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +43 -3
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +9 -2
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +10 -3
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +1 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +1 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +11 -2
- package/src/anyspend/react/components/AnySpendCustom.tsx +11 -2
- package/src/global-account/react/stores/useModalStore.ts +1 -1
|
@@ -57,6 +57,8 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
57
57
|
// Add refs to track URL state
|
|
58
58
|
const initialUrlProcessed = (0, react_4.useRef)(false);
|
|
59
59
|
const lastUrlUpdate = (0, react_4.useRef)(null);
|
|
60
|
+
// Track if onSuccess has been called for the current order
|
|
61
|
+
const onSuccessCalled = (0, react_4.useRef)(false);
|
|
60
62
|
const [activeTab, setActiveTab] = (0, react_4.useState)(defaultActiveTab);
|
|
61
63
|
const [orderId, setOrderId] = (0, react_4.useState)(loadOrder);
|
|
62
64
|
const { orderAndTransactions: oat, getOrderAndTransactionsError } = (0, react_1.useAnyspendOrderAndTransactions)(orderId);
|
|
@@ -394,12 +396,17 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
394
396
|
}
|
|
395
397
|
}, [anyspendQuote, isSrcInputDirty]);
|
|
396
398
|
(0, react_4.useEffect)(() => {
|
|
397
|
-
if (oat?.data?.order.status === "executed") {
|
|
399
|
+
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
398
400
|
console.log("Calling onSuccess");
|
|
399
401
|
const txHash = oat?.data?.executeTx?.txHash;
|
|
400
402
|
onSuccess?.(txHash);
|
|
403
|
+
onSuccessCalled.current = true;
|
|
401
404
|
}
|
|
402
|
-
}, [oat?.data?.
|
|
405
|
+
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
406
|
+
// Reset flag when orderId changes
|
|
407
|
+
(0, react_4.useEffect)(() => {
|
|
408
|
+
onSuccessCalled.current = false;
|
|
409
|
+
}, [orderId]);
|
|
403
410
|
const { createOrder, isCreatingOrder } = (0, react_1.useAnyspendCreateOrder)({
|
|
404
411
|
onSuccess: data => {
|
|
405
412
|
const orderId = data.data.id;
|
|
@@ -1,4 +1,37 @@
|
|
|
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
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -16,7 +49,7 @@ const simplehash_1 = require("../../../shared/utils/simplehash");
|
|
|
16
49
|
const invariant_1 = __importDefault(require("invariant"));
|
|
17
50
|
const lucide_react_1 = require("lucide-react");
|
|
18
51
|
const react_3 = require("motion/react");
|
|
19
|
-
const react_4 = require("react");
|
|
52
|
+
const react_4 = __importStar(require("react"));
|
|
20
53
|
const sonner_1 = require("sonner");
|
|
21
54
|
const chains_1 = require("viem/chains");
|
|
22
55
|
const FeatureFlagsContext_1 = require("../contexts/FeatureFlagsContext");
|
|
@@ -123,6 +156,8 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
123
156
|
// Update recipient logic to use custom recipient
|
|
124
157
|
const recipientAddress = customRecipientAddress || currentWallet.address;
|
|
125
158
|
const [orderId, setOrderId] = (0, react_4.useState)(loadOrder);
|
|
159
|
+
// Track if onSuccess has been called for the current order
|
|
160
|
+
const onSuccessCalled = react_4.default.useRef(false);
|
|
126
161
|
const [srcChainId, setSrcChainId] = (0, react_4.useState)(chains_1.base.id);
|
|
127
162
|
// Get token list for token balance check
|
|
128
163
|
const chainName = (0, react_4.useMemo)(() => (0, simplehash_1.simpleHashChainToChainName)(srcChainId), [srcChainId]);
|
|
@@ -236,12 +271,17 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
236
271
|
// Get geo data and onramp options (after quote is available)
|
|
237
272
|
const { geoData, isOnrampSupported, coinbaseAvailablePaymentMethods, stripeWeb2Support } = (0, react_1.useGeoOnrampOptions)(srcFiatAmount);
|
|
238
273
|
(0, react_4.useEffect)(() => {
|
|
239
|
-
if (oat?.data?.order.status === "executed") {
|
|
274
|
+
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
240
275
|
console.log("Calling onSuccess");
|
|
241
276
|
const txHash = oat?.data?.executeTx?.txHash;
|
|
242
277
|
onSuccess?.(txHash);
|
|
278
|
+
onSuccessCalled.current = true;
|
|
243
279
|
}
|
|
244
|
-
}, [oat?.data?.
|
|
280
|
+
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
281
|
+
// Reset flag when orderId changes
|
|
282
|
+
(0, react_4.useEffect)(() => {
|
|
283
|
+
onSuccessCalled.current = false;
|
|
284
|
+
}, [orderId]);
|
|
245
285
|
const { createOrder: createRegularOrder, isCreatingOrder: isCreatingRegularOrder } = (0, react_1.useAnyspendCreateOrder)({
|
|
246
286
|
onSuccess: data => {
|
|
247
287
|
setOrderId(data.data.id);
|
|
@@ -117,7 +117,7 @@ export interface AnySpendModalProps extends BaseModalProps {
|
|
|
117
117
|
/** Whether to hide the transaction history button */
|
|
118
118
|
hideTransactionHistoryButton?: boolean;
|
|
119
119
|
/** Callback function called when the transaction is successful */
|
|
120
|
-
onSuccess?: () => void;
|
|
120
|
+
onSuccess?: (txHash?: string) => void;
|
|
121
121
|
/** Token address of the destination token to buy (enables buy mode) */
|
|
122
122
|
destinationTokenAddress?: string;
|
|
123
123
|
/** Chain ID where the destination token exists (enables buy mode) */
|
|
@@ -50,6 +50,8 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
50
50
|
// Add refs to track URL state
|
|
51
51
|
const initialUrlProcessed = useRef(false);
|
|
52
52
|
const lastUrlUpdate = useRef(null);
|
|
53
|
+
// Track if onSuccess has been called for the current order
|
|
54
|
+
const onSuccessCalled = useRef(false);
|
|
53
55
|
const [activeTab, setActiveTab] = useState(defaultActiveTab);
|
|
54
56
|
const [orderId, setOrderId] = useState(loadOrder);
|
|
55
57
|
const { orderAndTransactions: oat, getOrderAndTransactionsError } = useAnyspendOrderAndTransactions(orderId);
|
|
@@ -387,12 +389,17 @@ function AnySpendInner({ destinationTokenAddress, destinationTokenChainId, mode
|
|
|
387
389
|
}
|
|
388
390
|
}, [anyspendQuote, isSrcInputDirty]);
|
|
389
391
|
useEffect(() => {
|
|
390
|
-
if (oat?.data?.order.status === "executed") {
|
|
392
|
+
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
391
393
|
console.log("Calling onSuccess");
|
|
392
394
|
const txHash = oat?.data?.executeTx?.txHash;
|
|
393
395
|
onSuccess?.(txHash);
|
|
396
|
+
onSuccessCalled.current = true;
|
|
394
397
|
}
|
|
395
|
-
}, [oat?.data?.
|
|
398
|
+
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
399
|
+
// Reset flag when orderId changes
|
|
400
|
+
useEffect(() => {
|
|
401
|
+
onSuccessCalled.current = false;
|
|
402
|
+
}, [orderId]);
|
|
396
403
|
const { createOrder, isCreatingOrder } = useAnyspendCreateOrder({
|
|
397
404
|
onSuccess: data => {
|
|
398
405
|
const orderId = data.data.id;
|
|
@@ -10,7 +10,7 @@ import { simpleHashChainToChainName } from "../../../shared/utils/simplehash.js"
|
|
|
10
10
|
import invariant from "invariant";
|
|
11
11
|
import { ChevronRight, ChevronRightCircle, Loader2 } from "lucide-react";
|
|
12
12
|
import { motion } from "motion/react";
|
|
13
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
13
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
14
14
|
import { toast } from "sonner";
|
|
15
15
|
import { base } from "viem/chains";
|
|
16
16
|
import { useFeatureFlags } from "../contexts/FeatureFlagsContext.js";
|
|
@@ -117,6 +117,8 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
117
117
|
// Update recipient logic to use custom recipient
|
|
118
118
|
const recipientAddress = customRecipientAddress || currentWallet.address;
|
|
119
119
|
const [orderId, setOrderId] = useState(loadOrder);
|
|
120
|
+
// Track if onSuccess has been called for the current order
|
|
121
|
+
const onSuccessCalled = React.useRef(false);
|
|
120
122
|
const [srcChainId, setSrcChainId] = useState(base.id);
|
|
121
123
|
// Get token list for token balance check
|
|
122
124
|
const chainName = useMemo(() => simpleHashChainToChainName(srcChainId), [srcChainId]);
|
|
@@ -230,12 +232,17 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
230
232
|
// Get geo data and onramp options (after quote is available)
|
|
231
233
|
const { geoData, isOnrampSupported, coinbaseAvailablePaymentMethods, stripeWeb2Support } = useGeoOnrampOptions(srcFiatAmount);
|
|
232
234
|
useEffect(() => {
|
|
233
|
-
if (oat?.data?.order.status === "executed") {
|
|
235
|
+
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
234
236
|
console.log("Calling onSuccess");
|
|
235
237
|
const txHash = oat?.data?.executeTx?.txHash;
|
|
236
238
|
onSuccess?.(txHash);
|
|
239
|
+
onSuccessCalled.current = true;
|
|
237
240
|
}
|
|
238
|
-
}, [oat?.data?.
|
|
241
|
+
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
242
|
+
// Reset flag when orderId changes
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
onSuccessCalled.current = false;
|
|
245
|
+
}, [orderId]);
|
|
239
246
|
const { createOrder: createRegularOrder, isCreatingOrder: isCreatingRegularOrder } = useAnyspendCreateOrder({
|
|
240
247
|
onSuccess: data => {
|
|
241
248
|
setOrderId(data.data.id);
|
|
@@ -117,7 +117,7 @@ export interface AnySpendModalProps extends BaseModalProps {
|
|
|
117
117
|
/** Whether to hide the transaction history button */
|
|
118
118
|
hideTransactionHistoryButton?: boolean;
|
|
119
119
|
/** Callback function called when the transaction is successful */
|
|
120
|
-
onSuccess?: () => void;
|
|
120
|
+
onSuccess?: (txHash?: string) => void;
|
|
121
121
|
/** Token address of the destination token to buy (enables buy mode) */
|
|
122
122
|
destinationTokenAddress?: string;
|
|
123
123
|
/** Chain ID where the destination token exists (enables buy mode) */
|
|
@@ -117,7 +117,7 @@ export interface AnySpendModalProps extends BaseModalProps {
|
|
|
117
117
|
/** Whether to hide the transaction history button */
|
|
118
118
|
hideTransactionHistoryButton?: boolean;
|
|
119
119
|
/** Callback function called when the transaction is successful */
|
|
120
|
-
onSuccess?: () => void;
|
|
120
|
+
onSuccess?: (txHash?: string) => void;
|
|
121
121
|
/** Token address of the destination token to buy (enables buy mode) */
|
|
122
122
|
destinationTokenAddress?: string;
|
|
123
123
|
/** Chain ID where the destination token exists (enables buy mode) */
|
package/package.json
CHANGED
|
@@ -134,6 +134,9 @@ function AnySpendInner({
|
|
|
134
134
|
toAmount?: string;
|
|
135
135
|
} | null>(null);
|
|
136
136
|
|
|
137
|
+
// Track if onSuccess has been called for the current order
|
|
138
|
+
const onSuccessCalled = useRef(false);
|
|
139
|
+
|
|
137
140
|
const [activeTab, setActiveTab] = useState<"crypto" | "fiat">(defaultActiveTab);
|
|
138
141
|
|
|
139
142
|
const [orderId, setOrderId] = useState<string | undefined>(loadOrder);
|
|
@@ -520,12 +523,18 @@ function AnySpendInner({
|
|
|
520
523
|
}, [anyspendQuote, isSrcInputDirty]);
|
|
521
524
|
|
|
522
525
|
useEffect(() => {
|
|
523
|
-
if (oat?.data?.order.status === "executed") {
|
|
526
|
+
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
524
527
|
console.log("Calling onSuccess");
|
|
525
528
|
const txHash = oat?.data?.executeTx?.txHash;
|
|
526
529
|
onSuccess?.(txHash);
|
|
530
|
+
onSuccessCalled.current = true;
|
|
527
531
|
}
|
|
528
|
-
}, [oat?.data?.
|
|
532
|
+
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
533
|
+
|
|
534
|
+
// Reset flag when orderId changes
|
|
535
|
+
useEffect(() => {
|
|
536
|
+
onSuccessCalled.current = false;
|
|
537
|
+
}, [orderId]);
|
|
529
538
|
|
|
530
539
|
const { createOrder, isCreatingOrder } = useAnyspendCreateOrder({
|
|
531
540
|
onSuccess: data => {
|
|
@@ -255,6 +255,9 @@ function AnySpendCustomInner({
|
|
|
255
255
|
|
|
256
256
|
const [orderId, setOrderId] = useState<string | undefined>(loadOrder);
|
|
257
257
|
|
|
258
|
+
// Track if onSuccess has been called for the current order
|
|
259
|
+
const onSuccessCalled = React.useRef(false);
|
|
260
|
+
|
|
258
261
|
const [srcChainId, setSrcChainId] = useState<number>(base.id);
|
|
259
262
|
|
|
260
263
|
// Get token list for token balance check
|
|
@@ -390,12 +393,18 @@ function AnySpendCustomInner({
|
|
|
390
393
|
useGeoOnrampOptions(srcFiatAmount);
|
|
391
394
|
|
|
392
395
|
useEffect(() => {
|
|
393
|
-
if (oat?.data?.order.status === "executed") {
|
|
396
|
+
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
394
397
|
console.log("Calling onSuccess");
|
|
395
398
|
const txHash = oat?.data?.executeTx?.txHash;
|
|
396
399
|
onSuccess?.(txHash);
|
|
400
|
+
onSuccessCalled.current = true;
|
|
397
401
|
}
|
|
398
|
-
}, [oat?.data?.
|
|
402
|
+
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
403
|
+
|
|
404
|
+
// Reset flag when orderId changes
|
|
405
|
+
useEffect(() => {
|
|
406
|
+
onSuccessCalled.current = false;
|
|
407
|
+
}, [orderId]);
|
|
399
408
|
|
|
400
409
|
const { createOrder: createRegularOrder, isCreatingOrder: isCreatingRegularOrder } = useAnyspendCreateOrder({
|
|
401
410
|
onSuccess: data => {
|
|
@@ -123,7 +123,7 @@ export interface AnySpendModalProps extends BaseModalProps {
|
|
|
123
123
|
/** Whether to hide the transaction history button */
|
|
124
124
|
hideTransactionHistoryButton?: boolean;
|
|
125
125
|
/** Callback function called when the transaction is successful */
|
|
126
|
-
onSuccess?: () => void;
|
|
126
|
+
onSuccess?: (txHash?: string) => void;
|
|
127
127
|
/** Token address of the destination token to buy (enables buy mode) */
|
|
128
128
|
destinationTokenAddress?: string;
|
|
129
129
|
/** Chain ID where the destination token exists (enables buy mode) */
|