Skip to content

Commit

Permalink
detect safe
Browse files Browse the repository at this point in the history
  • Loading branch information
namgold committed Aug 21, 2023
1 parent c7c2016 commit d0d2ac3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
29 changes: 0 additions & 29 deletions src/constants/connectors/evm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ChainId } from '@kyberswap/ks-sdk-core'
import SafeAppsSDK from '@safe-global/safe-apps-sdk'
import { OPTIONAL_EVENTS } from '@walletconnect/ethereum-provider'
import { CoinbaseWallet } from '@web3-react/coinbase-wallet'
import { initializeConnector } from '@web3-react/core'
Expand All @@ -17,34 +16,6 @@ import {
WALLET_CONNECT_SUPPORTED_CHAIN_IDS,
} from 'constants/networks'

type Opts = {
allowedDomains?: RegExp[]
debug?: boolean
}

const opts: Opts = {
// allowedDomains: [/kyberengineering.io$/, /kyberswap.com$/],
debug: true,
}

const appsSdk = new SafeAppsSDK(opts)
;(async () => {
const getSafeInfo = async (fn: 'getEnvironmentInfo' | 'getInfo' | 'requestAddressBook') => {
try {
console.log('safe ' + fn + ' start')
const promise = appsSdk.safe[fn]()
console.log('safe ' + fn + ' promise', { promise })
const result = await promise
console.log('safe ' + fn + ' result', { result })
} catch (error) {
console.log('safe' + fn + ' error', { error })
}
}
getSafeInfo('getEnvironmentInfo')
getSafeInfo('getInfo')
getSafeInfo('requestAddressBook')
})()

export const [injected, injectedHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
export const [rabby, rabbyHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
export const [krystal, krystalHooks] = initializeConnector<MetaMask>(actions => new MetaMask({ actions }))
Expand Down
14 changes: 10 additions & 4 deletions src/constants/wallets.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import SafeAppsSDK from '@safe-global/safe-apps-sdk'
import { BaseMessageSignerWalletAdapter, WalletReadyState } from '@solana/wallet-adapter-base'
import { Web3ReactHooks } from '@web3-react/core'
import { Connector } from '@web3-react/types'
Expand Down Expand Up @@ -78,11 +79,16 @@ const detectBlocto = (): WalletReadyState => {
return WalletReadyState.NotDetected
}

let isSafe = false
const appsSdk = new SafeAppsSDK({})
;(async () => {
try {
const result = await appsSdk.safe.getEnvironmentInfo()
if (result) isSafe = true
} catch (error) {}
})()
const detectSafe = (): WalletReadyState => {
// todo namgold: WIP
return WalletReadyState.Installed
// if (getIsGenericInjector()) return WalletReadyState.Installed
// return WalletReadyState.NotDetected
return isSafe ? WalletReadyState.Installed : WalletReadyState.NotDetected
}

const detectRabby = (): WalletReadyState => {
Expand Down

0 comments on commit d0d2ac3

Please sign in to comment.