fix(accounts): provision USDF core account for fresh onboards even with a stale cache - #1158
Merged
Merged
Conversation
…th a stale cache ensureCoreAccount gated onboarding on the in-memory `accounts` cache, which can still hold a prior account's USDF core-mint primary after a logout -> re-onboard (or account switch) in the same process. The gate then reported "already present" and released a freshly-onboarded account to the scanner with no core account server-side, so it could not receive a direct-send tip until a process restart cleared the cache — both Android and iOS senders saw "payments to external destinations must be withdrawals". - ensureCoreAccount is now server-authoritative: it always confirms the current owner via getAccounts and provisions the USDF primary when absent (checking account TYPE, not just mint), tolerating a race with the reactive bootstrap. - onUserLoggedIn clears the cached account list when the account changes, so no prior account's accounts bleed into a new one. Adds AccountControllerTest coverage for the stale-cache and account-switch cases.
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.
Problem
Sending a tip to a freshly-onboarded account failed on both Android and iOS with the server error:
The failure was recipient-specific ("works for some users"), cross-platform, and — tellingly — killing and relaunching the receiver's app fixed it.
Root cause
The tip send path is a legitimate direct send; the OCP server auto-opens the recipient's currency destination (
detectAutoOpenPrimaryAccount) only if it recognizes the recipient as an OCP user, which it does purely by the presence of a USDF core-mint PRIMARY (ocp-serverowner.go).On the client,
AccountController.ensureCoreAccount(the onboarding gate that's supposed to guarantee that primary) short-circuited on the in-memoryaccountscache. That cache still held the previous account's USDF primary after a logout → re-onboard in the same process, so the gate loggedUSDF core account already presentand provisioned nothing — releasing a fresh account to the scanner with no core account server-side (getAccountsreturnedNOT_FOUNDfor the new owner). Only a process restart cleared the cache, which is why relaunch "fixed" it.On-device logs (receiver, fresh onboard, same PID — no relaunch):
Fix
ensureCoreAccountis now server-authoritative — it always confirms the current owner viagetAccountsinstead of trusting the local cache, and provisions the USDF primary when absent (checking account type, not just mint), tolerating a race with the reactive account bootstrap.onUserLoggedInclears the cached account list when the account changes, preventing cross-account bleed into all consumers (balances,hasAccountFor, and the onboarding gate).Tests
AccountControllerTest(8 passing), including new regression coverage:ensureCoreAccount ignores a stale cached USDF primary from a prior accountonUserLoggedIn clears cached accounts when the account changesVerification
Verified on-device: a freshly-onboarded receiver now provisions its USDF core account during onboarding (
Provisioning USDF core account (onboarding gate)+ anOpenAccountActionfor the USDF mint), and receives a direct-send tip on the first attempt with no relaunch.