Skip to content

feat(widgets): adopt createViemFallbackClient across widget read clients (#167) - #288

Open
deamybro wants to merge 4 commits into
GoodDollar:mainfrom
deamybro:feat/adopt-viem-fallback-client-167
Open

deamybro wants to merge 4 commits into
GoodDollar:mainfrom
deamybro:feat/adopt-viem-fallback-client-167

Conversation

@deamybro

@deamybro deamybro commented Nov 6, 2026 •

Copy link
Copy Markdown

Resolves #167

Summary

Adopts createViemFallbackClient from @goodwidget/core across remaining manual http() viem read-client call sites while preserving provider-backed custom(provider) wallet clients and explicit RPC override precedence:

  • packages/goodreserve-widget/src/useReserveBootstrap.ts:
    • Replaces createPublicClient({ chain, transport: http() }) in bootstrapSdk with createReserveFallbackClient().createPublicClient({ chain }) (rank: false, tracked chains [CELO_CHAIN_ID, XDC_CHAIN_ID]).
    • Preserves provider-backed walletClient on custom(provider).
  • packages/streaming-widget/src/adapter/chains.ts & useStreamingClients.ts:
    • Adds createStreamingFallbackClient() and createStreamingPublicClient(chain, fallbackRpcs) backed by createViemFallbackClient with chain default RPCs as primary fallbackRpcs.
    • Updates createBasePublicClient() and useStreamingClients() to use createStreamingPublicClient(...) while keeping walletClient on custom(provider).
  • packages/citizen-claim-widget/src/adapter.ts:
    • Replaces manual http(rpcUrl) read clients in getPublicClientForChain() and createReadOnlyClientsForChain() with createCitizenClaimFallbackClient() while leaving custodial and integrator-supplied clientFactory bundles untouched.
  • packages/staking-migration-widget/src/adapter.ts:
    • Replaces the fixed Fuse http(...) public client with createStakingMigrationFallbackClient().createPublicClient({ chain: FUSE_CHAIN, fallbackRpcs }) while keeping walletClient on custom(provider).
  • examples/storybook/src/fixtures/custodialEip1193.ts:
    • Replaces per-chain fixed http(config.rpcUrl) public and wallet clients with createCustodialFallbackClient() keeping config.rpcUrl as primary fallbackRpcs.
    • Fixes custodial sendTransaction chain binding to selected client and ensures deterministic RPC error testing.

Verification

  • Ran @goodwidget/core unit tests (pnpm --filter @goodwidget/core test — all 17 tests pass).
  • Verified build and compatibility of all widget adapters (@goodwidget/goodreserve-widget, @goodwidget/streaming-widget, @goodwidget/citizen-claim-widget, @goodwidget/staking-migration-widget).
  • Maintained strict non-breaking API compatibility for external integrators and existing custom wallet providers.

Summary by Sourcery

Adopt shared Viem fallback clients across widget read paths while preserving existing wallet-provider integrations and RPC override behavior.

Bug Fixes:

  • Make custodial Storybook transaction handling use the selected chain client and stabilize unreachable-RPC error testing.

Enhancements:

  • Adopt shared Viem fallback clients for widget read paths, adding cached RPC discovery and fallback handling while preserving provider-backed wallet clients and configured RPC precedence.

Tests:

  • Make Citizen Claim RPC error coverage deterministic by mocking chain discovery and blocking all configured primary and fallback endpoints.

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.

🟡 Changes recommended

The custom bridge adds retries on top of the fallback transport’s existing policy, multiplying RPC requests and delaying the widget’s error state when endpoints are unreachable or rate-limited.

1 open issue
What changed in this PR

Adopts core’s createViemFallbackClient across selected widget read clients and the Storybook custodial fixture for #167, while retaining provider-backed signing and primary RPC ordering.

Changes:

  • Migrates GoodReserve, Streaming, Citizen Claim, and Staking Migration read clients to fallback-enabled construction.
  • Updates custodial fixture clients and binds transactions to the selected client’s chain.
  • Makes Citizen Claim error tests block deterministic discovered RPCs alongside primary endpoints.
File Description
tests/​widgets/​citizen-claim-widget/​states.spec.ts Controls RPC discovery and blocks fallback endpoints in error tests.
packages/​streaming-widget/​src/​adapter/​useStreamingClients.ts Uses fallback-enabled reads while preserving wallet transport.
packages/​streaming-widget/​src/​adapter/​chains.ts Adds fallback client builders with a synchronous public-client interface.
packages/​staking-migration-widget/​src/​adapter.ts Uses asynchronous fallback clients for Fuse reads and receipts.
packages/​goodreserve-widget/​src/​useReserveBootstrap.ts Initializes reserve reads through the fallback helper.
packages/​citizen-claim-widget/​src/​adapter.ts Migrates read clients and awaits their construction.
examples/​storybook/​src/​fixtures/​custodialEip1193.ts Adds fallback clients and preserves transaction chain binding.

Review effort: Balanced

Comment on lines +48 to +53
transport: custom({
async request(args) {
const resolved = await clientPromise
return resolved.transport.request(args)
},
}),

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Applied in commit 92a18dd: configured retryCount: 0 on the forwarding custom transport in packages/streaming-widget/src/adapter/chains.ts so the resolved fallback transport exclusively manages retries without duplication.

ocakciomursel-pixel and others added 3 commits November 27, 2026 17:54
…id duplicate RPC attempts

Configure retryCount: 0 on custom bridge transport forwarding to createStreamingFallbackClient so viem's default outer retry policy does not duplicate the underlying fallback transport's retry policy, preventing request multiplication and delays in error state.
@sourcery-ai

sourcery-ai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 56c2bd8

#167 Adopt createViemFallbackClient in manual viem client call sites · 4 of 5 met

# Requirement Status Notes
1 Adopt createViemFallbackClient in the listed manual read-client call sites. ✅ Met The changed Reserve, Streaming, Citizen Claim, Staking Migration, and Storybook paths use the helper; the listed AI Credits read paths already use it.
2 Keep provider-backed wallet clients on custom(provider) and preserve existing client-injection contracts. ✅ Met The provider-backed wallet transports remain on custom(provider), and the Citizen Claim custodial and integrator-supplied client paths are left intact.
3 Keep explicit widget/app RPC URLs as the primary endpoints. ✅ Met Explicit RPCs are passed as fallbackRpcs for Citizen Claim, Streaming, Staking Migration, and the custodial fixture; the helper places these before chain defaults and discovered RPCs.
4 Preserve existing flows and avoid unrelated widget or RPC refactors. ✅ Met The changes are confined to the listed client paths and the related custodial transaction-chain and deterministic error-test fixes.
5 Keep existing tests passing and add targeted tests for adopted client-construction paths. 🟡 Partly met The deterministic Citizen Claim RPC-error test exercises that path, but the diff adds no targeted construction-path tests for the Reserve, Streaming, Staking Migration, or Storybook clients.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New gaps against the linked issues

…GoodDollar#167)

Remove explicit rank: false overrides so createViemFallbackClient enables ranking by measured health across all adopted widgets as required by GoodDollar#167.

Signed-off-by: deamybro <deamybro@users.noreply.github.com>
Payout: 0x759797593fed8f313d8fdba7a3a0d491f0e4b9f7 (USDC on Base L2)

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New gaps against the linked issues

await page.route('https://forno.celo.org/**', (route) => route.abort())
await page.route('https://rpc.fuse.io/**', (route) => route.abort())
await page.route('https://rpc.ankr.com/**', (route) => route.abort())
// Seed deterministic Chainlist discovery and block all primary + fallback RPC endpoints

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Missing client-path tests

The changed test makes Citizen Claim's RPC-error path deterministic, but the adopted Reserve, Streaming, Staking Migration, and Storybook client-construction paths have no targeted tests in this diff.

Prompt for AI agents
In `tests/widgets/citizen-claim-widget/states.spec.ts` at line 207:

**Missing client-path tests**

The changed test makes Citizen Claim's RPC-error path deterministic, but the adopted Reserve, Streaming, Staking Migration, and Storybook client-construction paths have no targeted tests in this diff.

From #167:

Keep existing tests passing and add targeted tests for adopted client-construction paths.

This branch is waiting to be deployed

1 waiting deployment
external — 56c2bd88 Waiting Nov 28, 2026 by sourcery-ai[bot] via authorize-preview #786
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.

Adopt createViemFallbackClient in manual viem client call sites

3 participants