-
-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite): haptic-feedback settings, brightness settings
(cherry picked from commit ad333dd)
- Loading branch information
1 parent
f879a64
commit b032b45
Showing
11 changed files
with
183 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// origin: https://github.com/trezor/connect/blob/develop/src/js/core/methods/SetBrightness.js | ||
|
||
import { AbstractMethod } from '../core/AbstractMethod'; | ||
import { PROTO } from '../constants'; | ||
import { Assert } from '@trezor/schema-utils'; | ||
|
||
export default class SetBrightness extends AbstractMethod<'setBrightness', PROTO.SetBrightness> { | ||
init() { | ||
this.requiredPermissions = ['management']; | ||
this.useDeviceState = false; | ||
const { payload } = this; | ||
|
||
Assert(PROTO.SetBrightness, payload); | ||
|
||
this.params = { | ||
value: payload.value, | ||
}; | ||
} | ||
|
||
async run() { | ||
const cmd = this.device.getCommands(); | ||
const response = await cmd.typedCall('SetBrightness', 'Success', this.params); | ||
|
||
return response.message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PROTO } from '../../constants'; | ||
import type { Params, Response } from '../params'; | ||
|
||
export declare function setBrightness(params: Params<PROTO.SetBrightness>): Response<PROTO.Success>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/suite/src/views/settings/SettingsDevice/Brightness.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import TrezorConnect from '@trezor/connect'; | ||
import { analytics, EventType } from '@trezor/suite-analytics'; | ||
import { SettingsSectionItem } from 'src/components/settings'; | ||
import { ActionButton, ActionColumn, TextColumn, Translation } from 'src/components/suite'; | ||
import { SettingsAnchor } from 'src/constants/suite/anchors'; | ||
import { useDevice, useSelector } from '../../../hooks/suite'; | ||
|
||
interface DeviceLabelProps { | ||
isDeviceLocked: boolean; | ||
} | ||
|
||
export const Brightness = ({ isDeviceLocked }: DeviceLabelProps) => { | ||
const { device } = useDevice(); | ||
|
||
const showDebugMenu = useSelector(state => state.suite.settings.debug.showDebugMenu); | ||
|
||
const isSupportedDevice = device?.features?.capabilities?.includes('Capability_Brightness'); | ||
|
||
if (!showDebugMenu || !isSupportedDevice) { | ||
return null; | ||
} | ||
|
||
const handleClick = async () => { | ||
const result = await TrezorConnect.setBrightness({}); | ||
if (result.success) { | ||
analytics.report({ | ||
type: EventType.SettingsDeviceChangeBrightness, | ||
payload: {}, | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<SettingsSectionItem anchorId={SettingsAnchor.PinProtection}> | ||
<TextColumn | ||
title={<Translation id="TR_DEVICE_SETTINGS_BRIGHTNESS_TITLE" />} | ||
description={<Translation id="TR_DEVICE_SETTINGS_BRIGHTNESS_DESC" />} | ||
/> | ||
<ActionColumn> | ||
<ActionButton | ||
onClick={handleClick} | ||
isDisabled={isDeviceLocked} | ||
variant="secondary" | ||
data-test="@settings/device/brightness-switch" | ||
> | ||
<Translation id="TR_DEVICE_SETTINGS_BRIGHTNESS_BUTTON" /> | ||
</ActionButton> | ||
</ActionColumn> | ||
</SettingsSectionItem> | ||
); | ||
}; |
52 changes: 52 additions & 0 deletions
52
packages/suite/src/views/settings/SettingsDevice/HapticFeedback.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Switch } from '@trezor/components'; | ||
import { SettingsSectionItem } from 'src/components/settings'; | ||
import { ActionColumn, TextColumn, Translation } from 'src/components/suite'; | ||
import { SettingsAnchor } from 'src/constants/suite/anchors'; | ||
import { useDevice, useDispatch } from '../../../hooks/suite'; | ||
import { applySettings } from 'src/actions/settings/deviceSettingsActions'; | ||
import { analytics, EventType } from '@trezor/suite-analytics'; | ||
|
||
interface DeviceLabelProps { | ||
isDeviceLocked: boolean; | ||
} | ||
|
||
export const HapticFeedback = ({ isDeviceLocked }: DeviceLabelProps) => { | ||
const dispatch = useDispatch(); | ||
const { device } = useDevice(); | ||
|
||
const isSupportedDevice = device?.features?.capabilities?.includes('Capability_Haptic'); | ||
|
||
if (!isSupportedDevice) { | ||
return null; | ||
} | ||
|
||
const hapticEnabled = device?.features?.haptic_feedback ?? false; | ||
|
||
const handleChange = async () => { | ||
const result = await dispatch(applySettings({ haptic_feedback: !hapticEnabled })); | ||
|
||
if (result?.success) { | ||
analytics.report({ | ||
type: EventType.SettingsDeviceChangeHapticFeedback, | ||
payload: { value: !hapticEnabled }, | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<SettingsSectionItem anchorId={SettingsAnchor.PinProtection}> | ||
<TextColumn | ||
title={<Translation id="TR_DEVICE_SETTINGS_HAPTIC_FEEDBACK_TITLE" />} | ||
description={<Translation id="TR_DEVICE_SETTINGS_HAPTIC_FEEDBACK_DESC" />} | ||
/> | ||
<ActionColumn> | ||
<Switch | ||
isChecked={hapticEnabled} | ||
onChange={handleChange} | ||
isDisabled={isDeviceLocked} | ||
dataTest="@settings/device/haptic-switch" | ||
/> | ||
</ActionColumn> | ||
</SettingsSectionItem> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters