Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Aug 24, 2023
1 parent cedb8bd commit e50496c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,11 @@ describe('Metadata Actions', () => {
}
return { success: true, payload: undefined };
};
DropboxProvider.prototype.getFilesList = async () => {
return { success: true, payload: [] };
};
DropboxProvider.prototype.setFileContent = async () => {
return { success: true, payload: undefined };
};
DropboxProvider.prototype.getFilesList = () => ({ success: true, payload: [] });
DropboxProvider.prototype.setFileContent = () => ({
success: true,
payload: undefined,
});
});

fixtures.setDeviceMetadataKey.forEach(f => {
Expand Down
30 changes: 12 additions & 18 deletions packages/suite/src/actions/suite/metadataActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ import { selectSelectedProviderForLabels } from 'src/reducers/suite/metadataRedu

import { createAction } from '@reduxjs/toolkit';
import { notificationsActions } from '@suite-common/toast-notifications';
import {
DEFAULT_ACCOUNT_METADATA,
DEFAULT_WALLET_METADATA,
} from './constants/metadataConstants';
import { DEFAULT_ACCOUNT_METADATA, DEFAULT_WALLET_METADATA } from './constants/metadataConstants';

export const setAccountAdd = createAction(METADATA.ACCOUNT_ADD, (payload: Account) => ({
payload,
Expand Down Expand Up @@ -295,7 +292,6 @@ export const initProvider = () => (dispatch: Dispatch) => {
return decision.promise;
};


const setMetadata =
({
provider,
Expand Down Expand Up @@ -984,7 +980,7 @@ export const setMigrationStatus = (
});

/**
* Check whether encryption version migration is needed and if true execute it
* Check whether encryption version migration is needed and if yes execute it
*/
const handleEncryptionVersionMigration =
() =>
Expand Down Expand Up @@ -1024,19 +1020,17 @@ const handleEncryptionVersionMigration =

// 5. there are old files, but also all labelable entities currently known to suite have some record in currentEncryptionFiles.
// this means that they have already been migrated or dummy file was created
const everyEntityHasNewFile = dispatch(getLabelableEntities(device.state)).every(
entity => {
if (entity.type === 'device' && entity.status === 'disabled') return; // ts.
const everyEntityHasNewFile = dispatch(getLabelableEntities(device.state)).every(entity => {
if (entity.type === 'device' && entity.status === 'disabled') return; // ts.

const nextKeys = entity[METADATA.ENCRYPTION_VERSION];
const nextKeys = entity[METADATA.ENCRYPTION_VERSION];

if (!nextKeys) {
// todo: should never happend but happend once during testing.
throw new Error('metadata migration: next keys are missing');
}
return currentEncryptionFiles.find(file => file === nextKeys.fileName);
},
);
if (!nextKeys) {
// todo: should never happend but happend once during testing.
throw new Error('metadata migration: next keys are missing');
}
return currentEncryptionFiles.find(file => file === nextKeys.fileName);
});

if (everyEntityHasNewFile) {
return { success: true };
Expand All @@ -1053,7 +1047,7 @@ const handleEncryptionVersionMigration =
dispatch(syncMetadataKeys(prevEncryptionVersion));

// 8. get labelable entitites again (there was async operation in between)
const allEntities = dispatch(getLabelableEntitities(device.state));
const allEntities = dispatch(getLabelableEntities(device.state));

// 9. split labelable entities into 2 groups:
// - entitiesToMigrate: don't have new file && have old file
Expand Down
2 changes: 1 addition & 1 deletion suite-common/wallet-core/src/discovery/discoveryThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export const startDiscoveryThunk = createThunk(
// if previous discovery status was running (typically after application start or when user added a new account)
// trigger fetch metadata; necessary to load account labels
if (discovery.status === DiscoveryStatus.RUNNING && device.state) {
await dispatch(fetchAndSaveMetadata(device.state));
await dispatch(fetchAndSaveMetadata(device.state));
}

dispatch(
Expand Down

0 comments on commit e50496c

Please sign in to comment.