Skip to content

Commit

Permalink
wallet: only update transactions when UI visible (#1383)
Browse files Browse the repository at this point in the history
* wallet: only update transactions when UI visible

* refresh state when showing ui
  • Loading branch information
juliangruber authored Mar 5, 2024
1 parent f78d156 commit f4d2280
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion main/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
getOnboardingCompleted
} = require('./station-config')
const { showDialogSync } = require('./dialog')
const wallet = require('./wallet')

/**
* @param {import('./typings').Context} ctx
Expand All @@ -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} */
Expand Down
11 changes: 7 additions & 4 deletions main/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -241,6 +243,7 @@ function loadScheduledRewards () {

module.exports = {
setup,
refreshState,
getAddress,
getBalance,
getScheduledRewards,
Expand Down

0 comments on commit f4d2280

Please sign in to comment.