Skip to content

Commit

Permalink
fix: revert tests only changes (#2905)
Browse files Browse the repository at this point in the history
Co-authored-by: tomiir <[email protected]>
  • Loading branch information
enesozturk and tomiir authored Sep 23, 2024
1 parent 08c3393 commit c7ad1b0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test.skip('it should show disabled networks', async () => {
await modalPage.closeModal()
})

test.only('it should switch networks and sign', async () => {
test('it should switch networks and sign', async () => {
const chains = ['Polygon', 'Solana']

async function processChain(index: number) {
Expand Down
10 changes: 5 additions & 5 deletions packages/adapters/solana/src/providers/AuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ export class AuthProvider extends ProviderEventEmitter implements Provider, Prov
required?: Required
): Required extends true ? PublicKey : PublicKey | undefined {
const session = this.getSession()
const namespace = this.getActiveNamespace()
if (!session || namespace !== 'solana') {
if (!session) {
if (required) {
throw new Error('Account is required')
}
Expand Down Expand Up @@ -231,10 +230,11 @@ export class AuthProvider extends ProviderEventEmitter implements Provider, Prov
})

this.getProvider().onConnect(response => {
this.setSession(response)
const activeNamespace = this.getActiveNamespace()
const isSolanaNamespace =
typeof response.chainId === 'string' ? response.chainId?.startsWith('solana') : false

if (activeNamespace === 'solana') {
if (isSolanaNamespace) {
this.setSession(response)
this.emit('connect', this.getPublicKey(true))
}
})
Expand Down
66 changes: 26 additions & 40 deletions packages/core/src/controllers/ChainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,35 +222,19 @@ export const ChainController = {
)
},

setActiveNamespace(
chain: ChainNamespace | undefined,
caipNetwork?: NetworkControllerState['caipNetwork']
) {
if (caipNetwork?.chainNamespace) {
const newAdapter = chain ? state.chains.get(caipNetwork.chainNamespace) : undefined
const newNamespace = newAdapter?.chainNamespace !== state.activeChain

if (newAdapter && newNamespace) {
state.activeChain = newAdapter.chainNamespace
state.activeCaipNetwork = caipNetwork
state.activeCaipAddress = newAdapter.accountState?.caipAddress
SafeLocalStorage.setItem(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID, caipNetwork.id)

NetworkController.replaceState(newAdapter.networkState)
AccountController.replaceState(newAdapter.accountState)

PublicStateController.set({
activeChain: chain,
selectedNetworkId: newAdapter.networkState?.caipNetwork?.id
})
}
} else {
state.activeChain = chain
const caipNetworks = chain ? state.chains.get(chain)?.caipNetworks : []
state.activeCaipNetwork = caipNetworks?.[0]
setActiveNamespace(chain: ChainNamespace | undefined) {
state.activeChain = chain

const newAdapter = chain ? state.chains.get(chain) : undefined
const caipNetwork = newAdapter?.networkState?.caipNetwork

if (caipNetwork?.id) {
state.activeCaipAddress = newAdapter?.accountState?.caipAddress
state.activeCaipNetwork = caipNetwork
SafeLocalStorage.setItem(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID, caipNetwork?.id)
PublicStateController.set({
activeChain: chain,
selectedNetworkId: state.activeCaipNetwork?.id
selectedNetworkId: caipNetwork?.id
})
}
},
Expand All @@ -260,19 +244,21 @@ export const ChainController = {
return
}

const sameNamespace = caipNetwork.chainNamespace === state.activeChain
const newAdapter = state.chains.get(caipNetwork.chainNamespace)
state.activeChain = caipNetwork.chainNamespace
state.activeCaipNetwork = caipNetwork
state.activeCaipAddress = newAdapter?.accountState?.caipAddress

if (sameNamespace) {
state.activeChain = caipNetwork.chainNamespace
state.activeCaipNetwork = caipNetwork
PublicStateController.set({
activeChain: state.activeChain,
selectedNetworkId: state.activeCaipNetwork?.id
})
SafeLocalStorage.setItem(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID, caipNetwork.id)
} else {
this.setActiveNamespace(caipNetwork.chainNamespace, caipNetwork)
if (newAdapter) {
NetworkController.replaceState(newAdapter.networkState)
AccountController.replaceState(newAdapter.accountState)
}

PublicStateController.set({
activeChain: state.activeChain,
selectedNetworkId: state.activeCaipNetwork?.id
})
SafeLocalStorage.setItem(SafeLocalStorageKeys.ACTIVE_CAIP_NETWORK_ID, caipNetwork.id)
},

/**
Expand Down Expand Up @@ -303,9 +289,9 @@ export const ChainController = {
}
},

getNetworkControllerClient() {
getNetworkControllerClient(chainNamespace?: ChainNamespace) {
const walletId = SafeLocalStorage.getItem(SafeLocalStorageKeys.WALLET_ID)
const chain = state.activeChain
const chain = chainNamespace || state.activeChain
const isWcConnector = walletId === 'walletConnect'
const universalNetworkControllerClient = state.universalAdapter.networkControllerClient

Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/controllers/ConnectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ModalController } from './ModalController.js'
import { ConnectorController } from './ConnectorController.js'
import { EventsController } from './EventsController.js'
import type { ChainNamespace } from '@reown/appkit-common'
import { RouterController } from './RouterController.js'

// -- Types --------------------------------------------- //
export interface ConnectExternalOptions {
Expand Down Expand Up @@ -167,10 +166,6 @@ export const ConnectionController = {
state.recentWallet = undefined
TransactionsController.resetTransactions()
StorageUtil.deleteWalletConnectDeepLink()
if (ModalController.state.open) {
ModalController.close()
RouterController.reset('Connect')
}
},

setWcLinking(wcLinking: ConnectionControllerState['wcLinking']) {
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/controllers/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,14 @@ export const NetworkController = {
},

async switchActiveNetwork(network: NetworkControllerState['caipNetwork']) {
const networkControllerClient = ChainController.getNetworkControllerClient()
const networkControllerClient = ChainController.getNetworkControllerClient(
network?.chainNamespace
)

if (networkControllerClient) {
await networkControllerClient.switchCaipNetwork(network)
}

await networkControllerClient?.switchCaipNetwork(network)
ChainController.setActiveCaipNetwork(network)

if (network) {
Expand Down

0 comments on commit c7ad1b0

Please sign in to comment.