Skip to content

Commit

Permalink
fix wallet list
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvoskamp committed Feb 2, 2024
1 parent e3106ed commit 87c4e43
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 66 deletions.
11 changes: 1 addition & 10 deletions apps/laboratory/src/pages/library/ethers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@ const modal = createWeb3Modal({
enableAnalytics: true,
metadata: ConstantsUtil.Metadata,
termsConditionsUrl: 'https://walletconnect.com/terms',
privacyPolicyUrl: 'https://walletconnect.com/privacy',
customWallets: [
{
id: 'react-wallet-v2',
name: 'react-wallet-v2',
homepage: 'https://react-wallet-v2-git-chore-2111-walletconnect1.vercel.app',
mobile_link: 'https://react-wallet.walletconnect.com',
desktop_link: 'https://react-wallet.walletconnect.com'
}
]
privacyPolicyUrl: 'https://walletconnect.com/privacy'
})

ThemeStore.setModal(modal)
Expand Down
12 changes: 1 addition & 11 deletions apps/laboratory/src/pages/library/wagmi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@ const modal = createWeb3Modal({
enableAnalytics: true,
metadata: ConstantsUtil.Metadata,
termsConditionsUrl: 'https://walletconnect.com/terms',
privacyPolicyUrl: 'https://walletconnect.com/privacy',
customWallets: [
{
id: 'react-wallet-v2',
name: 'react-wallet-v2',
homepage: 'https://react-wallet-v2-git-chore-2111-walletconnect1.vercel.app',
mobile_link: 'https://react-wallet.walletconnect.com',
desktop_link: 'https://react-wallet.walletconnect.com',
webapp_link: 'https://react-wallet.walletconnect.com'
}
]
privacyPolicyUrl: 'https://walletconnect.com/privacy'
})

ThemeStore.setModal(modal)
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/controllers/ConnectorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export const ConnectorController = {
return state.connectors.find(c => c.type === 'EMAIL') as EmailConnector | undefined
},

getAnnouncedConnectorRdns() {
return state.connectors.filter(c => c.type === 'ANNOUNCED').map(c => c.info?.rdns)
},

getConnectors() {
return state.connectors
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ export class Web3Modal extends Web3ModalScaffold {
const connectors = this.getConnectors()
const existingConnector = connectors.find(c => c.name === info.name)
if (!existingConnector) {
const type = PresetsUtil.ConnectorTypesMap[ConstantsUtil.EIP6963_CONNECTOR_ID]
const type = PresetsUtil.ConnectorTypesMap[ConstantsUtil.INJECTED_CONNECTOR_ID]
if (type) {
this.addConnector({
id: ConstantsUtil.EIP6963_CONNECTOR_ID,
Expand Down
2 changes: 1 addition & 1 deletion packages/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ export class Web3Modal extends Web3ModalScaffold {
const connectors = this.getConnectors()
const existingConnector = connectors.find(c => c.name === info.name)
if (!existingConnector) {
const type = PresetsUtil.ConnectorTypesMap[ConstantsUtil.EIP6963_CONNECTOR_ID]
const type = PresetsUtil.ConnectorTypesMap[ConstantsUtil.INJECTED_CONNECTOR_ID]
if (type) {
this.addConnector({
id: ConstantsUtil.EIP6963_CONNECTOR_ID,
Expand Down
47 changes: 11 additions & 36 deletions packages/scaffold/src/views/w3m-connect-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ export class W3mConnectView extends LitElement {
<wui-flex flexDirection="column" padding="s" gap="xs">
<w3m-email-login-widget></w3m-email-login-widget>
${this.walletConnectConnectorTemplate()} ${this.recentTemplate()}
${this.announcedTemplate()} ${this.injectedTemplate()} ${this.featuredTemplate()}
${this.customTemplate()} ${this.recommendedTemplate()} ${this.externalTemplate()}
${this.allWalletsTemplate()}
${this.walletConnectConnectorTemplate()} ${this.recentTemplate()} ${this.injectedTemplate()}
${this.featuredTemplate()} ${this.customTemplate()} ${this.recommendedTemplate()}
${this.externalTemplate()} ${this.allWalletsTemplate()}
</wui-flex>
<w3m-legal-footer></w3m-legal-footer>
`
Expand Down Expand Up @@ -82,6 +81,7 @@ export class W3mConnectView extends LitElement {
if (!customWallets?.length) {
return null
}

const wallets = this.filterOutDuplicateWallets(customWallets)

return wallets.map(
Expand Down Expand Up @@ -136,25 +136,6 @@ export class W3mConnectView extends LitElement {
)
}

private announcedTemplate() {
return this.connectors.map(connector => {
if (connector.type !== 'ANNOUNCED') {
return null
}

return html`
<wui-list-wallet
imageSrc=${ifDefined(AssetUtil.getConnectorImage(connector))}
name=${connector.name ?? 'Unknown'}
@click=${() => this.onConnector(connector)}
tagVariant="success"
.installed=${true}
>
</wui-list-wallet>
`
})
}

private injectedTemplate() {
return this.connectors.map(connector => {
if (connector.type !== 'INJECTED') {
Expand All @@ -178,17 +159,11 @@ export class W3mConnectView extends LitElement {
}

private externalTemplate() {
const announcedRdns = ConnectorController.getAnnouncedConnectorRdns()

return this.connectors.map(connector => {
if (['WALLET_CONNECT', 'INJECTED', 'ANNOUNCED', 'EMAIL'].includes(connector.type)) {
return null
}

if (announcedRdns.includes(ConstantsUtil.CONNECTOR_RDNS_MAP[connector.id])) {
return null
}

return html`
<wui-list-wallet
imageSrc=${ifDefined(AssetUtil.getConnectorImage(connector))}
Expand Down Expand Up @@ -241,15 +216,16 @@ export class W3mConnectView extends LitElement {
const { connectors } = ConnectorController.state
const recent = StorageUtil.getRecentWallets()
const injected = connectors.filter(c => c.type === 'INJECTED')
const eip6963 = connectors.filter(c => c.type === 'ANNOUNCED')
const filteredInjected = injected.filter(i => i.name !== 'Browser Wallet')

if (featuredWalletIds || customWallets || !recommended.length) {
return null
}

// EIP6963 wallets are no longer serialized as ANNOUNCED in wagmiv2.
const eip6963Amount = eip6963.length || Math.max(0, injected.length - 1)
const overrideLength = eip6963Amount + recent.length
const overrideLength = filteredInjected.length + recent.length

const maxRecommended = Math.max(0, 2 - overrideLength)

const wallets = this.filterOutDuplicateWallets(recommended).slice(0, maxRecommended)

return wallets.map(
Expand Down Expand Up @@ -281,10 +257,9 @@ export class W3mConnectView extends LitElement {
const { connectors } = ConnectorController.state
const recent = StorageUtil.getRecentWallets()
const recentIds = recent.map(wallet => wallet.id)
const rdnsIds = connectors.map(c => c.info?.rdns).filter(Boolean)
const filtered = wallets.filter(
wallet =>
!recentIds.includes(wallet.id) &&
!connectors.find(c => c.id === wallet.rdns || c?.info?.rdns === wallet.rdns)
wallet => !recentIds.includes(wallet.id) && !rdnsIds.includes(wallet.rdns ?? undefined)
)

return filtered
Expand Down
11 changes: 8 additions & 3 deletions packages/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,21 @@ export class Web3Modal extends Web3ModalScaffold {
private syncConnectors(
connectors: Web3ModalClientOptions<CoreConfig>['wagmiConfig']['connectors']
) {
const uniqueIds = new Set()
const filteredConnectors = connectors.filter(
item => !uniqueIds.has(item.id) && uniqueIds.add(item.id)
)

const w3mConnectors: Connector[] = []

const coinbaseSDKId = ConstantsUtil.COINBASE_SDK_CONNECTOR_ID

// Check if coinbase injected connector is present
const coinbaseConnector = connectors.find(
const coinbaseConnector = filteredConnectors.find(
c => c.id === CoreConstants.CONNECTOR_RDNS_MAP[coinbaseSDKId]
)

connectors.forEach(({ id, name, type, icon }) => {
filteredConnectors.forEach(({ id, name, type, icon }) => {
// If coinbase injected connector is present, skip coinbase sdk connector.
const shouldSkip =
(coinbaseConnector && id === coinbaseSDKId) || ConstantsUtil.EMAIL_CONNECTOR_ID === id
Expand All @@ -358,7 +363,7 @@ export class Web3Modal extends Web3ModalScaffold {
}
})
this.setConnectors(w3mConnectors)
this.syncEmailConnector(connectors)
this.syncEmailConnector(filteredConnectors)
}

private async syncEmailConnector(
Expand Down

0 comments on commit 87c4e43

Please sign in to comment.