Skip to content
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
7 changes: 7 additions & 0 deletions .changeset/fix-injected-eip6963-filtering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@reown/appkit': patch
'@reown/appkit-controllers': patch
'@reown/appkit-adapter-wagmi': patch
---

Fix injected and EIP6963 wallets showing despite being disabled and appearing duplicated. `enableInjected` is now wired through to the controller state, the wagmi adapter no longer conflates the basic injected connector with EIP6963-discovered ones, featured/recommended wallets are deduped against connectors regardless of the `enableEIP6963` flag, and `includeWalletIds`/`excludeWalletIds` now also filter injected and EIP6963 connectors in the connect view.
17 changes: 12 additions & 5 deletions packages/adapters/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,18 @@ export class WagmiAdapter extends AdapterBlueprint {
* from wagmi since we already set it in chain adapter blueprint
*/

const { enableEIP6963: isEIP6963Enabled } = OptionsController.state || {}
if (
connector.type === CommonConstantsUtil.CONNECTOR_ID.INJECTED &&
isEIP6963Enabled === false
) {
const { enableEIP6963: isEIP6963Enabled, enableInjected: isInjectedEnabled } =
OptionsController.state || {}

const isInjectedType = connector.type === CommonConstantsUtil.CONNECTOR_ID.INJECTED
const isBasicInjected = connector.id === CommonConstantsUtil.CONNECTOR_ID.INJECTED
const isEip6963Connector = isInjectedType && !isBasicInjected

if (isBasicInjected && isInjectedEnabled === false) {
return
}

if (isEip6963Connector && isEIP6963Enabled === false) {
return
}

Expand Down
70 changes: 70 additions & 0 deletions packages/adapters/wagmi/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,76 @@ describe('WagmiAdapter', () => {
})
)
})

it('should skip basic injected connector when enableInjected is false', async () => {
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({
...OptionsController.state,
enableInjected: false,
enableEIP6963: true
})

const addConnectorSpy = vi.spyOn(adapter as any, 'addConnector')

const basicInjected = {
id: 'injected',
name: 'Browser Wallet',
type: 'injected',
getProvider() {
return Promise.resolve({ connect: vi.fn(), request: vi.fn() })
}
} as unknown as wagmiCore.Connector

await (adapter as any).addWagmiConnector(basicInjected)

expect(addConnectorSpy).not.toHaveBeenCalled()
})

it('should keep basic injected connector when enableEIP6963 is false but enableInjected is true', async () => {
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({
...OptionsController.state,
enableInjected: true,
enableEIP6963: false
})

const addConnectorSpy = vi.spyOn(adapter as any, 'addConnector')

const basicInjected = {
id: 'injected',
name: 'Browser Wallet',
type: 'injected',
getProvider() {
return Promise.resolve({ connect: vi.fn(), request: vi.fn() })
}
} as unknown as wagmiCore.Connector

await (adapter as any).addWagmiConnector(basicInjected)

expect(addConnectorSpy).toHaveBeenCalled()
})

it('should skip EIP6963-discovered connector when enableEIP6963 is false', async () => {
vi.spyOn(OptionsController, 'state', 'get').mockReturnValue({
...OptionsController.state,
enableInjected: true,
enableEIP6963: false
})

const addConnectorSpy = vi.spyOn(adapter as any, 'addConnector')

const eip6963Connector = {
id: 'io.metamask',
name: 'MetaMask',
type: 'injected',
info: { rdns: 'io.metamask' },
getProvider() {
return Promise.resolve({ connect: vi.fn(), request: vi.fn() })
}
} as unknown as wagmiCore.Connector

await (adapter as any).addWagmiConnector(eip6963Connector)

expect(addConnectorSpy).not.toHaveBeenCalled()
})
})

describe('WagmiAdapter - signMessage', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/appkit/src/client/appkit-base-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ export abstract class AppKitBaseClient {
OptionsController.setEnableWalletGuide(options.enableWalletGuide !== false)
OptionsController.setEnableWallets(options.enableWallets !== false)
OptionsController.setEIP6963Enabled(options.enableEIP6963 !== false)
OptionsController.setEnableInjected(options.enableInjected !== false)
OptionsController.setEnableCoinbase(options.enableCoinbase !== false)
OptionsController.setEnableNetworkSwitch(options.enableNetworkSwitch !== false)
OptionsController.setEnableReconnect(options.enableReconnect !== false)
Expand Down
4 changes: 4 additions & 0 deletions packages/controllers/src/controllers/OptionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ export const OptionsController = {
state.enableEIP6963 = enableEIP6963
},

setEnableInjected(enableInjected: OptionsControllerState['enableInjected']) {
state.enableInjected = enableInjected
},

setEnableCoinbase(enableCoinbase: OptionsControllerState['enableCoinbase']) {
state.enableCoinbase = enableCoinbase
},
Expand Down
25 changes: 25 additions & 0 deletions packages/controllers/src/utils/ConnectorUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ export const ConnectorUtil = {
return false
}

const { includeWalletIds, excludeWalletIds } = OptionsController.state
const isFilterableConnectorType =
connector.type === 'INJECTED' ||
connector.type === 'ANNOUNCED' ||
connector.type === 'MULTI_CHAIN'

if (isFilterableConnectorType) {
const connectorWalletId = connector.explorerId || connector.explorerWallet?.id

if (
excludeWalletIds?.length &&
connectorWalletId &&
excludeWalletIds.includes(connectorWalletId)
) {
return false
}

if (
includeWalletIds?.length &&
(!connectorWalletId || !includeWalletIds.includes(connectorWalletId))
) {
return false
}
}

return true
},

Expand Down
4 changes: 1 addition & 3 deletions packages/controllers/src/utils/WalletUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ interface AppKitWallet extends WcWallet {

export const WalletUtil = {
filterOutDuplicatesByRDNS(wallets: WcWallet[]) {
const connectors = OptionsController.state.enableEIP6963
? ConnectorController.state.connectors
: []
const connectors = ConnectorController.state.connectors
const recent = StorageUtil.getRecentWallets()

const connectorRDNSs = connectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,12 @@ describe('OptionsController', () => {
expect(OptionsController.state.enableMobileFullScreen).toBe(true)
spy.mockRestore()
})

it('should update state correctly on setEnableInjected()', () => {
OptionsController.setEnableInjected(false)
expect(OptionsController.state.enableInjected).toBe(false)

OptionsController.setEnableInjected(true)
expect(OptionsController.state.enableInjected).toBe(true)
})
})
79 changes: 79 additions & 0 deletions packages/controllers/tests/utils/ControllerUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,85 @@ describe('ConnectorUtil', () => {

expect(ConnectorUtil.showConnector(ANNOUNCED_CONNECTOR)).toBe(true)
})

it('should hide connector whose explorerId is in excludeWalletIds', () => {
ApiControllerRelative.state.excludedWallets = []
const originalExclude = OptionsControllerRelative.state.excludeWalletIds
OptionsControllerRelative.state.excludeWalletIds = ['phantom-id']

const phantom = {
...ANNOUNCED_CONNECTOR,
explorerId: 'phantom-id'
} as unknown as ConnectorWithProviders

expect(ConnectorUtil.showConnector(phantom)).toBe(false)

OptionsControllerRelative.state.excludeWalletIds = originalExclude
})

it('should hide connector when includeWalletIds is set and connector id not included', () => {
ApiControllerRelative.state.excludedWallets = []
const originalInclude = OptionsControllerRelative.state.includeWalletIds
OptionsControllerRelative.state.includeWalletIds = ['metamask-id']

const phantom = {
...ANNOUNCED_CONNECTOR,
explorerId: 'phantom-id'
} as unknown as ConnectorWithProviders

expect(ConnectorUtil.showConnector(phantom)).toBe(false)

OptionsControllerRelative.state.includeWalletIds = originalInclude
})

it('should show connector when its explorerId is in includeWalletIds', () => {
ApiControllerRelative.state.excludedWallets = []
const originalInclude = OptionsControllerRelative.state.includeWalletIds
OptionsControllerRelative.state.includeWalletIds = ['metamask-id']

const metamask = {
...ANNOUNCED_CONNECTOR,
explorerId: 'metamask-id'
} as unknown as ConnectorWithProviders

expect(ConnectorUtil.showConnector(metamask)).toBe(true)

OptionsControllerRelative.state.includeWalletIds = originalInclude
})

it('should fall back to explorerWallet.id when explorerId is not set', () => {
ApiControllerRelative.state.excludedWallets = []
const originalExclude = OptionsControllerRelative.state.excludeWalletIds
OptionsControllerRelative.state.excludeWalletIds = ['phantom-id']

const phantom = {
...ANNOUNCED_CONNECTOR,
explorerWallet: { id: 'phantom-id' }
} as unknown as ConnectorWithProviders

expect(ConnectorUtil.showConnector(phantom)).toBe(false)

OptionsControllerRelative.state.excludeWalletIds = originalExclude
})

it('should not filter EXTERNAL connectors by include/excludeWalletIds', () => {
ApiControllerRelative.state.excludedWallets = []
const originalInclude = OptionsControllerRelative.state.includeWalletIds
OptionsControllerRelative.state.includeWalletIds = ['metamask-id']

const external = {
id: 'external',
type: 'EXTERNAL',
info: { rdns: 'external.wallet' },
name: 'External Wallet',
chain: { id: 'eip155:1' },
explorerId: 'external-id'
} as unknown as ConnectorWithProviders

expect(ConnectorUtil.showConnector(external)).toBe(true)

OptionsControllerRelative.state.includeWalletIds = originalInclude
})
})

describe('getAuthName', () => {
Expand Down
13 changes: 13 additions & 0 deletions packages/scaffold-ui/test/WalletUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ describe('WalletUtil', () => {

expect(filteredWallets).toEqual(mockWallets)
})

it('should still dedup against connectors when enableEIP6963 is false', () => {
OptionsController.state.enableEIP6963 = false

const mockConnectors = [mockMetamaskConnector]
vi.spyOn(ConnectorController.state, 'connectors', 'get').mockReturnValue(mockConnectors)
vi.spyOn(StorageUtil, 'getRecentWallets').mockReturnValue([])
vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(false)

const filteredWallets = WalletUtil.filterOutDuplicatesByRDNS(mockWallets)

expect(filteredWallets).not.toContain(mockMetamaskWallet)
})
})

describe('filterOutDuplicatesByIds', () => {
Expand Down
Loading