Repository navigation
Compute the 24h price change when a provider does not send it - #1528
Merged
Merged
Conversation
The 24h price change is computed in PriceClient from a new get_chart_prices port read, instead of a helper that took the DatabaseClient inside the price adapter. No function outside storage takes a DatabaseClient: the 17 helpers in the assets, nft, prices, setup and rewards adapters became storage methods (get_nft_asset, get_referral_use_facts, get_abuse_facts), pure mappers and rules, or port methods the service composes. The dev seed is plain data written by the setup adapter, and the dev username goes through the rewards port. Every storage update is one update_x(filters, updates) method, for assets, devices, prices, price alerts, redemptions and transactions. Each filter enum implements QueryFilter, so reads and updates share one condition; AssetFilter gains ExcludeIds, and the asset and fiat flag updates use it instead of reading and diffing id sets. The fiat port no longer takes function pointers. Storage repositories and service ports use five verbs: get, add, set, update and delete. core/skills/architecture.md states the rules and check-boundaries enforces them.
…fallback # Conflicts: # core/crates/services/src/devices/devices_client.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
CoinGecko and other providers often send no 24h price change for smaller coins. The server saved it as 0, so the app showed "0.00%" even when the price had moved a lot, and price change alerts for those coins never fired.
What changed
Also in this PR
PriceClient. The price adapter exposesget_chart_prices(price_ids, from, until), andPriceClient::store_pricesfills in a missing change before saving. Covered bytest_store_prices_fills_a_missing_24h_change_from_the_price_a_day_ago.DatabaseClient. The 17 helpers that did (assets, nft, prices, setup dev seed, rewardsunits.rs) became one of:get_nft_asset,get_referral_use_facts,get_abuse_facts);apply_referral_codenow returns the decision, and the service callsset_referral.update_x(filters, updates). Each filter enum implementsQueryFilter, so reads and updates share one condition.AssetFilter::ExcludeIdsreplaces reading and diffing id sets for the image, price and fiat flags, and the fiat port no longer takes function pointers.get,add,set,update,delete. Port reads areget_*.core/skills/architecture.md(Repository Pattern) states them, andjust check-boundariesadds two rules: only storage takes aDatabaseClient, and repository methods use the five verbs.Checks
servicestestsstoragetestsswappertestsprimitivestestsjust lintcargo check --workspace --all-features --testsThe flag updates and the wallet-transactions query were also checked by hand against Postgres.