Skip to content

Commit

Permalink
:fix don't show browser wallet when injected provider is not detected (
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvoskamp authored Nov 20, 2024
1 parent 329cb92 commit c4d4d2c
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 3 deletions.
24 changes: 24 additions & 0 deletions .changeset/six-fans-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-wagmi': patch
'@apps/demo': patch
'@apps/gallery': patch
'@apps/laboratory': patch
'@reown/appkit-adapter-polkadot': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/appkit-common': patch
'@reown/appkit-core': patch
'@reown/appkit-experimental': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-siwx': patch
'@reown/appkit-ui': patch
'@reown/appkit-wallet': patch
---

Don't show browser wallet when injected provider is not detected
5 changes: 4 additions & 1 deletion packages/adapters/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ export class EthersAdapter extends AdapterBlueprint {

connectors.forEach(connector => {
const key = connector === 'coinbase' ? 'coinbaseWalletSDK' : connector

const injectedConnector = connector === ConstantsUtil.INJECTED_CONNECTOR_ID

if (this.namespace) {
this.addConnector({
id: connector,
Expand All @@ -269,7 +272,7 @@ export class EthersAdapter extends AdapterBlueprint {
name: PresetsUtil.ConnectorNamesMap[key],
imageId: PresetsUtil.ConnectorImageIds[key],
type: PresetsUtil.ConnectorTypesMap[key] ?? 'EXTERNAL',
info: { rdns: key },
info: injectedConnector ? undefined : { rdns: key },
chain: this.namespace,
chains: [],
provider: this.ethersConfig?.[connector as keyof ProviderType] as Provider
Expand Down
17 changes: 17 additions & 0 deletions packages/adapters/ethers/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ describe('EthersAdapter', () => {
expect(adapter.adapterType).toBe('ethers')
expect(adapter.namespace).toBe('eip155')
})

it('should not set info property for injected connector', () => {
const mockConnectors = [
{
id: 'Browser Wallet',
name: 'Browser Wallet',
type: 'injected',
info: { rdns: 'Browser Wallet' }
}
]

;(adapter as any).syncConnectors(mockConnectors)

const injectedConnector = mockConnectors.filter((c: any) => c.id === 'injected')[0]

expect(injectedConnector?.info).toBeUndefined()
})
})

describe('EthersAdapter - signMessage', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/adapters/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ export class Ethers5Adapter extends AdapterBlueprint {

connectors.forEach(connector => {
const key = connector === 'coinbase' ? 'coinbaseWalletSDK' : connector

const injectedConnector = connector === ConstantsUtil.INJECTED_CONNECTOR_ID

if (this.namespace) {
this.addConnector({
id: connector,
Expand All @@ -270,7 +273,7 @@ export class Ethers5Adapter extends AdapterBlueprint {
name: PresetsUtil.ConnectorNamesMap[key],
imageId: PresetsUtil.ConnectorImageIds[key],
type: PresetsUtil.ConnectorTypesMap[key] ?? 'EXTERNAL',
info: { rdns: key },
info: injectedConnector ? undefined : { rdns: key },
chain: this.namespace,
chains: [],
provider: this.ethersConfig?.[connector as keyof ProviderType] as Provider
Expand Down
17 changes: 17 additions & 0 deletions packages/adapters/ethers5/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ describe('Ethers5Adapter', () => {
expect(adapter.adapterType).toBe('ethers')
expect(adapter.namespace).toBe('eip155')
})

it('should not set info property for injected connector', () => {
const mockConnectors = [
{
id: 'Browser Wallet',
name: 'Browser Wallet',
type: 'injected',
info: { rdns: 'Browser Wallet' }
}
]

;(adapter as any).syncConnectors(mockConnectors)

const injectedConnector = mockConnectors.filter((c: any) => c.id === 'injected')[0]

expect(injectedConnector?.info).toBeUndefined()
})
})

describe('Ethers5Adapter - signMessage', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/adapters/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ export class WagmiAdapter extends AdapterBlueprint {
filteredConnectors.forEach(connector => {
const shouldSkip = ConstantsUtil.AUTH_CONNECTOR_ID === connector.id

const injectedConnector = connector.id === ConstantsUtil.INJECTED_CONNECTOR_ID

if (!shouldSkip && this.namespace) {
this.addConnector({
id: connector.id,
Expand All @@ -340,7 +342,7 @@ export class WagmiAdapter extends AdapterBlueprint {
name: PresetsUtil.ConnectorNamesMap[connector.id] ?? connector.name,
imageId: PresetsUtil.ConnectorImageIds[connector.id],
type: PresetsUtil.ConnectorTypesMap[connector.type] ?? 'EXTERNAL',
info: { rdns: connector.id },
info: injectedConnector ? undefined : { rdns: connector.id },
chain: this.namespace,
chains: []
})
Expand Down
17 changes: 17 additions & 0 deletions packages/adapters/wagmi/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ describe('WagmiAdapter', () => {
expect(adapter.adapterType).toBe('wagmi')
expect(adapter.namespace).toBe('eip155')
})

it('should not set info property for injected connector', () => {
const mockConnectors = [
{
id: 'Browser Wallet',
name: 'Browser Wallet',
type: 'injected',
info: { rdns: 'Browser Wallet' }
}
]

;(adapter as any).syncConnectors(mockConnectors)

const injectedConnector = mockConnectors.filter((c: any) => c.id === 'injected')[0]

expect(injectedConnector?.info).toBeUndefined()
})
})

describe('WagmiAdapter - signMessage', () => {
Expand Down

0 comments on commit c4d4d2c

Please sign in to comment.