Skip to content

fix(ai-credits-widget): stop failed reads from reporting as false state - #220

Merged
blueogin merged 2 commits into
mainfrom
fix/ai-credits-goodid-verification-flakiness
Aug 31, 2026
Merged

blueogin merged 2 commits into
mainfrom
fix/ai-credits-goodid-verification-flakiness

Conversation

@blueogin

Copy link
Copy Markdown
Contributor

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.

  • isGoodIdVerified caught RPC errors and returned false, so a forno timeout/429 was
    indistinguishable from "not whitelisted". It now rejects, and a failed read leaves the
    previous value alone.
  • Verification was awaited inside enrichAccountView (chained to the backend fetch, so a
    backend 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 status
    and withdrawable degrade individually instead of taking the view down. operator and
    withdrawableUsd are nullable = "not read", and unread fields are omitted from the state
    patch rather than written as false/null.
  • handleRefresh applies whatever succeeded, and only reports backend_unavailable when
    the credit read itself failed.
  • Connect load: the G$ balance read is guarded like its siblings — its failure used to drop
    the account view, minimums, price, config and buyer list and render a configured wallet as
    empty (gBalance: '0', buyers: [], buyerPubKey: null).
  • "Refresh Balance" now actually re-reads the G$ balance, which it never did.

About # (link your issue here)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • PR title matches follow: (Feature|Bug|Chore) Task Name
  • My code follows the style guidelines of this project
  • I have followed all the instructions described in the initial task (check Definitions of Done)
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added reference to a related issue in the repository
  • I have added a detailed description of the changes proposed in the pull request. I am as descriptive as possible, assisting reviewers as much as possible.
  • I have added screenshots related to my pull request (for frontend tasks)
  • I have pasted a gif showing the feature.
  • @mentions of the person or team responsible for reviewing proposed changes

@blueogin
blueogin requested review from a team and sirpy and a lite review from Copilot August 31, 2026 13:56
@blueogin
blueogin merged commit fe36c68 into main Aug 31, 2026
8 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 buildAccountView treat 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

2 active and 1 inactive deployments
preview-ai-credits — 541e28ac Deployed Aug 31, 2026 by blueogin via preview #291
preview-storybook — 541e28ac Deployed Aug 31, 2026 by blueogin via preview #328
internal — 541e28ac Deployed Aug 31, 2026 by blueogin via authorize-preview #328
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants