Skip to content

Commit 0914840

Browse files
Add check for context.connected in useContract for readiness (#189)
* Add check for `context.connected` in `useContract` for readiness * Add changeset * Update changeset message Co-authored-by: with-heart <[email protected]> * Refactor! Co-authored-by: with-heart <[email protected]> Co-authored-by: with-heart <[email protected]>
1 parent 3db211f commit 0914840

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

.changeset/rare-days-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web3-ui/hooks': patch
3+
---
4+
5+
`useContract` now initializes the contract only after the user has connected their wallet. This helps prevent errors from calling contracts without a connection.

packages/hooks/src/hooks/useContract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function useContract(address: string, abi) {
77
const [contract, setContract] = React.useState({});
88
const [isReady, setIsReady] = React.useState(false);
99
React.useEffect(() => {
10-
if (context) {
10+
if (context?.connected) {
1111
const newContract = new Contract(
1212
address,
1313
abi,

0 commit comments

Comments
 (0)