v0.2.6-pre.008

This commit is contained in:
2026-08-21 11:36:28 +02:00
parent 787df2861f
commit 1a9edd14e1
19 changed files with 902 additions and 45 deletions

View File

@@ -1,8 +1,10 @@
// file: crates/ksp-app-wallet-desk/src/tauri.rs
// version: 5
// version: 6
//! Tauri runtime assembly for the KSP wallet desktop application.
use tauri_plugin_dialog::DialogExt; // rust-rules: trait-import
/// Runs the Wallet Desk application.
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run(arguments: &[std::ffi::OsString]) -> ksp_core_lib::Result<()> {
@@ -32,16 +34,19 @@ fn configure_state(builder: tauri::Builder<tauri::Wry>, app_state: crate::AppSta
fn configure_plugins(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<tauri::Wry> {
let tracing_plugin = tauri_plugin_tracing::Builder::new().build::<tauri::Wry>();
return builder.plugin(tracing_plugin);
return builder.plugin(tauri_plugin_dialog::init()).plugin(tracing_plugin);
}
#[allow(clippy::question_mark_used)] // Tauri generates the question-mark operator internally for async command dispatch.
fn configure_commands(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<tauri::Wry> {
return builder.invoke_handler(tauri::generate_handler![
clear_import_source,
create_wallet,
deselect_wallet,
emit_frontend_log,
get_runtime_status,
import_wallet,
inspect_import_source,
list_wallets,
lock_wallet,
refresh_wallet_balance,
@@ -70,6 +75,15 @@ fn configure_setup(builder: tauri::Builder<tauri::Wry>) -> tauri::Builder<tauri:
});
}
#[tauri::command]
fn clear_import_source(state: tauri::State<'_, crate::AppState>) -> std::result::Result<(), crate::CommandErrorDto> {
let result = state.clear_import_source();
return match result {
std::result::Result::Ok(()) => std::result::Result::Ok(()),
std::result::Result::Err(error) => std::result::Result::Err(crate::CommandErrorDto::from_error(&error)),
};
}
#[tauri::command]
async fn create_wallet(
request: crate::WalletCreateRequestDto,
@@ -109,6 +123,59 @@ fn get_runtime_status(state: tauri::State<'_, crate::AppState>) -> std::result::
};
}
#[tauri::command]
async fn import_wallet(
request: crate::WalletImportRequestDto,
state: tauri::State<'_, crate::AppState>,
) -> std::result::Result<crate::WalletAuthorizedDto, crate::CommandErrorDto> {
let result = state.import_wallet(request).await;
return match result {
std::result::Result::Ok(value) => std::result::Result::Ok(value),
std::result::Result::Err(error) => std::result::Result::Err(crate::CommandErrorDto::from_error(&error)),
};
}
#[tauri::command]
async fn inspect_import_source(
app: tauri::AppHandle,
request: crate::WalletImportSourceRequestDto,
state: tauri::State<'_, crate::AppState>,
) -> std::result::Result<std::option::Option<crate::WalletTransferInspectionDto>, crate::CommandErrorDto> {
let cleared = state.clear_import_source();
if let std::result::Result::Err(error) = cleared {
return std::result::Result::Err(crate::CommandErrorDto::from_error(&error));
}
let format = request.format;
let extensions = [format.default_extension()];
let selected = app
.dialog()
.file()
.set_title("Select Solana keypair transfer source")
.add_filter("Solana keypair transfer", &extensions)
.blocking_pick_file();
let selected = match selected {
std::option::Option::Some(value) => value,
std::option::Option::None => {
ksp_logging_lib::debug!(target: crate::TRACING_TARGET, domain = crate::TRACING_DOMAIN_WALLET_IMPORT, transfer_format = format.code(), "Wallet import native picker cancelled");
return std::result::Result::Ok(std::option::Option::None);
},
};
let path = selected.into_path();
let path = match path {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => {
let error =
ksp_core_lib::Error::new(crate::ERROR_CODE_WALLET_IMPORT_SOURCE_INVALID, "Selected Wallet transfer source is not a local filesystem path");
return std::result::Result::Err(crate::CommandErrorDto::from_error(&error));
},
};
let result = state.stage_import_source(path, format).await;
return match result {
std::result::Result::Ok(value) => std::result::Result::Ok(std::option::Option::Some(value)),
std::result::Result::Err(error) => std::result::Result::Err(crate::CommandErrorDto::from_error(&error)),
};
}
#[tauri::command]
async fn refresh_wallet_balance(state: tauri::State<'_, crate::AppState>) -> std::result::Result<crate::WalletBalanceDto, crate::CommandErrorDto> {
let result = state.refresh_wallet_balance().await;