@@ -10,6 +10,7 @@ import { AlertCircle, ChevronDown } from "lucide-react-native";
1010import { useCallback , useState } from "react" ;
1111import { COLORS } from "../lib/constants" ;
1212import { useBalance } from "../hooks/useWallet" ;
13+
1314import Animated , {
1415 FadeInDown ,
1516 FadeOutDown ,
@@ -19,10 +20,12 @@ import Animated, {
1920import { NoahSafeAreaView } from "~/components/NoahSafeAreaView" ;
2021import { useBottomTabBarHeight } from "react-native-bottom-tabs" ;
2122import { PLATFORM } from "~/constants" ;
23+ import { useBtcToUsdRate } from "~/hooks/useMarketData" ;
2224
2325const HomeScreen = ( ) => {
2426 const navigation = useNavigation < NativeStackNavigationProp < HomeStackParamList > > ( ) ;
2527 const { data : balance , isFetching, refetch, error } = useBalance ( ) ;
28+ const { data : btcToUsdRate } = useBtcToUsdRate ( ) ;
2629 const [ isOpen , setIsOpen ] = useState ( false ) ;
2730 const bottomTabBarHeight = useBottomTabBarHeight ( ) ;
2831
@@ -31,6 +34,7 @@ const HomeScreen = () => {
3134 } , [ refetch ] ) ;
3235
3336 const totalBalance = balance ? balance . onchain + balance . offchain : 0 ;
37+ const totalBalanceInUsd = btcToUsdRate ? ( totalBalance / 100_000_000 ) * btcToUsdRate : 0 ;
3438 const errorMessage = error instanceof Error ? error . message : String ( error ) ;
3539
3640 const animatedRotation = useAnimatedStyle ( ( ) => {
@@ -77,13 +81,28 @@ const HomeScreen = () => {
7781 < Collapsible open = { isOpen } onOpenChange = { setIsOpen } className = "items-center" >
7882 < CollapsibleTrigger asChild >
7983 < Pressable >
80- < View className = "flex-row items-center space-x-2" >
81- < Text className = "text-4xl font-bold" >
82- { totalBalance . toLocaleString ( ) } sats
83- </ Text >
84- < Animated . View style = { animatedRotation } >
85- < ChevronDown className = "text-white" size = { 28 } />
86- </ Animated . View >
84+ < View className = "items-center" >
85+ { btcToUsdRate ? (
86+ < Text className = "text-2xl text-muted-foreground mb-2" >
87+ $
88+ { totalBalanceInUsd . toLocaleString ( undefined , {
89+ minimumFractionDigits : 2 ,
90+ maximumFractionDigits : 2 ,
91+ } ) }
92+ </ Text >
93+ ) : (
94+ < View className = "h-[32px] mb-2 justify-center" >
95+ < ActivityIndicator color = { COLORS . BITCOIN_ORANGE } />
96+ </ View >
97+ ) }
98+ < View className = "flex-row items-center space-x-2" >
99+ < Text className = "text-4xl font-bold" >
100+ { totalBalance . toLocaleString ( ) } sats
101+ </ Text >
102+ < Animated . View style = { animatedRotation } >
103+ < ChevronDown className = "text-white" size = { 28 } />
104+ </ Animated . View >
105+ </ View >
87106 </ View >
88107 </ Pressable >
89108 </ CollapsibleTrigger >
0 commit comments