Skip to content

Commit

Permalink
fix: switch account behavior for new SS (#3176)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir authored Oct 31, 2024
1 parent 132a9bb commit 3e27610
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useSignMessage } from 'wagmi'
import { ConstantsUtil } from '../../utils/ConstantsUtil'
import { useChakraToast } from '../Toast'
import { useAppKitAccount } from '@reown/appkit/react'
import type { Address } from 'viem'
import { type Address } from 'viem'

export function WagmiSignMessageTest() {
const toast = useChakraToast()
Expand Down
20 changes: 10 additions & 10 deletions packages/adapters/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,16 @@ export class WagmiAdapter implements ChainAdapter {
const chainId = this.appKit?.getCaipNetworkId<number>()
await connect(this.wagmiConfig, { connector, chainId })
},
reconnectExternal: async ({ id }) => {
if (!this.wagmiConfig) {
throw new Error('networkControllerClient:reconnectExternal - wagmiConfig is undefined')
}
const connector = this.wagmiConfig.connectors.find(c => c.id === id)
if (!connector) {
throw new Error('connectionControllerClient:reconnectExternal - connector is undefined')
}
await reconnect(this.wagmiConfig, { connectors: [connector] })
},
checkInstalled: ids => {
const injectedConnector = this.appKit
?.getConnectors()
Expand Down Expand Up @@ -1061,16 +1071,6 @@ export class WagmiAdapter implements ChainAdapter {
provider.onGetSmartAccountEnabledNetworks(networks => {
this.appKit?.setSmartAccountEnabledNetworks(networks, this.chainNamespace)
})

provider.onSetPreferredAccount(({ address, type }) => {
if (!address) {
return
}
this.appKit?.setPreferredAccountType(type as W3mFrameTypes.AccountType, this.chainNamespace)
if (this.wagmiConfig) {
reconnect(this.wagmiConfig, { connectors: [connector] })
}
})
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/adapters/wagmi/src/connectors/AuthConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createConnector, type CreateConfigParameters } from '@wagmi/core'
import { W3mFrameProvider } from '@reown/appkit-wallet'
import { ConstantsUtil as CommonConstantsUtil } from '@reown/appkit-common'
import { SwitchChainError, getAddress } from 'viem'
import type { Address, Hex } from 'viem'
import type { Address } from 'viem'
import { ConstantsUtil, ErrorUtil } from '@reown/appkit-utils'
import { NetworkUtil } from '@reown/appkit-common'
import { W3mFrameProviderSingleton } from '@reown/appkit/auth-provider'
Expand Down Expand Up @@ -128,7 +128,7 @@ export function authConnector(parameters: AuthParameters) {

config.emitter.emit('change', {
chainId: Number(chainId),
accounts: [response.address as Hex]
accounts: currentAccounts
})

return chain
Expand Down
1 change: 0 additions & 1 deletion packages/adapters/wagmi/src/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ describe('Wagmi Client', () => {
expect(mockProvider.onGetSmartAccountEnabledNetworks).toHaveBeenCalledWith(
expect.any(Function)
)
expect(mockProvider.onSetPreferredAccount).toHaveBeenCalledWith(expect.any(Function))
})

it.skip('should handle RPC requests correctly', async () => {
Expand Down

0 comments on commit 3e27610

Please sign in to comment.