From 39a20b2397f6d4b6f0d3fb3f1a15d9f4edf01bea Mon Sep 17 00:00:00 2001 From: Felipe Mendes Date: Fri, 27 Sep 2024 14:55:19 -0300 Subject: [PATCH] fix: v5 solana check installed extensions (#2957) --- .../base/adapters/solana/web3js/client.ts | 8 +++++++- .../web3js/providers/WalletConnectProvider.ts | 2 +- .../providers/WalletStandardProvider.ts | 13 ++++++------ .../w3m-connecting-wc-browser/index.ts | 19 +++++++++++------- .../src/views/w3m-connecting-wc-view/index.ts | 20 ++++++++++++++----- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/packages/base/adapters/solana/web3js/client.ts b/packages/base/adapters/solana/web3js/client.ts index 5866d386dd..e579b4fff3 100644 --- a/packages/base/adapters/solana/web3js/client.ts +++ b/packages/base/adapters/solana/web3js/client.ts @@ -259,7 +259,13 @@ export class SolanaWeb3JsClient implements ChainAdapter BigInt(0), - formatUnits: () => '' + formatUnits: () => '', + + checkInstalled: (ids: string[] = []) => { + const availableIds = new Set(this.availableProviders.map(provider => provider.name)) + + return ids.some(id => availableIds.has(id)) + } } } diff --git a/packages/base/adapters/solana/web3js/providers/WalletConnectProvider.ts b/packages/base/adapters/solana/web3js/providers/WalletConnectProvider.ts index f00cafefef..85af7a814b 100644 --- a/packages/base/adapters/solana/web3js/providers/WalletConnectProvider.ts +++ b/packages/base/adapters/solana/web3js/providers/WalletConnectProvider.ts @@ -81,7 +81,7 @@ export class WalletConnectProvider extends ProviderEventEmitter implements Provi return acc }, {}) - if (this.provider.session) { + if (this.provider.session?.namespaces['solana']) { this.session = this.provider.session } else { this.provider.on('display_uri', this.onUri) diff --git a/packages/base/adapters/solana/web3js/providers/WalletStandardProvider.ts b/packages/base/adapters/solana/web3js/providers/WalletStandardProvider.ts index bba28eef2f..8d7d25fbbe 100644 --- a/packages/base/adapters/solana/web3js/providers/WalletStandardProvider.ts +++ b/packages/base/adapters/solana/web3js/providers/WalletStandardProvider.ts @@ -65,17 +65,16 @@ export class WalletStandardProvider extends ProviderEventEmitter implements Prov // -- Public ------------------------------------------- // public get name() { + if (this.wallet.name === 'Trust') { + // The wallets from our list of wallets have not matching with the extension name + return 'Trust Wallet' + } + return this.wallet.name } public get type() { - const FILTER_OUT_ADAPTERS = ['Trust'] - - if (FILTER_OUT_ADAPTERS.includes(this.wallet.name)) { - return 'EXTERNAL' - } - - return 'ANNOUNCED' + return 'ANNOUNCED' as const } public get publicKey() { diff --git a/packages/scaffold-ui/src/partials/w3m-connecting-wc-browser/index.ts b/packages/scaffold-ui/src/partials/w3m-connecting-wc-browser/index.ts index 228be11c5c..4b8ddb3f1e 100644 --- a/packages/scaffold-ui/src/partials/w3m-connecting-wc-browser/index.ts +++ b/packages/scaffold-ui/src/partials/w3m-connecting-wc-browser/index.ts @@ -29,15 +29,20 @@ export class W3mConnectingWcBrowser extends W3mConnectingWidget { try { this.error = false const { connectors } = ConnectorController.state - const announcedConnector = connectors.find( - c => c.type === 'ANNOUNCED' && c.info?.rdns === this.wallet?.rdns + + const connector = connectors.find( + c => + (c.type === 'ANNOUNCED' && c.info?.rdns === this.wallet?.rdns) || + c.type === 'INJECTED' || + c.name === this.wallet?.name ) - const injectedConnector = connectors.find(c => c.type === 'INJECTED') - if (announcedConnector) { - await ConnectionController.connectExternal(announcedConnector, announcedConnector.chain) - } else if (injectedConnector) { - await ConnectionController.connectExternal(injectedConnector, injectedConnector.chain) + + if (connector) { + await ConnectionController.connectExternal(connector, connector.chain) + } else { + throw new Error('w3m-connecting-wc-browser: No connector found') } + ModalController.close() EventsController.sendEvent({ diff --git a/packages/scaffold-ui/src/views/w3m-connecting-wc-view/index.ts b/packages/scaffold-ui/src/views/w3m-connecting-wc-view/index.ts index 270ad271e6..727a321d19 100644 --- a/packages/scaffold-ui/src/views/w3m-connecting-wc-view/index.ts +++ b/packages/scaffold-ui/src/views/w3m-connecting-wc-view/index.ts @@ -30,6 +30,7 @@ export class W3mConnectingWcView extends LitElement { public constructor() { super() + this.determinePlatforms() this.initializeConnection() this.interval = setInterval(this.initializeConnection.bind(this), ConstantsUtil.TEN_SEC_MS) } @@ -44,8 +45,6 @@ export class W3mConnectingWcView extends LitElement { return html`` } - this.determinePlatforms() - return html` ${this.headerTemplate()}
${this.platformTemplate()}
@@ -55,6 +54,14 @@ export class W3mConnectingWcView extends LitElement { // -- Private ------------------------------------------- // private async initializeConnection(retry = false) { try { + if (this.platform === 'browser') { + /* + * If the platform is browser it means the user is using a browser wallet, + * in this case the connection is handled in w3m-connecting-wc-browser component. + */ + return + } + const { wcPairingExpiry } = ConnectionController.state if (retry || CoreHelperUtil.isPairingExpired(wcPairingExpiry)) { await ConnectionController.connectWalletConnect() @@ -112,16 +119,19 @@ export class W3mConnectingWcView extends LitElement { private determinePlatforms() { if (!this.wallet) { - throw new Error('w3m-connecting-wc-view:determinePlatforms No wallet') + this.platforms.push('qrcode') + this.platform = 'qrcode' + + return } if (this.platform) { return } - const { mobile_link, desktop_link, webapp_link, injected, rdns } = this.wallet + const { mobile_link, desktop_link, webapp_link, injected, rdns, name } = this.wallet const injectedIds = injected?.map(({ injected_id }) => injected_id).filter(Boolean) as string[] - const browserIds = rdns ? [rdns] : injectedIds ?? [] + const browserIds = [...(rdns ? [rdns] : injectedIds ?? []), name] const isBrowser = OptionsController.state.isUniversalProvider ? false : browserIds.length const isMobileWc = mobile_link const isWebWc = webapp_link