Skip to content

Commit

Permalink
fix: #4169
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Jul 25, 2024
1 parent 786ffb2 commit 07c1227
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-goats-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/core": patch
---

Fixed internal `extractRpcUrls` usage with `unstable_connector`.
13 changes: 10 additions & 3 deletions packages/core/src/createConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type Chain,
type Client,
createClient,
type EIP1193RequestFn,
type ClientConfig as viem_ClientConfig,
type Transport as viem_Transport,
} from 'viem'
Expand Down Expand Up @@ -582,11 +583,17 @@ export type Connector = ReturnType<CreateConnectorFn> & {
uid: string
}

export type Transport = (
params: Parameters<viem_Transport>[0] & {
export type Transport<
type extends string = string,
rpcAttributes = Record<string, any>,
eip1193RequestFn extends EIP1193RequestFn = EIP1193RequestFn,
> = (
params: Parameters<
viem_Transport<type, rpcAttributes, eip1193RequestFn>
>[0] & {
connectors?: StoreApi<Connector[]> | undefined
},
) => ReturnType<viem_Transport>
) => ReturnType<viem_Transport<type, rpcAttributes, eip1193RequestFn>>

type ClientConfig = LooseOmit<
viem_ClientConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transports/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type ConnectorTransport = Transport
export function unstable_connector(
connector: Pick<Connector, 'type'>,
config: ConnectorTransportConfig = {},
): Transport {
): Transport<'connector'> {
const { type } = connector
const { key = 'connector', name = 'Connector', retryDelay } = config

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/utils/extractRpcUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 07c1227

Please sign in to comment.