Repository navigation
Conversation
There was a problem hiding this comment.
🟡 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
92a18dd to
975812f
Compare
975812f to
c7431ec
Compare
Linked issuesChecked at commit b4b3e74 #167 Adopt createViemFallbackClient in manual viem client call sites · 6 of 9 met · 1 to check by hand
|
46a489f to
c0ff362
Compare
| test('adopted client construction: reserve client tracks Celo and XDC chains with fallback ranking enabled', async () => { | ||
| const celoChainId = 42220 | ||
| const xdcChainId = 50 | ||
| const client = createViemFallbackClient(createStorage(), { | ||
| chainIds: [celoChainId, xdcChainId], | ||
| fetch: async () => | ||
| new Response( | ||
| JSON.stringify([ | ||
| { chainId: celoChainId, rpc: ['https://celo-discovered.example'] }, | ||
| { chainId: xdcChainId, rpc: ['https://xdc-discovered.example'] }, | ||
| ]), | ||
| { status: 200, headers: { 'content-type': 'application/json' } }, | ||
| ), | ||
| }) | ||
|
|
||
| await client.ready | ||
|
|
||
| const celoChain = { ...createChain(['https://forno.celo.org']), id: celoChainId } | ||
| const xdcChain = { ...createChain(['https://rpc.ankr.com/xdc']), id: xdcChainId } | ||
|
|
||
| const celoUrls = await client.getRpcUrls(celoChain) | ||
| const xdcUrls = await client.getRpcUrls(xdcChain) | ||
|
|
||
| assert.deepEqual(celoUrls, ['https://forno.celo.org', 'https://celo-discovered.example']) | ||
| assert.deepEqual(xdcUrls, ['https://rpc.ankr.com/xdc', 'https://xdc-discovered.example']) | ||
| }) | ||
|
|
||
| test('adopted client construction: streaming client tracks Celo and Base with caller-first fallback ordering', async () => { | ||
| const baseChainId = 8453 | ||
| const celoChainId = 42220 | ||
| const client = createViemFallbackClient(createStorage(), { | ||
| chainIds: [celoChainId, baseChainId], | ||
| fetch: async () => | ||
| new Response( | ||
| JSON.stringify([ | ||
| { chainId: baseChainId, rpc: ['https://base-discovered.example'] }, | ||
| ]), | ||
| { status: 200, headers: { 'content-type': 'application/json' } }, | ||
| ), | ||
| }) | ||
|
|
||
| await client.ready | ||
|
|
||
| const baseChain = { ...createChain(['https://mainnet.base.org']), id: baseChainId } | ||
| const baseUrls = await client.getRpcUrls(baseChain, ['https://caller-override.example']) | ||
|
|
||
| assert.deepEqual(baseUrls, [ | ||
| 'https://caller-override.example', | ||
| 'https://mainnet.base.org', | ||
| 'https://base-discovered.example', | ||
| ]) | ||
| }) | ||
|
|
||
| test('adopted client construction: staking migration client tracks Fuse chain', async () => { | ||
| const fuseChainId = 122 | ||
| const client = createViemFallbackClient(createStorage(), { | ||
| chainIds: [fuseChainId], | ||
| fetch: async () => | ||
| new Response( | ||
| JSON.stringify([ | ||
| { chainId: fuseChainId, rpc: ['https://fuse-discovered.example'] }, | ||
| ]), | ||
| { status: 200, headers: { 'content-type': 'application/json' } }, | ||
| ), | ||
| }) | ||
|
|
||
| await client.ready | ||
|
|
||
| const fuseChain = { ...createChain(['https://rpc.fuse.io']), id: fuseChainId } | ||
| const fuseUrls = await client.getRpcUrls(fuseChain) | ||
|
|
||
| assert.deepEqual(fuseUrls, ['https://rpc.fuse.io', 'https://fuse-discovered.example']) | ||
| }) | ||
|
|
||
| test('adopted client construction: custodial Storybook fixture tracks multi-chain set', async () => { | ||
| const chainIds = [42220, 122, 50, 8453] | ||
| const client = createViemFallbackClient(createStorage(), { | ||
| chainIds, | ||
| fetch: async () => | ||
| new Response( | ||
| JSON.stringify(chainIds.map((id) => ({ chainId: id, rpc: [`https://chain-${id}.example`] }))), | ||
| { status: 200, headers: { 'content-type': 'application/json' } }, | ||
| ), | ||
| }) | ||
|
|
||
| await client.ready | ||
|
|
||
| for (const id of chainIds) { | ||
| const chain = { ...createChain([]), id } | ||
| const urls = await client.getRpcUrls(chain) | ||
| assert.deepEqual(urls, [`https://chain-${id}.example`]) | ||
| } | ||
| }) |
There was a problem hiding this comment.
🟡 Medium · Exercise widget client factories
The new tests create the core fallback client with representative chain settings, but do not call the widget-local factories changed in this PR. Add tests that exercise those factory paths so their wiring and RPC arguments are covered.
Prompt for AI agents
In `packages/core/src/viemFallbackClient.test.ts` at lines 260-352:
**Exercise widget client factories**
The new tests create the core fallback client with representative chain settings, but do not call the widget-local factories changed in this PR. Add tests that exercise those factory paths so their wiring and RPC arguments are covered.From #167:
Add targeted tests covering adopted client-construction paths.Sourcery withdrew this approval because the latest commits introduced blocking findings.
c0ff362 to
b4b3e74
Compare
… and make RPC error tests deterministic
…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.
…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)
… configurations (GoodDollar#167) Add unit test coverage verifying fallback discovery and chain tracking for Reserve, Streaming, Staking Migration, and multi-chain Custodial client configurations. Signed-off-by: deamybro <deamybro@users.noreply.github.com> Payout: 0x759797593fed8f313d8fdba7a3a0d491f0e4b9f7 (USDC on Base L2)
b4b3e74 to
d590aa9
Compare
There was a problem hiding this comment.
🟡 Changes recommended
RPC fallback changes can override caller endpoint precedence, silently discard valid HTTP overrides, and accumulate background probes when short-lived clients are recreated.
3 open issues
1 resolved since last review
Review effort: Balanced
| const publicClient = createPublicClient({ chain, transport: http(rpcUrl) }) | ||
| const publicClient = await createReserveFallbackClient().createPublicClient({ | ||
| chain, | ||
| ...(rpcUrl ? { fallbackRpcs: [rpcUrl] } : {}), |
…aller overrides (GoodDollar#167) Signed-off-by: deamybro <193015196+deamybro@users.noreply.github.com>
9096c0c to
40b8ef5
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because a case-sensitive scheme check can silently discard valid RPC overrides and route reserve reads to default or discovered endpoints instead.
2 resolved since last review
Review effort: Balanced
|
Addressed all three Copilot review findings in commit \40b8ef5:
|
… filtering (GoodDollar#167) Signed-off-by: deamybro <193015196+deamybro@users.noreply.github.com>
|
Updated |

Resolves #167
Summary
Adopts
createViemFallbackClientfrom@goodwidget/coreacross remaining manualhttp()viem read-client call sites while preserving provider-backedcustom(provider)wallet clients and explicit RPC override precedence:packages/goodreserve-widget/src/useReserveBootstrap.ts:createPublicClient({ chain, transport: http() })inbootstrapSdkwithcreateReserveFallbackClient().createPublicClient({ chain })(rank: false, tracked chains[CELO_CHAIN_ID, XDC_CHAIN_ID]).walletClientoncustom(provider).packages/streaming-widget/src/adapter/chains.ts&useStreamingClients.ts:createStreamingFallbackClient()andcreateStreamingPublicClient(chain, fallbackRpcs)backed bycreateViemFallbackClientwith chain default RPCs as primaryfallbackRpcs.createBasePublicClient()anduseStreamingClients()to usecreateStreamingPublicClient(...)while keepingwalletClientoncustom(provider).packages/citizen-claim-widget/src/adapter.ts:http(rpcUrl)read clients ingetPublicClientForChain()andcreateReadOnlyClientsForChain()withcreateCitizenClaimFallbackClient()while leaving custodial and integrator-suppliedclientFactorybundles untouched.packages/staking-migration-widget/src/adapter.ts:http(...)public client withcreateStakingMigrationFallbackClient().createPublicClient({ chain: FUSE_CHAIN, fallbackRpcs })while keepingwalletClientoncustom(provider).examples/storybook/src/fixtures/custodialEip1193.ts:http(config.rpcUrl)public and wallet clients withcreateCustodialFallbackClient()keepingconfig.rpcUrlas primaryfallbackRpcs.sendTransactionchain binding to selected client and ensures deterministic RPC error testing.Verification
@goodwidget/coreunit tests (pnpm --filter @goodwidget/core test— all 17 tests pass).@goodwidget/goodreserve-widget,@goodwidget/streaming-widget,@goodwidget/citizen-claim-widget,@goodwidget/staking-migration-widget).Summary by Sourcery
Adopt fallback RPC handling across widget read clients while retaining existing wallet-provider and RPC-override behavior.
Bug Fixes:
Enhancements:
Tests: