Skip to content

Commit

Permalink
feat
Browse files Browse the repository at this point in the history
  • Loading branch information
juriczech committed May 17, 2024
1 parent 1d981d4 commit f424f51
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { discoveryActions, deviceActions, authorizeDevice } from '@suite-common/
import { DEVICE, TRANSPORT } from '@trezor/connect';
import { notificationsActions } from '@suite-common/toast-notifications';

import { SUITE, MODAL } from 'src/actions/suite/constants';
import { SUITE } from 'src/actions/suite/constants';
import { TorStatus } from 'src/types/suite';

import * as suiteActions from '../suiteActions';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ComponentType } from 'react';

import type { NotificationEntry } from '@suite-common/toast-notifications';
import { AUTH_DEVICE, type NotificationEntry } from '@suite-common/toast-notifications';
import { DEVICE } from '@trezor/connect';

import { NotificationViewProps } from 'src/components/suite';
Expand Down Expand Up @@ -217,7 +217,7 @@ export const NotificationRenderer = ({
case 'coinjoin-interrupted':
return error(render, notification, 'TR_COINJOIN_INTERRUPTED_ERROR');
// Events:
case '@suite/device/authDevice':
case AUTH_DEVICE:
return info(render, notification, 'EVENT_WALLET_CREATED');
case DEVICE.CONNECT:
return (
Expand Down
10 changes: 6 additions & 4 deletions packages/suite/src/middlewares/suite/eventsMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
} from '@suite-common/wallet-core';
import * as deviceUtils from '@suite-common/suite-utils';
import { DEVICE } from '@trezor/connect';
import { notificationsActions, removeAccountEventsThunk } from '@suite-common/toast-notifications';
import {
AUTH_DEVICE,
notificationsActions,
removeAccountEventsThunk,
} from '@suite-common/toast-notifications';

import { SUITE } from 'src/actions/suite/constants';
import { AppState, Action, Dispatch } from 'src/types/suite';
Expand Down Expand Up @@ -106,9 +110,7 @@ const eventsMiddleware =
}

if (isAnyOf(authorizeDevice.fulfilled)(action)) {
api.dispatch(
notificationsActions.addEvent({ type: '@suite/device/authDevice', seen: true }),
);
api.dispatch(notificationsActions.addEvent({ type: AUTH_DEVICE, seen: true }));
}

return action;
Expand Down
3 changes: 2 additions & 1 deletion suite-common/toast-notifications/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,14 @@ export type ToastPayload = (
) &
NotificationOptions;

export const AUTH_DEVICE = 'auth-device';
export type NotificationEventPayload = (
| {
// only temporary, must be same as AUTH_DEVICE value in packages/suite/src/actions/suite/constants/suiteConstants.ts
// once that will be migrated to @suite-common, this should be replaced directly by suiteActions.authDevice.type
// this should not break type safety, if someone will change value of AUTH_DEVICE, it will throw error in place
// where action is used and you will need to change it also here
type: '@suite/device/authDevice';
type: typeof AUTH_DEVICE;
}
| ReceivedTransactionNotification
| {
Expand Down
5 changes: 0 additions & 5 deletions suite-common/wallet-core/src/device/deviceReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,7 @@ export const prepareDeviceReducer = createReducerWithExtraDeps(initialState, (bu
if (action.payload && action.payload.error) {
const { error } = action.payload;
if (error === 'auth-failed') {
if (!action.payload.device) return;
authFailed(state, action.payload.device);
} else if (error === 'passphrase-duplicate') {
// TODO probably create passphrase slice in suite native and on error
// set error in state to show alert
console.warn('passphrase duplicate');
}
}
})
Expand Down
7 changes: 5 additions & 2 deletions suite-common/wallet-core/src/device/deviceThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export const acquireDevice = createThunk(
type AuthorizeDeviceParams = { shouldIgnoreDeviceState: boolean } | undefined;
export type AuthorizeDeviceError = {
error: string;
device?: TrezorDevice;
device: TrezorDevice;
duplicate?: TrezorDevice;
};
type AuthorizeDeviceSuccess = { device: TrezorDevice; state: string };
Expand Down Expand Up @@ -369,7 +369,10 @@ export const authorizeDevice = createThunk<
}),
);

return rejectWithValue({ error: 'auth-failed', device } as AuthorizeDeviceError);
return rejectWithValue({
error: 'auth-failed',
device: device as TrezorDevice,
} as AuthorizeDeviceError);
},
);

Expand Down

0 comments on commit f424f51

Please sign in to comment.