forked from balancer/frontend-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preserve Safe App connection after new EOA connections (balancer…
- Loading branch information
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
import { Connector, useConnect } from 'wagmi' | ||
import { useEffect } from 'react' | ||
|
||
/* | ||
If the app is running as a Safe App and an EOA connection is created in another tab, | ||
this hook will ensure that the Safe App tab keeps connected to the Safe account. | ||
*/ | ||
export function useSafeAppConnectionGuard(newConnector?: Connector, chainId?: number) { | ||
const { connect, connectors } = useConnect() | ||
useEffect(() => { | ||
const safeConnector = connectors.find(c => c.id === 'safe') | ||
if (newConnector && newConnector?.id !== 'safe' && safeConnector) { | ||
connect({ chainId, connector: safeConnector }) | ||
} | ||
}, [newConnector]) | ||
} |