Repository navigation
fix(ai-credits-widget): stop failed reads from reporting as false state - #220
Merged
Merged
Conversation
…ve redundant checks
… operator status reads
blueogin
requested review from
a team and
sirpy
and
a lite review from Copilot
August 31, 2026 13:56
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the AI Credits widget’s adapter + data-fetch plumbing so intermittent RPC/backend failures don’t get surfaced to the UI as definitive negative states (e.g., “not verified”, zero balances) and so independent reads degrade individually instead of taking the whole account view down.
Changes:
- Make GoodID verification reads reject on failure (instead of returning
false) and move verification into its own adapter effect to avoid coupling it to backend credit fetches/refreshes. - Make
buildAccountViewtreat only the credit profile as load-bearing; outstanding/operator/withdrawable reads now degrade individually and avoid writing “unread” values into state. - Guard Celo G$ balance reads so a single balance RPC failure doesn’t reset unrelated state, and make “Refresh Balance” actually re-read the balance.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/ai-credits-widget/src/chainClient.ts |
Change GoodID verification read to reject on failure and document rationale. |
packages/ai-credits-widget/src/backendTypes.ts |
Allow operator/withdrawableUsd to be null to represent “unread”. |
packages/ai-credits-widget/src/backendClient.ts |
Decouple enrichment from network reads; make buildAccountView degrade non-critical reads independently. |
packages/ai-credits-widget/src/adapter.ts |
Restructure wallet load/refresh to preserve prior state on partial failures; add shared G$ balance read helper; move GoodID verification to its own effect. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
123
to
127
| const WALLET_LOADING_STATE: Partial<AiCreditsWidgetAdapterState> = { | ||
| gBalance: null, | ||
| gdUsdPerToken: null, | ||
| totalCreditUsd: null, | ||
| isGoodIdVerified: false, | ||
| minDepositUsd: null, |
Comment on lines
+451
to
+454
| const celoPublicClient = useMemo( | ||
| () => createPublicClient({ chain: CELO_CHAIN, transport: http() }), | ||
| [], | ||
| ) |
This branch was successfully deployed
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.
Description
A verified wallet intermittently lost its GoodID bonus — badge showed "verified" on one
load and "Verify to get Bonuses" on the next.
Root cause: reads that fail were reported
to the UI as definite negatives, and independent reads were batched so one failure
discarded the rest.
isGoodIdVerifiedcaught RPC errors and returnedfalse, so a forno timeout/429 wasindistinguishable from "not whitelisted". It now rejects, and a failed read leaves the
previous value alone.
enrichAccountView(chained to the backend fetch, so abackend error cleared it) and re-ran on every refresh. It now reads once per account in
its own effect, plus once on return from the GoodID flow.
buildAccountView: only the credit profile is load-bearing; outstanding, operator statusand withdrawable degrade individually instead of taking the view down.
operatorandwithdrawableUsdare nullable = "not read", and unread fields are omitted from the statepatch rather than written as
false/null.handleRefreshapplies whatever succeeded, and only reportsbackend_unavailablewhenthe credit read itself failed.
the account view, minimums, price, config and buyer list and render a configured wallet as
empty (
gBalance: '0',buyers: [],buyerPubKey: null).About # (link your issue here)
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: