-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
1,058 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { chain, config } from '@wagmi/test' | ||
import { expectTypeOf, test } from 'vitest' | ||
|
||
import { getClient } from './getClient.js' | ||
|
||
test('default', () => { | ||
const client = getClient(config) | ||
expectTypeOf(client.chain).toEqualTypeOf<typeof config['chains'][number]>() | ||
expectTypeOf(client.transport.type).toEqualTypeOf<'http'>() | ||
}) | ||
|
||
test('parameters: chainId', () => { | ||
const client = getClient(config, { | ||
chainId: chain.mainnet.id, | ||
}) | ||
expectTypeOf(client.chain).toEqualTypeOf<typeof chain.mainnet>() | ||
expectTypeOf(client.chain).not.toEqualTypeOf<typeof chain.mainnet2>() | ||
expectTypeOf(client.transport.type).toEqualTypeOf<'http'>() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { config } from '@wagmi/test' | ||
import { expect, test } from 'vitest' | ||
|
||
import { getClient } from './getClient.js' | ||
|
||
test('default', async () => { | ||
expect(getClient(config)).toBeDefined() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { type Client } from 'viem' | ||
|
||
import type { Config } from '../createConfig.js' | ||
import type { ChainIdParameter } from '../types/properties.js' | ||
import type { Evaluate } from '../types/utils.js' | ||
|
||
export type GetClientParameters< | ||
config extends Config = Config, | ||
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'], | ||
> = ChainIdParameter<config, chainId> | ||
|
||
export type GetClientReturnType< | ||
config extends Config = Config, | ||
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'], | ||
> = Evaluate< | ||
Client< | ||
config['_internal']['transports'][chainId], | ||
Extract<config['chains'][number], { id: chainId }> | ||
> | ||
> | ||
|
||
export function getClient< | ||
config extends Config, | ||
chainId extends config['chains'][number]['id'], | ||
>( | ||
config: config, | ||
parameters: GetClientParameters<config, chainId> = {}, | ||
): GetClientReturnType<config, chainId> { | ||
return config.getClient(parameters) as GetClientReturnType<config, chainId> | ||
} |
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions
7
.../core/src/actions/viem/getPublicClient.ts → packages/core/src/actions/getPublicClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
.../src/actions/viem/getWalletClient.test.ts → .../core/src/actions/getWalletClient.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
.../core/src/actions/viem/getWalletClient.ts → packages/core/src/actions/getWalletClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { config } from '@wagmi/test' | ||
import { expectTypeOf, test } from 'vitest' | ||
|
||
import { watchClient } from './watchClient.js' | ||
|
||
test('default', () => { | ||
watchClient(config, { | ||
onChange(client) { | ||
expectTypeOf(client.chain).toEqualTypeOf< | ||
typeof config['chains'][number] | ||
>() | ||
expectTypeOf(client.transport.type).toEqualTypeOf<'http'>() | ||
}, | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { config } from '@wagmi/test' | ||
import type { Client } from 'viem' | ||
import { expect, test } from 'vitest' | ||
|
||
import { switchChain } from './switchChain.js' | ||
import { watchClient } from './watchClient.js' | ||
|
||
test('default', async () => { | ||
const clients: Client[] = [] | ||
const unwatch = watchClient(config, { | ||
onChange(client) { | ||
clients.push(client) | ||
}, | ||
}) | ||
|
||
switchChain(config, { chainId: 456 }) | ||
switchChain(config, { chainId: 10 }) | ||
switchChain(config, { chainId: 1 }) | ||
|
||
expect(clients.length).toBe(3) | ||
|
||
unwatch() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Config } from '../createConfig.js' | ||
import { type GetClientReturnType, getClient } from './getClient.js' | ||
|
||
export type WatchClientParameters< | ||
config extends Config = Config, | ||
chainId extends config['chains'][number]['id'] = config['chains'][number]['id'], | ||
> = { | ||
onChange( | ||
publicClient: GetClientReturnType<config, chainId>, | ||
prevClient: GetClientReturnType<config, chainId>, | ||
): void | ||
} | ||
|
||
export type WatchClientReturnType = () => void | ||
|
||
/** https://alpha.wagmi.sh/core/api/actions/watchClient */ | ||
export function watchClient< | ||
config extends Config, | ||
chainId extends config['chains'][number]['id'], | ||
>( | ||
config: config, | ||
parameters: WatchClientParameters<config, chainId>, | ||
): WatchClientReturnType { | ||
const { onChange } = parameters | ||
return config.subscribe( | ||
() => getClient(config) as GetClientReturnType<config, chainId>, | ||
onChange, | ||
{ | ||
equalityFn(a, b) { | ||
return a?.uid === b?.uid | ||
}, | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { config } from '@wagmi/test' | ||
import { expectTypeOf, test } from 'vitest' | ||
|
||
import { watchPublicClient } from './watchPublicClient.js' | ||
|
||
test('default', () => { | ||
watchPublicClient(config, { | ||
onChange(client) { | ||
expectTypeOf(client.chain).toEqualTypeOf< | ||
typeof config['chains'][number] | ||
>() | ||
expectTypeOf(client.transport.type).toEqualTypeOf<'http'>() | ||
}, | ||
}) | ||
}) |
Oops, something went wrong.
7998d74
There was a problem hiding this comment.
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.vercel.app
wagmi-v2-git-alpha-wagmi-dev.vercel.app
wagmi-v2-wagmi-dev.vercel.app
alpha.wagmi.sh