From 4cbaf360478184ef51e26825921e1a0b00afa816 Mon Sep 17 00:00:00 2001 From: Tomas Martykan Date: Wed, 6 Nov 2024 15:20:33 +0100 Subject: [PATCH] fix(connect): emit changed event with state change in keepSession --- packages/connect/src/core/index.ts | 9 +++++++++ suite-common/wallet-core/src/device/deviceReducer.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/connect/src/core/index.ts b/packages/connect/src/core/index.ts index f3c49980aca..3b4589fbff7 100644 --- a/packages/connect/src/core/index.ts +++ b/packages/connect/src/core/index.ts @@ -696,6 +696,15 @@ const onCallDevice = async ( } // Work done + if ( + method.keepSession && + method.deviceState && + method.deviceState.sessionId !== device.getState()?.sessionId + ) { + // if session was changed from the one that was sent, send a device changed event + sendCoreMessage(createDeviceMessage(DEVICE.CHANGED, device.toMessageObject())); + } + // TODO: This requires a massive refactoring https://github.com/trezor/trezor-suite/issues/5323 // @ts-expect-error TODO: messageResponse should be assigned from the response of "inner" function const response = messageResponse; diff --git a/suite-common/wallet-core/src/device/deviceReducer.ts b/suite-common/wallet-core/src/device/deviceReducer.ts index a953908fe46..5c867469f69 100644 --- a/suite-common/wallet-core/src/device/deviceReducer.ts +++ b/suite-common/wallet-core/src/device/deviceReducer.ts @@ -67,7 +67,7 @@ const mergeDeviceState = ( // state was previously not defined, we can set it device.state === undefined || // update sessionId for the same staticSessionId - (upcomingState?.sessionId && + (upcomingState && device.state?.staticSessionId === upcomingState.staticSessionId && device.state?.sessionId !== upcomingState.sessionId) ) {