Skip to content

Commit

Permalink
fix: v5 solana check installed extensions (#2957)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka authored Sep 27, 2024
1 parent d488048 commit 39a20b2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
8 changes: 7 additions & 1 deletion packages/base/adapters/solana/web3js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,13 @@ export class SolanaWeb3JsClient implements ChainAdapter<SolStoreUtilState, CaipN

parseUnits: () => BigInt(0),

formatUnits: () => ''
formatUnits: () => '',

checkInstalled: (ids: string[] = []) => {
const availableIds = new Set(this.availableProviders.map(provider => provider.name))

return ids.some(id => availableIds.has(id))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
20 changes: 15 additions & 5 deletions packages/scaffold-ui/src/views/w3m-connecting-wc-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -44,8 +45,6 @@ export class W3mConnectingWcView extends LitElement {
return html`<w3m-connecting-wc-qrcode></w3m-connecting-wc-qrcode>`
}

this.determinePlatforms()

return html`
${this.headerTemplate()}
<div>${this.platformTemplate()}</div>
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 39a20b2

Please sign in to comment.