-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core,react,vue): connect parameters (#4453)
* wip: make config connectors generic * feat: tweaks * chore: changeset * refactor: types
- Loading branch information
Showing
28 changed files
with
367 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"wagmi": minor | ||
"@wagmi/vue": minor | ||
--- | ||
|
||
Added support to `useConnect` for custom `connector.connect` parameters. |
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,7 @@ | ||
--- | ||
"@wagmi/connectors": minor | ||
"@wagmi/core": minor | ||
--- | ||
|
||
Added narrowing to `config.connectors`. | ||
|
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,48 @@ | ||
import { accounts } from '@wagmi/test' | ||
import { http } from 'viem' | ||
import { mainnet } from 'viem/chains' | ||
import { expectTypeOf, test } from 'vitest' | ||
|
||
import type { CreateConnectorFn } from '../connectors/createConnector.js' | ||
import { mock } from '../connectors/mock.js' | ||
import { type Connector, createConfig } from '../createConfig.js' | ||
import { connect } from './connect.js' | ||
|
||
const config = createConfig({ | ||
chains: [mainnet], | ||
transports: { [mainnet.id]: http() }, | ||
}) | ||
|
||
test('parameters: connector (ConnectorFn)', () => { | ||
const connectorFn = mock({ accounts }) | ||
|
||
connect(config, { | ||
connector: connectorFn, | ||
foo: 'bar', | ||
}) | ||
expectTypeOf< | ||
typeof connectorFn extends CreateConnectorFn ? true : false | ||
>().toEqualTypeOf<true>() | ||
|
||
type Result = NonNullable< | ||
Parameters<typeof connect<typeof config, typeof connectorFn>>[1] | ||
> | ||
expectTypeOf<Result['foo']>().toEqualTypeOf<string | undefined>() | ||
}) | ||
|
||
test('parameters: connector (Connector)', () => { | ||
const connector = config._internal.connectors.setup(mock({ accounts })) | ||
|
||
connect(config, { | ||
connector, | ||
foo: 'bar', | ||
}) | ||
expectTypeOf< | ||
typeof connector extends Connector ? true : false | ||
>().toEqualTypeOf<true>() | ||
|
||
type Result = NonNullable< | ||
Parameters<typeof connect<typeof config, typeof connector>>[1] | ||
> | ||
expectTypeOf<Result['foo']>().toEqualTypeOf<string | undefined>() | ||
}) |
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 |
---|---|---|
|
@@ -86,20 +86,20 @@ test('behavior: account does not exist on connector', async () => { | |
|
||
test('behavior: reconnecting', async () => { | ||
config.setState((state) => ({ ...state, status: 'reconnecting' })) | ||
const { id, name, type, uuid } = connector | ||
const { id, name, type, uid } = connector | ||
await expect( | ||
getConnectorClient(config, { | ||
connector: { | ||
id, | ||
name, | ||
type, | ||
uuid, | ||
uid, | ||
} as unknown as Connector, | ||
}), | ||
).rejects.toThrowErrorMatchingInlineSnapshot(` | ||
[ConnectorUnavailableReconnectingError: Connector "Mock Connector" unavailable while reconnecting. | ||
Details: During the reconnection step, the only connector methods guaranteed to be available are: \`id\`, \`name\`, \`type\`, \`uuid\`. All other methods are not guaranteed to be available until reconnection completes and connectors are fully restored. This error commonly occurs for connectors that asynchronously inject after reconnection has already started. | ||
Details: During the reconnection step, the only connector methods guaranteed to be available are: \`id\`, \`name\`, \`type\`, \`uid\`. All other methods are not guaranteed to be available until reconnection completes and connectors are fully restored. This error commonly occurs for connectors that asynchronously inject after reconnection has already started. | ||
Version: @wagmi/[email protected]] | ||
`) | ||
config.setState((state) => ({ ...state, status: 'disconnected' })) | ||
|
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
Oops, something went wrong.