Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase polling frequency as we approach the ETA #2600

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions wormhole-connect/src/hooks/useTrackTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isCompleted } from '@wormhole-foundation/sdk';
import { RouteContext } from 'contexts/RouteContext';
import { useContext, useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { setRedeemTx, setTransferComplete } from 'store/redeem';
import type { RootState } from 'store';
import { sleep } from 'utils';

const TRACK_TIMEOUT = 120 * 1000;
Expand All @@ -13,9 +14,18 @@ const useTrackTransfer = (): void => {

const routeContext = useContext(RouteContext);

const { txData, timestamp } = useSelector((state: RootState) => state.redeem);

useEffect(() => {
let isActive = true;

let sleepTime = 5000;

if (txData && txData.eta && txData.eta < 30_000) {
// Poll aggressively for very fast transfers
sleepTime = 1000;
}

const track = async () => {
const { route, receipt } = routeContext;

Expand Down Expand Up @@ -59,10 +69,12 @@ const useTrackTransfer = (): void => {
}
} catch (e) {
console.error('Error tracking transfer:', e);
kev1n-peters marked this conversation as resolved.
Show resolved Hide resolved
sleepTime = 5000; // Back off if we were polling aggressively
}

// retry
// TODO: exponential backoff depending on the current state?
await sleep(5000);
await sleep(sleepTime);
}
};

Expand All @@ -71,7 +83,7 @@ const useTrackTransfer = (): void => {
return () => {
isActive = false;
};
}, [routeContext]);
}, [routeContext, txData?.eta, timestamp]);
};

export default useTrackTransfer;
3 changes: 1 addition & 2 deletions wormhole-connect/src/views/v2/Redeem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ const Redeem = () => {
route: routeName,
timestamp: txTimestamp,
isResumeTx,
txData,
} = useSelector((state: RootState) => state.redeem);

const { txData } = useSelector((state: RootState) => state.redeem);

const { state: receiptState } = routeContext.receipt || {};
const isTxAttested = receiptState && receiptState >= TransferState.Attested;
const isTxRefunded = receiptState === TransferState.Refunded;
Expand Down
Loading