Skip to content

Commit

Permalink
feat(suite-native): enable solana via message system
Browse files Browse the repository at this point in the history
  • Loading branch information
vytick committed Dec 2, 2024
1 parent 3c48e72 commit 14d6795
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 21 deletions.
1 change: 1 addition & 0 deletions suite-common/message-system/src/messageSystemTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const Feature = {
ethClaim: 'eth.staking.claim',
firmwareRevisionCheck: 'security.firmware.check',
firmwareHashCheck: 'security.firmware.hashCheck',
solanaMobile: 'mobile.solana',
} as const;

export type FeatureDomain = (typeof Feature)[keyof typeof Feature];
Expand Down
3 changes: 2 additions & 1 deletion suite-native/discovery/src/discoveryConfigSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
TokensRootState,
} from '@suite-native/tokens';
import { createWeakMapSelector, returnStableArrayIfEmpty } from '@suite-common/redux-utils';
import { MessageSystemRootState } from '@suite-common/message-system';

type DiscoveryInfo = {
startTimestamp: number;
Expand Down Expand Up @@ -97,7 +98,7 @@ export const selectDiscoveryInfo = (state: DiscoveryConfigSliceRootState) =>
state.discoveryConfig.discoveryInfo;

const createMemoizedSelector = createWeakMapSelector.withTypes<
DeviceRootState & DiscoveryConfigSliceRootState & FeatureFlagsRootState
DeviceRootState & DiscoveryConfigSliceRootState & FeatureFlagsRootState & MessageSystemRootState
>();

const selectIsSolanaEnabled = createSelectIsFeatureFlagEnabled(FeatureFlag.IsSolanaEnabled);
Expand Down
23 changes: 15 additions & 8 deletions suite-native/feature-flags/src/featureFlagsSlice.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

import { isAndroid } from '@trezor/env-utils';
import { MessageSystemRootState } from '@suite-common/message-system';
import { isDebugEnv, isDetoxTestBuild, isDevelopOrDebugEnv } from '@suite-native/config';
import { selectIsSolanaFeatureEnabled } from '@suite-native/message-system';

export const FeatureFlag = {
IsDeviceConnectEnabled: 'isDeviceConnectEnabled',
IsRippleSendEnabled: 'isRippleSendEnabled',
IsCardanoSendEnabled: 'isCardanoSendEnabled',
IsSolanaSendEnabled: 'isSolanaSendEnabled',
IsRegtestEnabled: 'isRegtestEnabled',
IsSolanaEnabled: 'IsSolanaEnabled',
IsConnectPopupEnabled: 'IsConnectPopupEnabled',
Expand All @@ -24,7 +25,6 @@ export const featureFlagsInitialState: FeatureFlagsState = {
[FeatureFlag.IsDeviceConnectEnabled]: isAndroid() || isDebugEnv(),
[FeatureFlag.IsRippleSendEnabled]: isAndroid() && isDevelopOrDebugEnv(),
[FeatureFlag.IsCardanoSendEnabled]: isAndroid() && isDevelopOrDebugEnv(),
[FeatureFlag.IsSolanaSendEnabled]: isAndroid() && isDevelopOrDebugEnv(),
[FeatureFlag.IsRegtestEnabled]: isDebugEnv() || isDetoxTestBuild(),
[FeatureFlag.IsSolanaEnabled]: false,
[FeatureFlag.IsConnectPopupEnabled]: isDevelopOrDebugEnv(),
Expand All @@ -34,7 +34,6 @@ export const featureFlagsPersistedKeys: Array<keyof FeatureFlagsState> = [
FeatureFlag.IsDeviceConnectEnabled,
FeatureFlag.IsRippleSendEnabled,
FeatureFlag.IsCardanoSendEnabled,
FeatureFlag.IsSolanaSendEnabled,
FeatureFlag.IsRegtestEnabled,
FeatureFlag.IsSolanaEnabled,
FeatureFlag.IsConnectPopupEnabled,
Expand All @@ -50,12 +49,20 @@ export const featureFlagsSlice = createSlice({
},
});

export const createSelectIsFeatureFlagEnabled =
(featureFlagKey: FeatureFlag) => (state: FeatureFlagsRootState) =>
state.featureFlags[featureFlagKey];
export const selectIsFeatureFlagEnabled = (
state: FeatureFlagsRootState & MessageSystemRootState,
key: FeatureFlag,
) => {
if (key === FeatureFlag.IsSolanaEnabled) {
return selectIsSolanaFeatureEnabled(state) || state.featureFlags[key];
}

return state.featureFlags[key];
};

export const selectIsFeatureFlagEnabled = (state: FeatureFlagsRootState, key: FeatureFlag) =>
state.featureFlags[key];
export const createSelectIsFeatureFlagEnabled =
(featureFlagKey: FeatureFlag) => (state: FeatureFlagsRootState & MessageSystemRootState) =>
selectIsFeatureFlagEnabled(state, featureFlagKey);

export const { toggleFeatureFlag } = featureFlagsSlice.actions;
export const featureFlagsReducer = featureFlagsSlice.reducer;
7 changes: 5 additions & 2 deletions suite-native/feature-flags/src/useFeatureFlag.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useDispatch, useSelector } from 'react-redux';

import { MessageSystemRootState } from '@suite-common/message-system';

import {
FeatureFlag,
FeatureFlagsRootState,
Expand All @@ -12,8 +14,9 @@ type FeatureFlagHookReturnType = [boolean, () => void];
export const useFeatureFlag = (featureFlag: FeatureFlag): FeatureFlagHookReturnType => {
const dispatch = useDispatch();

const isFeatureFlagEnabled = useSelector((state: FeatureFlagsRootState) =>
selectIsFeatureFlagEnabled(state, featureFlag),
const isFeatureFlagEnabled = useSelector(
(state: FeatureFlagsRootState & MessageSystemRootState) =>
selectIsFeatureFlagEnabled(state, featureFlag),
);

const toggleIsFeatureFlagEnabled = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ const iconVariantMap = {
export const KillswitchMessageScreen = () => {
const dispatch = useDispatch();
const openLink = useOpenLink();
const { applyStyle } = useNativeStyles();

const killswitch = A.head(useSelector(selectActiveKillswitchMessages));

const { applyStyle } = useNativeStyles();

if (!killswitch) return null;

const {
Expand Down
1 change: 1 addition & 0 deletions suite-native/message-system/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './messageSystemMiddleware';
export * from './components/MessageSystemBannerRenderer';
export * from './components/KillswitchMessageScreen';
export * from './selectors';
21 changes: 17 additions & 4 deletions suite-native/message-system/src/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { createMemoizedSelector, selectActiveFeatureMessages } from '@suite-common/message-system';
import {
createMemoizedSelector,
Feature,
MessageSystemRootState,
selectActiveFeatureMessages,
selectIsFeatureEnabled,
} from '@suite-common/message-system';

export const selectActiveKillswitchMessages = createMemoizedSelector(
[selectActiveFeatureMessages],
messages =>
messages.filter(
m => m.feature?.filter(item => item.domain === 'killswitch' && item.flag) ?? false,
),
messages.filter(m => {
const killswitchFeatures = m.feature?.filter(
item => item.domain === 'killswitch' && item?.flag,
);

return (killswitchFeatures?.length ?? 0) > 0;
}),
);

export const selectIsSolanaFeatureEnabled = (state: MessageSystemRootState) =>
selectIsFeatureEnabled(state, Feature.solanaMobile);
13 changes: 10 additions & 3 deletions suite-native/module-accounts-management/src/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { D, pipe } from '@mobily/ts-belt';

import { MessageSystemRootState } from '@suite-common/message-system';
import { NetworkSymbol, getNetworkType, networks } from '@suite-common/wallet-config';
import {
FeatureFlagsRootState,
Expand All @@ -22,18 +23,24 @@ export const selectIsNetworkSendFlowEnabled = (

if (PRODUCTION_SEND_COINS_WHITELIST.includes(networkSymbol)) return true;

const isRippleSendEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsRippleSendEnabled);
const isRippleSendEnabled = selectIsFeatureFlagEnabled(
state as FeatureFlagsRootState & MessageSystemRootState,
FeatureFlag.IsRippleSendEnabled,
);

if (isRippleSendEnabled && networkType === 'ripple') return true;

const isCardanoSendEnabled = selectIsFeatureFlagEnabled(
state,
state as FeatureFlagsRootState & MessageSystemRootState,
FeatureFlag.IsCardanoSendEnabled,
);

if (isCardanoSendEnabled && networkType === 'cardano') return true;

const isSolanaSendEnabled = selectIsFeatureFlagEnabled(state, FeatureFlag.IsSolanaSendEnabled);
const isSolanaSendEnabled = selectIsFeatureFlagEnabled(
state as FeatureFlagsRootState & MessageSystemRootState,
FeatureFlag.IsSolanaEnabled,
);

if (isSolanaSendEnabled && networkType === 'solana') return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const featureFlagsTitleMap = {
[FeatureFlagEnum.IsDeviceConnectEnabled]: 'Connect device',
[FeatureFlagEnum.IsRippleSendEnabled]: 'Ripple send',
[FeatureFlagEnum.IsCardanoSendEnabled]: 'Cardano send',
[FeatureFlagEnum.IsSolanaSendEnabled]: 'Solana send',
[FeatureFlagEnum.IsRegtestEnabled]: 'Regtest',
[FeatureFlagEnum.IsSolanaEnabled]: 'Solana',
[FeatureFlagEnum.IsConnectPopupEnabled]: 'Connect Popup',
Expand Down

0 comments on commit 14d6795

Please sign in to comment.