Skip to content

Commit

Permalink
fix: v5 remove names flow for solana (#2973)
Browse files Browse the repository at this point in the history
Co-authored-by: tomiir <[email protected]>
  • Loading branch information
zoruka and tomiir authored Oct 2, 2024
1 parent 63d4e2d commit a9d6860
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
14 changes: 14 additions & 0 deletions packages/core/src/controllers/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NetworkUtil, type Chain } from '@web3modal/common'
import { ChainController } from './ChainController.js'
import { PublicStateController } from './PublicStateController.js'
import { ConstantsUtil } from '../utils/ConstantsUtil.js'
import { ConstantsUtil as CommonConstantsUtil } from '@web3modal/common'

// -- Types --------------------------------------------- //
export interface NetworkControllerClient {
Expand Down Expand Up @@ -285,6 +286,19 @@ export const NetworkController = {
return Boolean(smartAccountEnabledNetworks?.includes(networkId))
},

checkIfNamesSupported() {
const chain = ChainController.state.activeChain

if (!chain) {
return false
}

const activeCaipNetwork = ChainController.state.chains.get(chain)?.networkState?.caipNetwork

// Names are only supported on EVM networks
return activeCaipNetwork?.chain === CommonConstantsUtil.CHAIN.EVM
},

resetNetwork() {
const chain = ChainController.state.activeChain

Expand Down
12 changes: 11 additions & 1 deletion packages/core/tests/controllers/NetworkController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ describe('NetworkController', () => {
'solana:mainnet:So11111111111111111111111111111111111111111'
)

mock.mockClear()
mock.mockRestore()
})

it('should check if network supports names feature', () => {
expect(NetworkController.checkIfNamesSupported()).toEqual(true)
NetworkController.setActiveCaipNetwork({
id: 'solana:mainnet',
name: 'Solana',
chain: ConstantsUtil.CHAIN.SOLANA
})
expect(NetworkController.checkIfNamesSupported()).toEqual(false)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ export class W3mAccountSettingsView extends LitElement {
private chooseNameButtonTemplate() {
const type = StorageUtil.getConnectedConnector()
const authConnector = ConnectorController.getAuthConnector()
if (!authConnector || type !== 'AUTH' || this.profileName) {
const hasNetworkSupport = NetworkController.checkIfNamesSupported()
if (!hasNetworkSupport || !authConnector || type !== 'AUTH' || this.profileName) {
return null
}

Expand Down

0 comments on commit a9d6860

Please sign in to comment.