This commit is contained in:
+45
-1
@@ -1,7 +1,9 @@
|
||||
use rabby_core::{
|
||||
demo_dashboard, wallet_feature_summary, WalletDashboard, WalletFeatureStatus, Workspace,
|
||||
};
|
||||
use rabby_runtime::wallet_vault::{EncryptedWalletVault, WalletVaultStatus};
|
||||
use serde::Serialize;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct FeatureRow {
|
||||
@@ -41,13 +43,55 @@ fn wallet_dashboard() -> WalletDashboard {
|
||||
demo_dashboard()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn save_demo_wallet_vault(
|
||||
passphrase: String,
|
||||
path: Option<String>,
|
||||
) -> Result<WalletVaultStatus, String> {
|
||||
let vault_path = resolve_vault_path(path);
|
||||
EncryptedWalletVault::save_dashboard(&vault_path, &demo_dashboard(), &passphrase)
|
||||
.map_err(|err| err.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn load_wallet_vault(path: String, passphrase: String) -> Result<WalletDashboard, String> {
|
||||
EncryptedWalletVault::load_dashboard(path, &passphrase).map_err(|err| err.to_string())
|
||||
}
|
||||
|
||||
fn resolve_vault_path(path: Option<String>) -> PathBuf {
|
||||
path.map(PathBuf::from)
|
||||
.unwrap_or_else(|| std::env::temp_dir().join("rabby-demo-wallet-vault.json"))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
workspace_summary,
|
||||
wallet_mvp_summary,
|
||||
wallet_dashboard
|
||||
wallet_dashboard,
|
||||
save_demo_wallet_vault,
|
||||
load_wallet_vault
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("failed to run Rabby Tauri application");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn default_vault_path_has_stable_file_name() {
|
||||
let path = resolve_vault_path(None);
|
||||
assert_eq!(
|
||||
path.file_name().and_then(|value| value.to_str()),
|
||||
Some("rabby-demo-wallet-vault.json")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_vault_path_is_preserved() {
|
||||
let path = resolve_vault_path(Some("/tmp/custom-rabby-vault.json".to_string()));
|
||||
assert_eq!(path, PathBuf::from("/tmp/custom-rabby-vault.json"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user