Skip to content

Commit

Permalink
feat(suite): brightness, protobuff and settings
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson committed May 20, 2024
1 parent c102ca1 commit d4439e8
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 26 deletions.
1 change: 1 addition & 0 deletions packages/connect/src/api/applySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class ApplySettings extends AbstractMethod<'applySettings', PROTO
safety_checks: payload.safety_checks,
experimental_features: payload.experimental_features,
_passphrase_source: payload.passphrase_source,
brightness: payload.brightness,
};
}

Expand Down
10 changes: 9 additions & 1 deletion packages/protobuf/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4566,6 +4566,9 @@
},
"Capability_Translations": {
"(bitcoin_only)": true
},
"Capability_Brightness": {
"(bitcoin_only)": true
}
},
"values": {
Expand All @@ -4587,7 +4590,8 @@
"Capability_ShamirGroups": 16,
"Capability_PassphraseEntry": 17,
"Capability_Solana": 18,
"Capability_Translations": 19
"Capability_Translations": 19,
"Capability_Brightness": 20
}
}
}
Expand Down Expand Up @@ -4657,6 +4661,10 @@
"hide_passphrase_from_host": {
"type": "bool",
"id": 11
},
"brightness": {
"type": "uint32",
"id": 12
}
}
},
Expand Down
18 changes: 10 additions & 8 deletions packages/protobuf/src/messages-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,7 @@ export enum Enum_Capability {
Capability_PassphraseEntry = 17,
Capability_Solana = 18,
Capability_Translations = 19,
Capability_Brightness = 20,
}

export type EnumEnum_Capability = Static<typeof EnumEnum_Capability>;
Expand Down Expand Up @@ -2283,6 +2284,7 @@ export const ApplySettings = Type.Object(
safety_checks: Type.Optional(SafetyCheckLevel),
experimental_features: Type.Optional(Type.Boolean()),
hide_passphrase_from_host: Type.Optional(Type.Boolean()),
brightness: Type.Optional(Type.Number()),
},
{ $id: 'ApplySettings' },
);
Expand Down Expand Up @@ -2818,12 +2820,6 @@ export const NEMDecryptedMessage = Type.Object(
{ $id: 'NEMDecryptedMessage' },
);

export type experimental_message = Static<typeof experimental_message>;
export const experimental_message = Type.Object({}, { $id: 'experimental_message' });

export type experimental_field = Static<typeof experimental_field>;
export const experimental_field = Type.Object({}, { $id: 'experimental_field' });

export type RippleGetAddress = Static<typeof RippleGetAddress>;
export const RippleGetAddress = Type.Object(
{
Expand Down Expand Up @@ -3398,6 +3394,12 @@ export const TezosSignedTx = Type.Object(
{ $id: 'TezosSignedTx' },
);

export type experimental_message = Static<typeof experimental_message>;
export const experimental_message = Type.Object({}, { $id: 'experimental_message' });

export type experimental_field = Static<typeof experimental_field>;
export const experimental_field = Type.Object({}, { $id: 'experimental_field' });

export type MessageType = Static<typeof MessageType>;
export const MessageType = Type.Object(
{
Expand Down Expand Up @@ -3626,8 +3628,6 @@ export const MessageType = Type.Object(
NEMSignedTx,
NEMDecryptMessage,
NEMDecryptedMessage,
experimental_message,
experimental_field,
RippleGetAddress,
RippleAddress,
RipplePayment,
Expand Down Expand Up @@ -3676,6 +3676,8 @@ export const MessageType = Type.Object(
TezosBallotOp,
TezosSignTx,
TezosSignedTx,
experimental_message,
experimental_field,
},
{ $id: 'MessageType' },
);
Expand Down
2 changes: 2 additions & 0 deletions packages/protobuf/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,7 @@ export enum Enum_Capability {
Capability_PassphraseEntry = 17,
Capability_Solana = 18,
Capability_Translations = 19,
Capability_Brightness = 20,
}

export type Capability = keyof typeof Enum_Capability;
Expand Down Expand Up @@ -1632,6 +1633,7 @@ export type ApplySettings = {
safety_checks?: SafetyCheckLevel;
experimental_features?: boolean;
hide_passphrase_from_host?: boolean;
brightness?: number;
};

// ChangeLanguage
Expand Down
6 changes: 6 additions & 0 deletions packages/suite-analytics/src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ export type SuiteAnalyticsEvent =
value: boolean;
};
}
| {
type: EventType.SettingsDeviceChangeBrightness;
payload: {
value: number;
};
}
| { type: EventType.SettingsDeviceWipe }
| {
type: EventType.SettingsDeviceChangePassphraseProtection;
Expand Down
4 changes: 4 additions & 0 deletions packages/suite/src/support/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,10 @@ export default defineMessages({
defaultMessage: 'Display Brightness',
id: 'TR_DEVICE_SETTINGS_BRIGHTNESS_TITLE',
},
TR_DEVICE_SETTINGS_BRIGHTNESS_BUTTON: {
defaultMessage: 'Change Brightness',
id: 'TR_DEVICE_SETTINGS_BRIGHTNESS_BUTTON',
},
TR_DEVICE_SETTINGS_WIPE_CODE_TITLE: {
defaultMessage: 'Set up wipe code',
id: 'TR_DEVICE_SETTINGS_WIPE_CODE_TITLE',
Expand Down
30 changes: 13 additions & 17 deletions packages/suite/src/views/settings/SettingsDevice/Brightness.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Switch } from '@trezor/components';
import { SettingsSectionItem } from 'src/components/settings';
import { ActionColumn, TextColumn, Translation } from 'src/components/suite';
import { ActionButton, ActionColumn, TextColumn, Translation } from 'src/components/suite';
import { SettingsAnchor } from 'src/constants/suite/anchors';
import { useDevice, useDispatch, useSelector } from '../../../hooks/suite';
import { applySettings } from 'src/actions/settings/deviceSettingsActions';
Expand All @@ -16,23 +15,18 @@ export const Brightness = ({ isDeviceLocked }: DeviceLabelProps) => {

const showDebugMenu = useSelector(state => state.suite.settings.debug.showDebugMenu);

const isSupportedDevice = true; //device?.features?.capabilities?.includes('Capability_Brightness');
const isSupportedDevice = device?.features?.capabilities?.includes('Capability_Brightness');

if (!showDebugMenu || !isSupportedDevice) {
return null;
}

const brightnessEnabled = true; // device?.features?.brightness ?? false;
const handleClick = () => {
dispatch(applySettings({ brightness: 0 }));

const handleChange = () => {
dispatch(
applySettings({
// brightness: !brightnessEnabled
}),
);
analytics.report({
type: EventType.SettingsDeviceChangeHapticFeedback,
payload: { value: !brightnessEnabled },
type: EventType.SettingsDeviceChangeBrightness,
payload: { value: 0 },
});
};

Expand All @@ -43,12 +37,14 @@ export const Brightness = ({ isDeviceLocked }: DeviceLabelProps) => {
description={<Translation id="TR_DEVICE_SETTINGS_BRIGHTNESS_DESC" />}
/>
<ActionColumn>
<Switch
isChecked={brightnessEnabled}
onChange={handleChange}
<ActionButton
onClick={handleClick}
isDisabled={isDeviceLocked}
dataTest="@settings/device/brightness-switch"
/>
variant="secondary"
data-test="@settings/device/brightness-switch"
>
<Translation id="TR_DEVICE_SETTINGS_BRIGHTNESS_BUTTON" />
</ActionButton>
</ActionColumn>
</SettingsSectionItem>
);
Expand Down

0 comments on commit d4439e8

Please sign in to comment.