@meshconnect/uwc-injected-connector 0.17.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,9 +30,16 @@ export class SolanaWalletService {
30
30
  return this.detectedWallets.find(w => w.uuid === uuid);
31
31
  }
32
32
  /**
33
- * Check if a Solana wallet is already connected
33
+ * Check if a Solana wallet is already connected.
34
+ *
35
+ * `allowSilentReconnect` (default true) gates the storage-flag reconnect
36
+ * below: even a "silent" `adapter.connect()` is a REAL provider connect —
37
+ * for a legacy-`injectedId` wallet in its in-app browser it parks the
38
+ * wallet's active namespace on Solana and swallows the next EVM send
39
+ * (ONC-3536 follow-up). Pass false to make this check purely passive.
34
40
  */
35
- async checkExistingConnection(adapter, walletUuid) {
41
+ async checkExistingConnection(adapter, walletUuid, options) {
42
+ const allowSilentReconnect = options?.allowSilentReconnect ?? true;
36
43
  try {
37
44
  const base58PublicKey = await adapter.publicKey?.toBase58();
38
45
  // Check if adapter has a publicKey (means it's connected)
@@ -41,7 +48,8 @@ export class SolanaWalletService {
41
48
  }
42
49
  // If this wallet was previously connected, try to reconnect
43
50
  // This should work without prompting for wallets that support it
44
- if (this.storageService.wasSolanaWalletPreviouslyConnected(walletUuid)) {
51
+ if (allowSilentReconnect &&
52
+ this.storageService.wasSolanaWalletPreviouslyConnected(walletUuid)) {
45
53
  const walletIsConnecting = await adapter.connecting;
46
54
  if (!walletIsConnecting) {
47
55
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"solana-wallet-service.js","sourceRoot":"","sources":["../../../src/services/solana/solana-wallet-service.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,gBAAgB,EAIjB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,MAAM,OAAO,mBAAmB;IACtB,eAAe,GAAyB,EAAE,CAAA;IAC1C,gBAAgB,GAAyB,IAAI,CAAA;IAC7C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AAE,CAAC;YACrC,IAAI,CAAC,cAAc,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAA;QACvD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,OAAO,IAAI,CAAC,gBAAgB,CAAA;IAC9B,CAAC;IAED;;;;;;;;;;OAUG;IACH,gBAAgB,CACd,QAA+C;QAE/C,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAA;QACrC,6EAA6E;QAC7E,4EAA4E;QAC5E,oEAAoE;QACpE,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,EAAE,KAAK,UAAU;YAAE,OAAO,SAAS,CAAA;QAClE,IACE,OAAO,MAAM,KAAK,WAAW;YAC5B,MAA6D;iBAC3D,yBAAyB,KAAK,IAAI,EACrC,CAAC;YACD,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;QAC3D,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;QACtC,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;QACzC,CAAC,CAAA;IACH,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;IACrB,CAAC;CACF"}
1
+ {"version":3,"file":"solana-wallet-service.js","sourceRoot":"","sources":["../../../src/services/solana/solana-wallet-service.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,gBAAgB,EAIjB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAEnD;;GAEG;AACH,MAAM,OAAO,mBAAmB;I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uwc-injected-connector",
3
- "version": "0.17.1",
3
+ "version": "0.19.0",
4
4
  "description": "Injected connector for Universal Wallet Connector",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,10 +28,10 @@
28
28
  "uuid": "^13.0.0",
29
29
  "viem": "^2.54.6",
30
30
  "@meshconnect/uwc-bridge-child": "0.3.0",
31
- "@meshconnect/uwc-constants": "0.6.13",
32
- "@meshconnect/uwc-ton-connector": "0.7.5",
33
- "@meshconnect/uwc-tron-connector": "0.5.3",
34
- "@meshconnect/uwc-types": "0.22.0"
31
+ "@meshconnect/uwc-constants": "0.7.0",
32
+ "@meshconnect/uwc-ton-connector": "0.7.6",
33
+ "@meshconnect/uwc-tron-connector": "0.5.4",
34
+ "@meshconnect/uwc-types": "0.23.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "typescript": "^5.9.3"
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './injected-connector'
2
+ export type { SecondarySolanaConnectSkippedInfo } from './services/connection-manager'
2
3
  export { getAvailableWallets, type DetectedWallet } from './eip6963-discovery'
3
4
  export {
4
5
  getSolanaWallets,
@@ -39,6 +39,7 @@ import { TronWalletService } from './services/tron/tron-wallet-service'
39
39
  import { TonWalletService } from './services/ton/ton-wallet-service'
40
40
  import { StorageService } from './services/storage-service'
41
41
  import { ConnectionManager } from './services/connection-manager'
42
+ import type { SecondarySolanaConnectSkippedInfo } from './services/connection-manager'
42
43
  import { SignatureService } from './services/signature-service'
43
44
  import { TransactionService } from './services/transaction-service'
44
45
  import type {
@@ -76,6 +77,23 @@ export interface InjectedConnectorOptions {
76
77
  * present but the wrong shape (see wallet-standard-discovery).
77
78
  */
78
79
  onLegacyDiscoveryFailure?: LegacyInjectedSolanaDiscoveryFailure | undefined
80
+ /**
81
+ * Triage telemetry sink (ONC-3536 follow-up): the secondary Solana gather
82
+ * was skipped for a legacy-`injectedId` wallet inside the wallet's own
83
+ * browser (framed or top-level in-app) so an EVM send can't be parked on
84
+ * the Solana namespace (see `ConnectionManager`).
85
+ */
86
+ onSecondarySolanaConnectSkipped?:
87
+ | ((info: SecondarySolanaConnectSkippedInfo) => void)
88
+ | undefined
89
+ /**
90
+ * Telemetry sink: the wallet-switch guard released live per-namespace state
91
+ * that belonged to a different wallet (see `ConnectionManager`). Carries
92
+ * only the released namespaces — never an address.
93
+ */
94
+ onWalletConnectionsReleased?:
95
+ | ((info: { namespaces: Namespace[] }) => void)
96
+ | undefined
79
97
  }
80
98
 
81
99
  export class InjectedConnector implements Connector {
@@ -129,7 +147,9 @@ export class InjectedConnector implements Connector {
129
147
  networks = [],
130
148
  onBridgeError,
131
149
  usingIntegratedBrowser = false,
132
- onLegacyDiscoveryFailure
150
+ onLegacyDiscoveryFailure,
151
+ onSecondarySolanaConnectSkipped,
152
+ onWalletConnectionsReleased
133
153
  } = options
134
154
 
135
155
  this.networkRpcMap = networkRpcMap
@@ -153,7 +173,12 @@ export class InjectedConnector implements Connector {
153
173
  this.ethereumService,
154
174
  this.solanaService,
155
175
  this.tronService,
156
- this.tonService
176
+ this.tonService,
177
+ {
178
+ usingIntegratedBrowser,
179
+ onSecondarySolanaConnectSkipped,
180
+ onWalletConnectionsReleased
181
+ }
157
182
  )
158
183
  this.signatureService = new SignatureService()
159
184
  this.transactionService = new TransactionService(this.networkRpcMap)
@@ -6,7 +6,14 @@ function makeProvider(
6
6
  namespaces: Partial<
7
7
  Record<
8
8
  'eip155' | 'solana' | 'tron' | 'tvm',
9
- { detectedWallet?: { uuid?: string; jsBridgeKey?: string } }
9
+ {
10
+ detectedWallet?: {
11
+ uuid?: string
12
+ jsBridgeKey?: string
13
+ legacyInjected?: boolean
14
+ }
15
+ injectedId?: string
16
+ }
10
17
  >
11
18
  >
12
19
  ): ExtensionInjectedProvider {
@@ -97,6 +104,7 @@ function makeTonService() {
97
104
  .map((id: string) => ({ address: addr, networkId: id }))
98
105
  ),
99
106
  isConnected: vi.fn().mockReturnValue(false),
107
+ getConnectedJsBridgeKey: vi.fn().mockReturnValue(null),
100
108
  disconnect: vi.fn()
101
109
  }
102
110
  }
@@ -706,3 +714,377 @@ describe('ConnectionManager — iframe-safe cross-namespace gather (ONC-3383)',
706
714
  expect(namespaces).not.toContain('eip155')
707
715
  })
708
716
  })
717
+
718
+ // ONC-3536 follow-up: wallets that declare a legacy `solana.injectedId`
719
+ // (Coinbase/Base Wallet's `coinbaseSolana`) treat the active namespace as
720
+ // exclusive in their in-app browser — ANY secondary Solana connect after an
721
+ // EVM connect (eager gather or silent storage-flag reconnect) parks the wallet
722
+ // on Solana and the following EVM eth_sendTransaction never surfaces an
723
+ // approval sheet (60s walletTimedOut — the USDC.base Legacy-mode hang, proven
724
+ // by a Mesh-free PoC on Coinbase Wallet 30.3.3). When framed, these wallets
725
+ // get NO secondary Solana connect; Phantom-style Wallet-Standard wallets and
726
+ // primary Solana connects are untouched.
727
+ describe('ConnectionManager — framed legacy-injectedId Solana gather skip (ONC-3536)', () => {
728
+ let ethService: ReturnType<typeof makeEthService>
729
+ let solanaService: ReturnType<typeof makeSolanaService>
730
+ let tronService: ReturnType<typeof makeTronService>
731
+ let tonService: ReturnType<typeof makeTonService>
732
+ let onSkip: ReturnType<typeof vi.fn>
733
+ let manager: ConnectionManager
734
+
735
+ beforeEach(() => {
736
+ ethService = makeEthService()
737
+ solanaService = makeSolanaService()
738
+ tronService = makeTronService()
739
+ tonService = makeTonService()
740
+ onSkip = vi.fn()
741
+ manager = new ConnectionManager(
742
+ ethService as any,
743
+ solanaService as any,
744
+ tronService as any,
745
+ tonService as any,
746
+ { onSecondarySolanaConnectSkipped: onSkip }
747
+ )
748
+ // Simulate running inside an iframe: window.top !== window.self
749
+ Object.defineProperty(window, 'top', { value: {}, configurable: true })
750
+
751
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
752
+ ethService.connect.mockResolvedValue('0xABC')
753
+ solanaService.findWalletByUuid.mockReturnValue({ adapter: {} })
754
+ })
755
+
756
+ afterEach(() => {
757
+ Object.defineProperty(window, 'top', { value: window, configurable: true })
758
+ })
759
+
760
+ const coinbaseLikeProvider = () =>
761
+ makeProvider({
762
+ eip155: { detectedWallet: { uuid: 'cb-eip155' } },
763
+ solana: {
764
+ injectedId: 'coinbaseSolana',
765
+ detectedWallet: { uuid: 'cb-solana', legacyInjected: true }
766
+ }
767
+ })
768
+
769
+ it('skips BOTH the eager connect and the silent reconnect when framed, and reports the skip', async () => {
770
+ const result = await manager.connectEthereum(
771
+ makeNetwork('eip155:8453', 'eip155'),
772
+ coinbaseLikeProvider()
773
+ )
774
+
775
+ expect(result.address).toBe('0xABC')
776
+ // No secondary Solana connect of any kind.
777
+ expect(solanaService.connect).not.toHaveBeenCalled()
778
+ expect(solanaService.checkExistingConnection).toHaveBeenCalledWith(
779
+ expect.anything(),
780
+ 'cb-solana',
781
+ { allowSilentReconnect: false }
782
+ )
783
+ // Triage telemetry fired with the metadata key + discovery mode.
784
+ expect(onSkip).toHaveBeenCalledTimes(1)
785
+ expect(onSkip).toHaveBeenCalledWith({
786
+ injectedId: 'coinbaseSolana',
787
+ outcome: 'connectSuppressed',
788
+ legacyInjected: true,
789
+ framed: true
790
+ })
791
+ })
792
+
793
+ it('skips TOP-LEVEL in the wallet in-app browser (usingIntegratedBrowser) — the dapp deep-link flow', async () => {
794
+ // The flow that reproduced the hang: link runs top-level inside the
795
+ // wallet's browser, so isFramedEmbed() is false — the gate must key on
796
+ // usingIntegratedBrowser.
797
+ Object.defineProperty(window, 'top', { value: window, configurable: true })
798
+ const inAppManager = new ConnectionManager(
799
+ ethService as any,
800
+ solanaService as any,
801
+ tronService as any,
802
+ tonService as any,
803
+ { usingIntegratedBrowser: true, onSecondarySolanaConnectSkipped: onSkip }
804
+ )
805
+
806
+ const result = await inAppManager.connectEthereum(
807
+ makeNetwork('eip155:8453', 'eip155'),
808
+ coinbaseLikeProvider()
809
+ )
810
+
811
+ expect(result.address).toBe('0xABC')
812
+ expect(solanaService.connect).not.toHaveBeenCalled()
813
+ expect(solanaService.checkExistingConnection).toHaveBeenCalledWith(
814
+ expect.anything(),
815
+ 'cb-solana',
816
+ { allowSilentReconnect: false }
817
+ )
818
+ expect(onSkip).toHaveBeenCalledWith({
819
+ injectedId: 'coinbaseSolana',
820
+ outcome: 'connectSuppressed',
821
+ legacyInjected: true,
822
+ framed: false
823
+ })
824
+ })
825
+
826
+ it('still surfaces an ALREADY-connected Solana account via the passive check, reported as alreadyConnected', async () => {
827
+ solanaService.checkExistingConnection.mockResolvedValue('SolAddr1')
828
+
829
+ const result = await manager.connectEthereum(
830
+ makeNetwork('eip155:8453', 'eip155'),
831
+ coinbaseLikeProvider()
832
+ )
833
+
834
+ expect(solanaService.connect).not.toHaveBeenCalled()
835
+ const namespaces = result.availableAddresses.map(
836
+ a => a.networkId.split(':')[0]
837
+ )
838
+ expect(namespaces).toContain('solana')
839
+ // No connect was made, but the ACTIVE gate observed a pre-authorized
840
+ // provider — reported so a follow-up hang is attributable to wallet-side
841
+ // state rather than a dead gate.
842
+ expect(onSkip).toHaveBeenCalledWith({
843
+ injectedId: 'coinbaseSolana',
844
+ outcome: 'alreadyConnected',
845
+ legacyInjected: true,
846
+ framed: true
847
+ })
848
+ })
849
+
850
+ it('keeps the framed gather for Wallet-Standard-only wallets (no injectedId — Phantom)', async () => {
851
+ solanaService.connect.mockResolvedValue('SolAddr1')
852
+
853
+ const result = await manager.connectEthereum(
854
+ makeNetwork('eip155:8453', 'eip155'),
855
+ makeProvider({
856
+ eip155: { detectedWallet: { uuid: 'ph-eip155' } },
857
+ solana: { detectedWallet: { uuid: 'ph-solana' } }
858
+ })
859
+ )
860
+
861
+ expect(solanaService.connect).toHaveBeenCalled()
862
+ expect(solanaService.checkExistingConnection).toHaveBeenCalledWith(
863
+ expect.anything(),
864
+ 'ph-solana',
865
+ { allowSilentReconnect: true }
866
+ )
867
+ const namespaces = result.availableAddresses.map(
868
+ a => a.networkId.split(':')[0]
869
+ )
870
+ expect(namespaces).toContain('solana')
871
+ expect(onSkip).not.toHaveBeenCalled()
872
+ })
873
+
874
+ it('keeps the eager gather in the top frame (extension) even with an injectedId', async () => {
875
+ Object.defineProperty(window, 'top', { value: window, configurable: true })
876
+ solanaService.connect.mockResolvedValue('SolAddr1')
877
+
878
+ await manager.connectEthereum(
879
+ makeNetwork('eip155:8453', 'eip155'),
880
+ coinbaseLikeProvider()
881
+ )
882
+
883
+ expect(solanaService.connect).toHaveBeenCalled()
884
+ expect(solanaService.checkExistingConnection).toHaveBeenCalledWith(
885
+ expect.anything(),
886
+ 'cb-solana',
887
+ { allowSilentReconnect: true }
888
+ )
889
+ expect(onSkip).not.toHaveBeenCalled()
890
+ })
891
+
892
+ it('reports the skip once per injectedId across repeated gathers (dedup)', async () => {
893
+ await manager.connectEthereum(
894
+ makeNetwork('eip155:8453', 'eip155'),
895
+ coinbaseLikeProvider()
896
+ )
897
+ await manager.connectEthereum(
898
+ makeNetwork('eip155:8453', 'eip155'),
899
+ coinbaseLikeProvider()
900
+ )
901
+
902
+ expect(onSkip).toHaveBeenCalledTimes(1)
903
+ })
904
+
905
+ it('caps an oversized injectedId to 64 chars before keying/reporting', async () => {
906
+ await manager.connectEthereum(
907
+ makeNetwork('eip155:8453', 'eip155'),
908
+ makeProvider({
909
+ eip155: { detectedWallet: { uuid: 'cb-eip155' } },
910
+ solana: {
911
+ injectedId: 'x'.repeat(200),
912
+ detectedWallet: { uuid: 'cb-solana', legacyInjected: true }
913
+ }
914
+ })
915
+ )
916
+
917
+ expect(onSkip).toHaveBeenCalledWith(
918
+ expect.objectContaining({ injectedId: 'x'.repeat(64) })
919
+ )
920
+ })
921
+
922
+ it('reports legacyInjected=false when the wallet registered via the Wallet Standard', async () => {
923
+ await manager.connectEthereum(
924
+ makeNetwork('eip155:8453', 'eip155'),
925
+ makeProvider({
926
+ eip155: { detectedWallet: { uuid: 'cb-eip155' } },
927
+ solana: {
928
+ injectedId: 'coinbaseSolana',
929
+ detectedWallet: { uuid: 'cb-solana' }
930
+ }
931
+ })
932
+ )
933
+
934
+ expect(solanaService.connect).not.toHaveBeenCalled()
935
+ expect(onSkip).toHaveBeenCalledWith({
936
+ injectedId: 'coinbaseSolana',
937
+ outcome: 'connectSuppressed',
938
+ legacyInjected: false,
939
+ framed: true
940
+ })
941
+ })
942
+ })
943
+
944
+ describe('ConnectionManager — wallet switch releases the other wallet’s connections', () => {
945
+ let ethService: ReturnType<typeof makeEthService>
946
+ let solanaService: ReturnType<typeof makeSolanaService>
947
+ let tronService: ReturnType<typeof makeTronService>
948
+ let tonService: ReturnType<typeof makeTonService>
949
+ let onWalletConnectionsReleased: ReturnType<typeof vi.fn>
950
+ let manager: ConnectionManager
951
+
952
+ beforeEach(() => {
953
+ ethService = makeEthService()
954
+ solanaService = makeSolanaService()
955
+ tronService = makeTronService()
956
+ tonService = makeTonService()
957
+ onWalletConnectionsReleased = vi.fn()
958
+ manager = new ConnectionManager(
959
+ ethService as any,
960
+ solanaService as any,
961
+ tronService as any,
962
+ tonService as any,
963
+ { onWalletConnectionsReleased }
964
+ )
965
+ })
966
+
967
+ it('does not reuse another wallet’s EVM connection — releases it and silently checks the requested wallet', async () => {
968
+ const walletAProvider = { isWalletA: true }
969
+ const walletBProvider = { isWalletB: true }
970
+
971
+ // Wallet A is live in the service; disconnect() clears that state (mirror
972
+ // the real service so the post-release branches see the cleared state).
973
+ ethService.getAccount.mockReturnValue('0xAAA')
974
+ ethService.getConnectedProvider.mockReturnValue(walletAProvider)
975
+ ethService.disconnect.mockImplementation(() => {
976
+ ethService.getAccount.mockReturnValue(null)
977
+ ethService.getConnectedProvider.mockReturnValue(null)
978
+ })
979
+
980
+ // The requested wallet (B) is detected with its own provider, and its
981
+ // origin permission already exists (silent check succeeds).
982
+ ethService.findWalletByUuid.mockReturnValue({ provider: walletBProvider })
983
+ ethService.checkExistingConnection.mockResolvedValue(['0xBBB'])
984
+
985
+ const result = await manager.checkExistingConnections(
986
+ 'eip155',
987
+ makeProvider({ eip155: { detectedWallet: { uuid: 'wallet-b-eip155' } } })
988
+ )
989
+
990
+ expect(ethService.disconnect).toHaveBeenCalledTimes(1)
991
+ expect(ethService.checkExistingConnection).toHaveBeenCalledWith(
992
+ walletBProvider
993
+ )
994
+ expect(result.address).toBe('0xBBB')
995
+ expect(ethService.setConnectionState).toHaveBeenCalledWith(
996
+ walletBProvider,
997
+ '0xBBB'
998
+ )
999
+ // The release is surfaced to the telemetry sink with the namespaces dropped.
1000
+ expect(onWalletConnectionsReleased).toHaveBeenCalledTimes(1)
1001
+ expect(onWalletConnectionsReleased).toHaveBeenCalledWith({
1002
+ namespaces: ['eip155']
1003
+ })
1004
+ })
1005
+
1006
+ it('keeps the same wallet’s EVM connection (no release, no re-check)', async () => {
1007
+ const walletAProvider = { isWalletA: true }
1008
+ ethService.getAccount.mockReturnValue('0xAAA')
1009
+ ethService.getConnectedProvider.mockReturnValue(walletAProvider)
1010
+ ethService.findWalletByUuid.mockReturnValue({ provider: walletAProvider })
1011
+
1012
+ const result = await manager.checkExistingConnections(
1013
+ 'eip155',
1014
+ makeProvider({ eip155: { detectedWallet: { uuid: 'wallet-a-eip155' } } })
1015
+ )
1016
+
1017
+ expect(ethService.disconnect).not.toHaveBeenCalled()
1018
+ expect(ethService.checkExistingConnection).not.toHaveBeenCalled()
1019
+ expect(result.address).toBe('0xAAA')
1020
+ // Nothing was released — the sink must stay silent (an emit here would be
1021
+ // the prod signal that the identity comparison broke).
1022
+ expect(onWalletConnectionsReleased).not.toHaveBeenCalled()
1023
+ })
1024
+
1025
+ it('releases another wallet’s gathered Solana state so it does not leak into the new session', async () => {
1026
+ const walletAAdapter = { isWalletAAdapter: true }
1027
+
1028
+ // Wallet A's Solana (from an earlier gather) is live.
1029
+ solanaService.getAccount.mockReturnValue('SolAAA')
1030
+ solanaService.getConnectedAdapter.mockReturnValue(walletAAdapter)
1031
+ solanaService.disconnect.mockImplementation(() => {
1032
+ solanaService.getAccount.mockReturnValue(null)
1033
+ solanaService.getConnectedAdapter.mockReturnValue(null)
1034
+ })
1035
+ // Wallet B declares no Solana namespace at all.
1036
+ solanaService.findWalletByUuid.mockReturnValue(null)
1037
+
1038
+ // Wallet B connects on EVM.
1039
+ ethService.findWalletByUuid.mockReturnValue({ provider: {} })
1040
+ ethService.checkExistingConnection.mockResolvedValue(['0xBBB'])
1041
+
1042
+ const result = await manager.checkExistingConnections(
1043
+ 'eip155',
1044
+ makeProvider({ eip155: { detectedWallet: { uuid: 'wallet-b-eip155' } } })
1045
+ )
1046
+
1047
+ expect(solanaService.disconnect).toHaveBeenCalledTimes(1)
1048
+ expect(result.availableAddresses.some(a => a.address === 'SolAAA')).toBe(
1049
+ false
1050
+ )
1051
+ expect(onWalletConnectionsReleased).toHaveBeenCalledWith({
1052
+ namespaces: ['solana']
1053
+ })
1054
+ })
1055
+
1056
+ it('ends another wallet’s TON session over the bridge before connecting', async () => {
1057
+ tonService.isConnected.mockReturnValue(true)
1058
+ tonService.getConnectedJsBridgeKey.mockReturnValue('tonkeeper')
1059
+ tonService.disconnect.mockImplementation(async () => {
1060
+ tonService.isConnected.mockReturnValue(false)
1061
+ tonService.getAccount.mockReturnValue(null)
1062
+ tonService.getConnectedJsBridgeKey.mockReturnValue(null)
1063
+ })
1064
+
1065
+ await manager.checkExistingConnections(
1066
+ 'tvm',
1067
+ makeProvider({ tvm: { detectedWallet: { jsBridgeKey: 'okxTonWallet' } } })
1068
+ )
1069
+
1070
+ expect(tonService.disconnect).toHaveBeenCalledTimes(1)
1071
+ expect(onWalletConnectionsReleased).toHaveBeenCalledWith({
1072
+ namespaces: ['tvm']
1073
+ })
1074
+ })
1075
+
1076
+ it('keeps the same TON wallet’s session (no release)', async () => {
1077
+ tonService.isConnected.mockReturnValue(true)
1078
+ tonService.getConnectedJsBridgeKey.mockReturnValue('tonkeeper')
1079
+ tonService.getAccount.mockReturnValue('TonAAA')
1080
+
1081
+ const result = await manager.checkExistingConnections(
1082
+ 'tvm',
1083
+ makeProvider({ tvm: { detectedWallet: { jsBridgeKey: 'tonkeeper' } } })
1084
+ )
1085
+
1086
+ expect(tonService.disconnect).not.toHaveBeenCalled()
1087
+ expect(result.address).toBe('TonAAA')
1088
+ expect(onWalletConnectionsReleased).not.toHaveBeenCalled()
1089
+ })
1090
+ })