Skip to content

Commit a97bfba

Browse files
authored
fix: active chain when disconnected (#3822)
* fix: resolves #3814 * chore: changeset
1 parent 83951a9 commit a97bfba

File tree

10 files changed

+607
-45
lines changed

10 files changed

+607
-45
lines changed

.changeset/fuzzy-avocados-taste.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@wagmi/core": patch
3+
"wagmi": patch
4+
---
5+
6+
Fixed an issue where Wagmi would not correctly rehydrate the active chain when a persisted store was being used.

packages/core/src/actions/disconnect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export async function disconnect(
4747
return {
4848
...x,
4949
connections: new Map(),
50-
current: undefined,
50+
current: null,
5151
status: 'disconnected',
5252
}
5353

packages/core/src/actions/reconnect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export async function reconnect(
116116
config.setState((x) => ({
117117
...x,
118118
connections: new Map(),
119-
current: undefined,
119+
current: null,
120120
status: 'disconnected',
121121
}))
122122
else config.setState((x) => ({ ...x, status: 'connected' }))

packages/core/src/createConfig.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ test('behavior: migrate chainId', async () => {
210210
{
211211
"chainId": 10,
212212
"connections": Map {},
213-
"current": undefined,
213+
"current": null,
214214
"status": "disconnected",
215215
}
216216
`)

packages/core/src/createConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export function createConfig<
192192
return {
193193
chainId: chains.getState()[0].id,
194194
connections: new Map<string, Connection>(),
195-
current: undefined,
195+
current: null,
196196
status: 'disconnected',
197197
} satisfies State
198198
}
@@ -358,7 +358,7 @@ export function createConfig<
358358
return {
359359
...x,
360360
connections: new Map(),
361-
current: undefined,
361+
current: null,
362362
status: 'disconnected',
363363
}
364364

@@ -526,7 +526,7 @@ export type State<
526526
> = {
527527
chainId: chains[number]['id']
528528
connections: Map<string, Connection>
529-
current: string | undefined
529+
current: string | null
530530
status: 'connected' | 'connecting' | 'disconnected' | 'reconnecting'
531531
}
532532

packages/core/src/createStorage.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test('getItem', () => {
2121
| {
2222
chainId?: number | undefined
2323
connections?: Map<string, Connection> | undefined
24-
current?: string | undefined
24+
current?: string | null | undefined
2525
status?:
2626
| 'connected'
2727
| 'connecting'
@@ -33,7 +33,7 @@ test('getItem', () => {
3333
| Promise<{
3434
chainId?: number | undefined
3535
connections?: Map<string, Connection> | undefined
36-
current?: string | undefined
36+
current?: string | null | undefined
3737
status?:
3838
| 'connected'
3939
| 'connecting'

playgrounds/next/src/app/contracts.ts

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
export const wagmiContractConfig = {
2+
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
3+
abi: [
4+
{ inputs: [], stateMutability: 'nonpayable', type: 'constructor' },
5+
{
6+
anonymous: false,
7+
inputs: [
8+
{
9+
indexed: true,
10+
name: 'owner',
11+
type: 'address',
12+
},
13+
{
14+
indexed: true,
15+
name: 'approved',
16+
type: 'address',
17+
},
18+
{
19+
indexed: true,
20+
name: 'tokenId',
21+
type: 'uint256',
22+
},
23+
],
24+
name: 'Approval',
25+
type: 'event',
26+
},
27+
{
28+
anonymous: false,
29+
inputs: [
30+
{
31+
indexed: true,
32+
name: 'owner',
33+
type: 'address',
34+
},
35+
{
36+
indexed: true,
37+
name: 'operator',
38+
type: 'address',
39+
},
40+
{
41+
indexed: false,
42+
name: 'approved',
43+
type: 'bool',
44+
},
45+
],
46+
name: 'ApprovalForAll',
47+
type: 'event',
48+
},
49+
{
50+
anonymous: false,
51+
inputs: [
52+
{
53+
indexed: true,
54+
name: 'from',
55+
type: 'address',
56+
},
57+
{ indexed: true, name: 'to', type: 'address' },
58+
{
59+
indexed: true,
60+
name: 'tokenId',
61+
type: 'uint256',
62+
},
63+
],
64+
name: 'Transfer',
65+
type: 'event',
66+
},
67+
{
68+
inputs: [
69+
{ name: 'to', type: 'address' },
70+
{ name: 'tokenId', type: 'uint256' },
71+
],
72+
name: 'approve',
73+
outputs: [],
74+
stateMutability: 'nonpayable',
75+
type: 'function',
76+
},
77+
{
78+
inputs: [{ name: 'owner', type: 'address' }],
79+
name: 'balanceOf',
80+
outputs: [{ name: '', type: 'uint256' }],
81+
stateMutability: 'view',
82+
type: 'function',
83+
},
84+
{
85+
inputs: [{ name: 'tokenId', type: 'uint256' }],
86+
name: 'getApproved',
87+
outputs: [{ name: '', type: 'address' }],
88+
stateMutability: 'view',
89+
type: 'function',
90+
},
91+
{
92+
inputs: [
93+
{ name: 'owner', type: 'address' },
94+
{ name: 'operator', type: 'address' },
95+
],
96+
name: 'isApprovedForAll',
97+
outputs: [{ name: '', type: 'bool' }],
98+
stateMutability: 'view',
99+
type: 'function',
100+
},
101+
{
102+
inputs: [],
103+
name: 'mint',
104+
outputs: [],
105+
stateMutability: 'nonpayable',
106+
type: 'function',
107+
},
108+
{
109+
inputs: [{ internalType: 'uint256', name: 'tokenId', type: 'uint256' }],
110+
name: 'mint',
111+
outputs: [],
112+
stateMutability: 'nonpayable',
113+
type: 'function',
114+
},
115+
{
116+
inputs: [],
117+
name: 'name',
118+
outputs: [{ name: '', type: 'string' }],
119+
stateMutability: 'view',
120+
type: 'function',
121+
},
122+
{
123+
inputs: [{ name: 'tokenId', type: 'uint256' }],
124+
name: 'ownerOf',
125+
outputs: [{ name: '', type: 'address' }],
126+
stateMutability: 'view',
127+
type: 'function',
128+
},
129+
{
130+
inputs: [
131+
{ name: 'from', type: 'address' },
132+
{ name: 'to', type: 'address' },
133+
{ name: 'tokenId', type: 'uint256' },
134+
],
135+
name: 'safeTransferFrom',
136+
outputs: [],
137+
stateMutability: 'nonpayable',
138+
type: 'function',
139+
},
140+
{
141+
inputs: [
142+
{ name: 'from', type: 'address' },
143+
{ name: 'to', type: 'address' },
144+
{ name: 'tokenId', type: 'uint256' },
145+
{ name: '_data', type: 'bytes' },
146+
],
147+
name: 'safeTransferFrom',
148+
outputs: [],
149+
stateMutability: 'nonpayable',
150+
type: 'function',
151+
},
152+
{
153+
inputs: [
154+
{ name: 'operator', type: 'address' },
155+
{ name: 'approved', type: 'bool' },
156+
],
157+
name: 'setApprovalForAll',
158+
outputs: [],
159+
stateMutability: 'nonpayable',
160+
type: 'function',
161+
},
162+
{
163+
inputs: [{ name: 'interfaceId', type: 'bytes4' }],
164+
name: 'supportsInterface',
165+
outputs: [{ name: '', type: 'bool' }],
166+
stateMutability: 'view',
167+
type: 'function',
168+
},
169+
{
170+
inputs: [],
171+
name: 'symbol',
172+
outputs: [{ name: '', type: 'string' }],
173+
stateMutability: 'view',
174+
type: 'function',
175+
},
176+
{
177+
inputs: [{ name: 'tokenId', type: 'uint256' }],
178+
name: 'tokenURI',
179+
outputs: [{ name: '', type: 'string' }],
180+
stateMutability: 'pure',
181+
type: 'function',
182+
},
183+
{
184+
inputs: [],
185+
name: 'totalSupply',
186+
outputs: [{ name: '', type: 'uint256' }],
187+
stateMutability: 'view',
188+
type: 'function',
189+
},
190+
{
191+
inputs: [
192+
{ name: 'from', type: 'address' },
193+
{ name: 'to', type: 'address' },
194+
{ name: 'tokenId', type: 'uint256' },
195+
],
196+
name: 'transferFrom',
197+
outputs: [],
198+
stateMutability: 'nonpayable',
199+
type: 'function',
200+
},
201+
],
202+
} as const

0 commit comments

Comments
 (0)