@@ -191,3 +191,99 @@ describe('Wallet integration report', () => {
191191 expect ( fs . existsSync ( REPORT_PATH ) ) . toBe ( true ) ;
192192 } ) ;
193193} ) ;
194+
195+ // ─── Regression tests for issue #175 ─────────────────────────────────────────
196+ // Verify that switching wallets updates walletStore address immediately and
197+ // leaves no stale address behind, which is the precondition that
198+ // useWalletAccountSync relies on to trigger a feed refresh.
199+
200+ describe ( 'Notification feed clears on wallet switch (issue #175)' , ( ) => {
201+ it ( 'walletStore address updates immediately when switching to a different wallet' , async ( ) => {
202+ const { wallet, store, kit } = await load ( ) ;
203+
204+ // Connect first wallet
205+ kit . __control . authModalImpl = async ( ) => {
206+ kit . __emit ( 'WALLET_SELECTED' , { id : 'freighter' } ) ;
207+ kit . __emit ( 'STATE_UPDATED' , { address : SUPPORTED_WALLETS [ 0 ] . address } ) ;
208+ } ;
209+ await wallet . connectWallet ( ) ;
210+ expect ( store . useWalletStore . getState ( ) . address ) . toBe ( SUPPORTED_WALLETS [ 0 ] . address ) ;
211+
212+ // Switch to second wallet — address in the store must change synchronously
213+ kit . __control . authModalImpl = async ( ) => {
214+ kit . __emit ( 'WALLET_SELECTED' , { id : 'albedo' } ) ;
215+ kit . __emit ( 'STATE_UPDATED' , { address : SUPPORTED_WALLETS [ 1 ] . address } ) ;
216+ } ;
217+ await wallet . connectWallet ( ) ;
218+
219+ expect ( store . useWalletStore . getState ( ) . address ) . toBe ( SUPPORTED_WALLETS [ 1 ] . address ) ;
220+ expect ( store . useWalletStore . getState ( ) . address ) . not . toBe ( SUPPORTED_WALLETS [ 0 ] . address ) ;
221+ } ) ;
222+
223+ it ( 'walletStore address is null after disconnect, clearing any previous account' , async ( ) => {
224+ const { wallet, store, kit } = await load ( ) ;
225+
226+ kit . __control . authModalImpl = async ( ) => {
227+ kit . __emit ( 'WALLET_SELECTED' , { id : 'freighter' } ) ;
228+ kit . __emit ( 'STATE_UPDATED' , { address : SUPPORTED_WALLETS [ 0 ] . address } ) ;
229+ } ;
230+ await wallet . connectWallet ( ) ;
231+ expect ( store . useWalletStore . getState ( ) . address ) . toBe ( SUPPORTED_WALLETS [ 0 ] . address ) ;
232+
233+ kit . __control . disconnectImpl = async ( ) => {
234+ kit . __emit ( 'DISCONNECT' , { } ) ;
235+ } ;
236+ await wallet . disconnectWallet ( ) ;
237+
238+ expect ( store . useWalletStore . getState ( ) . address ) . toBeNull ( ) ;
239+ expect ( localStorage . getItem ( WALLET_ADDRESS_KEY ) ) . toBeNull ( ) ;
240+ } ) ;
241+
242+ it ( 'no stale address remains in localStorage after switching wallets' , async ( ) => {
243+ const { wallet, store, kit } = await load ( ) ;
244+
245+ kit . __control . authModalImpl = async ( ) => {
246+ kit . __emit ( 'WALLET_SELECTED' , { id : 'freighter' } ) ;
247+ kit . __emit ( 'STATE_UPDATED' , { address : SUPPORTED_WALLETS [ 0 ] . address } ) ;
248+ } ;
249+ await wallet . connectWallet ( ) ;
250+
251+ kit . __control . authModalImpl = async ( ) => {
252+ kit . __emit ( 'WALLET_SELECTED' , { id : 'xbull' } ) ;
253+ kit . __emit ( 'STATE_UPDATED' , { address : SUPPORTED_WALLETS [ 2 ] . address } ) ;
254+ } ;
255+ await wallet . connectWallet ( ) ;
256+
257+ // localStorage must reflect the new account only
258+ expect ( localStorage . getItem ( WALLET_ADDRESS_KEY ) ) . toBe ( SUPPORTED_WALLETS [ 2 ] . address ) ;
259+ expect ( localStorage . getItem ( WALLET_ADDRESS_KEY ) ) . not . toBe ( SUPPORTED_WALLETS [ 0 ] . address ) ;
260+ expect ( store . useWalletStore . getState ( ) . address ) . toBe ( SUPPORTED_WALLETS [ 2 ] . address ) ;
261+ } ) ;
262+
263+ it ( 'switching wallets across all supported providers leaves only the current address' , async ( ) => {
264+ for ( const [ index , provider ] of SUPPORTED_WALLETS . entries ( ) ) {
265+ const { wallet, store, kit } = await load ( ) ;
266+
267+ // First connect one of the other wallets
268+ const previous = SUPPORTED_WALLETS [ ( index + 1 ) % SUPPORTED_WALLETS . length ] ;
269+ kit . __control . authModalImpl = async ( ) => {
270+ kit . __emit ( 'WALLET_SELECTED' , { id : previous . id } ) ;
271+ kit . __emit ( 'STATE_UPDATED' , { address : previous . address } ) ;
272+ } ;
273+ await wallet . connectWallet ( ) ;
274+
275+ // Now switch to the target provider
276+ kit . __control . authModalImpl = async ( ) => {
277+ kit . __emit ( 'WALLET_SELECTED' , { id : provider . id } ) ;
278+ kit . __emit ( 'STATE_UPDATED' , { address : provider . address } ) ;
279+ } ;
280+ await wallet . connectWallet ( ) ;
281+
282+ expect ( store . useWalletStore . getState ( ) . address ) . toBe ( provider . address ) ;
283+ expect ( localStorage . getItem ( WALLET_ADDRESS_KEY ) ) . toBe ( provider . address ) ;
284+ expect ( localStorage . getItem ( WALLET_ID_KEY ) ) . toBe ( provider . id ) ;
285+
286+ localStorage . clear ( ) ;
287+ }
288+ } ) ;
289+ } ) ;
0 commit comments