From 5199c6c742669893ffeb3d5bc6c3f41214acdbfc Mon Sep 17 00:00:00 2001 From: f321x Date: Tue, 13 Jan 2026 13:57:14 +0100 Subject: [PATCH] ExchangeRate: return NaN if rate is 0 Prevent DivisionByZero exceptions by returning `Decimal('NaN') instead of `Decimal(0)` if the exchange rate is 0. Fixes https://github.com/spesmilo/electrum/issues/10403 ``` >>> bool(Decimal(0)) False ``` --- electrum/exchange_rate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electrum/exchange_rate.py b/electrum/exchange_rate.py index 96403ca3f..2f2fc4506 100644 --- a/electrum/exchange_rate.py +++ b/electrum/exchange_rate.py @@ -209,7 +209,7 @@ class ExchangeBase(Logger): if ccy == 'BTC': return Decimal(1) rate = self._quotes.get(ccy) - if rate is None: + if not rate: # don't return 0 to prevent DivisionByZero exceptions return Decimal('NaN') if self._quotes_timestamp + SPOT_RATE_EXPIRY < time.time(): # Our rate is stale. Probably better to return no rate than an incorrect one.