From 56e1a49bda0f65e182bcc2f374057757c1534bd3 Mon Sep 17 00:00:00 2001 From: Tomas Martykan Date: Wed, 6 Nov 2024 15:59:15 +0100 Subject: [PATCH 1/2] 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) ) { From 161ddf8ebea0661b2a3ce4d7d490310fec246561 Mon Sep 17 00:00:00 2001 From: Tomas Martykan Date: Wed, 6 Nov 2024 16:01:03 +0100 Subject: [PATCH 2/2] fix(suite-common): cardano discovery update device --- .../wallet-core/src/discovery/discoveryThunks.ts | 12 +++++++++--- suite-native/discovery/src/discoveryThunks.ts | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/suite-common/wallet-core/src/discovery/discoveryThunks.ts b/suite-common/wallet-core/src/discovery/discoveryThunks.ts index d686f0a5af9..545c3d40b13 100644 --- a/suite-common/wallet-core/src/discovery/discoveryThunks.ts +++ b/suite-common/wallet-core/src/discovery/discoveryThunks.ts @@ -38,6 +38,7 @@ import { } from './discoveryReducer'; import { selectAccounts } from '../accounts/accountsReducer'; import { accountsActions } from '../accounts/accountsActions'; +import { selectDeviceByStaticSessionId } from '../device/deviceReducer'; type ProgressEvent = BundleProgress['payload']; @@ -332,9 +333,12 @@ export const getBundleThunk = createThunk( export const getAvailableCardanoDerivationsThunk = createThunk( `${DISCOVERY_MODULE_PREFIX}/getAvailableCardanoDerivations`, async ( - { deviceState, device }: { deviceState: StaticSessionId; device: TrezorDevice }, - { dispatch }, + { deviceState }: { deviceState: StaticSessionId }, + { getState, dispatch }, ): Promise<('normal' | 'legacy' | 'ledger')[] | undefined> => { + const device = selectDeviceByStaticSessionId(getState(), deviceState); + if (!device) return; + // If icarus and icarus-trezor derivations return same pub key // we can skip derivation of the latter as it would discover same accounts. // Ledger derivation will always result in different pub key except in shamir where all derivations are the same @@ -353,11 +357,13 @@ export const getAvailableCardanoDerivationsThunk = createThunk( const icarusTrezorPubKeyResult = await TrezorConnect.cardanoGetPublicKey({ ...commonParams, + device: icarusPubKeyResult.success ? icarusPubKeyResult.device : device, derivationType: getDerivationType('legacy'), }); const ledgerPubKeyResult = await TrezorConnect.cardanoGetPublicKey({ ...commonParams, + device: icarusTrezorPubKeyResult.success ? icarusTrezorPubKeyResult.device : device, derivationType: getDerivationType('ledger'), }); @@ -487,7 +493,7 @@ export const startDiscoveryThunk = createThunk( ) { // check if discovery of legacy (icarus-trezor) or ledger accounts is needed and update discovery accordingly availableCardanoDerivations = await dispatch( - getAvailableCardanoDerivationsThunk({ deviceState, device }), + getAvailableCardanoDerivationsThunk({ deviceState }), ).unwrap(); if (!availableCardanoDerivations) { // Edge case where getAvailableCardanoDerivations dispatches error, stops discovery and returns undefined. diff --git a/suite-native/discovery/src/discoveryThunks.ts b/suite-native/discovery/src/discoveryThunks.ts index 091ebf61c41..321249e7a45 100644 --- a/suite-native/discovery/src/discoveryThunks.ts +++ b/suite-native/discovery/src/discoveryThunks.ts @@ -209,7 +209,6 @@ const getCardanoSupportedAccountTypesThunk = createThunk( dispatch( getAvailableCardanoDerivationsThunk({ deviceState, - device, }), ).unwrap(), });