Skip to content

Commit

Permalink
refactor: add enum for setup messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Mar 11, 2024
1 parent ff3688b commit b6a3fef
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion electron/autoUpdaterManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class AutoUpdaterManager {
this.showDialog(actions)
})
autoUpdater.on('error', err => {
console.log('Error in auto-updater. ' + err)
console.log('Error in auto-updater ' + err)
})
autoUpdater.on('update-downloaded', () => {
this.closeWindowAndRestart(actions)
Expand Down
9 changes: 5 additions & 4 deletions src/services/handleIpcEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@/ipc/ipcEvents'
import { sendShutdownFinished } from '@/ipc/ipcMessages'
import { Router } from 'vue-router'
import { SetupMessages } from '@/types'

export function listenIpcMainEvents({
store,
Expand All @@ -25,20 +26,20 @@ export function listenIpcMainEvents({
console.log('Message from Main process:', message)
})
onDownloadProgress((progress: any) => {
store.commit('setMessage', { message: 'Updating wallet backend' })
store.commit('setMessage', { message: SetupMessages.updatingWalletBackend })
store.commit('setProgress', { progress: progress.percentage })
})
onDownloadedStatus(() => {
store.commit('setMessage', { message: 'wallet up to date' })
store.commit('setMessage', { message: SetupMessages.walletUpToDate })
})
onLoadedStatus((message: any) => {
if (Array.isArray(message) && message[0].isDefaultWallet) {
store.commit('setWalletOwner', { isDefaultWallet: true })
}
store.commit('setMessage', { message: 'loaded' })
store.commit('setMessage', { message: SetupMessages.loaded })
})
onRunningStatus(() => {
store.commit('setMessage', { message: 'Running wallet' })
store.commit('setMessage', { message: SetupMessages.runningWallet })
})
onOSNotSupported(() => {
router.push('/wallet-not-found')
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ export interface LanguageDictionary {
[LocaleCodes.en]: CustomLocale
[LocaleCodes.es]: CustomLocale
}

export enum SetupMessages {
runningWallet = 'Running wallet',
updatingWalletBackend = 'Updating wallet backend',
walletUpToDate = 'Wallet up to date',
loaded = 'Loaded',
}
33 changes: 17 additions & 16 deletions src/views/Setup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,30 @@
<div class="header">
<div class="filling-icon">
<font-awesome-icon
v-if="
setupMessage === 'Updating wallet backend' ||
setupMessage === 'wallet up to date'
"
v-if="isWalletUpdating || isWalletUpToDate"
class="icon"
icon="wallet"
/>
<font-awesome-icon
v-if="setupMessage === 'Running wallet' || !setupMessage"
v-if="isWalletRunning || !setupMessage"
class="icon"
icon="cogs"
/>
<font-awesome-icon
v-if="setupMessage === 'loaded'"
class="icon"
icon="check"
/>
<font-awesome-icon v-if="isWalletLoaded" class="icon" icon="check" />
<div class="banner" />
</div>
<div>
<p class="progress-title">{{ $t('preparing_sheikah') }}</p>
<p class="progress-subtitle">
{{ format(percentage) }}
<DotsLoading
v-if="theme === THEMES.DARK"
v-if="isThemeDark"
color="#d6d6d6"
data-test="loading-spinner"
class="spinner"
/>
<DotsLoading
v-if="theme === THEMES.LIGHT"
v-if="isThemeLight"
color="#444258"
data-test="loading-spinner"
class="spinner"
Expand All @@ -56,6 +49,7 @@ import { mapState, mapMutations } from 'vuex'
import { THEMES } from '@/constants'
import DotsLoading from '@/components/DotsLoading.vue'
import { checkDisconnection } from '@/services/checkDisconnection'
import { SetupMessages } from '@/types'
export default {
name: 'WalletNotFound',
Expand All @@ -73,14 +67,21 @@ export default {
progress: state => state.uiInteractions.setupProgress,
theme: state => state.wallet.theme,
}),
isWalletRunning: () => this.setupMessage === SetupMessages.runningWallet,
isWalletLoaded: () => this.setupMessage === SetupMessages.loaded,
isWalletUpToDate: () => this.setupMessage === SetupMessages.walletUpToDate,
isWalletUpdating: () =>
this.setupMessage === SetupMessages.updatingWalletBackend,
isThemeLight: () => this.theme === THEMES.LIGHT,
isThemeDark: () => this.theme === THEMES.DARK,
percentage() {
if (this.setupMessage === 'Updating wallet backend') {
if (this.isWalletUpdating) {
return Math.round(this.progress * 0.8)
} else if (this.setupMessage === 'wallet up to date') {
} else if (this.isWalletUpToDate) {
return 80
} else if (this.setupMessage === 'Running wallet') {
} else if (this.isWalletRunning) {
return 90
} else if (this.setupMessage === 'loaded') {
} else if (this.isWalletLoaded) {
return 100
} else {
return 0
Expand Down

0 comments on commit b6a3fef

Please sign in to comment.