Skip to content

fix: excludeWalletIds not working with bitcoin wallets #4120

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

Merged
merged 6 commits into from
Apr 1, 2025
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
24 changes: 24 additions & 0 deletions .changeset/young-beans-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@reown/appkit-controllers': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit': patch
'@reown/appkit-adapter-bitcoin': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/appkit-cli': patch
'@reown/appkit-common': patch
'@reown/appkit-core': patch
'@reown/appkit-experimental': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-siwe': patch
'@reown/appkit-siwx': patch
'@reown/appkit-ui': patch
'@reown/appkit-wallet': patch
'@reown/appkit-wallet-button': patch
---

Fixed an issue where `excludeWalletIds` option wasn't properly filtering Bitcoin wallets
2 changes: 1 addition & 1 deletion packages/appkit/src/client/appkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export class AppKit extends AppKitBaseClient {
super.initControllers(options)

if (this.options.excludeWalletIds) {
ApiController.initializeExcludedWalletRdns({ ids: this.options.excludeWalletIds })
ApiController.initializeExcludedWallets({ ids: this.options.excludeWalletIds })
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/appkit/tests/client/appkit-core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ describe('AppKitCore', () => {

describe('initialize', () => {
it('should not initialize excluded wallet rdns if basic is true', () => {
vi.spyOn(ApiController, 'initializeExcludedWalletRdns')
vi.spyOn(ApiController, 'initializeExcludedWallets')

new AppKit({
...mockOptions,
excludeWalletIds: ['eoa', 'ordinal']
})

expect(ApiController.initializeExcludedWalletRdns).not.toHaveBeenCalled()
expect(ApiController.initializeExcludedWallets).not.toHaveBeenCalled()
})
})

Expand Down
8 changes: 4 additions & 4 deletions packages/controllers/src/controllers/ApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface ApiControllerState {
wallets: WcWallet[]
search: WcWallet[]
isAnalyticsEnabled: boolean
excludedRDNS: string[]
excludedWallets: { rdns: string; name: string }[]
isFetchingRecommendedWallets: boolean
}

Expand All @@ -63,7 +63,7 @@ const state = proxy<ApiControllerState>({
wallets: [],
search: [],
isAnalyticsEnabled: false,
excludedRDNS: [],
excludedWallets: [],
isFetchingRecommendedWallets: false
})

Expand Down Expand Up @@ -244,7 +244,7 @@ export const ApiController = {
state.page = page
},

async initializeExcludedWalletRdns({ ids }: { ids: string[] }) {
async initializeExcludedWallets({ ids }: { ids: string[] }) {
const caipNetworkIds = ChainController.getRequestedCaipNetworkIds().join(',')

const { data } = await api.get<ApiGetWalletsResponse>({
Expand All @@ -261,7 +261,7 @@ export const ApiController = {
if (data) {
data.forEach(wallet => {
if (wallet?.rdns) {
state.excludedRDNS.push(wallet.rdns)
state.excludedWallets.push({ rdns: wallet.rdns, name: wallet.name })
}
})
}
Expand Down
16 changes: 11 additions & 5 deletions packages/controllers/tests/controllers/ApiController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('ApiController', () => {
wallets: [],
search: [],
isAnalyticsEnabled: false,
excludedRDNS: [],
excludedWallets: [],
isFetchingRecommendedWallets: false,
promises: {}
})
Expand Down Expand Up @@ -514,9 +514,9 @@ describe('ApiController', () => {
OptionsController.setExcludeWalletIds(excludeWalletIds)

const fetchSpy = vi.spyOn(api, 'get').mockResolvedValue({ data, count: data.length })
const fetchWalletsSpy = vi.spyOn(ApiController, 'initializeExcludedWalletRdns')
const fetchWalletsSpy = vi.spyOn(ApiController, 'initializeExcludedWallets')

await ApiController.initializeExcludedWalletRdns({ ids: excludeWalletIds })
await ApiController.initializeExcludedWallets({ ids: excludeWalletIds })

expect(fetchSpy).toHaveBeenCalledWith({
path: '/getWallets',
Expand All @@ -531,9 +531,15 @@ describe('ApiController', () => {
})

expect(fetchWalletsSpy).toHaveBeenCalledOnce()
expect(ApiController.state.excludedRDNS).toEqual(['io.metamask', 'app.phantom'])
expect(ApiController.state.excludedWallets).toEqual([
{ name: 'MetaMask', rdns: 'io.metamask' },
{ name: 'Phantom', rdns: 'app.phantom' }
])
const result = EIP6963Wallets.filter(
wallet => !ApiController.state.excludedRDNS.includes(wallet.rdns)
wallet =>
!ApiController.state.excludedWallets.some(
excludedWallet => excludedWallet.rdns === wallet.rdns
)
)
expect(result).toEqual(filteredWallet)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ifDefined } from 'lit/directives/if-defined.js'

import type { Connector } from '@reown/appkit-controllers'
import {
ApiController,
AssetUtil,
ConnectorController,
CoreHelperUtil,
Expand All @@ -14,6 +13,8 @@ import { customElement } from '@reown/appkit-ui'
import '@reown/appkit-ui/wui-flex'
import '@reown/appkit-ui/wui-list-wallet'

import { ConnectorUtil } from '../../utils/ConnectorUtil.js'

@customElement('w3m-connect-announced-widget')
export class W3mConnectAnnouncedWidget extends LitElement {
// -- Members ------------------------------------------- //
Expand Down Expand Up @@ -47,27 +48,23 @@ export class W3mConnectAnnouncedWidget extends LitElement {

return html`
<wui-flex flexDirection="column" gap="xs">
${announcedConnectors.map(connector => {
if (connector.info?.rdns && ApiController.state.excludedRDNS) {
if (ApiController.state.excludedRDNS.includes(connector?.info?.rdns)) {
return null
}
}

return html`
<wui-list-wallet
imageSrc=${ifDefined(AssetUtil.getConnectorImage(connector))}
name=${connector.name ?? 'Unknown'}
@click=${() => this.onConnector(connector)}
tagVariant="success"
tagLabel="installed"
data-testid=${`wallet-selector-${connector.id}`}
.installed=${true}
tabIdx=${ifDefined(this.tabIdx)}
>
</wui-list-wallet>
`
})}
${announcedConnectors
.filter(ConnectorUtil.showConnector)
.map(
connector => html`
<wui-list-wallet
imageSrc=${ifDefined(AssetUtil.getConnectorImage(connector))}
name=${connector.name ?? 'Unknown'}
@click=${() => this.onConnector(connector)}
tagVariant="success"
tagLabel="installed"
data-testid=${`wallet-selector-${connector.id}`}
.installed=${true}
tabIdx=${ifDefined(this.tabIdx)}
>
</wui-list-wallet>
`
)}
</wui-flex>
`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ifDefined } from 'lit/directives/if-defined.js'

import type { Connector, ConnectorWithProviders } from '@reown/appkit-controllers'
import {
ApiController,
AssetUtil,
ConnectionController,
ConnectorController,
Expand All @@ -15,6 +14,8 @@ import { customElement } from '@reown/appkit-ui'
import '@reown/appkit-ui/wui-flex'
import '@reown/appkit-ui/wui-list-wallet'

import { ConnectorUtil } from '../../utils/ConnectorUtil.js'

@customElement('w3m-connect-injected-widget')
export class W3mConnectInjectedWidget extends LitElement {
// -- State & Properties -------------------------------- // // -- State & Properties -------------------------------- //
Expand All @@ -40,22 +41,20 @@ export class W3mConnectInjectedWidget extends LitElement {
return html`
<wui-flex flexDirection="column" gap="xs">
${injectedConnectors.map(connector => {
const walletRDNS = connector.info?.rdns

if (!CoreHelperUtil.isMobile() && connector.name === 'Browser Wallet') {
return null
}

const walletRDNS = connector.info?.rdns

if (!walletRDNS && !ConnectionController.checkInstalled(undefined)) {
if (!walletRDNS && !ConnectionController.checkInstalled()) {
this.style.cssText = `display: none`

return null
}

if (walletRDNS && ApiController.state.excludedRDNS) {
if (ApiController.state.excludedRDNS.includes(walletRDNS)) {
return null
}
if (!ConnectorUtil.showConnector(connector)) {
return null
}

return html`
Expand Down
30 changes: 17 additions & 13 deletions packages/scaffold-ui/src/utils/ConnectorUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
StorageUtil,
type WcWallet
} from '@reown/appkit-controllers'
import { HelpersUtil } from '@reown/appkit-utils'

import { WalletUtil } from './WalletUtil.js'

Expand Down Expand Up @@ -57,30 +58,33 @@ export const ConnectorUtil = {
},

showConnector(connector: ConnectorWithProviders) {
const rdns = connector.info?.rdns

const isRDNSExcluded =
Boolean(rdns) && ApiController.state.excludedWallets.some(wallet => wallet.rdns === rdns)

const isNameExcluded =
Boolean(connector.name) &&
ApiController.state.excludedWallets.some(wallet =>
HelpersUtil.isLowerCaseMatch(wallet.name, connector.name)
)
Comment on lines +66 to +70
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bitcoin and solana doesn't have rdns so the only way to make sure they're excluded is to check by name


if (connector.type === 'INJECTED') {
if (!CoreHelperUtil.isMobile() && connector.name === 'Browser Wallet') {
return false
}

const walletRDNS = connector.info?.rdns

if (!walletRDNS && !ConnectionController.checkInstalled()) {
if (!rdns && !ConnectionController.checkInstalled()) {
return false
}

if (walletRDNS && ApiController.state.excludedRDNS) {
if (ApiController.state.excludedRDNS.includes(walletRDNS)) {
return false
}
if (isRDNSExcluded || isNameExcluded) {
return false
}
}

if (connector.type === 'ANNOUNCED') {
const rdns = connector.info?.rdns

if (rdns && ApiController.state.excludedRDNS.includes(rdns)) {
return false
}
if (connector.type === 'ANNOUNCED' && (isRDNSExcluded || isNameExcluded)) {
return false
}

return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('W3mAllWalletsSearch', () => {
recommended: [],
wallets: [],
isAnalyticsEnabled: false,
excludedRDNS: [],
excludedWallets: [],
isFetchingRecommendedWallets: false
}
vi.spyOn(ApiController, 'state', 'get').mockReturnValue(mockState)
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('W3mAllWalletsSearch', () => {
allRecommended: [],
wallets: mockWallets,
isAnalyticsEnabled: false,
excludedRDNS: [],
excludedWallets: [],
isFetchingRecommendedWallets: false
}
vi.spyOn(ApiController, 'state', 'get').mockReturnValue(mockState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const mockApiState: ApiControllerState = {
wallets: [],
search: [],
isAnalyticsEnabled: false,
excludedRDNS: [],
excludedWallets: [],
isFetchingRecommendedWallets: false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('W3mConnectAnnouncedWidget', () => {
beforeEach(() => {
vi.spyOn(ApiController, 'state', 'get').mockReturnValue({
...ApiController.state,
excludedRDNS: []
excludedWallets: []
})
})

Expand Down Expand Up @@ -93,7 +93,7 @@ describe('W3mConnectAnnouncedWidget', () => {

vi.spyOn(ApiController, 'state', 'get').mockReturnValue({
...ApiController.state,
excludedRDNS: ['mock.wallet']
excludedWallets: [{ name: 'Mock Wallet', rdns: 'mock.wallet' }]
})

const element: W3mConnectAnnouncedWidget = await fixture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('W3mConnectInjectedWidget', () => {
beforeEach(() => {
vi.spyOn(ApiController, 'state', 'get').mockReturnValue({
...ApiController.state,
excludedRDNS: []
excludedWallets: []
})
vi.spyOn(ConnectionController, 'checkInstalled').mockReturnValue(true)
})
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('W3mConnectInjectedWidget', () => {
it('should not render excluded RDNS wallets', async () => {
vi.spyOn(ApiController, 'state', 'get').mockReturnValue({
...ApiController.state,
excludedRDNS: ['mock.injected.wallet']
excludedWallets: [{ name: 'Mock Wallet', rdns: 'mock.injected.wallet' }]
})

const element: W3mConnectInjectedWidget = await fixture(
Expand All @@ -100,6 +100,7 @@ describe('W3mConnectInjectedWidget', () => {
element,
`wallet-selector-${MOCK_INJECTED_CONNECTOR.id}`
)

expect(walletSelector).toBeNull()
})

Expand Down
Loading
Loading