Skip to content

Commit

Permalink
feat(message-system): load valid experiments to store also for mobile…
Browse files Browse the repository at this point in the history
… app
  • Loading branch information
matejkriz committed Jan 14, 2025
1 parent 472c4ac commit a7f35d8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
6 changes: 6 additions & 0 deletions docs/features/message-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ Structure of config, types and optionality of specific keys can be found in the
"desktop": ">=24.5.1",
"mobile": "!",
"web": ">=24.5.1"
},
// It's very useful to define a duration for each experiment that starts the next day at the earliest,
// to minimize changing the application under the hands of those who have it open at the moment.
"duration": {
"from": "2021-03-01T12:10:00.000Z",
"to": "2022-01-31T12:10:00.000Z"
}
}
],
Expand Down
15 changes: 5 additions & 10 deletions packages/suite/src/middlewares/suite/messageSystemMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,19 @@ const messageSystemMiddleware =
const device = selectSelectedDevice(api.getState());
const { enabledNetworks } = api.getState().wallet.settings;

const validMessages = getValidMessages(config, {
const validationParams = {
device,
transports,
settings: {
tor: getIsTorEnabled(torStatus),
enabledNetworks,
},
});
};

const validMessages = getValidMessages(config, validationParams);
const categorizedValidMessages = categorizeMessages(validMessages);

const validExperiments = getValidExperiments(config, {
device,
transports,
settings: {
tor: getIsTorEnabled(torStatus),
enabledNetworks,
},
}).map(item => item.id);
const validExperiments = getValidExperiments(config, validationParams);

api.dispatch(messageSystemActions.updateValidMessages(categorizedValidMessages));
api.dispatch(messageSystemActions.updateValidExperiments(validExperiments));
Expand Down
8 changes: 2 additions & 6 deletions suite-common/message-system/src/messageSystemUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {
Device,
Environment,
Condition,
ExperimentsItem,
} from '@suite-common/suite-types';
import type { NetworkSymbol } from '@suite-common/wallet-config';
import type { TransportInfo } from '@trezor/connect';
Expand Down Expand Up @@ -289,10 +288,7 @@ export const getValidMessages = (config: MessageSystem | null, options: Options)
.map(action => action.message);
};

export const getValidExperiments = (
config: MessageSystem | null,
options: Options,
): ExperimentsItem[] => {
export const getValidExperiments = (config: MessageSystem | null, options: Options): string[] => {
if (!config?.experiments) {
return [];
}
Expand All @@ -303,5 +299,5 @@ export const getValidExperiments = (
!experiment.conditions.length ||
experiment.conditions.some(condition => validateConditions(condition, options)),
)
.map(experiment => experiment.experiment);
.map(experiment => experiment?.experiment?.id);
};
9 changes: 7 additions & 2 deletions suite-native/message-system/src/messageSystemMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
categorizeMessages,
getValidMessages,
selectMessageSystemConfig,
getValidExperiments,
} from '@suite-common/message-system';
import { deviceActions, selectSelectedDevice } from '@suite-common/wallet-core';
import {
Expand All @@ -30,17 +31,21 @@ export const messageSystemMiddleware = createMiddleware((action, { next, dispatc
const device = selectSelectedDevice(getState());
const enabledNetworks = selectDeviceEnabledDiscoveryNetworkSymbols(getState());

const validMessages = getValidMessages(config, {
const validationParams = {
device,
settings: {
tor: false, // not supported in suite-native
enabledNetworks,
},
});
};

const validMessages = getValidMessages(config, validationParams);
const categorizedValidMessages = categorizeMessages(validMessages);

const validExperiments = getValidExperiments(config, validationParams);

dispatch(messageSystemActions.updateValidMessages(categorizedValidMessages));
dispatch(messageSystemActions.updateValidExperiments(validExperiments));
}

return action;
Expand Down

0 comments on commit a7f35d8

Please sign in to comment.