Page MenuHomePhabricator

[electrum] fix fiat price cache not being created if it does not already exist
ClosedPublic

Authored by PiRK on Aug 20 2024, 09:40.

Details

Summary

The read_historcial_rates method returned None, so the cached_history var in get_historical_rates_safe was not properly initialized to an empty dict, and therefore cached_history.update(new_history) would raise (with the exception caught and ignored).
This makes cached_history is an empty dict {} if the file does not already exist.

Similar fix to commit a42cdb6 electroncash#2898

Test Plan

Run the application ./electrum-abc, go to Tools > Preferences > Fiat select a fiat currency that was never selected before, check the Show history rates checkbox.
Check that a new file was created for this currency in ~/.electrum-abc/cache and has a year worth of data.

Close Electrum ABC, edit the cache file (remove the last few entries) and save it, make sure the cached data file is older than 24 hours (touch -d "2 days ago" ~/.electrum-abc/cache/CoinGecko_GBP) so that the API call is triggered on the next restart of the application. Restart Electrum ABC, check that the cache file get updated with the previously removed entries).

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Aug 20 2024, 09:40
electrum/electrumabc/exchange_rate.py
162 ↗(On Diff #49286)

Here cached_history is now initialized to an empty dict if the above function didn't find a cache file.

163 ↗(On Diff #49286)

The logic remains unchanged, as both an empty dict and None evaluate to False in python, and a non-empty dict evaluates to True.

172 ↗(On Diff #49286)

This is the line that previously failed if cached_history was None

This revision is now accepted and ready to land.Aug 26 2024, 18:28