Skip to content

Commit

Permalink
refactor: make the wallet image listen state updates for embedded use…
Browse files Browse the repository at this point in the history
… case (#3466)
  • Loading branch information
enesozturk authored Dec 16, 2024
1 parent f83d09c commit 14af422
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
22 changes: 22 additions & 0 deletions .changeset/slimy-berries-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-core': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/appkit-cli': patch
'@reown/appkit-common': 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
---

refactor: make the wallet image listen state updates for embedded use case
2 changes: 1 addition & 1 deletion packages/core/src/controllers/AssetController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const AssetController = {
},

setConnectorImage(key: string, value: string) {
state.connectorImages[key] = value
state.connectorImages = { ...state.connectorImages, [key]: value }
},

setTokenImage(key: string, value: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Connector } from '@reown/appkit-core'
import {
AssetUtil,
AssetController,
ChainController,
ConnectorController,
CoreHelperUtil,
Expand All @@ -21,10 +21,13 @@ export class W3mConnectWalletConnectWidget extends LitElement {

@state() private connectors = ConnectorController.state.connectors

@state() private connectorImages = AssetController.state.connectorImages

public constructor() {
super()
this.unsubscribe.push(
ConnectorController.subscribeKey('connectors', val => (this.connectors = val))
ConnectorController.subscribeKey('connectors', val => (this.connectors = val)),
AssetController.subscribeKey('connectorImages', val => (this.connectorImages = val))
)
}

Expand All @@ -41,16 +44,17 @@ export class W3mConnectWalletConnectWidget extends LitElement {
}

const connector = this.connectors.find(c => c.id === 'walletConnect')

if (!connector) {
this.style.cssText = `display: none`

return null
}

const connectorImage = connector.imageUrl || this.connectorImages[connector?.imageId ?? '']

return html`
<wui-list-wallet
imageSrc=${ifDefined(AssetUtil.getConnectorImage(connector))}
imageSrc=${ifDefined(connectorImage)}
name=${connector.name ?? 'Unknown'}
@click=${() => this.onConnector(connector)}
tagLabel="qr code"
Expand Down

0 comments on commit 14af422

Please sign in to comment.