Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
Inform user about state of wallet-rpc download and monero wallet sync…
Browse files Browse the repository at this point in the history
… status
  • Loading branch information
binarybaron committed Dec 29, 2023
1 parent 4da0828 commit 217405e
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/main/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const queue = new PQueue({ concurrency: 1 });
let cli: ChildProcessWithoutNullStreams | null = null;

async function attemptKillMoneroWalletRpcProcess() {
if (process.env.SKIP_MONERO_WALLET_RPC_KILL === 'true') {
logger.debug('Skipping monero-wallet-rpc kill');
return;
}

const WIN_COMMAND = `powershell.exe "Get-Process | Where-Object {$_.Path -like '*monero-wallet-rpc*'} | Stop-Process -Force"`;
const UNIX_COMMAND = `ps aux | grep 'monero-wallet-rpc' | grep -v 'grep' | awk '{print $2}' | xargs kill -9`;

Expand Down Expand Up @@ -111,9 +116,7 @@ export async function spawnSubcommand(
);
}

if (process.env.SKIP_MONERO_WALLET_RPC_KILL !== 'true') {
attemptKillMoneroWalletRpcProcess();
}
attemptKillMoneroWalletRpcProcess();

cli = spawnProc(`./${binary.fileName}`, spawnArgs, {
cwd: binary.dirPath,
Expand Down
7 changes: 5 additions & 2 deletions src/main/cli/dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ export async function getFileData(file: string): Promise<string> {

export async function getCliLogStdOut(swapId: string): Promise<string> {
const logFile = await getCliLogFile(swapId);
const logData = await getFileData(logFile);
return logData;
try {
return await getFileData(logFile);
} catch (e) {
return '';
}
}

export async function makeFileExecutable(binary: Binary) {
Expand Down
53 changes: 53 additions & 0 deletions src/models/cliModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,56 @@ export function isCliLogFetchedPeerStatus(
): log is CliLogFetchedPeerStatus {
return log.fields.message === 'Fetched peer status';
}

export interface CliLogStartedSyncingMoneroWallet extends CliLog {
fields: {
message: 'Syncing Monero wallet';
current_sync_height?: boolean;
};
}

export function isCliLogStartedSyncingMoneroWallet(
log: CliLog
): log is CliLogStartedSyncingMoneroWallet {
return log.fields.message === 'Syncing Monero wallet';
}

export interface CliLogFinishedSyncingMoneroWallet extends CliLog {
fields: {
message: 'Synced Monero wallet';
};
}

export interface CliLogFailedToSyncMoneroWallet extends CliLog {
fields: {
message: 'Failed to sync Monero wallet';
error: string;
};
}

export function isCliLogFailedToSyncMoneroWallet(
log: CliLog
): log is CliLogFailedToSyncMoneroWallet {
return log.fields.message === 'Failed to sync Monero wallet';
}

export function isCliLogFinishedSyncingMoneroWallet(
log: CliLog
): log is CliLogFinishedSyncingMoneroWallet {
return log.fields.message === 'Synced Monero wallet';
}

export interface CliLogDownloadingMoneroWalletRpc extends CliLog {
fields: {
message: 'Downloading monero-wallet-rpc';
progress: string;
size: string;
download_url: string;
};
}

export function isCliLogDownloadingMoneroWalletRpc(
log: CliLog
): log is CliLogDownloadingMoneroWalletRpc {
return log.fields.message === 'Downloading monero-wallet-rpc';
}
11 changes: 11 additions & 0 deletions src/models/storeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ export interface SwapSlice {
provider: Provider | null;
spawnType: SwapSpawnType | null;
swapId: string | null;
parallelOperations: {
moneroWallet: {
isSyncing: boolean;
};
moneroWalletRpc: { updateState: false | MoneroWalletRpcUpdateState };
};
}

export type MoneroWalletRpcUpdateState = {
progress: string;
downloadUrl: string;
};

export interface SwapState {
type: SwapStateType;
}
Expand Down
20 changes: 20 additions & 0 deletions src/renderer/components/modal/swap/pages/SwapStatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,33 @@ import InitPage from './init/InitPage';
import XmrLockedPage from './in_progress/XmrLockedPage';
import BitcoinCancelledPage from './in_progress/BitcoinCancelledPage';
import BitcoinRefundedPage from './done/BitcoinRefundedPage';
import { useAppSelector } from '../../../../../store/hooks';
import DownloadingMoneroWalletRpcPage from './init/DownloadingMoneroWalletRpcPage';
import { SyncingMoneroWalletPage } from './in_progress/SyncingMoneroWalletPage';

export default function SwapStatePage({
swapState,
}: {
swapState: SwapState | null;
}) {
// TODO: Add punish page here, this is currently handled by the `process exited` page which is not optimal
const moneroWalletRpcDownloadState = useAppSelector(
(state) => state.swap.parallelOperations.moneroWalletRpc.updateState
);
const isSyncingMoneroWallet = useAppSelector(
(state) => state.swap.parallelOperations.moneroWallet.isSyncing
);

if (moneroWalletRpcDownloadState) {
return (
<DownloadingMoneroWalletRpcPage
updateState={moneroWalletRpcDownloadState}
/>
);
}
if (isSyncingMoneroWallet) {
return <SyncingMoneroWalletPage />;
}

if (swapState === null) {
return <InitPage />;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import CircularProgressWithSubtitle from '../../CircularProgressWithSubtitle';

export function SyncingMoneroWalletPage() {
return (
<CircularProgressWithSubtitle description="Syncing Monero wallet with blockchain, this might take a while..." />
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import CircularProgressWithSubtitle from '../../CircularProgressWithSubtitle';
import { MoneroWalletRpcUpdateState } from '../../../../../../models/storeModel';

export default function DownloadingMoneroWalletRpcPage({
updateState,
}: {
updateState: MoneroWalletRpcUpdateState;
}) {
return (
<CircularProgressWithSubtitle
description={`Updating monero-wallet-rpc (${updateState.progress}) `}
/>
);
}
27 changes: 27 additions & 0 deletions src/store/features/swapSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import {
isCliLogAdvancingState,
SwapSpawnType,
isCliLogBtcTxFound,
isCliLogStartedSyncingMoneroWallet,
isCliLogFinishedSyncingMoneroWallet,
isCliLogDownloadingMoneroWalletRpc,
isCliLogFailedToSyncMoneroWallet,
} from '../../models/cliModel';
import logger from '../../utils/logger';
import { Provider } from '../../models/apiModel';
Expand All @@ -46,6 +50,14 @@ const initialState: SwapSlice = {
stdOut: '',
provider: null,
spawnType: null,
parallelOperations: {
moneroWallet: {
isSyncing: false,
},
moneroWalletRpc: {
updateState: false,
},
},
};

export const swapSlice = createSlice({
Expand Down Expand Up @@ -216,6 +228,21 @@ export const swapSlice = createSlice({
};

slice.state = nextState;
} else if (isCliLogStartedSyncingMoneroWallet(log)) {
slice.parallelOperations.moneroWallet.isSyncing = true;
} else if (isCliLogFinishedSyncingMoneroWallet(log)) {
slice.parallelOperations.moneroWallet.isSyncing = false;
} else if (isCliLogFailedToSyncMoneroWallet(log)) {
slice.parallelOperations.moneroWallet.isSyncing = false;
} else if (isCliLogDownloadingMoneroWalletRpc(log)) {
slice.parallelOperations.moneroWalletRpc.updateState = {
progress: log.fields.progress,
downloadUrl: log.fields.download_url,
};

if (log.fields.progress === '100%') {
slice.parallelOperations.moneroWalletRpc.updateState = false;
}
} else {
logger.debug({ log }, `Swap log was not reduced`);
}
Expand Down

0 comments on commit 217405e

Please sign in to comment.