This repository has been archived by the owner on Nov 28, 2024. It is now read-only.
-
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.
Merge pull request #17 from darwinia-network/support-xaccount
Implement automatic Safe login via custom hook
- Loading branch information
Showing
5 changed files
with
40 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,5 @@ yarn-error.log* | |
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
/.vscode | ||
/.vscode | ||
certificates |
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
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,34 @@ | ||
import { useConnect, useReconnect } from 'wagmi'; | ||
import { useEffect } from 'react'; | ||
import { Connector } from 'wagmi'; | ||
|
||
interface AppConnector extends Connector { | ||
rkDetails?: { | ||
installed: boolean; | ||
isRainbowKitConnector: boolean; | ||
}; | ||
} | ||
|
||
function useAppAutoConnect() { | ||
const { connect, connectors } = useConnect(); | ||
const { reconnect } = useReconnect(); | ||
|
||
useEffect(() => { | ||
if (window.self !== window.top) { | ||
const appConnector = connectors.find( | ||
(connector: AppConnector) => | ||
connector.id === 'safe' && | ||
connector.rkDetails?.installed && | ||
connector.rkDetails?.isRainbowKitConnector | ||
) as AppConnector; | ||
|
||
if (appConnector) { | ||
connect({ connector: appConnector }); | ||
return; | ||
} | ||
} | ||
reconnect(); | ||
}, [connect, connectors, reconnect]); | ||
} | ||
|
||
export { useAppAutoConnect }; |
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