From 217405e563664db6c3981af50a79cffa23f428d1 Mon Sep 17 00:00:00 2001 From: binarybaron <86064887+binarybaron@users.noreply.github.com> Date: Fri, 29 Dec 2023 14:15:32 +0100 Subject: [PATCH] Inform user about state of wallet-rpc download and monero wallet sync status --- src/main/cli/cli.ts | 9 ++-- src/main/cli/dirs.ts | 7 ++- src/models/cliModel.ts | 53 +++++++++++++++++++ src/models/storeModel.ts | 11 ++++ .../modal/swap/pages/SwapStatePage.tsx | 20 +++++++ .../in_progress/SyncingMoneroWalletPage.tsx | 7 +++ .../init/DownloadingMoneroWalletRpcPage.tsx | 14 +++++ src/store/features/swapSlice.ts | 27 ++++++++++ 8 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 src/renderer/components/modal/swap/pages/in_progress/SyncingMoneroWalletPage.tsx create mode 100644 src/renderer/components/modal/swap/pages/init/DownloadingMoneroWalletRpcPage.tsx diff --git a/src/main/cli/cli.ts b/src/main/cli/cli.ts index c8b46669..43102806 100644 --- a/src/main/cli/cli.ts +++ b/src/main/cli/cli.ts @@ -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`; @@ -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, diff --git a/src/main/cli/dirs.ts b/src/main/cli/dirs.ts index a6a71e9d..4d79bda6 100644 --- a/src/main/cli/dirs.ts +++ b/src/main/cli/dirs.ts @@ -141,8 +141,11 @@ export async function getFileData(file: string): Promise { export async function getCliLogStdOut(swapId: string): Promise { 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) { diff --git a/src/models/cliModel.ts b/src/models/cliModel.ts index b5f66881..2503c32d 100644 --- a/src/models/cliModel.ts +++ b/src/models/cliModel.ts @@ -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'; +} diff --git a/src/models/storeModel.ts b/src/models/storeModel.ts index afaa5f38..ee37c53d 100644 --- a/src/models/storeModel.ts +++ b/src/models/storeModel.ts @@ -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; } diff --git a/src/renderer/components/modal/swap/pages/SwapStatePage.tsx b/src/renderer/components/modal/swap/pages/SwapStatePage.tsx index 87164931..6caa3679 100644 --- a/src/renderer/components/modal/swap/pages/SwapStatePage.tsx +++ b/src/renderer/components/modal/swap/pages/SwapStatePage.tsx @@ -28,6 +28,9 @@ 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, @@ -35,6 +38,23 @@ export default function SwapStatePage({ 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 ( + + ); + } + if (isSyncingMoneroWallet) { + return ; + } if (swapState === null) { return ; diff --git a/src/renderer/components/modal/swap/pages/in_progress/SyncingMoneroWalletPage.tsx b/src/renderer/components/modal/swap/pages/in_progress/SyncingMoneroWalletPage.tsx new file mode 100644 index 00000000..17e37f13 --- /dev/null +++ b/src/renderer/components/modal/swap/pages/in_progress/SyncingMoneroWalletPage.tsx @@ -0,0 +1,7 @@ +import CircularProgressWithSubtitle from '../../CircularProgressWithSubtitle'; + +export function SyncingMoneroWalletPage() { + return ( + + ); +} diff --git a/src/renderer/components/modal/swap/pages/init/DownloadingMoneroWalletRpcPage.tsx b/src/renderer/components/modal/swap/pages/init/DownloadingMoneroWalletRpcPage.tsx new file mode 100644 index 00000000..7cc43bd6 --- /dev/null +++ b/src/renderer/components/modal/swap/pages/init/DownloadingMoneroWalletRpcPage.tsx @@ -0,0 +1,14 @@ +import CircularProgressWithSubtitle from '../../CircularProgressWithSubtitle'; +import { MoneroWalletRpcUpdateState } from '../../../../../../models/storeModel'; + +export default function DownloadingMoneroWalletRpcPage({ + updateState, +}: { + updateState: MoneroWalletRpcUpdateState; +}) { + return ( + + ); +} diff --git a/src/store/features/swapSlice.ts b/src/store/features/swapSlice.ts index 29d57739..93f5fb3b 100644 --- a/src/store/features/swapSlice.ts +++ b/src/store/features/swapSlice.ts @@ -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'; @@ -46,6 +50,14 @@ const initialState: SwapSlice = { stdOut: '', provider: null, spawnType: null, + parallelOperations: { + moneroWallet: { + isSyncing: false, + }, + moneroWalletRpc: { + updateState: false, + }, + }, }; export const swapSlice = createSlice({ @@ -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`); }