mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-07-29 17:48:43 -04:00
wip: refactor request.rs to allow type safety
This commit is contained in:
parent
757183e857
commit
472e3a57b3
16 changed files with 955 additions and 743 deletions
|
@ -1,17 +1,29 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
use swap::{api::{request::{Method, Request}, Context}, cli::command::{Bitcoin, Monero}};
|
||||
use swap::{
|
||||
api::{
|
||||
request::{get_balance, BalanceArgs, BalanceResponse},
|
||||
Context,
|
||||
},
|
||||
cli::command::{Bitcoin, Monero},
|
||||
};
|
||||
|
||||
// Lazy load the Context
|
||||
static CONTEXT: OnceCell<Arc<Context>> = OnceCell::new();
|
||||
|
||||
#[tauri::command]
|
||||
async fn balance() -> String {
|
||||
async fn balance() -> Result<BalanceResponse, String> {
|
||||
let context = CONTEXT.get().unwrap();
|
||||
let request = Request::new(Method::Balance { force_refresh: true });
|
||||
let response = request.call(context.clone()).await.unwrap();
|
||||
response.to_string()
|
||||
|
||||
get_balance(
|
||||
BalanceArgs {
|
||||
force_refresh: true,
|
||||
},
|
||||
context.clone(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
fn setup<'a>(app: &'a mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
@ -34,7 +46,9 @@ fn setup<'a>(app: &'a mut tauri::App) -> Result<(), Box<dyn std::error::Error>>
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
CONTEXT.set(Arc::new(context)).expect("Failed to initialize cli context");
|
||||
CONTEXT
|
||||
.set(Arc::new(context))
|
||||
.expect("Failed to initialize cli context");
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue