Skip to content

Commit

Permalink
feat: implement modal to reset wallet backend
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Mar 21, 2024
1 parent 2bbeb68 commit 369faa9
Show file tree
Hide file tree
Showing 16 changed files with 261 additions and 15 deletions.
1 change: 1 addition & 0 deletions electron/ipc/ipcActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export const IPC_ACTIONS = {
SET_LOADED_STATUS: 'SET_LOADED_STATUS',
SET_DOWNLOAD_PROGRESS: 'SET_DOWNLOAD_PROGRESS',
SET_OS_NOT_SUPPORTED: 'SET_OS_NOT_SUPPORTED',
CLEAR_WALLET_FILES: 'CLEAR_WALLET_FILES',
},
}
18 changes: 8 additions & 10 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AutoUpdaterManager } from '../autoUpdaterManager'
import overwriteWitnetNodeConfiguration from '../utils/overwriteWitnetNodeConfiguration'
import { SHEIKAH_PATH } from '../constants'

const { SHUTDOWN, SHUTDOWN_FINISHED } = IPC_ACTIONS.Window
const { SHUTDOWN, SHUTDOWN_FINISHED, CLEAR_WALLET_FILES } = IPC_ACTIONS.Window

globalThis.__filename = fileURLToPath(import.meta.url)
globalThis.__dirname = dirname(__filename)
Expand Down Expand Up @@ -71,7 +71,6 @@ async function createWindow() {

if (!process.env.VITE_DEV_SERVER_URL) {
// Hide electron toolbar in production environment
win.setMenuBarVisibility(false)
const menu = Menu.buildFromTemplate([
{
label: 'Menu',
Expand All @@ -89,18 +88,11 @@ async function createWindow() {
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', role: 'cut' },
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', role: 'copy' },
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', role: 'paste' },
{
label: 'Clean Data & Relaunch',
click: () => {
walletManager.clearWalletFiles(SHEIKAH_PATH)
win.webContents.send(SHUTDOWN)
actions.relaunch()
},
},
],
},
])
Menu.setApplicationMenu(menu)
win.setMenuBarVisibility(false)
}

if (app.isPackaged) {
Expand Down Expand Up @@ -167,6 +159,12 @@ ipcMain.on(SHUTDOWN_FINISHED, () => {
}
})

ipcMain.on(CLEAR_WALLET_FILES, () => {
walletManager.setRelaunch(true)
walletManager.clearWalletFiles(SHEIKAH_PATH)
win.webContents.send(SHUTDOWN)
})

app.on('activate', () => {
const allWindows = BrowserWindow.getAllWindows()
if (allWindows.length) {
Expand Down
4 changes: 4 additions & 0 deletions electron/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
SET_LOADED_STATUS,
SET_OS_NOT_SUPPORTED,
SHUTDOWN_FINISHED,
CLEAR_WALLET_FILES,
} = IPC_ACTIONS.Window

// --------- Expose some API to the Renderer process ---------
Expand Down Expand Up @@ -197,4 +198,7 @@ contextBridge.exposeInMainWorld('ipcAPI', {
sendShutdownFinished: () => {
ipcRenderer.send(SHUTDOWN_FINISHED)
},
sendClearWalletFiles: () => {
ipcRenderer.send(CLEAR_WALLET_FILES)
},
})
12 changes: 11 additions & 1 deletion electron/walletManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ interface GithubTagInfo {
export class WalletManager {
public webContents: Electron.WebContents | null
public isUpdating: boolean = false
public relaunch: boolean = false
public walletProcess: cp.ChildProcessWithoutNullStreams | null = null
private existDirectory: boolean
private needToDownloadWallet: boolean = true
Expand Down Expand Up @@ -148,6 +149,10 @@ export class WalletManager {
this.isUpdating = status
}

public setRelaunch(status: boolean) {
this.relaunch = status
}

// Download a wallet release from the url specified
public async downloadWallet(actions: Actions, releaseUrl: string) {
console.info(
Expand Down Expand Up @@ -312,7 +317,12 @@ export class WalletManager {
})

this.walletProcess.on('exit', () => {
actions.quitApp()
if (this.relaunch) {
actions.quitApp()
actions.relaunch()
} else {
actions.quitApp()
}
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<DescriptionModal />
<RenameConfirmation />
<DeleteWalletConfirmation />
<DeleteWalletFilesModal />
<ExportXprvModal v-if="isExportXprvQrVisible" />
</div>
</el-config-provider>
Expand All @@ -28,6 +29,7 @@ import LogoutModal from '@/components/LogoutModal.vue'
import DescriptionModal from '@/components/DescriptionModal.vue'
import RenameConfirmation from '@/components/RenameConfirmation.vue'
import DeleteWalletConfirmation from '@/components/DeleteWalletConfirmation.vue'
import DeleteWalletFilesModal from '@/components/DeleteWalletFilesModal.vue'
import ExportXprvModal from '@/components/ExportXprvModal.vue'
import { ref, watch, onMounted, onBeforeUnmount, type Ref, toRefs } from 'vue'
import { LANGUAGES } from '@/constants'
Expand Down
2 changes: 2 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ declare module 'vue' {
DeleteBtnDark: typeof import('./components/svg/DeleteBtnDark.vue')['default']
DeleteWallet: typeof import('./components/DeleteWallet.vue')['default']
DeleteWalletConfirmation: typeof import('./components/DeleteWalletConfirmation.vue')['default']
DeleteWalletFiles: typeof import('./components/DeleteWalletFiles.vue')['default']
DeleteWalletFilesModal: typeof import('./components/DeleteWalletFilesModal.vue')['default']
DeployDataRequest: typeof import('./components/SendTransaction/DeployDataRequest.vue')['default']
DescriptionModal: typeof import('./components/DescriptionModal.vue')['default']
Disclaimer: typeof import('./components/card/Disclaimer.vue')['default']
Expand Down
60 changes: 60 additions & 0 deletions src/components/DeleteWalletFiles.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<Card
class="card"
:title="$t('reset_wallet_files')"
:border="true"
type="danger"
shadow="thin"
>
<p class="text">
<span class="bold">{{ $t('please_note').toUpperCase() }}</span>
{{ $t('delete_wallet_files_info') }}
</p>
<div class="btn-container">
<el-button
type="danger"
class="delete"
@click="showDeleteWalletFilesModal"
>
{{ $t('delete_wallet_files_action') }}
</el-button>
</div>
</Card>
</template>

<script>
import { mapMutations } from 'vuex'
import Card from '@/components/card/Card.vue'
export default {
name: 'SettingsOptionCurrenty',
components: { Card },
methods: {
...mapMutations({
showDeleteWalletFilesModal: 'showDeleteWalletFilesModal',
}),
},
}
</script>

<style lang="scss" scoped>
@import '@/styles/_colors.scss';
.card {
.content {
border-radius: 4px;
}
.bold {
font-weight: bold;
}
.btn-container {
margin-top: 32px;
text-align: right;
width: 100%;
display: flex;
justify-content: flex-end;
}
}
</style>
136 changes: 136 additions & 0 deletions src/components/DeleteWalletFilesModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<template>
<el-dialog
v-model="isDeleteWalletFilesModalVisibleLocal"
class="delete"
:show-close="true"
@close="close"
>
<template #header>
<div class="title-container">
<font-awesome-icon class="icon" icon="exclamation-triangle" />
<p class="title">{{ $t('warning') }}</p>
</div>
</template>
<p class="text">
{{ $t('delete_files_confirmation_0') }}
</p>
<p class="text">
{{ $t('delete_files_confirmation_1') }}
</p>
<p class="text">
{{ $t('delete_files_confirmation_2') }}
</p>
<template #footer>
<div class="dialog-footer">
<el-button type="danger" plain @click="close">{{
$t('cancel')
}}</el-button>
<el-button type="danger" @click="callDelete">{{
$t('delete_wallet_files_action')
}}</el-button>
</div>
</template>
</el-dialog>
</template>

<script>
import { mapState, mapActions, mapMutations, mapGetters } from 'vuex'
export default {
name: 'DeleteConfirmation',
data() {
return {
error: null,
walletName: '',
}
},
computed: {
...mapState({
isDeleteWalletFilesModalVisible: state => {
return state.uiInteractions.isDeleteWalletFilesModalVisible
},
}),
...mapGetters(['unlockedWallet']),
validateDelete() {
return this.walletName === this.unlockedWallet.name
},
isDeleteWalletFilesModalVisibleLocal: {
set() {
this.$emit('close')
},
get() {
return this.isDeleteWalletFilesModalVisible
},
},
},
watch: {
walletName() {
this.clearDeleteWalletError()
},
},
beforeUnmount() {
this.error = null
},
methods: {
...mapActions({
deleteWalletFiles: 'deleteWalletFiles',
}),
...mapMutations({
close: 'closeDeleteWalletFilesModal',
}),
clearDeleteWalletError() {
this.error = null
},
callDelete() {
this.deleteWalletFiles()
this.close()
},
},
}
</script>

<style lang="scss">
@import '@/styles/_colors.scss';
.delete {
.title-container {
align-items: center;
color: $red-2;
display: flex;
.title {
color: $red-2;
font-size: 32px;
}
.icon {
font-size: 36px;
margin-right: 8px;
}
}
.el-dialog__body {
padding: 10px 20px;
word-break: break-word;
.input {
margin: 8px 0;
}
.error {
color: $red-2;
font-size: 14px;
margin-top: 8px;
}
.text {
margin-bottom: 8px;
.wallet-name {
color: var(--primary-color);
font-family: 'Roboto Mono';
}
}
}
}
</style>
7 changes: 7 additions & 0 deletions src/components/SettingsSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
data-test="settings-delete"
class="setting"
/>
<DeleteWalletFiles
v-if="setting === SETTINGS.DELETE_FILES"
data-test="settings-delete"
class="setting"
/>
</div>
</div>
</template>
Expand All @@ -58,6 +63,7 @@ import SettingsAppearance from '@/components/SettingsAppearance.vue'
import SettingsResync from '@/components/SettingsResync.vue'
import RenameWallet from '@/components/RenameWallet.vue'
import DeleteWallet from '@/components/DeleteWallet.vue'
import DeleteWalletFiles from '@/components/DeleteWalletFiles.vue'
import ExportXprv from '@/components/ExportXprv.vue'
import Community from '@/components/Community.vue'
import { SETTINGS } from '@/constants'
Expand All @@ -74,6 +80,7 @@ export default {
SettingsAppearance,
RenameWallet,
DeleteWallet,
DeleteWalletFiles,
},
props: {
settings: {
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export const SETTINGS = {
APPEARANCE: 'APPEARANCE',
RENAME: 'RENAME',
DELETE: 'DELETE',
DELETE_FILES: 'DELETE_FILES',
}

export const SETTINGS_SECTIONS = {
Expand All @@ -204,6 +205,7 @@ export const SETTINGS_BY_SECTION = {
SETTINGS.RESYNC,
SETTINGS.RENAME,
SETTINGS.DELETE,
SETTINGS.DELETE_FILES,
],
NOTIFICATIONS: [SETTINGS.NOTIFICATIONS],
ABOUT: [SETTINGS.COMMUNITY],
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ interface Window {
onDownloadProgress: (fn: any) => void
onOSNotSupported: (fn: any) => void
sendShutdownFinished: () => void
sendClearWalletFiles: () => void
}
}
4 changes: 2 additions & 2 deletions src/ipc/ipcMessages.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { sendShutdownFinished } = window['ipcAPI']
const { sendShutdownFinished, sendClearWalletFiles } = window['ipcAPI']

export { sendShutdownFinished }
export { sendShutdownFinished, sendClearWalletFiles }
8 changes: 7 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,5 +433,11 @@
"export_xprv_modal_title": "Export XPRV",
"export_xprv_modal_warning": "You can use this QR code to import your wallet in {0}. Make sure you are the only person who can see this QR before showing it.",
"export_xprv_modal_show_qr": "Show QR",
"export_xprv_modal_hide_qr": "Hide QR"
"export_xprv_modal_hide_qr": "Hide QR",
"delete_wallet_files_info": "This action resets the wallet backend, your wallet storage will not be altered. Once the reset action is finished, Sheikah application will be closed and the latest wallet backend version will be downloaded.",
"delete_wallet_files_action": "Reset",
"reset_wallet_files": "Reset wallet backend",
"delete_files_confirmation_0": "Reseting the wallet backend will clear the wallet backend files.",
"delete_files_confirmation_1": "Sheikah application will inmediatly be closed. When opening the application again, all the wallet backend files will be downloaded again.",
"delete_files_confirmation_2": "If you still want to reset the wallet backend files, click the 'Reset' button."
}
Loading

0 comments on commit 369faa9

Please sign in to comment.