mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-12-20 19:06:43 -05:00
feat(tauri): Initialize Context in background (#59)
This PR does the following: - The Context (including Bitcoin wallet, Monero wallet, ...) is initialized in the background. This allows the window to be displayed instantly upon startup. - Host sends events to Guest about progress of Context initialization. Those events are used to display an alert in the navigation bar. - If a Tauri command is invoked which requires the Context to be available, an error will be returned - As soon as the Context becomes available the `Guest` requests the history and Bitcoin balance - Re-enables Material UI animations
This commit is contained in:
parent
792fbbf746
commit
e4141c763b
17 changed files with 369 additions and 191 deletions
76
src-gui/src/renderer/components/alert/DaemonStatusAlert.tsx
Normal file
76
src-gui/src/renderer/components/alert/DaemonStatusAlert.tsx
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
import { CircularProgress } from "@material-ui/core";
|
||||
import { Alert, AlertProps } from "@material-ui/lab";
|
||||
import { TauriContextInitializationProgress } from "models/tauriModel";
|
||||
import { useState } from "react";
|
||||
import { useAppSelector } from "store/hooks";
|
||||
import { exhaustiveGuard } from "utils/typescriptUtils";
|
||||
|
||||
const FUNNY_INIT_MESSAGES = [
|
||||
"Initializing quantum entanglement...",
|
||||
"Generating one-time pads from cosmic background radiation...",
|
||||
"Negotiating key exchange with aliens...",
|
||||
"Optimizing elliptic curves for maximum sneakiness...",
|
||||
"Transforming plaintext into ciphertext via arcane XOR rituals...",
|
||||
"Salting your hash with exotic mathematical seasonings...",
|
||||
"Performing advanced modular arithmetic gymnastics...",
|
||||
"Consulting the Oracle of Randomness...",
|
||||
"Executing top-secret permutation protocols...",
|
||||
"Summoning prime factors from the mathematical aether...",
|
||||
"Deploying steganographic squirrels to hide your nuts of data...",
|
||||
"Initializing the quantum superposition of your keys...",
|
||||
"Applying post-quantum cryptographic voodoo...",
|
||||
"Encrypting your data with the tears of frustrated regulators...",
|
||||
];
|
||||
|
||||
function LoadingSpinnerAlert({ ...rest }: AlertProps) {
|
||||
return <Alert icon={<CircularProgress size={22} />} {...rest} />;
|
||||
}
|
||||
|
||||
export default function DaemonStatusAlert() {
|
||||
const contextStatus = useAppSelector((s) => s.rpc.status);
|
||||
|
||||
const [initMessage] = useState(
|
||||
FUNNY_INIT_MESSAGES[Math.floor(Math.random() * FUNNY_INIT_MESSAGES.length)],
|
||||
);
|
||||
|
||||
if (contextStatus == null) {
|
||||
return (
|
||||
<LoadingSpinnerAlert severity="warning">
|
||||
{initMessage}
|
||||
</LoadingSpinnerAlert>
|
||||
);
|
||||
}
|
||||
|
||||
switch (contextStatus.type) {
|
||||
case "Initializing":
|
||||
switch (contextStatus.content) {
|
||||
case TauriContextInitializationProgress.OpeningBitcoinWallet:
|
||||
return (
|
||||
<LoadingSpinnerAlert severity="warning">
|
||||
Connecting to the Bitcoin network
|
||||
</LoadingSpinnerAlert>
|
||||
);
|
||||
case TauriContextInitializationProgress.OpeningMoneroWallet:
|
||||
return (
|
||||
<LoadingSpinnerAlert severity="warning">
|
||||
Connecting to the Monero network
|
||||
</LoadingSpinnerAlert>
|
||||
);
|
||||
case TauriContextInitializationProgress.OpeningDatabase:
|
||||
return (
|
||||
<LoadingSpinnerAlert severity="warning">
|
||||
Opening the local database
|
||||
</LoadingSpinnerAlert>
|
||||
);
|
||||
}
|
||||
break;
|
||||
case "Available":
|
||||
return <Alert severity="success">The daemon is running</Alert>;
|
||||
case "Failed":
|
||||
return (
|
||||
<Alert severity="error">The daemon has stopped unexpectedly</Alert>
|
||||
);
|
||||
default:
|
||||
return exhaustiveGuard(contextStatus);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
import { CircularProgress } from "@material-ui/core";
|
||||
import { Alert } from "@material-ui/lab";
|
||||
import { RpcProcessStateType } from "models/rpcModel";
|
||||
import { useAppSelector } from "store/hooks";
|
||||
|
||||
// TODO: Reimplement this using Tauri
|
||||
// Currently the RPC process is always available, so this component is not needed
|
||||
// since the UI is only displayed when the RPC process is available
|
||||
export default function RpcStatusAlert() {
|
||||
const rpcProcess = useAppSelector((s) => s.rpc.process);
|
||||
if (rpcProcess.type === RpcProcessStateType.STARTED) {
|
||||
return (
|
||||
<Alert severity="warning" icon={<CircularProgress size={22} />}>
|
||||
The swap daemon is starting
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
if (rpcProcess.type === RpcProcessStateType.LISTENING_FOR_CONNECTIONS) {
|
||||
return <Alert severity="success">The swap daemon is running</Alert>;
|
||||
}
|
||||
if (rpcProcess.type === RpcProcessStateType.NOT_STARTED) {
|
||||
return <Alert severity="warning">The swap daemon is being started</Alert>;
|
||||
}
|
||||
if (rpcProcess.type === RpcProcessStateType.EXITED) {
|
||||
return (
|
||||
<Alert severity="error">The swap daemon has stopped unexpectedly</Alert>
|
||||
);
|
||||
}
|
||||
return <></>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue