Skip to content

Commit

Permalink
fix: active chain when disconnected (#3822)
Browse files Browse the repository at this point in the history
* fix: resolves #3814

* chore: changeset
  • Loading branch information
jxom authored Apr 15, 2024
1 parent 83951a9 commit a97bfba
Show file tree
Hide file tree
Showing 10 changed files with 607 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .changeset/fuzzy-avocados-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wagmi/core": patch
"wagmi": patch
---

Fixed an issue where Wagmi would not correctly rehydrate the active chain when a persisted store was being used.
2 changes: 1 addition & 1 deletion packages/core/src/actions/disconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function disconnect(
return {
...x,
connections: new Map(),
current: undefined,
current: null,
status: 'disconnected',
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/actions/reconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export async function reconnect(
config.setState((x) => ({
...x,
connections: new Map(),
current: undefined,
current: null,
status: 'disconnected',
}))
else config.setState((x) => ({ ...x, status: 'connected' }))
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/createConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ test('behavior: migrate chainId', async () => {
{
"chainId": 10,
"connections": Map {},
"current": undefined,
"current": null,
"status": "disconnected",
}
`)
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/createConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function createConfig<
return {
chainId: chains.getState()[0].id,
connections: new Map<string, Connection>(),
current: undefined,
current: null,
status: 'disconnected',
} satisfies State
}
Expand Down Expand Up @@ -358,7 +358,7 @@ export function createConfig<
return {
...x,
connections: new Map(),
current: undefined,
current: null,
status: 'disconnected',
}

Expand Down Expand Up @@ -526,7 +526,7 @@ export type State<
> = {
chainId: chains[number]['id']
connections: Map<string, Connection>
current: string | undefined
current: string | null
status: 'connected' | 'connecting' | 'disconnected' | 'reconnecting'
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/createStorage.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('getItem', () => {
| {
chainId?: number | undefined
connections?: Map<string, Connection> | undefined
current?: string | undefined
current?: string | null | undefined
status?:
| 'connected'
| 'connecting'
Expand All @@ -33,7 +33,7 @@ test('getItem', () => {
| Promise<{
chainId?: number | undefined
connections?: Map<string, Connection> | undefined
current?: string | undefined
current?: string | null | undefined
status?:
| 'connected'
| 'connecting'
Expand Down
202 changes: 202 additions & 0 deletions playgrounds/next/src/app/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
export const wagmiContractConfig = {
address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
abi: [
{ inputs: [], stateMutability: 'nonpayable', type: 'constructor' },
{
anonymous: false,
inputs: [
{
indexed: true,
name: 'owner',
type: 'address',
},
{
indexed: true,
name: 'approved',
type: 'address',
},
{
indexed: true,
name: 'tokenId',
type: 'uint256',
},
],
name: 'Approval',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
name: 'owner',
type: 'address',
},
{
indexed: true,
name: 'operator',
type: 'address',
},
{
indexed: false,
name: 'approved',
type: 'bool',
},
],
name: 'ApprovalForAll',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
name: 'from',
type: 'address',
},
{ indexed: true, name: 'to', type: 'address' },
{
indexed: true,
name: 'tokenId',
type: 'uint256',
},
],
name: 'Transfer',
type: 'event',
},
{
inputs: [
{ name: 'to', type: 'address' },
{ name: 'tokenId', type: 'uint256' },
],
name: 'approve',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [{ name: 'owner', type: 'address' }],
name: 'balanceOf',
outputs: [{ name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ name: 'tokenId', type: 'uint256' }],
name: 'getApproved',
outputs: [{ name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ name: 'owner', type: 'address' },
{ name: 'operator', type: 'address' },
],
name: 'isApprovedForAll',
outputs: [{ name: '', type: 'bool' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'mint',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [{ internalType: 'uint256', name: 'tokenId', type: 'uint256' }],
name: 'mint',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'name',
outputs: [{ name: '', type: 'string' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ name: 'tokenId', type: 'uint256' }],
name: 'ownerOf',
outputs: [{ name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ name: 'from', type: 'address' },
{ name: 'to', type: 'address' },
{ name: 'tokenId', type: 'uint256' },
],
name: 'safeTransferFrom',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{ name: 'from', type: 'address' },
{ name: 'to', type: 'address' },
{ name: 'tokenId', type: 'uint256' },
{ name: '_data', type: 'bytes' },
],
name: 'safeTransferFrom',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{ name: 'operator', type: 'address' },
{ name: 'approved', type: 'bool' },
],
name: 'setApprovalForAll',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [{ name: 'interfaceId', type: 'bytes4' }],
name: 'supportsInterface',
outputs: [{ name: '', type: 'bool' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'symbol',
outputs: [{ name: '', type: 'string' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ name: 'tokenId', type: 'uint256' }],
name: 'tokenURI',
outputs: [{ name: '', type: 'string' }],
stateMutability: 'pure',
type: 'function',
},
{
inputs: [],
name: 'totalSupply',
outputs: [{ name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ name: 'from', type: 'address' },
{ name: 'to', type: 'address' },
{ name: 'tokenId', type: 'uint256' },
],
name: 'transferFrom',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
],
} as const
Loading

0 comments on commit a97bfba

Please sign in to comment.