Skip to content
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

fix: Connector image mismatch #2745

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0e5f82d
fix: remove localstorage setting of wallets in favor of connectedACco…
tomiir Aug 26, 2024
7549581
chore: wagmi connector image fix
tomiir Aug 26, 2024
965f377
chore: remove unused imports
tomiir Aug 26, 2024
348e7c0
fix: lockfile
tomiir Aug 26, 2024
b29372c
fix: import code style
tomiir Aug 26, 2024
a6f8754
Merge branch 'main' into tomas/apkt-841-bug-incorrect-wallet-image-sh…
tomiir Aug 28, 2024
c9be0ad
Merge branch 'main' of github.com:WalletConnect/web3modal into tomas/…
tomiir Aug 28, 2024
32a4be8
fix: test fixtures
tomiir Aug 28, 2024
1180a48
feat: sync wallet info on solana
tomiir Aug 28, 2024
433ecfd
Merge branch 'main' into tomas/apkt-841-bug-incorrect-wallet-image-sh…
tomiir Aug 28, 2024
6532698
Merge branch 'main' of github.com:WalletConnect/web3modal into tomas/…
tomiir Aug 28, 2024
2101c5f
chore: remove .only
tomiir Aug 28, 2024
bb95238
Merge branch 'tomas/apkt-841-bug-incorrect-wallet-image-shown-if-conn…
tomiir Aug 28, 2024
d470688
chore: add danger rule to prevent .only
tomiir Aug 28, 2024
3e792a0
chore: remove ethers5 email tests as its not stable
tomiir Aug 28, 2024
359d4f1
chore: fix ethers test, increase timeouts
tomiir Aug 28, 2024
1b346bb
Merge branch 'main' into tomas/apkt-841-bug-incorrect-wallet-image-sh…
tomiir Aug 28, 2024
80272e4
chore: restrict only first switch
tomiir Aug 28, 2024
2788ed6
Merge branch 'tomas/apkt-841-bug-incorrect-wallet-image-shown-if-conn…
tomiir Aug 28, 2024
2401fcc
Merge branch 'main' into tomas/apkt-841-bug-incorrect-wallet-image-sh…
tomiir Aug 28, 2024
cf4d62c
fix: smart-account-spec
tomiir Aug 28, 2024
f191beb
Merge branch 'tomas/apkt-841-bug-incorrect-wallet-image-shown-if-conn…
tomiir Aug 28, 2024
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
14 changes: 13 additions & 1 deletion packages/base/adapters/evm/ethers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ export class EVMEthersClient {
EthersStoreUtil.setProvider(WalletConnectProvider as unknown as Provider)
EthersStoreUtil.setStatus('connected')
EthersStoreUtil.setIsConnected(true)

this.appKit?.setAllAccounts(
WalletConnectProvider.accounts.map(address => ({ address, type: 'eoa' })),
this.chain
Expand Down Expand Up @@ -1336,7 +1337,6 @@ export class EVMEthersClient {
}
} else if (providerType === ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID) {
const provider = EthersStoreUtil.state.provider as unknown as EthereumProvider

if (provider.session) {
this.appKit?.setConnectedWalletInfo(
{
Expand All @@ -1347,6 +1347,18 @@ export class EVMEthersClient {
this.chain
)
}
} else if (providerType === ConstantsUtil.COINBASE_SDK_CONNECTOR_ID) {
const connector = this.appKit
?.getConnectors()
.find(c => c.id === ConstantsUtil.COINBASE_SDK_CONNECTOR_ID)

this.appKit?.setConnectedWalletInfo(
{
name: 'Coinbase Wallet',
icon: this.appKit?.getConnectorImage(connector)
},
this.chain
)
} else if (currentActiveWallet) {
this.appKit?.setConnectedWalletInfo({ name: currentActiveWallet }, this.chain)
}
Expand Down
6 changes: 5 additions & 1 deletion packages/base/adapters/evm/wagmi/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,12 @@ export class EVMWagmiClient {
)
}
} else {
const wagmiConnector = this.appKit?.getConnectors().find(c => c.id === connector.id)
this.appKit?.setConnectedWalletInfo(
{ name: connector.name, icon: connector.icon },
{
name: connector.name,
icon: connector.icon || this.appKit.getConnectorImage(wagmiConnector)
},
this.chain
)
}
Expand Down
6 changes: 5 additions & 1 deletion packages/base/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
RouterController,
EnsController,
OptionsController,
NetworkController
NetworkController,
AssetUtil
} from '@web3modal/core'
import { setColorTheme, setThemeVariables } from '@web3modal/ui'
import { ConstantsUtil, type Chain } from '@web3modal/common'
Expand Down Expand Up @@ -298,6 +299,9 @@ export class AppKit {
BlockchainApiController.setClientId(clientId)
}

public getConnectorImage: (typeof AssetUtil)['getConnectorImage'] = connector =>
AssetUtil.getConnectorImage(connector)

// -- Private ------------------------------------------------------------------
private async initControllers(options: AppKitOptions) {
OptionsController.setProjectId(options.projectId)
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/controllers/ConnectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export const ConnectionController = {

try {
await client.disconnect()
StorageUtil.removeConnectedWalletImageUrl()
this.resetWcConnection()
} catch (error) {
throw new Error('Failed to disconnect')
Expand Down
27 changes: 0 additions & 27 deletions packages/core/src/utils/StorageUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { WcWallet, ConnectorType, SocialProvider } from './TypeUtil.js'
// -- Helpers -----------------------------------------------------------------
const WC_DEEPLINK = 'WALLETCONNECT_DEEPLINK_CHOICE'
const W3M_RECENT = '@w3m/recent'
const W3M_CONNECTED_WALLET_IMAGE_URL = '@w3m/connected_wallet_image_url'
const W3M_CONNECTED_CONNECTOR = '@w3m/connected_connector'
const W3M_CONNECTED_SOCIAL = '@w3m/connected_social'
const W3M_CONNECTED_SOCIAL_USERNAME = '@w3m-storage/SOCIAL_USERNAME'
Expand Down Expand Up @@ -68,32 +67,6 @@ export const StorageUtil = {
return []
},

setConnectedWalletImageUrl(imageUrl: string) {
try {
localStorage.setItem(W3M_CONNECTED_WALLET_IMAGE_URL, imageUrl)
} catch {
console.info('Unable to set Connected Wallet Image Url')
}
},

removeConnectedWalletImageUrl() {
try {
localStorage.removeItem(W3M_CONNECTED_WALLET_IMAGE_URL)
} catch {
console.info('Unable to remove Connected Wallet Image Url')
}
},

getConnectedWalletImageUrl() {
try {
return localStorage.getItem(W3M_CONNECTED_WALLET_IMAGE_URL)
} catch {
console.info('Unable to set Connected Wallet Image Url')
}

return undefined
},

setConnectedConnector(connectorType: ConnectorType) {
try {
localStorage.setItem(W3M_CONNECTED_CONNECTOR, connectorType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
EventsController,
ModalController,
OptionsController,
RouterController,
StorageUtil
RouterController
} from '@web3modal/core'
import { ConstantsUtil } from '@web3modal/scaffold-utils'
import { customElement } from '@web3modal/ui'
Expand Down Expand Up @@ -68,10 +67,6 @@ export class W3mConnectCoinbaseWidget extends LitElement {
try {
ConnectionController.setWcError(false)

if (connector.imageUrl) {
StorageUtil.setConnectedWalletImageUrl(connector.imageUrl)
}

await ConnectionController.connectExternal(connector, connector.chain)

if (OptionsController.state.isSiweEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
EventsController,
ModalController,
OptionsController,
RouterController,
StorageUtil
RouterController
} from '@web3modal/core'
import { ConstantsUtil } from '@web3modal/scaffold-utils'
import { customElement } from '@web3modal/ui'
Expand Down Expand Up @@ -37,9 +36,6 @@ export class W3mConnectingExternalView extends W3mConnectingWidget {
try {
this.error = false
if (this.connector) {
if (this.connector.imageUrl) {
StorageUtil.setConnectedWalletImageUrl(this.connector.imageUrl)
}
/**
* Coinbase SDK works with popups and popups requires user interaction to be opened since modern browsers block popups which triggered programmatically.
* Instead of opening a popup in first render for `W3mConnectingWidget`, we need to trigger connection for Coinbase connector specifically when users select it.
Expand Down
16 changes: 0 additions & 16 deletions packages/scaffold-ui/src/views/w3m-connecting-wc-view/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { BaseError, Platform } from '@web3modal/core'
import {
AssetUtil,
ConnectionController,
ConnectorController,
ConstantsUtil,
CoreHelperUtil,
EventsController,
Expand Down Expand Up @@ -59,20 +57,6 @@ export class W3mConnectingWcView extends LitElement {
try {
const { wcPairingExpiry } = ConnectionController.state
if (retry || CoreHelperUtil.isPairingExpired(wcPairingExpiry)) {
if (this.wallet) {
const url = AssetUtil.getWalletImage(this.wallet)
if (url) {
StorageUtil.setConnectedWalletImageUrl(url)
}
} else {
const connectors = ConnectorController.state.connectors
const connector = connectors.find(c => c.type === 'WALLET_CONNECT')
const url = AssetUtil.getConnectorImage(connector)
if (url) {
StorageUtil.setConnectedWalletImageUrl(url)
}
}

await ConnectionController.connectWalletConnect()
this.finalizeConnection()
if (
Expand Down
4 changes: 2 additions & 2 deletions packages/siwe/scaffold/partials/w3m-connecting-siwe/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { customElement } from '@web3modal/ui'
import { LitElement, html } from 'lit'
import styles from './styles.js'
import { OptionsController, StorageUtil } from '@web3modal/core'
import { AccountController, OptionsController } from '@web3modal/core'

@customElement('w3m-connecting-siwe')
export class W3mConnectingSiwe extends LitElement {
Expand All @@ -10,7 +10,7 @@ export class W3mConnectingSiwe extends LitElement {
// -- Members ------------------------------------------- //
private readonly dappImageUrl = OptionsController.state.metadata?.icons

private readonly walletImageUrl = StorageUtil.getConnectedWalletImageUrl()
private readonly walletImageUrl = AccountController.state.connectedWalletInfo?.icon

public override firstUpdated() {
const visuals = this.shadowRoot?.querySelectorAll('wui-visual-thumbnail')
Expand Down
Loading