Skip to content

Commit 2661646

Browse files
authoredJul 18, 2024··
FIX: useConnectorClient to be enabled only when connected or reconnecting (#4124)
* update enabled param for useConnectorClient and add a test * bring updated hook * change set * apply review
1 parent 4f5dca9 commit 2661646

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed
 

‎.changeset/silent-countries-study.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"wagmi": patch
3+
"@wagmi/vue": patch
4+
---
5+
6+
Updated `useConnectorClient` to be enabled when status is `'reconnecting'` or `'connected'` (previously was also enabled when status was `'connecting'`).

‎packages/react/src/hooks/useConnectorClient.test.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ test('behavior: disabled when properties missing', async () => {
160160
await waitFor(() => expect(result.current.isPending).toBeTruthy())
161161
})
162162

163+
test('behavior: disabled when connecting', async () => {
164+
const { result } = renderHook(() => useConnectorClient())
165+
166+
config.setState((x) => ({ ...x, status: 'connecting' }))
167+
168+
await wait(100)
169+
expect(result.current.isLoading).not.toBeTruthy()
170+
})
171+
163172
test('behavior: re-render does not invalidate query', async () => {
164173
const { getByTestId } = render(<Parent />)
165174

‎packages/react/src/hooks/useConnectorClient.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ export function useConnectorClient<
8181
chainId: parameters.chainId ?? chainId,
8282
connector: parameters.connector ?? connector,
8383
})
84-
const enabled = Boolean(status !== 'disconnected' && (query.enabled ?? true))
84+
const enabled = Boolean(
85+
(status === 'connected' || status === 'reconnecting') &&
86+
(query.enabled ?? true),
87+
)
8588

8689
const addressRef = useRef(address)
8790
// biome-ignore lint/correctness/useExhaustiveDependencies: `queryKey` not required

‎packages/vue/src/composables/useConnectorClient.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,12 @@ test('behavior: disabled when properties missing', async () => {
145145
await wait(100)
146146
expect(connectorClient.isPending.value).toBe(true)
147147
})
148+
149+
test('behavior: disabled when connecting', async () => {
150+
const [connectorClient] = renderComposable(() => useConnectorClient())
151+
152+
config.setState((x) => ({ ...x, status: 'connecting' }))
153+
154+
await wait(100)
155+
expect(connectorClient.isLoading.value).not.toBeTruthy()
156+
})

‎packages/vue/src/composables/useConnectorClient.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export function useConnectorClient<
9797
connector: connector as Connector,
9898
})
9999
const enabled = Boolean(
100-
status.value !== 'disconnected' && (query.enabled ?? true),
100+
(status.value === 'connected' || status.value === 'reconnecting') &&
101+
(query.enabled ?? true),
101102
)
102103
return {
103104
...query,

0 commit comments

Comments
 (0)
Please sign in to comment.