Skip to content

Commit

Permalink
chore(reset): allow user not to reset wallet data (#532)
Browse files Browse the repository at this point in the history
![Screenshot from 2024-09-19
14-16-33](https://github.com/user-attachments/assets/227dda48-fb21-40bc-9793-e71b2339c4d7)

---------

Co-authored-by: Keith Simon <[email protected]>
  • Loading branch information
mmrrnn and Krakaw authored Sep 19, 2024
1 parent dbd8706 commit 77da443
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 14 deletions.
5 changes: 4 additions & 1 deletion public/locales/af/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"min": "Minimum is 1 sekonde"
},
"last-block-added-time": "Tyd toe laaste blok by ketting gevoeg was",
"visual-mode": "Visuele modus"
"visual-mode": "Visuele modus",
"reset-settings": "Reset Settings",
"reset-permanently": "Are you sure you want to reset all settings permanently?",
"reset-wallet": "Reset wallet"
}
1 change: 1 addition & 0 deletions public/locales/cn/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"cancel": "取消",
"reset-settings": "重置设置",
"reset-permanently": "您确定要永久重置所有设置吗?",
"reset-wallet": "Reset wallet",
"experimental-title": "实验性功能",
"experimental-warning": "⚠️ 警告:这些功能正在积极开发中,可能会表现得不可预测。请谨慎操作。"
}
1 change: 1 addition & 0 deletions public/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"cancel": "Cancel",
"reset-settings": "Reset Settings",
"reset-permanently": "Are you sure you want to reset all settings permanently?",
"reset-wallet": "Reset wallet",
"experimental-title": "Experimental Features",
"experimental-warning": "⚠️ Warning: These features are under active development and could behave unpredictably. Please proceed carefully."
}
3 changes: 2 additions & 1 deletion public/locales/pl/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"yes": "Tak",
"cancel": "Anuluj",
"reset-settings": "Resetuj ustawienia",
"reset-permanently": "Czy na pewno chcesz trwale zresetować ustawienia?"
"reset-permanently": "Czy na pewno chcesz trwale zresetować ustawienia?",
"reset-wallet": "Resetuj porfel"
}
3 changes: 2 additions & 1 deletion public/locales/tr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
"yes": "Evet",
"cancel": "İptal",
"reset-settings": "Ayarları sıfırla",
"reset-permanently": "Tüm ayarları kalıcı olarak sıfırlamak istediğinizden emin misiniz?"
"reset-permanently": "Tüm ayarları kalıcı olarak sıfırlamak istediğinizden emin misiniz?",
"reset-wallet": "Reset wallet"
}
2 changes: 1 addition & 1 deletion src-tauri/src/binary_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::download_utils::{download_file_with_retries, extract, validate_checks
use crate::{github, ProgressTracker};
use anyhow::{anyhow, Error};
use async_trait::async_trait;
use log::{debug, error, info, warn};
use log::{debug, error, warn};
use regex::Regex;
use semver::{Version, VersionReq};
use std::collections::HashMap;
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/hardware_monitor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{ops::Deref, sync::LazyLock};

use log::{debug, info, warn};
use log::{debug, warn};
use nvml_wrapper::{enum_wrappers::device::TemperatureSensor, Nvml};
use serde::Serialize;
use sysinfo::{Component, Components, CpuRefreshKind, RefreshKind, System};
Expand Down
14 changes: 7 additions & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ fn log_web_message(level: String, message: Vec<String>) {

#[tauri::command]
async fn reset_settings<'r>(
reset_wallet: bool,
_window: tauri::Window,
state: tauri::State<'_, UniverseAppState>,
app: tauri::AppHandle,
Expand Down Expand Up @@ -937,7 +938,12 @@ async fn reset_settings<'r>(
}

// Exclude EBWebView because it is still being used.
let folder_block_list = ["EBWebView"];
let mut folder_block_list = vec!["EBWebView"];
if !reset_wallet {
folder_block_list.push("esmeralda");
folder_block_list.push("nextnet");
}

for dir in &dirs_to_remove {
// check if dir exists
if dir.clone().unwrap().exists() {
Expand All @@ -961,12 +967,6 @@ async fn reset_settings<'r>(
})?;
}
}
// info!(target: LOG_TARGET, "[reset_settings] Removing {:?} directory", dir);
// remove_dir_all(dir.clone().unwrap()).map_err(|e|
// {
// error!(target: LOG_TARGET, "[reset_settings] Could not remove {:?} directory: {:?}", dir, e);
// format!("Could not remove directory: {}", e)
// })?;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import { CircularProgress } from '@app/components/elements/CircularProgress.tsx'
import { Stack } from '@app/components/elements/Stack.tsx';
import { Dialog, DialogContent } from '@app/components/elements/dialog/Dialog.tsx';
import { useTranslation } from 'react-i18next';
import { ToggleSwitch } from '@app/components/elements/ToggleSwitch';

export const ResetSettingsButton = () => {
const [open, setOpen] = useState(false);
const [loading, setLoading] = useState(false);
const setError = useAppStateStore((state) => state.setError);
const [resetWallet, setResetWallet] = useState(false);
const { t } = useTranslation('settings', { useSuspense: false });

const resetSettings = () => {
setLoading(true);
invoke('reset_settings')
invoke('reset_settings', { resetWallet })
.then(() => {
setLoading(false);
setOpen(false);
Expand All @@ -40,8 +42,13 @@ export const ResetSettingsButton = () => {
<DialogContent>
<Stack direction="column" alignItems="center" justifyContent="space-between">
<Typography variant="h2">{t('reset-settings')}</Typography>
<ToggleSwitch
checked={resetWallet}
onChange={() => setResetWallet((p) => !p)}
label={t('reset-wallet')}
/>
<Typography variant="p">{t('reset-permanently')}</Typography>
<Stack direction="row">
<Stack direction="row" justifyContent="space-between" style={{ marginTop: '8px' }}>
<Button disabled={loading} onClick={handleClose} color="warning">
{t('cancel')}
</Button>
Expand Down
1 change: 1 addition & 0 deletions src/types/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare module '@tauri-apps/api/tauri' {
function invoke(param: 'get_applications_versions'): Promise<ApplicationsVersions>;
function invoke(param: 'set_monero_address', payload: { moneroAddress: string }): Promise<void>;
function invoke(param: 'get_monero_address'): Promise<string>;
function invoke(param: 'reset_settings', payload: { resetWallet: boolean }): Promise<string>;
function invoke(
param: 'log_web_message',
payload: { level: 'log' | 'error' | 'warn' | 'info'; message: string }
Expand Down

0 comments on commit 77da443

Please sign in to comment.