From 42739d9456a94c6057d2d2975353ed73eab04cbb Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Tue, 15 Oct 2024 19:26:53 +0200 Subject: [PATCH] Fix daemon url --- .../core/services/daemon/daemon.service.ts | 59 +++++++++++-------- src/polyfills.ts | 1 + 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/app/core/services/daemon/daemon.service.ts b/src/app/core/services/daemon/daemon.service.ts index c9134f8..16b6ae9 100644 --- a/src/app/core/services/daemon/daemon.service.ts +++ b/src/app/core/services/daemon/daemon.service.ts @@ -91,9 +91,25 @@ export class DaemonService { private openDbPromise: Promise; private daemonRunning?: boolean; - private url: string = "http://127.0.0.1:28081"; + private get url(): string { + return `http://127.0.0.1:${this.port}`; + } public settings: DaemonSettings; + private get port(): number { + if (this.settings.rpcBindPort > 0) { + return this.settings.rpcBindPort; + } + else if (this.settings.mainnet) { + return 18081; + } + else if (this.settings.testnet) { + return 28081; + } + + return 38081; + } + //private url: string = "http://node2.monerodevs.org:28089"; //private url: string = "https://testnet.xmr.ditatompel.com"; //private url: string = "https://xmr.yemekyedim.com:18081"; @@ -119,22 +135,11 @@ export class DaemonService { this.openDbPromise = this.openDatabase(); this.settings = new DaemonSettings(); - const wdw = (window as any); - - if (this.electronService.isElectron) { - this.electronService.ipcRenderer.on('monero-close', (event, code: number | null) => { - console.log(event); - console.log(code); - this.onClose(); - }); - } - else if (wdw.electronAPI && wdw.electronAPI.onMoneroClose) { - wdw.electronAPI.onMoneroClose((event: any, code: number) => { - console.log(event); - console.log(code); - this.onClose(); - }); - } + window.electronAPI.onMoneroClose((event: any, code: number) => { + console.log(event); + console.log(code); + this.onClose(); + }); } public async isWifiConnected(): Promise { @@ -365,18 +370,20 @@ export class DaemonService { if (started) { console.log("Daemon started"); - this.isRunning(true).then((running: boolean) => { - this.onDaemonStatusChanged.emit(running); - this.starting = false; - resolve(); + this.delay(3000).then(() => { + this.isRunning(true).then((running: boolean) => { + this.onDaemonStatusChanged.emit(running); + this.starting = false; + resolve(); + }).catch((error: any) => { + console.error(error); + this.onDaemonStatusChanged.emit(false); + this.starting = false; + reject(error); + }); }).catch((error: any) => { console.error(error); - this.onDaemonStatusChanged.emit(false); - this.starting = false; - reject(error); }); - - } else { console.log("Daemon not started"); diff --git a/src/polyfills.ts b/src/polyfills.ts index 4b21307..f641105 100644 --- a/src/polyfills.ts +++ b/src/polyfills.ts @@ -60,6 +60,7 @@ declare global { electronAPI: { startMonerod: (options: string[]) => void; onMonerodStarted: (callback: (event: any, started: boolean) => void) => void; + onMoneroClose: (callback: (event: any, code: number) => void) => void; isWifiConnected: () => void; onIsWifiConnectedResponse: (callback: (event: any, connected: boolean) => void) => void; getOsType: () => void;