Skip to content

Commit

Permalink
account ls now abbreviates all lots by default (use --all to view all)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed May 19, 2024
1 parent a7a2a03 commit 5bcb8ea
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ async fn process_exchange_sell(
println!("Placing sell order for ◎{amount} at ${price}");
println!("Lots");
for lot in &order_lots {
println_lot(
maybe_println_lot(
deposit_account.token,
lot,
Decimal::from_f64(price),
Expand All @@ -945,6 +945,7 @@ async fn process_exchange_sell(
&mut 0.,
None,
true,
true,
)
.await;
}
Expand Down Expand Up @@ -1679,7 +1680,7 @@ fn liquidity_token_ui_amount(
}

#[allow(clippy::too_many_arguments)]
async fn println_lot(
async fn maybe_println_lot(
token: MaybeToken,
lot: &Lot,
current_price: Option<Decimal>,
Expand All @@ -1690,6 +1691,7 @@ async fn println_lot(
total_current_value: &mut f64,
notifier: Option<&Notifier>,
verbose: bool,
print: bool,
) {
let current_value = current_price.map(|current_price| {
f64::try_from(Decimal::from_f64(token.ui_amount(lot.amount)).unwrap() * current_price)
Expand Down Expand Up @@ -1761,13 +1763,16 @@ async fn println_lot(
description,
);

if !token.fiat_fungible() {
if let Some(notifier) = notifier {
notifier.send(&msg).await;
}
// if !token.fiat_fungible() {

if let Some(notifier) = notifier {
notifier.send(&msg).await;
}

if print {
println!("{msg}");
}
// }
}

fn format_disposed_lot(
Expand Down Expand Up @@ -1920,7 +1925,7 @@ async fn process_account_add(
acquisition: LotAcquistion::new(when.unwrap_or_else(today), decimal_price, kind),
amount,
};
println_lot(
maybe_println_lot(
token,
&lot,
Some(current_price),
Expand All @@ -1931,6 +1936,7 @@ async fn process_account_add(
&mut 0.,
None,
true,
true,
)
.await;

Expand Down Expand Up @@ -2096,7 +2102,7 @@ async fn process_account_list(
db: &Db,
rpc_client: &RpcClient,
account_filter: Option<Pubkey>,
show_all_disposed_lots: bool,
show_all_lots: bool,
summary_only: bool,
notifier: &Notifier,
verbose: bool,
Expand Down Expand Up @@ -2219,10 +2225,15 @@ async fn process_account_list(
let mut account_unrealized_short_term_gain = 0.;
let mut account_unrealized_long_term_gain = 0.;

for lot in lots {
if !show_all_lots && lots.len() > 5 {
println!(" ...");
}

for (i, lot) in lots.iter().enumerate() {
let mut account_unrealized_gain = 0.;
let mut long_term_cap_gain = false;
println_lot(

maybe_println_lot(
account.token,
lot,
current_token_price,
Expand All @@ -2233,6 +2244,11 @@ async fn process_account_list(
&mut account_current_value,
None,
verbose,
if show_all_lots {
true
} else {
lots.len() < 5 || (i > lots.len().saturating_sub(5))
},
)
.await;

Expand Down Expand Up @@ -2271,7 +2287,7 @@ async fn process_account_list(
for lot in lots {
let mut account_unrealized_gain = 0.;
let mut long_term_cap_gain = false;
println_lot(
maybe_println_lot(
account.token,
lot,
current_token_price,
Expand All @@ -2282,6 +2298,7 @@ async fn process_account_list(
&mut account_current_value,
None,
verbose,
true,
)
.await;

Expand Down Expand Up @@ -2366,7 +2383,7 @@ async fn process_account_list(
verbose,
);

if show_all_disposed_lots {
if show_all_lots {
println!("{msg}");
} else {
if disposed_lots.len() > 5 && i == disposed_lots.len().saturating_sub(5) {
Expand Down Expand Up @@ -3692,7 +3709,7 @@ async fn process_account_sync(
notifier.send(&msg).await;
println!("{msg}");

println_lot(
maybe_println_lot(
account.token,
&lot,
Some(current_sol_price),
Expand All @@ -3703,6 +3720,7 @@ async fn process_account_sync(
&mut 0.,
Some(notifier),
true,
true,
)
.await;
account.lots.push(lot);
Expand Down Expand Up @@ -3749,7 +3767,7 @@ async fn process_account_sync(
notifier.send(&msg).await;
println!("{msg}");

println_lot(
maybe_println_lot(
account.token,
&lot,
Some(current_token_price),
Expand All @@ -3760,6 +3778,7 @@ async fn process_account_sync(
&mut 0.,
Some(notifier),
true,
true,
)
.await;
account.lots.push(lot);
Expand Down

0 comments on commit 5bcb8ea

Please sign in to comment.