Skip to content

Commit

Permalink
Fixed handling of fee on ignored transactions
Browse files Browse the repository at this point in the history
Even if some transactions should be ignored, they might still have
charged a relevant fee. In these cases, we now replace the transaction
with a Fee transaction.
  • Loading branch information
bjorn committed Nov 23, 2023
1 parent a3cb6bd commit 197df05
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,28 @@ fn load_transactions(wallets: &mut Vec<Wallet>, ignored_currencies: &Vec<String>
merge_consecutive_trades(&mut source_transactions);

// remove transactions with ignored currencies
source_transactions.retain(|tx| {
match tx.incoming_outgoing() {
source_transactions.retain_mut(|tx| {
let retain_tx = match tx.incoming_outgoing() {
(None, None) => true,
(None, Some(amount)) |
(Some(amount), None) => !ignored_currencies.contains(&amount.currency),
(Some(incoming), Some(outgoing)) => {
// Trades can only be ignored, if both the incoming and outgoing currencies are ignored
!(ignored_currencies.contains(&incoming.currency) && ignored_currencies.contains(&outgoing.currency))
}
}
};

retain_tx || tx.fee.take().is_some_and(|fee| {
if !ignored_currencies.contains(&fee.currency) {
// We can't ignore the fee, so keep the transaction just for the fee
tx.operation = Operation::Fee(fee);
tx.value = tx.fee_value.take();

true
} else {
false
}
})
});

source.transaction_count = source_transactions.len();
Expand Down

0 comments on commit 197df05

Please sign in to comment.