mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-29 20:16:33 -05:00
feat(tauri, gui): Send event on changes to details, timelocks and tx_lock confirmations (#100)
- Send event when new swap state is inserated into database. The event only has the `swap_id` attached. The frontend then sends a request to the `get_swap_info` command to retrieve the updated version - Send event when the Bitcoin lock transaction gets a new confirmation - A new `watcher` daemon runs contineously and sends an event when the timelock updated. The event has the the `swap_id` and the timelock attached - Display logs on `ProcessExitedPage` (if swap was stopped prematurely) - Rename `CliLogEmittedEvent` to `TauriLogEvent` - Apply env_filter to tracing terminal writer to silence logging from other crates - Add `.env.*` files in `src-gui` to `.gitingore` Closes #93 and #12
This commit is contained in:
parent
e6dc7ddcef
commit
8f33fe5b41
28 changed files with 429 additions and 208 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use crate::cli::api::tauri_bindings::TauriEmitter;
|
||||
use crate::cli::api::tauri_bindings::TauriHandle;
|
||||
use crate::database::Swap;
|
||||
use crate::monero::{Address, TransferProof};
|
||||
use crate::protocol::{Database, State};
|
||||
|
|
@ -15,6 +17,7 @@ use super::AccessMode;
|
|||
|
||||
pub struct SqliteDatabase {
|
||||
pool: Pool<Sqlite>,
|
||||
tauri_handle: Option<TauriHandle>,
|
||||
}
|
||||
|
||||
impl SqliteDatabase {
|
||||
|
|
@ -30,7 +33,10 @@ impl SqliteDatabase {
|
|||
let options = options.disable_statement_logging();
|
||||
|
||||
let pool = SqlitePool::connect_with(options.to_owned()).await?;
|
||||
let mut sqlite = Self { pool };
|
||||
let mut sqlite = Self {
|
||||
pool,
|
||||
tauri_handle: None,
|
||||
};
|
||||
|
||||
if !read_only {
|
||||
sqlite.run_migrations().await?;
|
||||
|
|
@ -39,6 +45,11 @@ impl SqliteDatabase {
|
|||
Ok(sqlite)
|
||||
}
|
||||
|
||||
pub fn with_tauri_handle(mut self, tauri_handle: impl Into<Option<TauriHandle>>) -> Self {
|
||||
self.tauri_handle = tauri_handle.into();
|
||||
self
|
||||
}
|
||||
|
||||
async fn run_migrations(&mut self) -> anyhow::Result<()> {
|
||||
sqlx::migrate!("./migrations").run(&self.pool).await?;
|
||||
Ok(())
|
||||
|
|
@ -204,9 +215,9 @@ impl Database for SqliteDatabase {
|
|||
let mut conn = self.pool.acquire().await?;
|
||||
let entered_at = OffsetDateTime::now_utc();
|
||||
|
||||
let swap_id = swap_id.to_string();
|
||||
let swap = serde_json::to_string(&Swap::from(state))?;
|
||||
let entered_at = entered_at.to_string();
|
||||
let swap_id_str = swap_id.to_string();
|
||||
|
||||
sqlx::query!(
|
||||
r#"
|
||||
|
|
@ -216,13 +227,17 @@ impl Database for SqliteDatabase {
|
|||
state
|
||||
) values (?, ?, ?);
|
||||
"#,
|
||||
swap_id,
|
||||
swap_id_str,
|
||||
entered_at,
|
||||
swap
|
||||
)
|
||||
.execute(&mut conn)
|
||||
.await?;
|
||||
|
||||
// Emit event to Tauri, the frontend will then send another request to get the latest state
|
||||
// This is why we don't send the state here
|
||||
self.tauri_handle.emit_swap_state_change_event(swap_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue