use comfy_table::{presets::UTF8_FULL_CONDENSED, Table};
use eyre::Result;
use crate::client::Client;
use crate::service::quote;
pub struct Args {
pub chain_id: String,
pub pairs: Vec<String>,
pub amount: String,
pub json: bool,
}
pub async fn run(client: &Client, args: Args) -> Result<()> {
let results = quote::batch_quote(client, &args.chain_id, &args.pairs, &args.amount).await?;
if args.json {
let json_results: Vec<_> = results
.iter()
.map(|r| {
serde_json::json!({
"pair": r.pair,
"output": r.output,
"route": r.route,
"error": r.error,
})
})
.collect();
println!("{}", serde_json::to_string_pretty(&json_results)?);
return Ok(());
}
let mut table = Table::new();
table.load_preset(UTF8_FULL_CONDENSED);
table.set_header(vec!["Pair", "Output", "Route"]);
for r in &results {
if let Some(err) = &r.error {
table.add_row(vec![&r.pair, err, "-"]);
} else {
table.add_row(vec![
&r.pair,
r.output.as_deref().unwrap_or("-"),
r.route.as_deref().unwrap_or("-"),
]);
}
}
println!("{table}");
Ok(())
}