Skip to content

Commit

Permalink
Check status on initial page load
Browse files Browse the repository at this point in the history
  • Loading branch information
arhtudormorar committed Sep 13, 2024
1 parent d319e8b commit f601426
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ function manageTransaction({
}

if (hasStatusChanged) {
//otherwise, it will just trigger the change of status

updateSignedTransactionStatus({
sessionId,
status,
Expand Down
9 changes: 6 additions & 3 deletions src/core/methods/trackTransactions/trackTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ export async function trackTransactions(props?: TransactionsTrackerType) {
props?.getTransactionsByHash ?? defaultGetTxByHash;

// Function that handles message (checking transaction status)
const onMessage = () => {
const recheckStatus = () => {
checkTransactionStatus({
shouldRefreshBalance: isWebsocketCompleted,
getTransactionsByHash,
...props
});
};

// recheck on page initial page load
recheckStatus();

if (isWebsocketCompleted) {
// Do not set polling interval if websocket is complete
if (pollingIntervalTimer) {
Expand All @@ -41,13 +44,13 @@ export async function trackTransactions(props?: TransactionsTrackerType) {
store.subscribe(async ({ account: { websocketEvent } }) => {
if (websocketEvent?.message && timestamp !== websocketEvent.timestamp) {
timestamp = websocketEvent.timestamp;
onMessage();
recheckStatus();
}
});
} else {
// Set polling interval if websocket is not complete and no existing interval is set
if (!pollingIntervalTimer) {
pollingIntervalTimer = setInterval(onMessage, pollingInterval);
pollingIntervalTimer = setInterval(recheckStatus, pollingInterval);
}
}

Expand Down

0 comments on commit f601426

Please sign in to comment.