@@ -1105,27 +952,19 @@ describe('useEtherspotTransactions()', () => {
{children}
);
-
const { result } = renderHook(() => useEtherspotTransactions(), {
wrapper,
});
expect(result.current.isEstimating).toBe(false);
- jest.useFakeTimers();
-
let estimatePromise;
act(() => {
estimatePromise = result.current.estimate(['test-id-1']);
});
await waitFor(() => expect(result.current.isEstimating).toBe(true));
-
- jest.advanceTimersByTime(30000);
-
- await waitFor(() => expect(result.current.isEstimating).toBe(false), {
- timeout: 31000,
- });
+ await waitFor(() => expect(result.current.isEstimating).toBe(false));
const estimated1 = await estimatePromise;
expect(result.current.containsEstimatingError).toBe(true);
@@ -1136,15 +975,12 @@ describe('useEtherspotTransactions()', () => {
expect(onEstimated1.mock.calls[0][0]).toStrictEqual(
estimated1[0].estimatedBatches
);
-
act(() => {
estimatePromise = result.current.estimate(['test-id-2', 'test-id-3']);
});
await waitFor(() => expect(result.current.isEstimating).toBe(true));
- await waitFor(() => expect(result.current.isEstimating).toBe(false), {
- timeout: 31000,
- });
+ await waitFor(() => expect(result.current.isEstimating).toBe(false));
const estimated2 = await estimatePromise;
expect(result.current.containsEstimatingError).toBe(false);
@@ -1161,15 +997,12 @@ describe('useEtherspotTransactions()', () => {
expect(onEstimated3.mock.calls[0][0]).toStrictEqual(
estimated2[1].estimatedBatches
);
-
- jest.useRealTimers();
});
it('sends valid and returns error messages for invalid batch group by ID', async () => {
const onSent1 = jest.fn((estimated) => estimated);
const onSent2 = jest.fn((estimated) => estimated);
const onSent3 = jest.fn((estimated) => estimated);
-
const wrapper = ({ children }) => (
@@ -1219,27 +1052,19 @@ describe('useEtherspotTransactions()', () => {
{children}
);
-
const { result } = renderHook(() => useEtherspotTransactions(), {
wrapper,
});
expect(result.current.isSending).toBe(false);
- jest.useFakeTimers();
-
let sendPromise;
act(() => {
sendPromise = result.current.send(['test-id-1']);
});
await waitFor(() => expect(result.current.isSending).toBe(true));
-
- jest.advanceTimersByTime(30000);
-
- await waitFor(() => expect(result.current.isSending).toBe(false), {
- timeout: 31000,
- });
+ await waitFor(() => expect(result.current.isSending).toBe(false));
const sent1 = await sendPromise;
expect(sent1.length).toBe(1);
@@ -1248,15 +1073,12 @@ describe('useEtherspotTransactions()', () => {
'Transaction reverted: chain too hot'
);
expect(onSent1.mock.calls[0][0]).toStrictEqual(sent1[0].sentBatches);
-
act(() => {
sendPromise = result.current.send(['test-id-2', 'test-id-3']);
});
await waitFor(() => expect(result.current.isSending).toBe(true));
- await waitFor(() => expect(result.current.isSending).toBe(false), {
- timeout: 31000,
- });
+ await waitFor(() => expect(result.current.isSending).toBe(false));
const sent2 = await sendPromise;
expect(sent2.length).toBe(2);
@@ -1265,7 +1087,5 @@ describe('useEtherspotTransactions()', () => {
expect(sent2[1].sentBatches[0].userOpHash).toBe('0x47');
expect(onSent2.mock.calls[0][0]).toStrictEqual(sent2[0].sentBatches);
expect(onSent3.mock.calls[0][0]).toStrictEqual(sent2[1].sentBatches);
-
- jest.useRealTimers();
});
});
diff --git a/package.json b/package.json
index 3ecf93b..be631c6 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "@etherspot/transaction-kit",
"description": "React Etherspot Transaction Kit",
- "version": "1.0.3",
+ "version": "1.0.4",
"main": "dist/cjs/index.js",
"scripts": {
"rollup:build": "NODE_OPTIONS=--max-old-space-size=8192 rollup -c --bundleConfigAsCjs",
diff --git a/src/contexts/EtherspotTransactionKitContext.tsx b/src/contexts/EtherspotTransactionKitContext.tsx
index 2b82ad5..6e43bdc 100644
--- a/src/contexts/EtherspotTransactionKitContext.tsx
+++ b/src/contexts/EtherspotTransactionKitContext.tsx
@@ -16,7 +16,7 @@ export interface IEtherspotTransactionKitContext {
send: (batchesIds?: string[]) => Promise;
getTransactionHash: (
userOpHash: string,
- batchId: number,
+ batchId?: number,
timeout?: number,
retryInterval?: number
) => Promise;
diff --git a/src/providers/EtherspotTransactionKitContextProvider.tsx b/src/providers/EtherspotTransactionKitContextProvider.tsx
index 43124a9..a3c5cf4 100644
--- a/src/providers/EtherspotTransactionKitContextProvider.tsx
+++ b/src/providers/EtherspotTransactionKitContextProvider.tsx
@@ -212,44 +212,7 @@ const EtherspotTransactionKitContextProvider = ({
estimatedBatch.userOp
);
- // get transaction hash or userOp receipt...
- let userOpsReceipt;
- const timeout = Date.now() + 30 * 1000; // 30 seconds timeout
-
- try {
- while (!userOpsReceipt && Date.now() < timeout) {
- await new Promise((resolve) => {
- setTimeout(resolve, 2000);
- }); // Retry every 2 sec
-
- try {
- userOpsReceipt =
- await etherspotModulaSdk.getUserOpReceipt(userOpHash);
- } catch (error) {
- console.error(
- 'Error fetching transaction hash. Please check if the transaction has gone through, or try to send the transaction again:',
- error
- );
- }
- }
-
- if (!userOpsReceipt) {
- console.warn(
- 'Failed to get the transaction hash within 30 seconds. Please check if the transaction has gone through, or try to send the transaction again.'
- );
- }
- } catch (e) {
- console.error(
- 'Unexpected error while fetching the transaction hash. Please check if the transaction has gone through, or try to send the transaction again:',
- e
- );
- }
-
- sentBatches.push({
- ...estimatedBatch,
- userOpHash,
- transactionHash: userOpsReceipt,
- });
+ sentBatches.push({ ...estimatedBatch, userOpHash });
} catch (e) {
const errorMessage = parseEtherspotErrorMessage(
e,
@@ -280,25 +243,25 @@ const EtherspotTransactionKitContextProvider = ({
const getTransactionHash = async (
userOpHash: string,
- batchId: number,
- timeout: number = 30 * 1000,
- retryInterval: number = 2000
+ batchId?: number,
+ timeout: number = 30 * 1000, // Default to 30 sec
+ retryInterval: number = 2000 // Default to 2 sec
): Promise => {
const etherspotModulaSdk = await getSdk(batchId);
let transactionHash = null;
- const timeoutTotal = Date.now() + timeout; // 30 seconds timeout
+ const timeoutTotal = Date.now() + timeout; // Timeout duration
while (!transactionHash && Date.now() < timeoutTotal) {
await new Promise((resolve) => {
setTimeout(resolve, retryInterval);
- }); // Retry every 2 sec
+ }); // Retry every retryInterval ms
try {
transactionHash = await etherspotModulaSdk.getUserOpReceipt(userOpHash);
} catch (error) {
console.error(
- 'Error fetching transaction hash. Please try again:',
+ 'Error fetching transaction hash. Please check if the transaction has gone through, or try to send the transaction again:',
error
);
}
@@ -306,7 +269,7 @@ const EtherspotTransactionKitContextProvider = ({
if (!transactionHash) {
console.warn(
- 'Failed to get the transaction hash within 30 seconds. Please try again'
+ 'Failed to get the transaction hash within time limit. Please try again'
);
}
diff --git a/src/types/EtherspotTransactionKit.ts b/src/types/EtherspotTransactionKit.ts
index d930369..793b995 100644
--- a/src/types/EtherspotTransactionKit.ts
+++ b/src/types/EtherspotTransactionKit.ts
@@ -35,7 +35,6 @@ export interface EstimatedBatch extends IBatch {
export interface SentBatch extends EstimatedBatch {
errorMessage?: string;
userOpHash?: string;
- transactionHash?: string;
}
export interface IBatches {