Skip to content

Commit 75a5a5f

Browse files
committed
sentry - routes - campaign - get_delta_budget - fix logic & naming
1 parent 5177217 commit 75a5a5f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

sentry/src/routes/campaign.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,20 +330,22 @@ pub mod update_campaign {
330330
.checked_sub(&current_budget)
331331
.and_then(|delta_budget| old_remaining.checked_add(&delta_budget))
332332
.ok_or(Error::Calculation)?;
333+
// new remaining > old remaining
333334
let increase_by = new_remaining
334335
.checked_sub(&old_remaining)
335336
.ok_or(Error::Calculation)?;
336337

337338
DeltaBudget::Increase(increase_by)
338339
}
339340
DeltaBudget::Decrease(()) => {
340-
// delta budget = New budget - Old budget ( the difference between the new and old when New > Old)
341+
// delta budget = Old budget - New budget ( the difference between the new and old when New < Old)
341342
let new_remaining = &current_budget
342343
.checked_sub(&new_budget)
343-
.and_then(|delta_budget| old_remaining.checked_add(&delta_budget))
344+
.and_then(|delta_budget| old_remaining.checked_sub(&delta_budget))
344345
.ok_or(Error::Calculation)?;
345-
let decrease_by = new_remaining
346-
.checked_sub(&old_remaining)
346+
// old remaining > new remaining
347+
let decrease_by = old_remaining
348+
.checked_sub(&new_remaining)
347349
.ok_or(Error::Calculation)?;
348350

349351
DeltaBudget::Decrease(decrease_by)

0 commit comments

Comments
 (0)