Skip to content

Commit a13aa8d

Browse files
tmmstarc007
andauthoredNov 13, 2024··
feat: support multiple rdns to filter 6963 providers (#4406)
* feat: support multiple rdns values to prevent duplicate connectors * chore: tweaks --------- Co-authored-by: Saurabh Chauhan <36479565+starc007@users.noreply.github.com>
1 parent e9ca469 commit a13aa8d

File tree

7 files changed

+41
-9
lines changed

7 files changed

+41
-9
lines changed
 

‎.changeset/quick-pans-grow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wagmi/core": patch
3+
---
4+
5+
Added support for multiple connector `rdns` entries.

‎.changeset/wild-guests-tell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wagmi/connectors": patch
3+
---
4+
5+
Added additional RDNS to MetaMask Connector.

‎packages/connectors/src/metaMask.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
9595
return createConnector<Provider, Properties>((config) => ({
9696
id: 'metaMaskSDK',
9797
name: 'MetaMask',
98-
rdns: 'io.metamask',
98+
rdns: ['io.metamask', 'io.metamask.mobile'],
9999
type: metaMask.type,
100100
async setup() {
101101
const provider = await this.getProvider()

‎packages/core/src/connectors/createConnector.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export type CreateConnectorFn<
3737
readonly icon?: string | undefined
3838
readonly id: string
3939
readonly name: string
40-
readonly rdns?: string | undefined
40+
readonly rdns?: string | readonly string[] | undefined
4141
readonly supportsSimulation?: boolean | undefined
4242
readonly type: string
4343

‎packages/core/src/createConfig.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ test('behavior: eip 6963 providers', async () => {
394394
createConnector((c) => {
395395
return {
396396
...mock({ accounts })(c),
397-
rdns: 'com.mock',
397+
rdns: ['com.mock', 'com.baz'],
398398
}
399399
}),
400400
],
@@ -413,9 +413,12 @@ test('behavior: eip 6963 providers', async () => {
413413
announceProvider(detail_3)()
414414
await wait(100)
415415

416-
expect(config.connectors.map((x) => x.rdns ?? x.id)).toMatchInlineSnapshot(`
416+
expect(
417+
config.connectors.flatMap((x) => x.rdns ?? x.id),
418+
).toMatchInlineSnapshot(`
417419
[
418420
"com.mock",
421+
"com.baz",
419422
"com.example",
420423
"com.foo",
421424
"com.bar",

‎packages/core/src/createConfig.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ export function createConfig<
9898
for (const connectorFns of rest.connectors ?? []) {
9999
const connector = setup(connectorFns)
100100
collection.push(connector)
101-
if (!ssr && connector.rdns) rdnsSet.add(connector.rdns)
101+
if (!ssr && connector.rdns) {
102+
const rdnsValues =
103+
typeof connector.rdns === 'string' ? [connector.rdns] : connector.rdns
104+
for (const rdns of rdnsValues) {
105+
rdnsSet.add(rdns)
106+
}
107+
}
102108
}
103109
if (!ssr && mipd) {
104110
const providers = mipd.getProviders()
@@ -323,11 +329,17 @@ export function createConfig<
323329

324330
// EIP-6963 subscribe for new wallet providers
325331
mipd?.subscribe((providerDetails) => {
326-
const connectorIdSet = new Set()
327-
const connectorRdnsSet = new Set()
332+
const connectorIdSet = new Set<string>()
333+
const connectorRdnsSet = new Set<string>()
328334
for (const connector of connectors.getState()) {
329335
connectorIdSet.add(connector.id)
330-
if (connector.rdns) connectorRdnsSet.add(connector.rdns)
336+
if (connector.rdns) {
337+
const rdnsValues =
338+
typeof connector.rdns === 'string' ? [connector.rdns] : connector.rdns
339+
for (const rdns of rdnsValues) {
340+
connectorRdnsSet.add(rdns)
341+
}
342+
}
331343
}
332344

333345
const newConnectors: Connector[] = []

‎packages/core/src/hydrate.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ export function hydrate(config: Config, parameters: HydrateParameters) {
2727
config._internal.connectors.setState((connectors) => {
2828
const rdnsSet = new Set<string>()
2929
for (const connector of connectors ?? []) {
30-
if (connector.rdns) rdnsSet.add(connector.rdns)
30+
if (connector.rdns) {
31+
const rdnsValues = Array.isArray(connector.rdns)
32+
? connector.rdns
33+
: [connector.rdns]
34+
for (const rdns of rdnsValues) {
35+
rdnsSet.add(rdns)
36+
}
37+
}
3138
}
3239
const mipdConnectors = []
3340
const providers = config._internal.mipd?.getProviders() ?? []

0 commit comments

Comments
 (0)
Please sign in to comment.