From f4d2280d7468b1494cc82bd07ba02b15f463eb84 Mon Sep 17 00:00:00 2001 From: Julian Gruber Date: Tue, 5 Mar 2024 07:05:25 -0800 Subject: [PATCH] wallet: only update transactions when UI visible (#1383) * wallet: only update transactions when UI visible * refresh state when showing ui --- main/ui.js | 6 +++++- main/wallet.js | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/main/ui.js b/main/ui.js index 9d57c1c5b..8a8464994 100644 --- a/main/ui.js +++ b/main/ui.js @@ -10,6 +10,7 @@ const { getOnboardingCompleted } = require('./station-config') const { showDialogSync } = require('./dialog') +const wallet = require('./wallet') /** * @param {import('./typings').Context} ctx @@ -35,7 +36,10 @@ module.exports = async function (ctx) { } }) - ui.on('show', () => { ctx.isShowingUI = true }) + ui.on('show', () => { + ctx.isShowingUI = true + wallet.refreshState().catch(console.error) + }) ui.on('hide', () => { ctx.isShowingUI = false }) /** @type {import('vite').ViteDevServer} */ diff --git a/main/wallet.js b/main/wallet.js index 1cd2107cb..bdca431a4 100644 --- a/main/wallet.js +++ b/main/wallet.js @@ -66,10 +66,12 @@ async function refreshState () { } catch (err) { log.error('Cannot update balance:', err) } - try { - await backend.fetchAllTransactions() - } catch (err) { - log.error('Cannot update transactions:', err) + if (ctx?.isShowingUI) { + try { + await backend.fetchAllTransactions() + } catch (err) { + log.error('Cannot update transactions:', err) + } } } @@ -241,6 +243,7 @@ function loadScheduledRewards () { module.exports = { setup, + refreshState, getAddress, getBalance, getScheduledRewards,