-
Notifications
You must be signed in to change notification settings - Fork 38
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 #134 from gnosis/detect-safe
Detect Adjust WalletConnected Safes
- Loading branch information
Showing
3 changed files
with
24 additions
and
6 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
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,21 @@ | ||
export async function checkConnectedToSafe(provider: any): Promise<boolean> { | ||
if (provider == null) return false | ||
|
||
const wc = | ||
(await provider.getWalletConnector?.()) || | ||
(await provider.connection?.getWalletConnector?.()) || | ||
provider.wc || | ||
provider.connection?.wc | ||
|
||
const peerName = wc?.peerMeta?.name | ||
|
||
if (peerName === 'Safe Multisig WalletConnect' || peerName?.startsWith?.('Gnosis Safe')) { | ||
return true | ||
} | ||
|
||
if (provider._providers) { | ||
return (await Promise.all(provider._providers.map(checkConnectedToSafe))).includes(true) | ||
} | ||
|
||
return false | ||
} |