-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
140 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
80 changes: 80 additions & 0 deletions
80
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,80 @@ | ||
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> | ||
); | ||
} | ||
|
||
if (typeof firmwareChangelog === 'string') { | ||
return <Text>{firmwareChangelog}</Text>; | ||
} | ||
|
||
return firmwareChangelog.map((text, index) => { | ||
const key = text + index; | ||
|
||
if (text.startsWith('#')) { | ||
const strippedText = text.replaceAll('#', '').trim(); | ||
|
||
return <ChangelogSectionTitle key={key}>{strippedText}</ChangelogSectionTitle>; | ||
} | ||
|
||
let formattedText = text; | ||
|
||
if (text.startsWith(' - ')) { | ||
formattedText = formattedText.replace(' - ', ' • '); | ||
} | ||
|
||
return <Text key={key}>{formattedText}</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="generic.buttons.close" /> | ||
</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