Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect Adjust WalletConnected Safes #134

Merged
merged 4 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contract-proxy-kit",
"version": "2.2.0-alpha.1",
"version": "2.2.0-alpha.3",
"description": "Enable batched transactions and contract account interactions using a unique deterministic Gnosis Safe.",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
Expand Down
7 changes: 2 additions & 5 deletions src/CPK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
StandardTransaction,
normalizeGasLimit
} from './utils/transactions'
import { checkConnectedToSafe } from './utils/checkConnectedToSafe'

export interface CPKConfig {
ethLibAdapter: EthLibAdapter
Expand Down Expand Up @@ -92,11 +93,7 @@ class CPK {

const ownerAccount = await this.getOwnerAccount()

const provider = this.#ethLibAdapter.getProvider()
const wc = provider && (provider.wc || (provider.connection && provider.connection.wc))
if (wc && wc.peerMeta && wc.peerMeta.name && wc.peerMeta.name.startsWith('Gnosis Safe')) {
this.#isConnectedToSafe = true
}
this.#isConnectedToSafe = await checkConnectedToSafe(this.#ethLibAdapter.getProvider())

this.#multiSend = this.#ethLibAdapter.getContract(multiSendAbi, network.multiSendAddress)

Expand Down
21 changes: 21 additions & 0 deletions src/utils/checkConnectedToSafe.ts
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')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to startsWith('Safe') ... just to be on the safe side (no pun intended)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw the multisig identifies itself as Gnosis Safe Multisig so the current logic should work.

see https://github.com/gnosis/safe-react-apps/pull/78/files#diff-791a7865e89890c3f6524eff6f43a645c54438fec18d7064aaff481efa0b9debL27

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, maybe, though German just merged it with the stricter check, so I guess that's going to stay for now 😅

return true
}

if (provider._providers) {
return (await Promise.all(provider._providers.map(checkConnectedToSafe))).includes(true)
}

return false
}