Skip to content

Commit

Permalink
fix(suite): metadata actions types
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan authored and komret committed Feb 27, 2025
1 parent d2a0879 commit 57a9a9a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
12 changes: 6 additions & 6 deletions packages/suite/src/actions/suite/metadataActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type MetadataAction =
}
| {
type: typeof METADATA.REMOVE_PROVIDER;
payload: MetadataProvider;
payload: Pick<MetadataProvider, 'clientId'>;
}
| {
type: typeof METADATA.ADD_PROVIDER;
Expand All @@ -46,15 +46,15 @@ export type MetadataAction =
| {
type: typeof METADATA.SET_DATA;
payload: {
provider: MetadataProvider;
data: Record<string, Labels>;
provider: Omit<MetadataProvider, 'data'> & Pick<Partial<MetadataProvider>, 'data'>;
data: Record<string, Labels> | undefined;
};
}
| {
type: typeof METADATA.SET_SELECTED_PROVIDER;
payload: {
dataType: DataType;
clientId: string;
clientId: string | undefined;
};
}
| {
Expand Down Expand Up @@ -100,7 +100,7 @@ export const disposeMetadataKeys = () => (dispatch: Dispatch, getState: GetState
});

devices.forEach(device => {
if (device.state) {
if (device.state?.staticSessionId) {
// set metadata as disabled for this device, remove all metadata related information
dispatch({
type: METADATA.SET_DEVICE_METADATA,
Expand Down Expand Up @@ -134,7 +134,7 @@ export const setMetadata =
}: {
provider: MetadataProvider;
fileName: string;
data: WalletLabels | AccountLabels | PasswordManagerState | undefined;
data: WalletLabels | AccountLabels | PasswordManagerState; // | undefined;
}) =>
(dispatch: Dispatch) => {
dispatch({
Expand Down
10 changes: 5 additions & 5 deletions packages/suite/src/actions/suite/metadataPasswordsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export const fetchPasswords =

// this triggers renewal of access token if needed. Otherwise multiple requests
// to renew access token are issued by every provider.getFileContent
const response = await provider.getProviderDetails();
if (!response.success) {
const providerDetails = await provider.getProviderDetails();
if (!providerDetails.success) {
return dispatch(
metadataProviderActions.handleProviderError({
error: response,
error: providerDetails,
action: ProviderErrorAction.LOAD,
clientId: provider.clientId,
}),
Expand All @@ -55,7 +55,7 @@ export const fetchPasswords =
dispatch({
type: METADATA.SET_DATA,
payload: {
provider,
provider: providerDetails.payload,
data: {
[keys.fileName]: decrypted,
},
Expand All @@ -76,7 +76,7 @@ export const fetchPasswords =
export const init = () => async (dispatch: Dispatch, getState: GetState) => {
let device = selectSelectedDevice(getState());

if (!device?.state) {
if (!device?.state?.staticSessionId) {
console.error('no device state!');

return Promise.resolve();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const disconnectProvider =
// flush reducer
dispatch({
type: METADATA.REMOVE_PROVIDER,
payload: provider,
payload: { clientId },
});
dispatch({
type: METADATA.SET_SELECTED_PROVIDER,
Expand Down
4 changes: 4 additions & 0 deletions packages/suite/src/reducers/suite/metadataReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ const metadataReducer = (state = initialState, action: Action): MetadataState =>
);
break;
case METADATA.SET_SELECTED_PROVIDER:
if (!action.payload.clientId) {
delete draft.selectedProvider[action.payload.dataType];
break;
}
draft.selectedProvider[action.payload.dataType] = action.payload.clientId;
break;
case METADATA.SET_EDITING:
Expand Down
2 changes: 1 addition & 1 deletion suite-common/metadata-types/src/metadataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export interface WalletLabels {
walletLabel?: string;
}

export type Labels = AccountLabels | WalletLabels;
export type Labels = AccountLabels | WalletLabels | PasswordManagerState;

export type DeviceMetadata = DeviceEntityKeys;

Expand Down

0 comments on commit 57a9a9a

Please sign in to comment.