diff --git a/make_post_sell/views/crypto.py b/make_post_sell/views/crypto.py index 4efe03f..af4478e 100644 --- a/make_post_sell/views/crypto.py +++ b/make_post_sell/views/crypto.py @@ -558,9 +558,32 @@ def crypto_quote(request): # Estimate base amount and fee (this is approximate since we don't store it separately) settings = request.registry.settings - fee_buffer = float( - settings.get(f"{coin_type.lower()}.fee_buffer", coin_info["default_fee_buffer"]) - ) + + # Calculate the fee the same way it was calculated during payment creation + if coin_type == "XMR" and crypto_payment.shop_sweep_to_address: + # Calculate base amount from the total + base_amount_crypto = float(crypto_payment.invoice.total) / float( + crypto_payment.rate_locked_usd_per_coin + ) + base_amount_piconero = int( + base_amount_crypto * coin_info["smallest_unit_divisor"] + ) + fee_buffer = estimate_monero_fee_for_quote( + settings, crypto_payment.shop_sweep_to_address, base_amount_piconero + ) + elif coin_type == "DOGE": + fee_buffer = estimate_dogecoin_fee_for_quote(settings) + else: + # Fallback to settings (but double it since all fees are doubled now) + fee_buffer = ( + float( + settings.get( + f"{coin_type.lower()}.fee_buffer", coin_info["default_fee_buffer"] + ) + ) + * 2 + ) + amount_crypto_base = amount_crypto_with_fee - fee_buffer return {