|
| 1 | +import React, { ReactElement } from 'react'; |
| 2 | +import { Platform, StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; |
| 3 | + |
| 4 | +import { useTranslation } from 'react-i18next'; |
| 5 | +import { useDisplayValues } from '../../hooks/displayValues'; |
| 6 | +import useWeatherWidget from '../../hooks/weatherWidget'; |
| 7 | +import { BodyM, BodyMSB, BodySSB, Title } from '../../styles/text'; |
| 8 | +import BaseWidget from './BaseWidget'; |
| 9 | + |
| 10 | +type TWeatherWidgetOptions = { |
| 11 | + showStatus: boolean; |
| 12 | + showText: boolean; |
| 13 | + showMedian: boolean; |
| 14 | + showNextBlockFee: boolean; |
| 15 | +}; |
| 16 | + |
| 17 | +const WeatherWidget = ({ |
| 18 | + options, |
| 19 | + isEditing = false, |
| 20 | + style, |
| 21 | + testID, |
| 22 | + onPressIn, |
| 23 | + onLongPress, |
| 24 | +}: { |
| 25 | + options: TWeatherWidgetOptions; |
| 26 | + isEditing?: boolean; |
| 27 | + style?: StyleProp<ViewStyle>; |
| 28 | + testID?: string; |
| 29 | + onPressIn?: () => void; |
| 30 | + onLongPress?: () => void; |
| 31 | +}): ReactElement => { |
| 32 | + const { t } = useTranslation('widgets'); |
| 33 | + const { data } = useWeatherWidget(); |
| 34 | + const { condition, currentFee, nextBlockFee } = data; |
| 35 | + const currentFeeFiat = useDisplayValues(currentFee); |
| 36 | + |
| 37 | + return ( |
| 38 | + <BaseWidget |
| 39 | + id="weather" |
| 40 | + // isLoading={status === 'loading'} |
| 41 | + isEditing={isEditing} |
| 42 | + style={style} |
| 43 | + testID={testID} |
| 44 | + onPressIn={onPressIn} |
| 45 | + onLongPress={onLongPress}> |
| 46 | + <View style={styles.container}> |
| 47 | + {options.showStatus && ( |
| 48 | + <View style={styles.condition}> |
| 49 | + <Title style={styles.conditionText}> |
| 50 | + {t(`weather.condition.${condition}.title`)} |
| 51 | + </Title> |
| 52 | + |
| 53 | + <Title style={styles.conditionIcon}> |
| 54 | + {condition === 'good' && '☀️'} |
| 55 | + {condition === 'average' && '⛅'} |
| 56 | + {condition === 'poor' && '⛈️'} |
| 57 | + </Title> |
| 58 | + </View> |
| 59 | + )} |
| 60 | + |
| 61 | + {options.showText && ( |
| 62 | + <BodyM>{t(`weather.condition.${condition}.description`)}</BodyM> |
| 63 | + )} |
| 64 | + |
| 65 | + {(options.showMedian || options.showNextBlockFee) && ( |
| 66 | + <View style={styles.rows}> |
| 67 | + {options.showMedian && ( |
| 68 | + <View style={styles.row}> |
| 69 | + <View style={styles.columnLeft}> |
| 70 | + <BodySSB color="secondary" numberOfLines={1}> |
| 71 | + {t('weather.current_fee')} |
| 72 | + </BodySSB> |
| 73 | + </View> |
| 74 | + <View style={styles.columnRight}> |
| 75 | + <BodyMSB numberOfLines={1}> |
| 76 | + {currentFeeFiat.fiatSymbol} {currentFeeFiat.fiatFormatted} |
| 77 | + </BodyMSB> |
| 78 | + </View> |
| 79 | + </View> |
| 80 | + )} |
| 81 | + |
| 82 | + {options.showNextBlockFee && ( |
| 83 | + <View style={styles.row}> |
| 84 | + <View style={styles.columnLeft}> |
| 85 | + <BodySSB color="secondary" numberOfLines={1}> |
| 86 | + {t('weather.next_block')} |
| 87 | + </BodySSB> |
| 88 | + </View> |
| 89 | + <View style={styles.columnRight}> |
| 90 | + <BodyMSB numberOfLines={1}>{nextBlockFee} bitcoin/vB</BodyMSB> |
| 91 | + </View> |
| 92 | + </View> |
| 93 | + )} |
| 94 | + </View> |
| 95 | + )} |
| 96 | + </View> |
| 97 | + </BaseWidget> |
| 98 | + ); |
| 99 | +}; |
| 100 | + |
| 101 | +const styles = StyleSheet.create({ |
| 102 | + container: { |
| 103 | + flex: 1, |
| 104 | + gap: 16, |
| 105 | + }, |
| 106 | + condition: { |
| 107 | + flexDirection: 'row', |
| 108 | + alignItems: 'center', |
| 109 | + justifyContent: 'space-between', |
| 110 | + }, |
| 111 | + conditionText: { |
| 112 | + fontSize: 34, |
| 113 | + fontWeight: 'bold', |
| 114 | + lineHeight: 34, |
| 115 | + letterSpacing: 0, |
| 116 | + maxWidth: '70%', |
| 117 | + }, |
| 118 | + conditionIcon: { |
| 119 | + height: 100, |
| 120 | + marginTop: 0, |
| 121 | + paddingTop: 16, |
| 122 | + paddingBottom: -16, |
| 123 | + ...Platform.select({ |
| 124 | + ios: { |
| 125 | + fontSize: 100, |
| 126 | + lineHeight: 100, |
| 127 | + }, |
| 128 | + android: { |
| 129 | + fontSize: 85, |
| 130 | + lineHeight: 85, |
| 131 | + }, |
| 132 | + }), |
| 133 | + }, |
| 134 | + rows: { |
| 135 | + gap: 8, |
| 136 | + }, |
| 137 | + row: { |
| 138 | + flexDirection: 'row', |
| 139 | + alignItems: 'center', |
| 140 | + justifyContent: 'space-between', |
| 141 | + minHeight: 20, |
| 142 | + }, |
| 143 | + columnLeft: { |
| 144 | + flex: 1, |
| 145 | + flexDirection: 'row', |
| 146 | + alignItems: 'center', |
| 147 | + }, |
| 148 | + columnRight: { |
| 149 | + flex: 1, |
| 150 | + flexDirection: 'row', |
| 151 | + alignItems: 'center', |
| 152 | + justifyContent: 'flex-end', |
| 153 | + }, |
| 154 | +}); |
| 155 | + |
| 156 | +export default WeatherWidget; |
0 commit comments