use super::*;
pub(in crate::tui::runtime) fn spawn_tx_context_task(
kp: Arc<Keypair>,
symbol: String,
http: Arc<PhoenixHttpClient>,
ctx_chan: UnboundedSender<TxCtxMsg>,
status_chan: UnboundedSender<TxStatusMsg>,
) -> tokio::task::JoinHandle<()> {
let wallet = match solana_pubkey::Pubkey::from_str(&kp.pubkey().to_string()) {
Ok(pk) => pk,
Err(e) => {
warn!(error = %e, "failed to convert wallet pubkey for TxContext task");
return tokio::spawn(async {});
}
};
tokio::spawn(async move {
match TxContext::new(&kp, &symbol, Arc::clone(&http)).await {
Ok(ctx) => {
let ctx = Arc::new(ctx);
let _ = ctx_chan.send((wallet, symbol, ctx));
}
Err(e) => {
warn!(error = %e, "TxContext init failed");
let _ = status_chan.send(TxStatusMsg::SetStatus {
title: format!("Failed to load trading context: {}", e),
detail: String::new(),
});
}
}
})
}
pub(in crate::tui::runtime) fn spawn_blockhash_refresh_task(
tx_context: Arc<TxContext>,
) -> tokio::task::JoinHandle<()> {
tokio::spawn(async move {
let mut interval = tokio::time::interval(Duration::from_millis(1800));
loop {
interval.tick().await;
tx_context.push_blockhash().await;
}
})
}