Skip to content
Closed
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
15 changes: 5 additions & 10 deletions src-gui/src/store/middleware/storeListener.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createListenerMiddleware } from "@reduxjs/toolkit";
import { throttle, debounce } from "lodash";
import { throttle } from "lodash";
import {
getAllSwapInfos,
getAllSwapTimelocks,
Expand Down Expand Up @@ -42,22 +42,17 @@ const throttledGetSwapInfoFunctions = new Map<
// Function to get or create a throttled getSwapInfo for a specific swap_id
const getThrottledSwapInfoUpdater = (swapId: string) => {
if (!throttledGetSwapInfoFunctions.has(swapId)) {
// Create a throttled function that executes at most once every 2 seconds
// but will wait for 3 seconds of quiet during rapid calls (using debounce)
const debouncedGetSwapInfo = debounce(() => {
// Execute immediately on the first progress event, then coalesce rapid
// follow-up events so the history view is kept fresh without hammering RPC.
const throttledFunction = throttle(() => {
logger.debug(`Executing getSwapInfo for swap ${swapId}`);
getSwapInfo(swapId).catch((error) => {
logger.debug(`Failed to fetch swap info for swap ${swapId}: ${error}`);
});
getSwapTimelock(swapId).catch((error) => {
logger.debug(`Failed to fetch timelock for swap ${swapId}: ${error}`);
});
}, 3000); // 3 seconds debounce for rapid calls

const throttledFunction = throttle(debouncedGetSwapInfo, 2000, {
leading: true, // Execute immediately on first call
trailing: true, // Execute on trailing edge if needed
});
}, 2000);

throttledGetSwapInfoFunctions.set(swapId, throttledFunction);
}
Expand Down