From 3e27610ee55efdcf75d468201c924fd935846006 Mon Sep 17 00:00:00 2001 From: tomiir Date: Thu, 31 Oct 2024 15:42:10 +0100 Subject: [PATCH] fix: switch account behavior for new SS (#3176) --- .../components/Wagmi/WagmiSignMessageTest.tsx | 2 +- packages/adapters/wagmi/src/client.ts | 20 +++++++++---------- .../wagmi/src/connectors/AuthConnector.ts | 4 ++-- .../adapters/wagmi/src/tests/client.test.ts | 1 - 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apps/laboratory/src/components/Wagmi/WagmiSignMessageTest.tsx b/apps/laboratory/src/components/Wagmi/WagmiSignMessageTest.tsx index 766c86954c..55e8247d41 100644 --- a/apps/laboratory/src/components/Wagmi/WagmiSignMessageTest.tsx +++ b/apps/laboratory/src/components/Wagmi/WagmiSignMessageTest.tsx @@ -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() diff --git a/packages/adapters/wagmi/src/client.ts b/packages/adapters/wagmi/src/client.ts index 825799fe90..61beae5f57 100644 --- a/packages/adapters/wagmi/src/client.ts +++ b/packages/adapters/wagmi/src/client.ts @@ -399,6 +399,16 @@ export class WagmiAdapter implements ChainAdapter { const chainId = this.appKit?.getCaipNetworkId() 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() @@ -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] }) - } - }) } } diff --git a/packages/adapters/wagmi/src/connectors/AuthConnector.ts b/packages/adapters/wagmi/src/connectors/AuthConnector.ts index 6e5676d144..ab58a4646e 100644 --- a/packages/adapters/wagmi/src/connectors/AuthConnector.ts +++ b/packages/adapters/wagmi/src/connectors/AuthConnector.ts @@ -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' @@ -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 diff --git a/packages/adapters/wagmi/src/tests/client.test.ts b/packages/adapters/wagmi/src/tests/client.test.ts index b3d6c5a038..4a5d3fe2b2 100644 --- a/packages/adapters/wagmi/src/tests/client.test.ts +++ b/packages/adapters/wagmi/src/tests/client.test.ts @@ -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 () => {