Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connect): emit changed event with state change in keepSession #15276

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/connect/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion suite-common/wallet-core/src/device/deviceReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
) {
Expand Down
12 changes: 9 additions & 3 deletions suite-common/wallet-core/src/discovery/discoveryThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountInfo | null>['payload'];

Expand Down Expand Up @@ -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
Expand All @@ -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'),
});

Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion suite-native/discovery/src/discoveryThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ const getCardanoSupportedAccountTypesThunk = createThunk(
dispatch(
getAvailableCardanoDerivationsThunk({
deviceState,
device,
}),
).unwrap(),
});
Expand Down
Loading