@@ -16,12 +16,31 @@ use throttle::{throttle, Throttle};
1616use tokio:: sync:: RwLock ;
1717use uuid:: Uuid ;
1818
19- use crate :: cli:: api:: {
20- request:: { GetMoneroBalanceResponse , GetMoneroHistoryResponse , GetMoneroSyncProgressResponse } ,
21- tauri_bindings:: { MoneroWalletUpdate , TauriEmitter , TauriEvent , TauriHandle } ,
22- } ;
23-
24- use super :: { BlockHeight , TxHash , WatchRequest } ;
19+ use swap_core:: monero:: primitives:: { Amount , BlockHeight , PrivateViewKey , TxHash , WatchRequest } ;
20+
21+ pub type TauriHandle = Arc < dyn MoneroTauriHandle > ;
22+ pub trait MoneroTauriHandle : Send + Sync {
23+ /// tauri_handle.emit_unified_event(TauriEvent::MoneroWalletUpdate(
24+ /// MoneroWalletUpdate::BalanceChange(GetMoneroBalanceResponse {
25+ /// total_balance, unlocked_balance,
26+ /// })
27+ /// ));
28+ fn balance_change ( & self , total_balance : Amount , unlocked_balance : Amount ) ;
29+
30+ /// tauri_handle.emit_unified_event(TauriEvent::MoneroWalletUpdate(
31+ /// MoneroWalletUpdate::HistoryUpdate(
32+ /// GetMoneroHistoryResponse { transactions }
33+ /// ),
34+ /// ));
35+ fn history_update ( & self , transactions : Vec < monero_sys:: TransactionInfo > ) ;
36+
37+ /// tauri_handle.emit_unified_event(TauriEvent::MoneroWalletUpdate(
38+ /// MoneroWalletUpdate::SyncProgress(GetMoneroSyncProgressResponse {
39+ /// current_block, target_block, progress_percentage,
40+ /// }),
41+ /// ));
42+ fn sync_progress ( & self , current_block : u64 , target_block : u64 , progress_percentage : f32 ) ;
43+ }
2544
2645/// Entrance point to the Monero blockchain.
2746/// You can use this struct to open specific wallets and monitor the blockchain.
@@ -84,13 +103,7 @@ impl TauriWalletListener {
84103 }
85104 } ;
86105
87- let response = GetMoneroBalanceResponse {
88- total_balance : total_balance. into ( ) ,
89- unlocked_balance : unlocked_balance. into ( ) ,
90- } ;
91- tauri. emit_unified_event ( TauriEvent :: MoneroWalletUpdate (
92- MoneroWalletUpdate :: BalanceChange ( response) ,
93- ) ) ;
106+ tauri. balance_change ( total_balance. into ( ) , unlocked_balance. into ( ) ) ;
94107 } ) ;
95108 }
96109 } ;
@@ -111,11 +124,8 @@ impl TauriWalletListener {
111124 return ;
112125 }
113126 } ;
114- let response = GetMoneroHistoryResponse { transactions } ;
115127
116- tauri. emit_unified_event ( TauriEvent :: MoneroWalletUpdate (
117- MoneroWalletUpdate :: HistoryUpdate ( response) ,
118- ) ) ;
128+ tauri. history_update ( transactions) ;
119129 } ) ;
120130 }
121131 } ;
@@ -138,16 +148,11 @@ impl TauriWalletListener {
138148 } ;
139149
140150 let progress_percentage = sync_progress. percentage ( ) ;
141-
142- let response = GetMoneroSyncProgressResponse {
143- current_block : sync_progress. current_block ,
144- target_block : sync_progress. target_block ,
145- progress_percentage : progress_percentage,
146- } ;
147-
148- tauri. emit_unified_event ( TauriEvent :: MoneroWalletUpdate (
149- MoneroWalletUpdate :: SyncProgress ( response) ,
150- ) ) ;
151+ tauri. sync_progress (
152+ sync_progress. current_block ,
153+ sync_progress. target_block ,
154+ progress_percentage,
155+ ) ;
151156 } ) ;
152157 }
153158 } ;
@@ -367,7 +372,7 @@ impl Wallets {
367372 & self ,
368373 swap_id : Uuid ,
369374 spend_key : monero:: PrivateKey ,
370- view_key : super :: PrivateViewKey ,
375+ view_key : PrivateViewKey ,
371376 tx_lock_id : TxHash ,
372377 ) -> Result < Arc < Wallet > > {
373378 // Derive wallet address from the keys
0 commit comments