From 07c1227f306d0efb9421d4bb77a774f92f5fcf45 Mon Sep 17 00:00:00 2001 From: Tom Meagher Date: Thu, 25 Jul 2024 12:08:45 -0400 Subject: [PATCH] fix: #4169 --- .changeset/orange-goats-rush.md | 5 +++++ packages/core/src/createConfig.ts | 13 ++++++++++--- packages/core/src/transports/connector.ts | 2 +- packages/core/src/utils/extractRpcUrls.ts | 8 ++++---- 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 .changeset/orange-goats-rush.md diff --git a/.changeset/orange-goats-rush.md b/.changeset/orange-goats-rush.md new file mode 100644 index 0000000000..3d6bb907c3 --- /dev/null +++ b/.changeset/orange-goats-rush.md @@ -0,0 +1,5 @@ +--- +"@wagmi/core": patch +--- + +Fixed internal `extractRpcUrls` usage with `unstable_connector`. diff --git a/packages/core/src/createConfig.ts b/packages/core/src/createConfig.ts index 4429a4c3bb..55a95db43c 100644 --- a/packages/core/src/createConfig.ts +++ b/packages/core/src/createConfig.ts @@ -8,6 +8,7 @@ import { type Chain, type Client, createClient, + type EIP1193RequestFn, type ClientConfig as viem_ClientConfig, type Transport as viem_Transport, } from 'viem' @@ -582,11 +583,17 @@ export type Connector = ReturnType & { uid: string } -export type Transport = ( - params: Parameters[0] & { +export type Transport< + type extends string = string, + rpcAttributes = Record, + eip1193RequestFn extends EIP1193RequestFn = EIP1193RequestFn, +> = ( + params: Parameters< + viem_Transport + >[0] & { connectors?: StoreApi | undefined }, -) => ReturnType +) => ReturnType> type ClientConfig = LooseOmit< viem_ClientConfig, diff --git a/packages/core/src/transports/connector.ts b/packages/core/src/transports/connector.ts index 9f52336796..0f03d43188 100644 --- a/packages/core/src/transports/connector.ts +++ b/packages/core/src/transports/connector.ts @@ -30,7 +30,7 @@ export type ConnectorTransport = Transport export function unstable_connector( connector: Pick, config: ConnectorTransportConfig = {}, -): Transport { +): Transport<'connector'> { const { type } = connector const { key = 'connector', name = 'Connector', retryDelay } = config diff --git a/packages/core/src/utils/extractRpcUrls.ts b/packages/core/src/utils/extractRpcUrls.ts index 2fab6c0657..a617eac13c 100644 --- a/packages/core/src/utils/extractRpcUrls.ts +++ b/packages/core/src/utils/extractRpcUrls.ts @@ -12,8 +12,8 @@ export function extractRpcUrls(parameters: ExtractRpcUrlsParameters) { if (!parameters.transports) return [fallbackUrl] const transport = parameters.transports?.[chain.id]?.({ chain }) - const transports = transport?.value?.transports || [transport] - return transports.map( - ({ value }: { value: { url: string } }) => value.url || fallbackUrl, - ) + const transports = (transport?.value?.transports as NonNullable< + typeof transport + >[]) || [transport] + return transports.map(({ value }) => value?.url || fallbackUrl) }