Skip to content

Commit

Permalink
Fix: remove recommended injected wallet in web3-onboard (#3123)
Browse files Browse the repository at this point in the history
* Fix: remove recommended injected wallet in web3-onboard

* Don't autoconnect wc on mobile
  • Loading branch information
katspaugh authored Jan 18, 2024
1 parent 8533621 commit 946d56e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/hooks/wallets/__tests__/useOnboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { getConnectedWallet, switchWallet } from '../useOnboard'
// mock wallets
jest.mock('@/hooks/wallets/wallets', () => ({
getDefaultWallets: jest.fn(() => []),
getRecommendedInjectedWallets: jest.fn(() => []),
}))

describe('useOnboard', () => {
Expand Down
13 changes: 0 additions & 13 deletions src/hooks/wallets/useOnboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ const trackWalletType = (wallet: ConnectedWallet) => {
.catch(() => null)
}

// Detect mobile devices
const isMobile = () => /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)

// Detect injected wallet
const hasInjectedWallet = () => typeof window !== 'undefined' && !!window?.ethereum

let isConnecting = false

// Wrapper that tracks/sets the last used wallet
Expand All @@ -124,13 +118,6 @@ export const connectWallet = async (

isConnecting = true

// On mobile, automatically choose WalletConnect if there is no injected wallet
if (!options && isMobile() && !hasInjectedWallet()) {
options = {
autoSelect: WALLETCONNECT,
}
}

let wallets: WalletState[] | undefined

try {
Expand Down
8 changes: 2 additions & 6 deletions src/hooks/wallets/wallets.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CYPRESS_MNEMONIC, TREZOR_APP_URL, TREZOR_EMAIL, WC_PROJECT_ID } from '@/config/constants'
import type { RecommendedInjectedWallets, WalletInit } from '@web3-onboard/common/dist/types.d'
import type { WalletInit } from '@web3-onboard/common/dist/types.d'
import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'

import coinbaseModule from '@web3-onboard/coinbase'
import injectedWalletModule, { ProviderLabel } from '@web3-onboard/injected-wallets'
import injectedWalletModule from '@web3-onboard/injected-wallets'
import keystoneModule from '@web3-onboard/keystone/dist/index'
import ledgerModule from '@web3-onboard/ledger/dist/index'
import trezorModule from '@web3-onboard/trezor'
Expand Down Expand Up @@ -51,10 +51,6 @@ export const getAllWallets = (chain: ChainInfo): WalletInit[] => {
return Object.values(WALLET_MODULES).map((module) => module(chain))
}

export const getRecommendedInjectedWallets = (): RecommendedInjectedWallets[] => {
return [{ name: ProviderLabel.MetaMask, url: 'https://metamask.io' }]
}

export const isWalletSupported = (disabledWallets: string[], walletLabel: string): boolean => {
const legacyWalletName = CGW_NAMES?.[walletLabel.toUpperCase() as WALLET_KEYS]
return !disabledWallets.includes(legacyWalletName || walletLabel)
Expand Down
3 changes: 1 addition & 2 deletions src/services/onboard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Onboard, { type OnboardAPI } from '@web3-onboard/core'
import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { hexValue } from '@ethersproject/bytes'
import { getAllWallets, getRecommendedInjectedWallets } from '@/hooks/wallets/wallets'
import { getAllWallets } from '@/hooks/wallets/wallets'
import { getRpcServiceUrl } from '@/hooks/wallets/web3'
import type { EnvState } from '@/store/settingsSlice'

Expand Down Expand Up @@ -44,7 +44,6 @@ export const createOnboard = (
name: 'Safe{Wallet}',
icon: location.origin + '/images/logo-round.svg',
description: 'Safe{Wallet} – smart contract wallet for Ethereum (ex-Gnosis Safe multisig)',
recommendedInjectedWallets: getRecommendedInjectedWallets(),
},

connect: {
Expand Down

1 comment on commit 946d56e

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 78.87% 11242/14254
🔴 Branches 56.6% 2484/4389
🟡 Functions 63.08% 1787/2833
🟢 Lines 80.24% 10142/12639

Test suite run success

1368 tests passing in 185 suites.

Report generated by 🧪jest coverage report action from 946d56e

Please sign in to comment.