mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-12-21 19:36:56 -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
|
|
@ -28,10 +28,7 @@ import {
|
|||
RedactArgs,
|
||||
RedactResponse,
|
||||
} from "models/tauriModel";
|
||||
import {
|
||||
rpcSetBalance,
|
||||
rpcSetSwapInfo,
|
||||
} from "store/features/rpcSlice";
|
||||
import { rpcSetBalance, rpcSetSwapInfo } from "store/features/rpcSlice";
|
||||
import { store } from "./store/storeRenderer";
|
||||
import { Maker } from "models/apiModel";
|
||||
import { providerToConcatenatedMultiAddr } from "utils/multiAddrUtils";
|
||||
|
|
@ -50,12 +47,16 @@ export const PRESET_RENDEZVOUS_POINTS = [
|
|||
];
|
||||
|
||||
export async function fetchSellersAtPresetRendezvousPoints() {
|
||||
await Promise.all(PRESET_RENDEZVOUS_POINTS.map(async (rendezvousPoint) => {
|
||||
const response = await listSellersAtRendezvousPoint(rendezvousPoint);
|
||||
store.dispatch(discoveredMakersByRendezvous(response.sellers));
|
||||
await Promise.all(
|
||||
PRESET_RENDEZVOUS_POINTS.map(async (rendezvousPoint) => {
|
||||
const response = await listSellersAtRendezvousPoint(rendezvousPoint);
|
||||
store.dispatch(discoveredMakersByRendezvous(response.sellers));
|
||||
|
||||
logger.info(`Discovered ${response.sellers.length} sellers at rendezvous point ${rendezvousPoint} during startup fetch`);
|
||||
}));
|
||||
logger.info(
|
||||
`Discovered ${response.sellers.length} sellers at rendezvous point ${rendezvousPoint} during startup fetch`,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function invoke<ARGS, RESPONSE>(
|
||||
|
|
@ -73,8 +74,16 @@ async function invokeNoArgs<RESPONSE>(command: string): Promise<RESPONSE> {
|
|||
|
||||
export async function checkBitcoinBalance() {
|
||||
// If we are already syncing, don't start a new sync
|
||||
if (Object.values(store.getState().rpc?.state.background ?? {}).some(progress => progress.componentName === "SyncingBitcoinWallet" && progress.progress.type === "Pending")) {
|
||||
console.log("checkBitcoinBalance() was called but we are already syncing Bitcoin, skipping");
|
||||
if (
|
||||
Object.values(store.getState().rpc?.state.background ?? {}).some(
|
||||
(progress) =>
|
||||
progress.componentName === "SyncingBitcoinWallet" &&
|
||||
progress.progress.type === "Pending",
|
||||
)
|
||||
) {
|
||||
console.log(
|
||||
"checkBitcoinBalance() was called but we are already syncing Bitcoin, skipping",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -138,14 +147,14 @@ export async function buyXmr(
|
|||
"buy_xmr",
|
||||
bitcoin_change_address == null
|
||||
? {
|
||||
seller: providerToConcatenatedMultiAddr(seller),
|
||||
monero_receive_address,
|
||||
}
|
||||
seller: providerToConcatenatedMultiAddr(seller),
|
||||
monero_receive_address,
|
||||
}
|
||||
: {
|
||||
seller: providerToConcatenatedMultiAddr(seller),
|
||||
monero_receive_address,
|
||||
bitcoin_change_address,
|
||||
},
|
||||
seller: providerToConcatenatedMultiAddr(seller),
|
||||
monero_receive_address,
|
||||
bitcoin_change_address,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -187,11 +196,11 @@ export async function getLogsOfSwap(
|
|||
|
||||
/// Call the rust backend to redact logs.
|
||||
export async function redactLogs(
|
||||
logs: (string | CliLog)[]
|
||||
logs: (string | CliLog)[],
|
||||
): Promise<(string | CliLog)[]> {
|
||||
const response = await invoke<RedactArgs, RedactResponse>("redact", {
|
||||
text: logsToRawString(logs)
|
||||
})
|
||||
text: logsToRawString(logs),
|
||||
});
|
||||
|
||||
return parseLogsFromString(response.text);
|
||||
}
|
||||
|
|
@ -213,35 +222,37 @@ export async function initializeContext() {
|
|||
// - Fetch the status of all nodes for each blockchain in parallel
|
||||
// - Return the first available node for each blockchain
|
||||
// - If no node is available for a blockchain, return null for that blockchain
|
||||
const [bitcoinNode, moneroNode] = await Promise.all([Blockchain.Bitcoin, Blockchain.Monero].map(async (blockchain) => {
|
||||
const nodes = store.getState().settings.nodes[network][blockchain];
|
||||
const [bitcoinNode, moneroNode] = await Promise.all(
|
||||
[Blockchain.Bitcoin, Blockchain.Monero].map(async (blockchain) => {
|
||||
const nodes = store.getState().settings.nodes[network][blockchain];
|
||||
|
||||
if (nodes.length === 0) {
|
||||
return null;
|
||||
}
|
||||
if (nodes.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return await Promise.any(nodes.map(async node => {
|
||||
const isAvailable = await getNodeStatus(node, blockchain, network);
|
||||
try {
|
||||
return await Promise.any(
|
||||
nodes.map(async (node) => {
|
||||
const isAvailable = await getNodeStatus(node, blockchain, network);
|
||||
|
||||
if (isAvailable) {
|
||||
return node;
|
||||
}
|
||||
if (isAvailable) {
|
||||
return node;
|
||||
}
|
||||
|
||||
throw new Error(`No available ${blockchain} node found`);
|
||||
}));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
throw new Error(`No available ${blockchain} node found`);
|
||||
}),
|
||||
);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
// Initialize Tauri settings with null values
|
||||
const tauriSettings: TauriSettings = {
|
||||
electrum_rpc_url: bitcoinNode,
|
||||
monero_node_url: moneroNode,
|
||||
use_tor: useTor
|
||||
use_tor: useTor,
|
||||
};
|
||||
|
||||
logger.info("Initializing context with settings", tauriSettings);
|
||||
|
|
@ -253,35 +264,57 @@ export async function initializeContext() {
|
|||
}
|
||||
|
||||
export async function getWalletDescriptor() {
|
||||
return await invokeNoArgs<ExportBitcoinWalletResponse>("get_wallet_descriptor");
|
||||
return await invokeNoArgs<ExportBitcoinWalletResponse>(
|
||||
"get_wallet_descriptor",
|
||||
);
|
||||
}
|
||||
|
||||
export async function getMoneroNodeStatus(node: string, network: Network): Promise<boolean> {
|
||||
const response = await invoke<CheckMoneroNodeArgs, CheckMoneroNodeResponse>("check_monero_node", {
|
||||
url: node,
|
||||
network,
|
||||
});
|
||||
export async function getMoneroNodeStatus(
|
||||
node: string,
|
||||
network: Network,
|
||||
): Promise<boolean> {
|
||||
const response = await invoke<CheckMoneroNodeArgs, CheckMoneroNodeResponse>(
|
||||
"check_monero_node",
|
||||
{
|
||||
url: node,
|
||||
network,
|
||||
},
|
||||
);
|
||||
|
||||
return response.available;
|
||||
}
|
||||
|
||||
export async function getElectrumNodeStatus(url: string): Promise<boolean> {
|
||||
const response = await invoke<CheckElectrumNodeArgs, CheckElectrumNodeResponse>("check_electrum_node", {
|
||||
const response = await invoke<
|
||||
CheckElectrumNodeArgs,
|
||||
CheckElectrumNodeResponse
|
||||
>("check_electrum_node", {
|
||||
url,
|
||||
});
|
||||
|
||||
return response.available;
|
||||
}
|
||||
|
||||
export async function getNodeStatus(url: string, blockchain: Blockchain, network: Network): Promise<boolean> {
|
||||
export async function getNodeStatus(
|
||||
url: string,
|
||||
blockchain: Blockchain,
|
||||
network: Network,
|
||||
): Promise<boolean> {
|
||||
switch (blockchain) {
|
||||
case Blockchain.Monero: return await getMoneroNodeStatus(url, network);
|
||||
case Blockchain.Bitcoin: return await getElectrumNodeStatus(url);
|
||||
default: throw new Error(`Unsupported blockchain: ${blockchain}`);
|
||||
case Blockchain.Monero:
|
||||
return await getMoneroNodeStatus(url, network);
|
||||
case Blockchain.Bitcoin:
|
||||
return await getElectrumNodeStatus(url);
|
||||
default:
|
||||
throw new Error(`Unsupported blockchain: ${blockchain}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateNodeStatus(node: string, blockchain: Blockchain, network: Network) {
|
||||
async function updateNodeStatus(
|
||||
node: string,
|
||||
blockchain: Blockchain,
|
||||
network: Network,
|
||||
) {
|
||||
const status = await getNodeStatus(node, blockchain, network);
|
||||
|
||||
store.dispatch(setStatus({ node, status, blockchain }));
|
||||
|
|
@ -293,9 +326,11 @@ export async function updateAllNodeStatuses() {
|
|||
|
||||
// For all nodes, check if they are available and store the new status (in parallel)
|
||||
await Promise.all(
|
||||
Object.values(Blockchain).flatMap(blockchain =>
|
||||
settings.nodes[network][blockchain].map(node => updateNodeStatus(node, blockchain, network))
|
||||
)
|
||||
Object.values(Blockchain).flatMap((blockchain) =>
|
||||
settings.nodes[network][blockchain].map((node) =>
|
||||
updateNodeStatus(node, blockchain, network),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -310,10 +345,19 @@ export async function getDataDir(): Promise<string> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function resolveApproval(requestId: string, accept: boolean): Promise<void> {
|
||||
await invoke<ResolveApprovalArgs, ResolveApprovalResponse>("resolve_approval_request", { request_id: requestId, accept });
|
||||
export async function resolveApproval(
|
||||
requestId: string,
|
||||
accept: boolean,
|
||||
): Promise<void> {
|
||||
await invoke<ResolveApprovalArgs, ResolveApprovalResponse>(
|
||||
"resolve_approval_request",
|
||||
{ request_id: requestId, accept },
|
||||
);
|
||||
}
|
||||
|
||||
export async function saveLogFiles(zipFileName: string, content: Record<string, string>): Promise<void> {
|
||||
export async function saveLogFiles(
|
||||
zipFileName: string,
|
||||
content: Record<string, string>,
|
||||
): Promise<void> {
|
||||
await invokeUnsafe<void>("save_txt_files", { zipFileName, content });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue