diff --git a/packages/suite/src/actions/suite/__fixtures__/suiteActions.ts b/packages/suite/src/actions/suite/__fixtures__/suiteActions.ts index 1be24e4987b7..67fdcd0dfeb7 100644 --- a/packages/suite/src/actions/suite/__fixtures__/suiteActions.ts +++ b/packages/suite/src/actions/suite/__fixtures__/suiteActions.ts @@ -1,5 +1,5 @@ import { testMocks } from '@suite-common/test-utils'; -import { discoveryActions, deviceActions, authorizeDevice } from '@suite-common/wallet-core'; +import { discoveryActions, deviceActions, authorizeDeviceThunk } from '@suite-common/wallet-core'; import { DEVICE, TRANSPORT } from '@trezor/connect'; import { notificationsActions } from '@suite-common/toast-notifications'; @@ -768,14 +768,14 @@ const authorizeDeviceActions = [ { description: `without device`, state: {}, - result: authorizeDevice.rejected.type, + result: authorizeDeviceThunk.rejected.type, }, { description: `with disconnected device`, state: { selectedDevice: getSuiteDevice(), }, - result: authorizeDevice.rejected.type, + result: authorizeDeviceThunk.rejected.type, }, { description: `with unacquired device`, @@ -785,7 +785,7 @@ const authorizeDeviceActions = [ connected: true, }), }, - result: authorizeDevice.rejected.type, + result: authorizeDeviceThunk.rejected.type, }, { description: `with device which already has state`, @@ -795,7 +795,7 @@ const authorizeDeviceActions = [ state: '012345', }), }, - result: authorizeDevice.rejected.type, + result: authorizeDeviceThunk.rejected.type, }, { description: `with device in unexpected mode`, @@ -805,7 +805,7 @@ const authorizeDeviceActions = [ mode: 'bootloader', }), }, - result: authorizeDevice.rejected.type, + result: authorizeDeviceThunk.rejected.type, }, { description: `with device which needs FW update`, @@ -815,7 +815,7 @@ const authorizeDeviceActions = [ firmware: 'required', }), }, - result: authorizeDevice.rejected.type, + result: authorizeDeviceThunk.rejected.type, }, { description: `success`, @@ -824,7 +824,7 @@ const authorizeDeviceActions = [ connected: true, }), }, - result: authorizeDevice.fulfilled.type, + result: authorizeDeviceThunk.fulfilled.type, }, { description: `duplicate detected`, @@ -849,7 +849,7 @@ const authorizeDeviceActions = [ state: undefined, }), ], - result: authorizeDevice.rejected.type, + result: authorizeDeviceThunk.rejected.type, deviceReducerResult: [ getSuiteDevice({ connected: true, @@ -891,7 +891,7 @@ const authorizeDeviceActions = [ state: undefined, }), ], - result: authorizeDevice.rejected.type, + result: authorizeDeviceThunk.rejected.type, deviceReducerResult: [ getSuiteDevice({ connected: true, @@ -920,7 +920,7 @@ const authorizeDeviceActions = [ error: 'getDeviceState error', }, }, - result: authorizeDevice.rejected.type, + result: authorizeDeviceThunk.rejected.type, }, ]; diff --git a/packages/suite/src/actions/suite/__tests__/suiteActions.test.ts b/packages/suite/src/actions/suite/__tests__/suiteActions.test.ts index 83d42656ad52..8973a4ac757c 100644 --- a/packages/suite/src/actions/suite/__tests__/suiteActions.test.ts +++ b/packages/suite/src/actions/suite/__tests__/suiteActions.test.ts @@ -10,7 +10,7 @@ import { deviceActions, acquireDevice, authConfirm, - authorizeDevice, + authorizeDeviceThunk, createDeviceInstance, forgetDisconnectedDevices, handleDeviceConnect, @@ -245,7 +245,7 @@ describe('Suite Actions', () => { devices: f.devicesState ?? [], }); const store = initStore(state); - await store.dispatch(authorizeDevice()); + await store.dispatch(authorizeDeviceThunk()); if (!f.result) { expect(filterThunkActionTypes(store.getActions()).length).toEqual(0); } else { diff --git a/packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/PassphraseDuplicateModal.tsx b/packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/PassphraseDuplicateModal.tsx index 1b0e68bb05ff..6c4501e185b7 100644 --- a/packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/PassphraseDuplicateModal.tsx +++ b/packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/PassphraseDuplicateModal.tsx @@ -1,6 +1,6 @@ import styled from 'styled-components'; -import { authorizeDevice, switchDuplicatedDevice } from '@suite-common/wallet-core'; +import { authorizeDeviceThunk, switchDuplicatedDevice } from '@suite-common/wallet-core'; import { Button, Image } from '@trezor/components'; import { Translation, Modal } from 'src/components/suite'; @@ -23,7 +23,7 @@ export const PassphraseDuplicateModal = ({ device, duplicate }: PassphraseDuplic const isDeviceLocked = isLocked(); const handleSwitchDevice = () => dispatch(switchDuplicatedDevice({ device, duplicate })); - const handleAuthorizeDevice = () => dispatch(authorizeDevice()); + const handleAuthorizeDevice = () => dispatch(authorizeDeviceThunk()); return ( { const dispatch = useDispatch(); const { isLocked } = useDevice(); - const handleClick = () => dispatch(authorizeDevice()); + const handleClick = () => dispatch(authorizeDeviceThunk()); return ( { if ( isAnyOf( - authorizeDevice.fulfilled, - authorizeDevice.rejected, + authorizeDeviceThunk.fulfilled, + authorizeDeviceThunk.rejected, deviceActions.selectDevice, deviceActions.receiveAuthConfirm, deviceActions.updatePassphraseMode, diff --git a/packages/suite/src/middlewares/wallet/discoveryMiddleware.ts b/packages/suite/src/middlewares/wallet/discoveryMiddleware.ts index c516f46cea25..a2ee83e8cbc9 100644 --- a/packages/suite/src/middlewares/wallet/discoveryMiddleware.ts +++ b/packages/suite/src/middlewares/wallet/discoveryMiddleware.ts @@ -1,5 +1,5 @@ import { - authorizeDevice, + authorizeDeviceThunk, deviceActions, selectDevice, selectDeviceDiscovery, @@ -10,7 +10,6 @@ import { stopDiscoveryThunk, updateNetworkSettingsThunk, } from '@suite-common/wallet-core'; -import { isAnyOf } from '@reduxjs/toolkit'; import * as discoveryActions from '@suite-common/wallet-core'; import { UI } from '@trezor/connect'; import { DiscoveryStatus } from '@suite-common/wallet-constants'; @@ -107,11 +106,11 @@ export const prepareDiscoveryMiddleware = createMiddlewareWithExtraDeps( // 3. begin auth process if (authorizationIntent) { - dispatch(authorizeDevice()); + dispatch(authorizeDeviceThunk()); } // 4. device state received - if (authorizeDevice.fulfilled.match(action)) { + if (authorizeDeviceThunk.fulfilled.match(action)) { // `device` is always present here // to avoid typescript conditioning use device from action as a fallback (never used) dispatch( @@ -139,7 +138,7 @@ export const prepareDiscoveryMiddleware = createMiddlewareWithExtraDeps( becomesConnected || action.type === SUITE.APP_CHANGED || deviceActions.selectDevice.match(action) || - authorizeDevice.fulfilled.match(action) || + authorizeDeviceThunk.fulfilled.match(action) || walletSettingsActions.changeNetworks.match(action) || accountsActions.changeAccountVisibility.match(action) ) { diff --git a/packages/suite/src/reducers/suite/__fixtures__/deviceReducer.ts b/packages/suite/src/reducers/suite/__fixtures__/deviceReducer.ts index a34f6e820cee..912c0fa25543 100644 --- a/packages/suite/src/reducers/suite/__fixtures__/deviceReducer.ts +++ b/packages/suite/src/reducers/suite/__fixtures__/deviceReducer.ts @@ -1,5 +1,5 @@ import { testMocks } from '@suite-common/test-utils'; -import { authorizeDevice, deviceActions } from '@suite-common/wallet-core'; +import { authorizeDeviceThunk, deviceActions } from '@suite-common/wallet-core'; import { DEVICE } from '@trezor/connect'; const { getConnectDevice, getSuiteDevice } = testMocks; @@ -850,7 +850,7 @@ const authDevice = [ initialState: { devices: [SUITE_DEVICE] }, actions: [ { - type: authorizeDevice.fulfilled.type, + type: authorizeDeviceThunk.fulfilled.type, payload: { device: SUITE_DEVICE, state: 'A', @@ -875,7 +875,7 @@ const authDevice = [ }, actions: [ { - type: authorizeDevice.fulfilled.type, + type: authorizeDeviceThunk.fulfilled.type, payload: { device: SUITE_DEVICE, state: 'A', @@ -904,7 +904,7 @@ const authDevice = [ }, actions: [ { - type: authorizeDevice.fulfilled.type, + type: authorizeDeviceThunk.fulfilled.type, payload: { device: getSuiteDevice({ instance: 1 }), state: 'A', @@ -933,7 +933,7 @@ const authDevice = [ initialState: { devices: [SUITE_DEVICE] }, actions: [ { - type: authorizeDevice.fulfilled.type, + type: authorizeDeviceThunk.fulfilled.type, payload: { device: getConnectDevice({ type: 'unacquired', @@ -953,7 +953,7 @@ const authDevice = [ initialState: { devices: [] }, actions: [ { - type: authorizeDevice.fulfilled.type, + type: authorizeDeviceThunk.fulfilled.type, payload: { device: SUITE_DEVICE, state: 'A', diff --git a/packages/suite/src/utils/suite/logsUtils.ts b/packages/suite/src/utils/suite/logsUtils.ts index 73c5e1d95d16..2925e62f1d66 100644 --- a/packages/suite/src/utils/suite/logsUtils.ts +++ b/packages/suite/src/utils/suite/logsUtils.ts @@ -3,7 +3,7 @@ import { discoveryActions, accountsActions, selectDevices, - authorizeDevice, + authorizeDeviceThunk, } from '@suite-common/wallet-core'; import { isAnyOf } from '@reduxjs/toolkit'; import { @@ -124,7 +124,7 @@ export const redactAction = (action: LogEntry) => { }; } - if (authorizeDevice.fulfilled.match(action)) { + if (authorizeDeviceThunk.fulfilled.match(action)) { payload = { state: REDACTED_REPLACEMENT, ...redactDevice(action.payload.device), diff --git a/packages/suite/src/views/dashboard/components/PortfolioCard/components/Exception.tsx b/packages/suite/src/views/dashboard/components/PortfolioCard/components/Exception.tsx index 94fc621a96be..584544e55972 100644 --- a/packages/suite/src/views/dashboard/components/PortfolioCard/components/Exception.tsx +++ b/packages/suite/src/views/dashboard/components/PortfolioCard/components/Exception.tsx @@ -4,7 +4,7 @@ import styled from 'styled-components'; import { authConfirm, - authorizeDevice, + authorizeDeviceThunk, restartDiscoveryThunk as restartDiscovery, } from '@suite-common/wallet-core'; import * as accountUtils from '@suite-common/wallet-utils'; @@ -135,7 +135,7 @@ export const Exception = ({ exception, discovery }: ExceptionProps) => { title="TR_ACCOUNT_EXCEPTION_AUTH_ERROR" description="TR_ACCOUNT_EXCEPTION_AUTH_ERROR_DESC" cta={{ - action: () => dispatch(authorizeDevice()), + action: () => dispatch(authorizeDeviceThunk()), }} dataTestBase={exception.type} /> diff --git a/suite-common/wallet-core/src/device/deviceReducer.ts b/suite-common/wallet-core/src/device/deviceReducer.ts index 7529d44ea2c1..28ef67a941a5 100644 --- a/suite-common/wallet-core/src/device/deviceReducer.ts +++ b/suite-common/wallet-core/src/device/deviceReducer.ts @@ -15,7 +15,7 @@ import { import { isNative } from '@trezor/env-utils'; import { deviceActions } from './deviceActions'; -import { authorizeDevice } from './deviceThunks'; +import { authorizeDeviceThunk } from './deviceThunks'; import { PORTFOLIO_TRACKER_DEVICE_ID, PORTFOLIO_TRACKER_DEVICE_STATE } from './deviceConstants'; export type State = { @@ -341,7 +341,7 @@ const authFailed = (draft: State, device: TrezorDevice) => { }; /** - * Action handler: authorizeDevice.pending + * Action handler: authorizeDeviceThunk.pending * Reset authFailed flag * @param {State} draft * @returns @@ -516,13 +516,13 @@ export const prepareDeviceReducer = createReducerWithExtraDeps(initialState, (bu .addCase(deviceActions.updatePassphraseMode, (state, { payload }) => { changePassphraseMode(state, payload.device, payload.hidden, payload.alwaysOnDevice); }) - .addCase(authorizeDevice.pending, state => { + .addCase(authorizeDeviceThunk.pending, state => { resetAuthFailed(state); }) - .addCase(authorizeDevice.fulfilled, (state, { payload }) => { + .addCase(authorizeDeviceThunk.fulfilled, (state, { payload }) => { authDevice(state, payload.device, payload.state); }) - .addCase(authorizeDevice.rejected, (state, action) => { + .addCase(authorizeDeviceThunk.rejected, (state, action) => { if (action.payload && action.payload.error) { const { error } = action.payload; if (error === 'auth-failed' && action.payload.device) { diff --git a/suite-common/wallet-core/src/device/deviceThunks.ts b/suite-common/wallet-core/src/device/deviceThunks.ts index 57deb99530fb..b0f643e984bd 100644 --- a/suite-common/wallet-core/src/device/deviceThunks.ts +++ b/suite-common/wallet-core/src/device/deviceThunks.ts @@ -281,7 +281,7 @@ export type AuthorizeDeviceError = { }; type AuthorizeDeviceSuccess = { device: TrezorDevice; state: string }; -export const authorizeDevice = createThunk< +export const authorizeDeviceThunk = createThunk< AuthorizeDeviceSuccess, AuthorizeDeviceParams, { rejectValue: AuthorizeDeviceError } diff --git a/suite-native/device/src/hooks/useHandleDeviceConnection.ts b/suite-native/device/src/hooks/useHandleDeviceConnection.ts index 85bc76f6a941..5c6e1bb9f4a3 100644 --- a/suite-native/device/src/hooks/useHandleDeviceConnection.ts +++ b/suite-native/device/src/hooks/useHandleDeviceConnection.ts @@ -13,13 +13,13 @@ import { StackToStackCompositeNavigationProps, } from '@suite-native/navigation'; import { - authorizeDevice, selectIsPortfolioTrackerDevice, selectDeviceRequestedPin, selectIsDeviceConnected, selectIsDeviceConnectedAndAuthorized, selectIsNoPhysicalDeviceConnected, selectIsDeviceUsingPassphrase, + authorizeDeviceThunk, } from '@suite-common/wallet-core'; import { selectIsOnboardingFinished } from '@suite-native/settings'; import { requestPrioritizedDeviceAccess } from '@suite-native/device-mutex'; @@ -53,7 +53,7 @@ export const useHandleDeviceConnection = () => { !isDeviceConnectedAndAuthorized && !isBiometricsOverlayVisible ) { - requestPrioritizedDeviceAccess(() => dispatch(authorizeDevice())); + requestPrioritizedDeviceAccess(() => dispatch(authorizeDeviceThunk())); // Note: Passphrase protected device (excluding empty passphrase, e. g. standard wallet with passphrase protection on device), // post auth navigation is handled in @suite-native/module-passphrase for custom UX flow. diff --git a/suite-native/device/src/middlewares/deviceMiddleware.ts b/suite-native/device/src/middlewares/deviceMiddleware.ts index d44d730f5d22..3abf3edddde1 100644 --- a/suite-native/device/src/middlewares/deviceMiddleware.ts +++ b/suite-native/device/src/middlewares/deviceMiddleware.ts @@ -3,7 +3,7 @@ import { AnyAction, isAnyOf } from '@reduxjs/toolkit'; import { createMiddlewareWithExtraDeps } from '@suite-common/redux-utils'; import { DEVICE } from '@trezor/connect'; import { - authorizeDevice, + authorizeDeviceThunk, deviceActions, forgetDisconnectedDevices, handleDeviceDisconnect, @@ -17,8 +17,8 @@ import { wipeDisconnectedDevicesDataThunk } from '../deviceThunks'; const isActionDeviceRelated = (action: AnyAction): boolean => { if ( isAnyOf( - authorizeDevice.fulfilled, - authorizeDevice.rejected, + authorizeDeviceThunk.fulfilled, + authorizeDeviceThunk.rejected, deviceActions.selectDevice, deviceActions.receiveAuthConfirm, deviceActions.updatePassphraseMode, diff --git a/suite-native/discovery/src/discoveryMiddleware.ts b/suite-native/discovery/src/discoveryMiddleware.ts index 06f8f68f192a..3454b534fc9b 100644 --- a/suite-native/discovery/src/discoveryMiddleware.ts +++ b/suite-native/discovery/src/discoveryMiddleware.ts @@ -4,7 +4,7 @@ import { discoveryActions, selectDeviceModel, selectDeviceFirmwareVersion, - authorizeDevice, + authorizeDeviceThunk, } from '@suite-common/wallet-core'; import { createMiddlewareWithExtraDeps } from '@suite-common/redux-utils'; import { isFirmwareVersionSupported } from '@suite-native/device'; @@ -41,12 +41,12 @@ export const prepareDiscoveryMiddleware = createMiddlewareWithExtraDeps( } } - // We need to wait until `authorizeDevice` action is fulfilled, because we need + // We need to wait until `authorizeDeviceThunk` action is fulfilled, because we need // to know the device state when starting discovery of newly authorized device. next(action); // On successful authorization, create discovery instance and run it. - if (authorizeDevice.fulfilled.match(action) && isDeviceFirmwareVersionSupported) { + if (authorizeDeviceThunk.fulfilled.match(action) && isDeviceFirmwareVersionSupported) { dispatch( startDescriptorPreloadedDiscoveryThunk({ deviceState: action.payload.state, diff --git a/suite-native/module-connect-device/src/components/PinFormControlButtons.tsx b/suite-native/module-connect-device/src/components/PinFormControlButtons.tsx index 078419d5f3b9..0fc17cfd255a 100644 --- a/suite-native/module-connect-device/src/components/PinFormControlButtons.tsx +++ b/suite-native/module-connect-device/src/components/PinFormControlButtons.tsx @@ -26,7 +26,7 @@ import { selectDevice, selectDeviceAuthFailed, removeButtonRequests, - authorizeDevice, + authorizeDeviceThunk, } from '@suite-common/wallet-core'; import { useAlert } from '@suite-native/alerts'; import { useOpenLink } from '@suite-native/link'; @@ -104,7 +104,7 @@ export const PinFormControlButtons = () => { onPressPrimaryButton: () => { if (hasDeviceAuthFailed) { // Ask for new PIN entry after 3 wrong attempts. - requestPrioritizedDeviceAccess(() => dispatch(authorizeDevice())); + requestPrioritizedDeviceAccess(() => dispatch(authorizeDeviceThunk())); } }, secondaryButtonTitle: ( diff --git a/suite-native/module-connect-device/src/screens/ConnectAndUnlockDeviceScreen.tsx b/suite-native/module-connect-device/src/screens/ConnectAndUnlockDeviceScreen.tsx index dd09a981e9a5..6796629722a2 100644 --- a/suite-native/module-connect-device/src/screens/ConnectAndUnlockDeviceScreen.tsx +++ b/suite-native/module-connect-device/src/screens/ConnectAndUnlockDeviceScreen.tsx @@ -9,7 +9,11 @@ import { Translation } from '@suite-native/intl'; import { ConnectDeviceAnimation } from '@suite-native/device'; import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; import { Screen } from '@suite-native/navigation'; -import { selectDevice, selectIsDeviceAuthorized, authorizeDevice } from '@suite-common/wallet-core'; +import { + selectDevice, + selectIsDeviceAuthorized, + authorizeDeviceThunk, +} from '@suite-common/wallet-core'; import { requestPrioritizedDeviceAccess } from '@suite-native/device-mutex'; import { ConnectDeviceScreenHeader } from '../components/ConnectDeviceScreenHeader'; @@ -40,7 +44,7 @@ export const ConnectAndUnlockDeviceScreen = () => { useEffect(() => { if (isFocused && device && !isDeviceAuthorized) { // When user cancelled the authorization, we need to authorize the device again. - requestPrioritizedDeviceAccess(() => dispatch(authorizeDevice())); + requestPrioritizedDeviceAccess(() => dispatch(authorizeDeviceThunk())); } }, [isDeviceAuthorized, device, dispatch, isFocused]); diff --git a/suite-native/passphrase/src/passphraseSlice.ts b/suite-native/passphrase/src/passphraseSlice.ts index 9a36a892fa08..d191d390ecd6 100644 --- a/suite-native/passphrase/src/passphraseSlice.ts +++ b/suite-native/passphrase/src/passphraseSlice.ts @@ -1,6 +1,6 @@ import { createSlice } from '@reduxjs/toolkit'; -import { AuthorizeDeviceError, authorizeDevice } from '@suite-common/wallet-core'; +import { AuthorizeDeviceError, authorizeDeviceThunk } from '@suite-common/wallet-core'; type PassphraseState = { error: AuthorizeDeviceError | null; @@ -20,10 +20,10 @@ export const passphraseSlice = createSlice({ reducers: {}, extraReducers: builder => { builder - .addCase(authorizeDevice.pending, state => { + .addCase(authorizeDeviceThunk.pending, state => { state.error = null; }) - .addCase(authorizeDevice.rejected, (state, { payload }) => { + .addCase(authorizeDeviceThunk.rejected, (state, { payload }) => { if (payload?.error === 'passphrase-duplicate') { state.error = payload; } diff --git a/suite-native/passphrase/src/passphraseThunks.ts b/suite-native/passphrase/src/passphraseThunks.ts index 90f277f50d21..42860c4c0b84 100644 --- a/suite-native/passphrase/src/passphraseThunks.ts +++ b/suite-native/passphrase/src/passphraseThunks.ts @@ -1,6 +1,6 @@ import { createThunk } from '@suite-common/redux-utils'; import { - authorizeDevice, + authorizeDeviceThunk, deviceActions, selectDevice, selectDeviceThunk, @@ -65,6 +65,6 @@ export const retryPassphraseAuthenticationThunk = createThunk( if (!device) return; dispatch(deviceActions.removeButtonRequests({ device })); - dispatch(authorizeDevice({ shouldIgnoreDeviceState: true })); + dispatch(authorizeDeviceThunk({ shouldIgnoreDeviceState: true })); }, );