Skip to content

Commit 6df3a20

Browse files
authored
[react] feat: return setChain success (#956)
* Return success on chain switch to add the ability to confirm successfully adding a new chain * Bump patch number.
1 parent 72950af commit 6df3a20

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/react",
3-
"version": "2.1.2",
3+
"version": "2.1.3",
44
"description": "Collection of React Hooks for web3-onboard",
55
"module": "dist/index.js",
66
"browser": "dist/index.js",

packages/react/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const useSetChain = (
7575
connectedChain: ConnectedChain | null
7676
settingChain: boolean
7777
},
78-
(options: SetChainOptions) => Promise<void>
78+
(options: SetChainOptions) => Promise<boolean>
7979
] => {
8080
if (!web3Onboard) throw new Error('Must initialize before using hooks.')
8181

@@ -108,12 +108,14 @@ export const useSetChain = (
108108
return () => subscription.unsubscribe()
109109
}, [])
110110

111-
const set = useCallback(async (options: SetChainOptions) => {
111+
const set = useCallback(async (options: SetChainOptions): Promise<boolean> => {
112112
setInProgress(true)
113113

114-
await setChain({ ...options, wallet: walletLabel })
114+
const success = await setChain({ ...options, wallet: walletLabel })
115115

116116
setInProgress(false)
117+
118+
return success;
117119
}, [])
118120

119121
return [{ chains, connectedChain, settingChain }, set]

0 commit comments

Comments
 (0)