-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: balance history tooltip (#268)
- Loading branch information
Showing
57 changed files
with
405 additions
and
63 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
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
49 changes: 49 additions & 0 deletions
49
src/screens/HomeFlow/BalanceHistory/components/PagerHeader/components/InfoButton.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,49 @@ | ||
// SPDX-License-Identifier: ice License 1.0 | ||
|
||
import {Touchable} from '@components/Touchable'; | ||
import {COLORS} from '@constants/colors'; | ||
import {SMALL_BUTTON_HIT_SLOP} from '@constants/styles'; | ||
import {Coordinates} from '@screens/Modals/types'; | ||
import {InfoOutlineIcon} from '@svg/InfoOutlineIcon'; | ||
import {isRTL} from '@translations/i18n'; | ||
import React, {useRef} from 'react'; | ||
import {StyleSheet, TouchableOpacity} from 'react-native'; | ||
import {rem} from 'rn-units'; | ||
|
||
type Props = { | ||
onInfoIconPressed?: (coordinates: Coordinates) => void; | ||
}; | ||
|
||
const ICON_SIZE = rem(10); | ||
|
||
export function InfoButton({onInfoIconPressed}: Props) { | ||
const buttonRef = useRef<TouchableOpacity>(null); | ||
|
||
const onInfoPress = () => { | ||
buttonRef.current?.measure((_, __, width, height, x, y) => { | ||
onInfoIconPressed?.({ | ||
top: y + height, | ||
left: x + width / 2, | ||
}); | ||
}); | ||
}; | ||
return onInfoIconPressed ? ( | ||
<Touchable | ||
ref={buttonRef} | ||
hitSlop={SMALL_BUTTON_HIT_SLOP} | ||
onPress={onInfoPress}> | ||
<InfoOutlineIcon | ||
style={styles.infoButton} | ||
color={COLORS.shamrock} | ||
width={ICON_SIZE} | ||
height={ICON_SIZE} | ||
/> | ||
</Touchable> | ||
) : null; | ||
} | ||
const styles = StyleSheet.create({ | ||
infoButton: { | ||
marginLeft: isRTL ? 0 : rem(4), | ||
marginRight: isRTL ? rem(4) : 0, | ||
}, | ||
}); |
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
142 changes: 142 additions & 0 deletions
142
src/screens/Modals/BalanceHistoryTooltip/components/Tooltip/index.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,142 @@ | ||
// SPDX-License-Identifier: ice License 1.0 | ||
|
||
import {COLORS} from '@constants/colors'; | ||
import {commonStyles, windowHeight, windowWidth} from '@constants/styles'; | ||
import {Coordinates} from '@screens/Modals/types'; | ||
import {balanceSummarySelector} from '@store/modules/Tokenomics/selectors'; | ||
import {RoundedTriangle} from '@svg/RoundedTriangle'; | ||
import {isRTL, t} from '@translations/i18n'; | ||
import {formatNumberString, parseNumber} from '@utils/numbers'; | ||
import {font} from '@utils/styles'; | ||
import React, {memo, useRef} from 'react'; | ||
import {StyleSheet, Text, View, ViewStyle} from 'react-native'; | ||
import {LayoutChangeEvent} from 'react-native/Libraries/Types/CoreEventTypes'; | ||
import {useSelector} from 'react-redux'; | ||
import {rem} from 'rn-units'; | ||
|
||
type Props = { | ||
coordinates: Coordinates; | ||
}; | ||
|
||
export const ROUNDED_TRIANGLE_SIZE = rem(20); | ||
|
||
function getRight(coordinates: Coordinates) { | ||
return ( | ||
coordinates.right ?? (coordinates.left ? windowWidth - coordinates.left : 0) | ||
); | ||
} | ||
function getTop(coordinates: Coordinates) { | ||
return ( | ||
coordinates.top ?? | ||
(coordinates.bottom ? windowHeight - coordinates.bottom : 0) | ||
); | ||
} | ||
|
||
const CELLS_NUMBER = 2; | ||
|
||
export const Tooltip = memo(({coordinates}: Props) => { | ||
const balanceSummary = useSelector(balanceSummarySelector); | ||
const right = getRight(coordinates); | ||
|
||
const maxWidthRef = useRef(0); | ||
const numberCellsToRenderRef = useRef(CELLS_NUMBER); | ||
const [cellDynamicStyle, setCellDynamicStyle] = | ||
React.useState<ViewStyle | null>(null); | ||
const onCellLayout = ({nativeEvent}: LayoutChangeEvent) => { | ||
maxWidthRef.current = Math.max( | ||
maxWidthRef.current, | ||
nativeEvent.layout.width, | ||
); | ||
numberCellsToRenderRef.current -= 1; | ||
if (!numberCellsToRenderRef.current) { | ||
setCellDynamicStyle({ | ||
width: maxWidthRef.current, | ||
}); | ||
} | ||
}; | ||
return ( | ||
<View | ||
style={[ | ||
styles.mainContainer, | ||
commonStyles.shadow, | ||
{ | ||
top: getTop(coordinates) + ROUNDED_TRIANGLE_SIZE, | ||
right: isRTL ? (windowWidth - right) / 2 : right / 2, | ||
}, | ||
]}> | ||
<RoundedTriangle | ||
fill={COLORS.gulfBlue} | ||
width={ROUNDED_TRIANGLE_SIZE} | ||
height={ROUNDED_TRIANGLE_SIZE} | ||
style={[ | ||
styles.arrow, | ||
{ | ||
right: isRTL | ||
? (windowWidth - right) / 2 - ROUNDED_TRIANGLE_SIZE / 2 - rem(3) | ||
: right / 2 - ROUNDED_TRIANGLE_SIZE / 2 - rem(2), | ||
}, | ||
]} | ||
/> | ||
<View style={[styles.cell, cellDynamicStyle]} onLayout={onCellLayout}> | ||
<Text style={styles.labelText}>{t('balance_history.you')}</Text> | ||
<Text style={styles.valueText}> | ||
{balanceSummary && | ||
formatNumberString( | ||
String( | ||
parseNumber(balanceSummary.totalMiningBlockchain) - | ||
parseNumber( | ||
balanceSummary.totalMainnetRewardPoolContribution, | ||
), | ||
), | ||
{minimumFractionDigits: 0, maximumFractionDigits: 0}, | ||
)} | ||
</Text> | ||
</View> | ||
<View style={styles.cellSeparator} /> | ||
<View style={[styles.cell, cellDynamicStyle]} onLayout={onCellLayout}> | ||
<Text style={styles.labelText}> | ||
{t('balance_history.contribution')} | ||
</Text> | ||
<Text style={styles.valueText}> | ||
{balanceSummary && | ||
formatNumberString( | ||
balanceSummary.totalMainnetRewardPoolContribution, | ||
{minimumFractionDigits: 0, maximumFractionDigits: 0}, | ||
)} | ||
</Text> | ||
</View> | ||
</View> | ||
); | ||
}); | ||
|
||
const styles = StyleSheet.create({ | ||
mainContainer: { | ||
backgroundColor: COLORS.midnightSapphire, | ||
position: 'absolute', | ||
borderRadius: rem(12), | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}, | ||
cell: { | ||
minWidth: rem(100), | ||
padding: rem(10), | ||
alignItems: 'center', | ||
}, | ||
cellSeparator: { | ||
width: 1, | ||
backgroundColor: COLORS.periwinkleGray, | ||
height: '80%', | ||
}, | ||
labelText: { | ||
...font(10, 14, 'regular', 'white', 'center'), | ||
textTransform: 'uppercase', | ||
opacity: 0.7, | ||
}, | ||
valueText: { | ||
...font(14, 20, 'bold'), | ||
}, | ||
arrow: { | ||
position: 'absolute', | ||
top: -ROUNDED_TRIANGLE_SIZE + rem(4), | ||
}, | ||
}); |
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,29 @@ | ||
// SPDX-License-Identifier: ice License 1.0 | ||
|
||
import {commonStyles} from '@constants/styles'; | ||
import {HomeTabStackParamList, MainStackParamList} from '@navigation/Main'; | ||
import {RouteProp, useNavigation, useRoute} from '@react-navigation/native'; | ||
import {NativeStackNavigationProp} from '@react-navigation/native-stack'; | ||
import {Tooltip} from '@screens/Modals/BalanceHistoryTooltip/components/Tooltip'; | ||
import React, {memo} from 'react'; | ||
import {TouchableWithoutFeedback, View} from 'react-native'; | ||
|
||
export const BalanceHistoryTooltip = memo(() => { | ||
const navigation = | ||
useNavigation<NativeStackNavigationProp<HomeTabStackParamList>>(); | ||
const { | ||
params: {coords}, | ||
} = useRoute<RouteProp<MainStackParamList, 'BalanceHistoryTooltip'>>(); | ||
|
||
const closeMenu = () => { | ||
navigation.goBack(); | ||
}; | ||
|
||
return ( | ||
<TouchableWithoutFeedback onPress={closeMenu}> | ||
<View style={commonStyles.flexOne}> | ||
<Tooltip coordinates={coords} /> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
); | ||
}); |
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,8 @@ | ||
// SPDX-License-Identifier: ice License 1.0 | ||
|
||
export type Coordinates = { | ||
top?: number; | ||
right?: number; | ||
bottom?: number; | ||
left?: number; | ||
}; |
Oops, something went wrong.