-
-
Notifications
You must be signed in to change notification settings - Fork 287
fix(ramps-controller): refresh countries catalog on app startup #9261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amitabh94
wants to merge
5
commits into
main
Choose a base branch
from
fix/tram-3682-countries-catalog-refresh-on-start
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+198
−17
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
931fefc
fix(ramps-controller): refresh countries catalog on app startup
amitabh94 fa3622c
chore(ramps-controller): fix Prettier in RampsController tests
amitabh94 27b4f2d
chore: fix changelog
wenfix ff0aa42
chore: link changelog entries to PR for changelog check
wenfix 82c35e8
test(ramps-controller): cover catalog-sync guards; fix changelog afte…
wenfix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Init contradicts catalog sync grace
Medium Severity
After
getCountries(),#syncUserRegionFromCountriesCatalogkeeps a persisteduserRegionwhen the refreshed catalog is empty or no longer contains that region.#runInitstill always callssetUserRegionwith the persisted code, which throws and runs#cleanupState, so startup can fail and wipe the saved region in cases the new tests treat as safe forgetCountriesalone.Additional Locations (1)
packages/ramps-controller/src/RampsController.ts#L1435-L1455Reviewed by Cursor Bugbot for commit 82c35e8. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amitabh94, thoughts on the following?
Finding:
init()can wipe the saved user region on app startupStatus: Flagged by Cursor Bugbot (Medium severity), confirmed by code review.
Summary
PR #9261 (part of the Ramps Hardening epic) changes the wallet so that, on every app
startup, it stops trusting the saved list of countries and re-downloads it fresh.
This fixes the original bug where Costa Rica users saw a stale default amount of
100instead of
25,000.However, it introduces a new edge case: if that startup download succeeds but comes
back empty — or comes back without the user's own country — the app will erase the user's
saved region entirely (it gets set to "none"). The user would effectively look like a
brand-new user with no region, until the next successful refresh re-establishes it.
This is the opposite of what the hardening work is trying to achieve (keeping the user's
region and its correct preset amounts stable across restarts).
When does it actually happen?
It does not happen on a normal failed network call (a true failure is caught earlier
and the saved region is left alone). It happens only in this narrower window:
partial/garbled-but-valid response).
In those cases the saved region is wiped.
Before this PR, this could not happen at startup because the previously-saved country list
(which contained the user's region) was reused. Now the list is always discarded and
re-fetched, so the empty/incomplete-response case is reachable on every cold start.
Technical detail
In
RampsController.ts:#runInit()(the startup routine):await this.getCountries({ forceRefresh: true })— re-downloads the catalog. Insidethis,
#syncUserRegionFromCountriesCatalog()gracefully keeps the existing regionif the catalog is empty or doesn't contain the region (it just returns, no change).
await this.setUserRegion(persistedRegionCode).setUserRegion()does the opposite of the grace logic: ifcountries.datais empty,or
findRegionFromCode()returns nothing, it calls#cleanupState()and throws.#cleanupState()→resetDependentResources(state, { clearUserRegionData: true })→state.userRegion = null.So the lenient guards added in
#syncUserRegionFromCountriesCatalog()are immediatelyundone by the
setUserRegion()call in#runInit(). The net startup behavior in theempty/region-missing case is: throw + null out
userRegion.The two unit tests added in the PR (
leaves userRegion unchanged when the refreshed catalog is empty/... region is absent ...) assert the grace behavior forgetCountries()inisolation, which is accurate — but they do not reflect what
init()does end-to-end, sothey can give a false sense of safety.
Options
Fix it (recommended). Make
init()consistent with the grace logic: when a region isalready saved, don't let a transient/incomplete fresh catalog wipe it; keep the strict
"throw if no region" behavior only for a brand-new user (the geolocation path, where no
valid region exists yet). Sketch:
Tradeoff: with this change, a
forceRefreshinit would no longer re-runresetDependentResourcesfor an already-persisted region (today it does, becausesetUserRegiontreatsforceRefreshas a region change). Need product confirmation thatthat's acceptable.
Accept as-is / out of scope. Decide the empty/region-missing-but-200 response is not
a realistic case for this API, document the decision on the PR, and ship unchanged.
Alternative hardening: keep calling
setUserRegion, but change it so it does not nullout a previously-valid region on a transient empty catalog (riskier —
setUserRegionisalso used for explicit user-driven region changes where throwing is intended).
Recommendation
Address it as Option 1 (small, contained change in
#runInitplus an init-level test thatasserts the saved region survives an empty/region-missing startup refresh), pending
confirmation of the
forceRefresh/resetDependentResourcestradeoff noted above.