-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): FW update changelog (#16205)
- Loading branch information
Showing
5 changed files
with
152 additions
and
1 deletion.
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
86 changes: 86 additions & 0 deletions
86
suite-native/module-device-settings/src/screens/FirmwareUpdateScreen/FirmwareChangelog.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,86 @@ | ||
import { useMemo } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { BottomSheet, Button, Text } from '@suite-native/atoms'; | ||
import { selectFirmwareChangelog } from '@suite-common/wallet-core'; | ||
import { Translation } from '@suite-native/intl'; | ||
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||
|
||
type FirmwareChangelogProps = { | ||
isVisible: boolean; | ||
onClose: () => void; | ||
}; | ||
|
||
const changelogSectionTitleTextStyle = prepareNativeStyle(utils => ({ | ||
...utils.typography.highlight, | ||
paddingTop: utils.spacings.sp24, | ||
})); | ||
|
||
const buttonContainerStyle = prepareNativeStyle(utils => ({ | ||
marginTop: utils.spacings.sp32, | ||
})); | ||
|
||
const ChangelogSectionTitle = ({ children }: { children: React.ReactNode }) => { | ||
const { applyStyle } = useNativeStyles(); | ||
|
||
return <Text style={applyStyle(changelogSectionTitleTextStyle)}>{children}</Text>; | ||
}; | ||
|
||
export const FirmwareChangelog = ({ isVisible, onClose }: FirmwareChangelogProps) => { | ||
const firmwareChangelog = useSelector(selectFirmwareChangelog); | ||
const { applyStyle } = useNativeStyles(); | ||
|
||
const formattedChangelog = useMemo(() => { | ||
if (!firmwareChangelog) { | ||
return ( | ||
<Text> | ||
<Translation id="moduleDeviceSettings.firmware.firmwareUpdateScreen.changelog.changelogUnavailable" /> | ||
</Text> | ||
); | ||
} | ||
|
||
let firmwareChangelogLines: string[] = []; | ||
if (typeof firmwareChangelog === 'string') { | ||
firmwareChangelogLines = firmwareChangelog.split('\n'); | ||
} else { | ||
firmwareChangelogLines = firmwareChangelog; | ||
} | ||
|
||
return firmwareChangelogLines.map((text, index) => { | ||
const key = text + index; | ||
|
||
// Match any number of '#' at the start of the line followed by text | ||
if (/^#+\s*(.+)/.test(text)) { | ||
const strippedText = text.replace(/^#+\s*/, '').trim(); | ||
|
||
return <ChangelogSectionTitle key={key}>{strippedText}</ChangelogSectionTitle>; | ||
} | ||
|
||
// Match common list item markers with optional spaces | ||
const listItemRegex = /^\s*[-+*]\s+(.+)/; | ||
if (listItemRegex.test(text)) { | ||
const formattedText = text.replace(listItemRegex, ' • $1'); | ||
|
||
return <Text key={key}>{formattedText}</Text>; | ||
} | ||
|
||
return <Text key={key}>{text}</Text>; | ||
}); | ||
}, [firmwareChangelog]); | ||
|
||
return ( | ||
<BottomSheet isVisible={isVisible} onClose={onClose} isScrollable isCloseDisplayed={false}> | ||
<Text variant="titleSmall" color="textDefault"> | ||
<Translation id="moduleDeviceSettings.firmware.firmwareUpdateScreen.changelog.title" /> | ||
</Text> | ||
{formattedChangelog} | ||
<Button | ||
onPress={onClose} | ||
style={applyStyle(buttonContainerStyle)} | ||
colorScheme="tertiaryElevation0" | ||
> | ||
<Translation id="moduleDeviceSettings.firmware.firmwareUpdateScreen.changelog.closeButton" /> | ||
</Button> | ||
</BottomSheet> | ||
); | ||
}; |
46 changes: 46 additions & 0 deletions
46
...ative/module-device-settings/src/screens/FirmwareUpdateScreen/FirmwareChangelogButton.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,46 @@ | ||
import { TouchableOpacity } from 'react-native'; | ||
import { useState } from 'react'; | ||
|
||
import { Text } from '@suite-native/atoms'; | ||
import { Translation } from '@suite-native/intl'; | ||
import { Icon } from '@suite-native/icons'; | ||
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||
|
||
import { FirmwareChangelog } from './FirmwareChangelog'; | ||
|
||
const linkTextStyle = prepareNativeStyle(utils => ({ | ||
color: utils.colors.textSubdued, | ||
textDecorationLine: 'underline', | ||
})); | ||
|
||
const linkContainerStyle = prepareNativeStyle(_utils => ({ | ||
alignItems: 'center', | ||
flexDirection: 'row', | ||
justifyContent: 'flex-end', | ||
gap: 2, | ||
})); | ||
|
||
export const FirmwareChangelogButton = () => { | ||
const { applyStyle } = useNativeStyles(); | ||
const [isVisible, setIsVisible] = useState(false); | ||
|
||
const handlePress = () => { | ||
setIsVisible(true); | ||
}; | ||
|
||
const handleClose = () => { | ||
setIsVisible(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<TouchableOpacity style={applyStyle(linkContainerStyle)} onPress={handlePress}> | ||
<Icon name="question" size="medium" color="iconSubdued" /> | ||
<Text variant="body" color="textSubdued" style={applyStyle(linkTextStyle)}> | ||
<Translation id="moduleDeviceSettings.firmware.firmwareUpdateScreen.changelog.button" /> | ||
</Text> | ||
</TouchableOpacity> | ||
<FirmwareChangelog isVisible={isVisible} onClose={handleClose} /> | ||
</> | ||
); | ||
}; |
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