Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// data provided by TrezorConnect are mocked
import { connectInitThunk } from '@suite-common/connect-init';
import { prepareFirmwareReducer } from '@suite-common/firmware';
import { prepareLabelingReducer, prepareSuiteSyncReducer } from '@suite-common/suite-sync';
import { labelingReducer, suiteSyncReducer } from '@suite-common/suite-sync';
import { testMocks } from '@suite-common/test-utils';
import {
acquireDevice,
Expand Down Expand Up @@ -32,8 +32,6 @@ const { getSuiteDevice } = testMocks;

const firmwareReducer = prepareFirmwareReducer(extraDependencies);
const deviceReducer = prepareDeviceReducer(extraDependencies);
const labelingReducer = prepareLabelingReducer(extraDependencies);
const suiteSyncReducer = prepareSuiteSyncReducer(extraDependencies);

const TrezorConnect = testMocks.getTrezorConnectMock();

Expand Down
8 changes: 3 additions & 5 deletions packages/suite/src/actions/suiteSync/suiteSyncSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AnyAction, createSliceWithExtraDeps } from '@suite-common/redux-utils';
import {
SuiteSyncState,
initialSuiteSyncState as commonInitialState,
prepareSuiteSyncReducer,
suiteSyncReducer,
} from '@suite-common/suite-sync';

import { Action } from 'src/types/suite';
Expand Down Expand Up @@ -30,9 +30,7 @@ export const suiteSyncSlice = createSliceWithExtraDeps({
state.showEnableSuiteSyncModal = action.payload.show;
},
},
extraReducers: (builder, extra) => {
const commonReducer = prepareSuiteSyncReducer(extra);

extraReducers: builder => {
builder
.addCase(STORAGE.LOAD, (state, action) => {
const actionWithPayload = action as Action;
Expand All @@ -51,7 +49,7 @@ export const suiteSyncSlice = createSliceWithExtraDeps({
}
})
.addDefaultCase((state, action) => {
commonReducer(state, action as AnyAction);
suiteSyncReducer(state, action as AnyAction);
});
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { MetadataAddPayload } from '@suite-common/metadata-types';
import { createThunk } from '@suite-common/redux-utils';
import { NetworkSymbol } from '@suite-common/wallet-config';
import type { StaticSessionId } from '@trezor/connect';
import { exhaustive } from '@trezor/type-utils';

type ProcessMetadataMessageThunkParams = {
deviceStaticSessionId: StaticSessionId;
payload: MetadataAddPayload;
value: string | undefined;
};

/**
* This is a compatibility thunk to map the old Metadata code to a new Evolu storage.
*
* @deprecated This shall be removed, once we phase out the old Metadata code.
*/
export const processLegacyMetadataIntoSuiteSyncThunk = createThunk<
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved out of the SuiteSync

void,
ProcessMetadataMessageThunkParams,
void
>(
'@suite/labeling/processMetadataMessageThunk',
({ payload, deviceStaticSessionId, value }, { extra: { services } }) => {
const labelType = payload.type;

switch (labelType) {
case 'walletLabel':
services.suiteSync.labeling.updateWalletLabel({
deviceStaticSessionId,
label: value ?? null,
});
break;

case 'accountLabel':
services.suiteSync.labeling.updateAccountLabel({
deviceStaticSessionId,
accountKey: payload.entityKey,
label: value ?? null,
});
break;

case 'addressLabel':
services.suiteSync.labeling.updateAddressLabel({
deviceStaticSessionId,
address: payload.defaultValue, // WTF, but this is the address. For example: `"bc1q9mnl3ae6dra54uu2n9hp3d4jwkt0c2ux5l79ja"`
// entityKey is for example `zpub6rY6av7j6m7Lnd6rgqw5jffjX2rgeirDWWivEmFDMCKxt7FkWD5XQSrXCSW2Vsh3vnqUo1r9XjoGZiW41jqfEBkrxxdPnS15QhwJFjwfZ1U-btc-momP8m1p6w1nteR3hNREZjNc48buvpPv8K@BCCD2503E021276E78A8EBB2:2`
label: value ?? null,
accountDescriptor: payload.accountDescriptor,
networkSymbol: payload.networkSymbol as NetworkSymbol,
});
break;

case 'outputLabel':
services.suiteSync.labeling.updateOutputLabel({
deviceStaticSessionId,
txId: payload.txid,
outputIndex: Number(payload.outputIndex),
label: value ?? null,
accountDescriptor: payload.accountDescriptor,
networkSymbol: payload.networkSymbol as NetworkSymbol,
});
break;

default:
exhaustive(labelType);
}
},
);
5 changes: 3 additions & 2 deletions packages/suite/src/actions/wallet/send/sendFormThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isRejected } from '@reduxjs/toolkit';

import { MetadataAddPayload } from '@suite-common/metadata-types';
import { createThunk } from '@suite-common/redux-utils';
import { processMetadataMessageThunk, selectIsSuiteSyncEnabled } from '@suite-common/suite-sync';
import { selectIsSuiteSyncEnabled } from '@suite-common/suite-sync';
import {
cancelSignSendFormTransactionThunk,
enhancePrecomposedTransactionThunk,
Expand Down Expand Up @@ -39,6 +39,7 @@ import { RBF_ERROR_ALREADY_MINED } from './replaceByFeeErrorThunk';
import { MODULE_PREFIX } from './sendThunksConsts';
import { findLabelsToBeMovedOrDeletedThunk } from '../moveLabelsForRbf/findLabelsToBeMovedOrDeletedThunk';
import { moveLabelsForRbfThunk } from '../moveLabelsForRbf/moveLabelsForRbfThunk';
import { processLegacyMetadataIntoSuiteSyncThunk } from '../processLegacyMetadataIntoSuiteSyncThunk';

export const saveSendFormDraftThunk = createThunk(
`${MODULE_PREFIX}/saveSendFormDraftThunk`,
Expand Down Expand Up @@ -166,7 +167,7 @@ const applySendFormMetadataLabelsThunk = createThunk<
synchronize(() => {
if (isSuiteSyncEnabled) {
return dispatch(
processMetadataMessageThunk({
processLegacyMetadataIntoSuiteSyncThunk({
payload: output,
deviceStaticSessionId: selectedAccount.deviceState,
value: output.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useMemo, useRef, useState } from 'react';

import styled from 'styled-components';

import { processMetadataMessageThunk, selectShouldOfferSecureSync } from '@suite-common/suite-sync';
import { selectShouldOfferSecureSync } from '@suite-common/suite-sync';
import { Button, DropdownMenuItemProps, Row, Text, Tooltip } from '@trezor/components';
import { StaticSessionId } from '@trezor/connect';
import { spacingsPx } from '@trezor/theme';
Expand All @@ -21,6 +21,7 @@ import { MetadataAddPayload } from 'src/types/suite/metadata';
import { LabelContentProps, LabelingVariant, MetadataProps, PrimitiveProps } from './definitions';
import { withDropdown } from './withDropdown';
import { withEditable } from './withEditable';
import { processLegacyMetadataIntoSuiteSyncThunk } from '../../../../actions/wallet/processLegacyMetadataIntoSuiteSyncThunk';
import { useLabelingCombined } from '../../../../hooks/suite/useLabelingCombined';
import { AccountTypeBadge } from '../../AccountTypeBadge';
import { NO_HIGHLIGHT_ATTRIBUTE } from '../../FindBar/consts';
Expand Down Expand Up @@ -443,7 +444,9 @@ export const MetadataLabeling = ({
setPending(true);

if (isSuiteSyncEnabled) {
await dispatch(processMetadataMessageThunk({ payload, deviceStaticSessionId, value }));
await dispatch(
processLegacyMetadataIntoSuiteSyncThunk({ payload, deviceStaticSessionId, value }),
);

setShowSuccess(true);
// Intentional pattern how to use timers with useEffect
Expand Down
11 changes: 4 additions & 7 deletions packages/suite/src/hooks/suite/useLabelingCombined.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useServices } from '@suite-common/redux-utils';
import {
selectIsFeatureSuiteSyncAvailable,
selectIsSuiteSyncDebugEnabled,
selectIsSuiteSyncEnabled,
suiteSyncActions,
useToggleSuiteSyncMethods,
} from '@suite-common/suite-sync';
import { selectDeviceByStaticSessionId } from '@suite-common/wallet-core';
import type { StaticSessionId } from '@trezor/connect';
Expand All @@ -27,16 +27,14 @@ type UseLabelingCombinedParams = {
*/
export const useLabelingCombined = ({ deviceStaticSessionId }: UseLabelingCombinedParams) => {
const dispatch = useDispatch();
const { suiteSync } = useServices();

const device = useSelector(state =>
deviceStaticSessionId !== undefined
? selectDeviceByStaticSessionId(state, deviceStaticSessionId)
: undefined,
);

const { disableSuiteSyncIfNeeded, enableSuiteSyncIfNeeded: enableSuiteSyncIfNeededCommon } =
useToggleSuiteSyncMethods();

const isSuiteSyncDebugEnabled = useSelector(selectIsSuiteSyncDebugEnabled);
const isFeatureSuiteSyncAvailable = useSelector(selectIsFeatureSuiteSyncAvailable);
const isSuiteSyncEnabled = useSelector(selectIsSuiteSyncEnabled);
Expand Down Expand Up @@ -65,12 +63,12 @@ export const useLabelingCombined = ({ deviceStaticSessionId }: UseLabelingCombin
provider: 'evolu',
},
});
enableSuiteSyncIfNeededCommon();
suiteSync.turnOnSuiteSync();
};

const legacyEnableIfNeeded = () => {
if (!legacyMetadataState.enabled) {
disableSuiteSyncIfNeeded(); // Enabling Legacy Labeling implicitly disables Evolu
suiteSync.turnOffSuiteSync(); // Enabling Legacy Labeling implicitly disables Evolu
dispatch(metadataLabelingActions.init(true));
}
};
Expand All @@ -88,7 +86,6 @@ export const useLabelingCombined = ({ deviceStaticSessionId }: UseLabelingCombin
isSuiteSyncDebugEnabled,
hasDeviceSuiteSyncOwner,
enableSuiteSyncIfNeeded,
disableSuiteSyncIfNeeded,

/** Legacy Labeling */
isMetadataEnabled: legacyMetadataState.enabled,
Expand Down
2 changes: 1 addition & 1 deletion packages/suite/src/middlewares/suite/suiteMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const prepareSuiteMiddleware = createMiddlewareWithExtraDeps(

dispatch(handleDeviceDisconnect(device));
if (isTrezorDeviceWithState(device)) {
extra.services.suiteSync.unsubscribeSuiteSyncStorage({ device });
extra.services.suiteSync.turnOffSuiteSyncForWallet({ device });
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/suite/src/reducers/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import walletReducers from 'src/reducers/wallet';
// toastMiddleware can be used only in suite-desktop and suite-web
// it's not included into `@suite-middlewares` index
import { geolocationReducer } from '@suite-common/geolocation';
import { prepareLabelingReducer } from '@suite-common/suite-sync';
import { labelingReducer } from '@suite-common/suite-sync';
import { OPEN_USER_CONTEXT } from 'src/actions/suite/constants/modalConstants';
import toastMiddleware from 'src/middlewares/suite/toastMiddleware';
import { globalSendReceiveFilters } from 'src/slices/wallet/globalSendReceiveFilters';
Expand All @@ -51,7 +51,6 @@ const firmwareReducer = prepareFirmwareReducer(extraDependencies);
const tokenDefinitionsReducer = prepareTokenDefinitionsReducer(extraDependencies);
const bluetoothReducer = bluetoothSlice.prepareReducer(extraDependencies);
const thpReducer = prepareThpReducer(extraDependencies);
const labelingReducer = prepareLabelingReducer(extraDependencies);
const suiteSyncReducer = suiteSyncSlice.prepareReducer(extraDependencies);

const rootReducer = combineReducers({
Expand Down
36 changes: 23 additions & 13 deletions packages/suite/src/support/extraDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type History, createMemoryHistory } from 'history';

import { createElectronSecureStorage } from '@suite/secure-storage-electron';
import { createWebauthnSecureStorage } from '@suite/secure-storage-webauthn';
import { createSuiteSyncDesktop } from '@suite/suite-sync';
import { createSuiteSyncDesktopCompositionRoot } from '@suite/suite-sync';
import { FW_HASH_CHECK_DEFAULT_TIMEOUTS } from '@suite-common/firmware-authenticity';
import {
ExtraDependenciesStatic,
Expand All @@ -25,6 +25,7 @@ import {
SendState,
TransactionsState,
WalletSettingsState,
delegatedIdentityKeyCompositionRoot,
} from '@suite-common/wallet-core';
import { buildHistoricRatesFromStorage, getAccountKey } from '@suite-common/wallet-utils';
import TrezorConnect, { StaticSessionId } from '@trezor/connect';
Expand Down Expand Up @@ -69,20 +70,29 @@ export const createRouterServices = (history: History) => ({
navigate: (to: To, state?: LocationPushState) => history.push(to, state),
});

const secureStorage = isDesktop()
? createElectronSecureStorage({ desktopApi })
: createWebauthnSecureStorage();
export const suiteExtraFactory: ExtraWithStoreFactory = store => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: This shall be moved/named suiteCompositionRoot.ts

const secureStorage = isDesktop()
? createElectronSecureStorage({ desktopApi })
: createWebauthnSecureStorage();

export const suiteExtraFactory: ExtraWithStoreFactory = store => ({
services: {
suiteSync: createSuiteSyncDesktop({
...store,
secureStorage,
trezorConnect: TrezorConnect,
}),
const { ensureDelegatedIdentityKey } = delegatedIdentityKeyCompositionRoot({
...store,
secureStorage,
},
});
trezorConnect: TrezorConnect,
});

return {
services: {
suiteSync: createSuiteSyncDesktopCompositionRoot({
...store,
secureStorage,
trezorConnect: TrezorConnect,
ensureDelegatedIdentityKey,
}),
secureStorage,
},
};
};

export const extraDependencies: ExtraDependenciesStatic = {
thunks: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';

import { useServices } from '@suite-common/redux-utils';
import { selectIsFeatureSuiteSyncAvailable } from '@suite-common/suite-sync';
import { LoadingContent } from '@trezor/components';
import { EventType, analytics } from '@trezor/suite-analytics';
Expand All @@ -25,6 +26,7 @@ import { LabelingSwitchToLegacyModal } from '../../../components/suite/labeling/

export const Labeling = () => {
const { translationString } = useTranslation();
const { suiteSync } = useServices();

const [legacyModalWarningVisible, setLegacyModalWarningVisible] = useState(false);
const { device } = useDevice();
Expand All @@ -36,7 +38,6 @@ export const Labeling = () => {
legacyMetadataState,
legacyEnableIfNeeded,
legacyDisableIfNeeded,
disableSuiteSyncIfNeeded,
enableSuiteSyncIfNeeded,
isEvoluSupportedByDevice,
isSuiteSyncEnabled,
Expand Down Expand Up @@ -65,15 +66,15 @@ export const Labeling = () => {
switch (value) {
case 'off':
legacyDisableIfNeeded();
disableSuiteSyncIfNeeded();
suiteSync.turnOffSuiteSync();
break;

case 'secure-sync':
enableSuiteSyncIfNeeded();
break;

case 'legacy':
disableSuiteSyncIfNeeded();
suiteSync.turnOffSuiteSync();
legacyEnableIfNeeded();
break;

Expand Down Expand Up @@ -120,7 +121,7 @@ export const Labeling = () => {
<LabelingSwitchToLegacyModal
onClose={() => setLegacyModalWarningVisible(false)}
onSwitch={() => {
disableSuiteSyncIfNeeded();
suiteSync.turnOffSuiteSync();
legacyEnableIfNeeded();
setLegacyModalWarningVisible(false);
}}
Expand Down
2 changes: 1 addition & 1 deletion suite-common/redux-utils/src/extraDependenciesType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {

import { MetadataAddPayload } from '@suite-common/metadata-types';
import { SecureStorage } from '@suite-common/secure-storage';
import { SuiteSync } from '@suite-common/suite-sync-storage';
import { SuiteSync } from '@suite-common/suite-sync';
import {
ReportSecurityCheckProps,
Route,
Expand Down
25 changes: 0 additions & 25 deletions suite-common/suite-sync-storage/src/SuiteSync.ts

This file was deleted.

Loading
Loading