Skip to content

Commit

Permalink
chore: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Sep 11, 2023
1 parent 5d922ac commit 92c69ff
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
1 change: 0 additions & 1 deletion packages/connectors/src/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export function ledger(parameters: LedgerParameters = {}) {
try {
await provider?.disconnect?.().catch(() => {})
} catch (error) {
console.log({ error })
if (!/No matching key/i.test((error as Error).message)) throw error
} finally {
provider.removeListener(
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/actions/disconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ export async function disconnect(
})

// Set recent connector if exists
setTimeout(async () => {
{
const current = config.state.current
if (!current) return
const connector = config.state.connections.get(current)?.connector
console.log({ connector })
if (!connector) return
await config.storage?.setItem('recentConnectorId', connector.id)
})
}
}
11 changes: 10 additions & 1 deletion packages/core/src/createConfig.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { http, createClient, webSocket } from 'viem'
import { mainnet, sepolia } from 'viem/chains'
import { expectTypeOf, test } from 'vitest'

import { createConfig } from './createConfig.js'
import { type CreateConfigParameters, createConfig } from './createConfig.js'

test('high-level config', () => {
// Create config without needing to import viem modules.
Expand Down Expand Up @@ -56,3 +56,12 @@ test('`chains` must have at least one chain`', () => {
}),
})
})

test('behavior: parameters should not include certain client config properties', () => {
type Result = keyof CreateConfigParameters
expectTypeOf<'account' extends Result ? true : false>().toEqualTypeOf<false>()
expectTypeOf<'chain' extends Result ? true : false>().toEqualTypeOf<false>()
expectTypeOf<
'transport' extends Result ? true : false
>().toEqualTypeOf<false>()
})
18 changes: 10 additions & 8 deletions packages/core/src/createConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ import {
import { Emitter, type EventData, createEmitter } from './createEmitter.js'
import { type Storage, createStorage, noopStorage } from './createStorage.js'
import { ChainNotConfiguredError } from './errors/config.js'
import type { Evaluate, ExactPartial, OneOf } from './types/utils.js'
import type { Evaluate, ExactPartial, LooseOmit, OneOf } from './types/utils.js'
import { uid } from './utils/uid.js'

export type CreateConfigParameters<
chains extends readonly [Chain, ...Chain[]],
transports extends Record<chains[number]['id'], Transport>,
chains extends readonly [Chain, ...Chain[]] = readonly [Chain, ...Chain[]],
transports extends Record<chains[number]['id'], Transport> = Record<
chains[number]['id'],
Transport
>,
> = Evaluate<
{
chains: chains
Expand Down Expand Up @@ -162,13 +165,12 @@ export function createConfig<
else {
const chainId = chain.id as chains[number]['id']
// Grab all properties off `rest` and resolve for use in `createClient`
const properties: Omit<viem_ClientConfig, 'transport'> = {}
for (const entry of Object.entries(rest)) {
const key = entry[0] as keyof typeof rest
const properties: Partial<viem_ClientConfig> = {}
const entries = Object.entries(rest) as [keyof typeof rest, any][]
for (const [key, value] of entries) {
if (key === 'client' || key === 'connectors' || key === 'transports')
continue
else {
const value = entry[1]
if (typeof value === 'object') properties[key] = value[chainId]
else properties[key] = value
}
Expand Down Expand Up @@ -374,7 +376,7 @@ export type Connector = ReturnType<CreateConnectorFn> & {
uid: string
}

type ClientConfig = Omit<
type ClientConfig = LooseOmit<
viem_ClientConfig,
'account' | 'chain' | 'key' | 'name' | 'transport' | 'type'
>
4 changes: 2 additions & 2 deletions packages/core/src/query/getWalletClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('default', () => {
{
"queryFn": [Function],
"queryKey": [
"connectorClient",
"walletClient",
{
"connectorUid": undefined,
},
Expand All @@ -24,7 +24,7 @@ test('parameters: chainId', () => {
{
"queryFn": [Function],
"queryKey": [
"connectorClient",
"walletClient",
{
"chainId": 1,
"connectorUid": undefined,
Expand Down

1 comment on commit 92c69ff

@vercel
Copy link

@vercel vercel bot commented on 92c69ff Sep 11, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

wagmi-v2 – ./docs

wagmi-v2-wagmi-dev.vercel.app
wagmi-v2.vercel.app
alpha.wagmi.sh
wagmi-v2-git-alpha-wagmi-dev.vercel.app

Please sign in to comment.