mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-25 18:26:28 -05:00
refactor(gui): Update MUI to v7 (#383)
* task(gui): update to mui v5 * task(gui): use sx prop instead of system props * task(gui): update to mui v6 and replace makeStyles with sx prop * task(gui): update to mui v7 * task(gui): update react * fix(gui): fix import * task(gui): adjust theme and few components to fix migration introduced styling errors * fix(gui): animation issues with text field animations * fix(gui): remove 'darker' theme and make 'dark' theme the default - with the new update 'dark' theme is already quite dark and therefore a 'darker' theme not necessary - the default theme is set to 'dark' now in settings initialization * feat(tooling): Upgrade dprint to 0.50.0, eslint config, prettier, justfile commands - Upgrade dprint to 0.50.0 - Use sane default eslint config (fairly permissive) - `dprint fmt` now runs prettier for the `src-gui` folder - Added `check_gui_eslint`, `check_gui_tsc` and `check_gui` commands * refactor: fix a few eslint errors * dprint fmt * fix tsc complains * nitpick: small spacing issue --------- Co-authored-by: Binarybaron <binarybaron@protonmail.com> Co-authored-by: Mohan <86064887+binarybaron@users.noreply.github.com>
This commit is contained in:
parent
2ba69ba340
commit
430a22fbf6
169 changed files with 12883 additions and 3950 deletions
|
|
@ -1,10 +1,27 @@
|
|||
import { listen } from "@tauri-apps/api/event";
|
||||
import { TauriContextStatusEvent, TauriEvent } from "models/tauriModel";
|
||||
import { contextStatusEventReceived, receivedCliLog, rpcSetBalance, timelockChangeEventReceived, approvalEventReceived, backgroundProgressEventReceived } from "store/features/rpcSlice";
|
||||
import {
|
||||
contextStatusEventReceived,
|
||||
receivedCliLog,
|
||||
rpcSetBalance,
|
||||
timelockChangeEventReceived,
|
||||
approvalEventReceived,
|
||||
backgroundProgressEventReceived,
|
||||
} from "store/features/rpcSlice";
|
||||
import { swapProgressEventReceived } from "store/features/swapSlice";
|
||||
import logger from "utils/logger";
|
||||
import { fetchAllConversations, updateAlerts, updatePublicRegistry, updateRates } from "./api";
|
||||
import { checkContextAvailability, getSwapInfo, initializeContext, updateAllNodeStatuses } from "./rpc";
|
||||
import {
|
||||
fetchAllConversations,
|
||||
updateAlerts,
|
||||
updatePublicRegistry,
|
||||
updateRates,
|
||||
} from "./api";
|
||||
import {
|
||||
checkContextAvailability,
|
||||
getSwapInfo,
|
||||
initializeContext,
|
||||
updateAllNodeStatuses,
|
||||
} from "./rpc";
|
||||
import { store } from "./store/storeRenderer";
|
||||
import { exhaustiveGuard } from "utils/typescriptUtils";
|
||||
|
||||
|
|
@ -23,81 +40,86 @@ const UPDATE_RATE_INTERVAL = 5 * 60 * 1_000;
|
|||
const FETCH_CONVERSATIONS_INTERVAL = 10 * 60 * 1_000;
|
||||
|
||||
function setIntervalImmediate(callback: () => void, interval: number): void {
|
||||
callback();
|
||||
setInterval(callback, interval);
|
||||
callback();
|
||||
setInterval(callback, interval);
|
||||
}
|
||||
|
||||
export async function setupBackgroundTasks(): Promise<void> {
|
||||
// Setup periodic fetch tasks
|
||||
setIntervalImmediate(updatePublicRegistry, PROVIDER_UPDATE_INTERVAL);
|
||||
setIntervalImmediate(updateAllNodeStatuses, STATUS_UPDATE_INTERVAL);
|
||||
setIntervalImmediate(updateRates, UPDATE_RATE_INTERVAL);
|
||||
setIntervalImmediate(fetchAllConversations, FETCH_CONVERSATIONS_INTERVAL);
|
||||
// Setup periodic fetch tasks
|
||||
setIntervalImmediate(updatePublicRegistry, PROVIDER_UPDATE_INTERVAL);
|
||||
setIntervalImmediate(updateAllNodeStatuses, STATUS_UPDATE_INTERVAL);
|
||||
setIntervalImmediate(updateRates, UPDATE_RATE_INTERVAL);
|
||||
setIntervalImmediate(fetchAllConversations, FETCH_CONVERSATIONS_INTERVAL);
|
||||
|
||||
// Fetch all alerts
|
||||
updateAlerts();
|
||||
// Fetch all alerts
|
||||
updateAlerts();
|
||||
|
||||
// Setup Tauri event listeners
|
||||
// Check if the context is already available. This is to prevent unnecessary re-initialization
|
||||
if (await checkContextAvailability()) {
|
||||
store.dispatch(contextStatusEventReceived(TauriContextStatusEvent.Available));
|
||||
} else {
|
||||
// Warning: If we reload the page while the Context is being initialized, this function will throw an error
|
||||
// Setup Tauri event listeners
|
||||
// Check if the context is already available. This is to prevent unnecessary re-initialization
|
||||
if (await checkContextAvailability()) {
|
||||
store.dispatch(
|
||||
contextStatusEventReceived(TauriContextStatusEvent.Available),
|
||||
);
|
||||
} else {
|
||||
// Warning: If we reload the page while the Context is being initialized, this function will throw an error
|
||||
initializeContext().catch((e) => {
|
||||
logger.error(
|
||||
e,
|
||||
"Failed to initialize context on page load. This might be because we reloaded the page while the context was being initialized",
|
||||
);
|
||||
// Wait a short time before retrying
|
||||
setTimeout(() => {
|
||||
initializeContext().catch((e) => {
|
||||
logger.error(e, "Failed to initialize context on page load. This might be because we reloaded the page while the context was being initialized");
|
||||
// Wait a short time before retrying
|
||||
setTimeout(() => {
|
||||
initializeContext().catch((e) => {
|
||||
logger.error(e, "Failed to initialize context even after retry");
|
||||
});
|
||||
}, 2000);
|
||||
logger.error(e, "Failed to initialize context even after retry");
|
||||
});
|
||||
}
|
||||
|
||||
// Listen for the unified event
|
||||
listen<TauriEvent>(TAURI_UNIFIED_EVENT_CHANNEL_NAME, (event) => {
|
||||
const { channelName, event: eventData } = event.payload;
|
||||
|
||||
switch (channelName) {
|
||||
case "SwapProgress":
|
||||
store.dispatch(swapProgressEventReceived(eventData));
|
||||
break;
|
||||
|
||||
case "ContextInitProgress":
|
||||
store.dispatch(contextStatusEventReceived(eventData));
|
||||
break;
|
||||
|
||||
case "CliLog":
|
||||
store.dispatch(receivedCliLog(eventData));
|
||||
break;
|
||||
|
||||
case "BalanceChange":
|
||||
store.dispatch(rpcSetBalance((eventData).balance));
|
||||
break;
|
||||
|
||||
case "SwapDatabaseStateUpdate":
|
||||
getSwapInfo(eventData.swap_id);
|
||||
|
||||
// This is ugly but it's the best we can do for now
|
||||
// Sometimes we are too quick to fetch the swap info and the new state is not yet reflected
|
||||
// in the database. So we wait a bit before fetching the new state
|
||||
setTimeout(() => getSwapInfo(eventData.swap_id), 3000);
|
||||
break;
|
||||
|
||||
case "TimelockChange":
|
||||
store.dispatch(timelockChangeEventReceived(eventData));
|
||||
break;
|
||||
|
||||
case "Approval":
|
||||
store.dispatch(approvalEventReceived(eventData));
|
||||
break;
|
||||
|
||||
case "BackgroundProgress":
|
||||
store.dispatch(backgroundProgressEventReceived(eventData));
|
||||
break;
|
||||
|
||||
default:
|
||||
exhaustiveGuard(channelName);
|
||||
}
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Listen for the unified event
|
||||
listen<TauriEvent>(TAURI_UNIFIED_EVENT_CHANNEL_NAME, (event) => {
|
||||
const { channelName, event: eventData } = event.payload;
|
||||
|
||||
switch (channelName) {
|
||||
case "SwapProgress":
|
||||
store.dispatch(swapProgressEventReceived(eventData));
|
||||
break;
|
||||
|
||||
case "ContextInitProgress":
|
||||
store.dispatch(contextStatusEventReceived(eventData));
|
||||
break;
|
||||
|
||||
case "CliLog":
|
||||
store.dispatch(receivedCliLog(eventData));
|
||||
break;
|
||||
|
||||
case "BalanceChange":
|
||||
store.dispatch(rpcSetBalance(eventData.balance));
|
||||
break;
|
||||
|
||||
case "SwapDatabaseStateUpdate":
|
||||
getSwapInfo(eventData.swap_id);
|
||||
|
||||
// This is ugly but it's the best we can do for now
|
||||
// Sometimes we are too quick to fetch the swap info and the new state is not yet reflected
|
||||
// in the database. So we wait a bit before fetching the new state
|
||||
setTimeout(() => getSwapInfo(eventData.swap_id), 3000);
|
||||
break;
|
||||
|
||||
case "TimelockChange":
|
||||
store.dispatch(timelockChangeEventReceived(eventData));
|
||||
break;
|
||||
|
||||
case "Approval":
|
||||
store.dispatch(approvalEventReceived(eventData));
|
||||
break;
|
||||
|
||||
case "BackgroundProgress":
|
||||
store.dispatch(backgroundProgressEventReceived(eventData));
|
||||
break;
|
||||
|
||||
default:
|
||||
exhaustiveGuard(channelName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue