Skip to content

Commit

Permalink
feat(mobile): remote feature flag for FW update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodonisko committed Jan 13, 2025
1 parent d989b4e commit b512d83
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 7 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 @@ -25,6 +25,7 @@ export const Feature = {
ethClaim: 'eth.staking.claim',
firmwareRevisionCheck: 'security.firmware.check',
firmwareHashCheck: 'security.firmware.hashCheck',
firmwareUpdate: 'device.firmware.update',
} as const;

export type FeatureDomain = (typeof Feature)[keyof typeof Feature];
Expand Down
1 change: 1 addition & 0 deletions suite-native/firmware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@shopify/react-native-skia": "^1.5.10",
"@suite-common/firmware": "workspace:*",
"@suite-common/icons": "workspace:*",
"@suite-common/message-system": "workspace:*",
"@suite-native/link": "workspace:*",
"@trezor/connect": "workspace:*",
"@trezor/react-native-usb": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useSelector } from 'react-redux';

import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags';
import {
selectIsFeatureEnabled,
Feature,
MessageSystemRootState,
} from '@suite-common/message-system';

export const useIsFirmwareUpdateFeatureEnabled = () => {
const localFeatureFlag = useFeatureFlag(FeatureFlag.IsFirmwareUpdateEnabled);
const remoteFeatureFlag = useSelector((state: MessageSystemRootState) =>
selectIsFeatureEnabled(state, Feature.firmwareUpdate, true),
);

const isFirmwareUpdateEnabled = localFeatureFlag && remoteFeatureFlag;

return isFirmwareUpdateEnabled;
};
1 change: 1 addition & 0 deletions suite-native/firmware/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './nativeFirmwareSlice';
export * from './components/UpdateProgressIndicatorDemo';
export * from './screens/FirmwareUpdateInProgressScreen';
export * from './hooks/useIsFirmwareUpdateFeatureEnabled';
3 changes: 3 additions & 0 deletions suite-native/firmware/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"references": [
{ "path": "../../suite-common/firmware" },
{ "path": "../../suite-common/icons" },
{
"path": "../../suite-common/message-system"
},
{ "path": "../link" },
{ "path": "../../packages/connect" },
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
DeviceSettingsStackParamList,
} from '@suite-native/navigation';
import { isDevelopOrDebugEnv } from '@suite-native/config';
import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags';
import { useIsFirmwareUpdateFeatureEnabled } from '@suite-native/firmware';

import { DeviceSettingsCardLayout } from './DeviceSettingsCardLayout';

Expand Down Expand Up @@ -66,7 +66,7 @@ export const DeviceFirmwareCard = () => {
selectIsDiscoveryActiveByDeviceState(state, device?.state),
);
const navigation = useNavigation<NavigationProp>();
const isFirmwareUpdateEnabled = useFeatureFlag(FeatureFlag.IsFirmwareUpdateEnabled);
const isFirmwareUpdateEnabled = useIsFirmwareUpdateFeatureEnabled();

if (!device || !deviceModel) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
selectDeviceState,
} from '@suite-common/wallet-core';
import { useAlert } from '@suite-native/alerts';
import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags';
import { useIsFirmwareUpdateFeatureEnabled } from '@suite-native/firmware';

import { FirmwareUpdateVersionCard } from './FirmwareVersionCard';

Expand All @@ -43,7 +43,7 @@ export const FirmwareUpdateScreen = () => {
const isDiscoveryRunning = useSelector((state: DiscoveryRootState & DeviceRootState) =>
selectIsDiscoveryActiveByDeviceState(state, deviceState),
);
const isFirmwareUpdateEnabled = useFeatureFlag(FeatureFlag.IsFirmwareUpdateEnabled);
const isFirmwareUpdateEnabled = useIsFirmwareUpdateFeatureEnabled();

const handleShowSeedBottomSheet = useCallback(() => {
showAlert({
Expand All @@ -68,7 +68,7 @@ export const FirmwareUpdateScreen = () => {
<Button
onPress={handleShowSeedBottomSheet}
style={applyStyle(firmwareUpdateButtonStyle)}
isDisabled={isDiscoveryRunning || isFirmwareUpdateEnabled}
isDisabled={isDiscoveryRunning || !isFirmwareUpdateEnabled}
isLoading={isDiscoveryRunning}
>
<Translation id="moduleDeviceSettings.firmware.firmwareUpdateScreen.updateButton" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
DeviceStackRoutes,
} from '@suite-native/navigation';
import { Translation } from '@suite-native/intl';
import { FeatureFlag, useFeatureFlag } from '@suite-native/feature-flags';
import { useIsFirmwareUpdateFeatureEnabled } from '@suite-native/firmware';

const containerStyle = prepareNativeStyle(utils => ({
flexDirection: 'row',
Expand Down Expand Up @@ -76,7 +76,7 @@ export const FirmwareUpdateAlert = () => {
);

const isClosed = useAtomValue(isClosedAtom);
const isFirmwareUpdateEnabled = useFeatureFlag(FeatureFlag.IsFirmwareUpdateEnabled);
const isFirmwareUpdateEnabled = useIsFirmwareUpdateFeatureEnabled();

const isUpgradable = deviceReleaseInfo?.isNewer;

Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10341,6 +10341,7 @@ __metadata:
"@shopify/react-native-skia": "npm:^1.5.10"
"@suite-common/firmware": "workspace:*"
"@suite-common/icons": "workspace:*"
"@suite-common/message-system": "workspace:*"
"@suite-native/link": "workspace:*"
"@trezor/connect": "workspace:*"
"@trezor/react-native-usb": "workspace:*"
Expand Down

0 comments on commit b512d83

Please sign in to comment.