Skip to content

Commit b41fc98

Browse files
chore: improve readability
1 parent 2e77b1d commit b41fc98

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

operate/services/manage.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -2550,8 +2550,8 @@ def _compute_refill_requirement(
25502550
f"Argument 'sender_balance' must be >= 0 ({sender_balance=})."
25512551
)
25522552

2553-
total_minimum_shortfall = 0
2554-
total_recommended_shortfall = 0
2553+
minimum_obligations_shortfall = 0
2554+
recommended_obligations_shortfall = 0
25552555

25562556
for address, requirements in asset_funding_values.items():
25572557
topup = requirements["topup"]
@@ -2568,17 +2568,23 @@ def _compute_refill_requirement(
25682568
)
25692569

25702570
if balance < threshold:
2571-
total_minimum_shortfall += threshold - balance
2572-
total_recommended_shortfall += topup - balance
2571+
minimum_obligations_shortfall += threshold - balance
2572+
recommended_obligations_shortfall += topup - balance
25732573

2574-
if sender_balance - total_minimum_shortfall < sender_threshold:
2575-
total_minimum_shortfall += sender_threshold
2574+
# Compute sender's remaining balance after covering obligations
2575+
remaining_balance_minimum = sender_balance - minimum_obligations_shortfall
2576+
remaining_balance_recommended = (
2577+
sender_balance - recommended_obligations_shortfall
2578+
)
25762579

2577-
if sender_balance - total_recommended_shortfall < sender_threshold:
2578-
total_recommended_shortfall += sender_topup
2580+
# Determine if the sender needs additional refill
2581+
minimum_refill = 0
2582+
recommended_refill = 0
2583+
if remaining_balance_minimum < sender_threshold:
2584+
minimum_refill = sender_threshold - remaining_balance_minimum
25792585

2580-
minimum_refill = max(total_minimum_shortfall - sender_balance, 0)
2581-
recommended_refill = max(total_recommended_shortfall - sender_balance, 0)
2586+
if remaining_balance_recommended < sender_threshold:
2587+
recommended_refill = sender_topup - remaining_balance_recommended
25822588

25832589
return {
25842590
"minimum_refill": minimum_refill,

0 commit comments

Comments
 (0)