@@ -11,6 +11,7 @@ import { useFocusEffect, useNavigation } from '@react-navigation/native';
1111import type { NativeStackNavigationProp } from '@react-navigation/native-stack' ;
1212
1313import { PointHistoryList } from '@/components/PointHistoryList' ;
14+ import { useIncomingPoints , usePoints } from '@/hooks/usePoints' ;
1415import BellWhiteIcon from '@/images/icons/bell_white.svg' ;
1516import ClockIcon from '@/images/icons/clock.svg' ;
1617import LockWhiteIcon from '@/images/icons/lock_white.svg' ;
@@ -36,24 +37,17 @@ import {
3637} from '@/utils/notifications/notificationService' ;
3738import {
3839 formatTimeUntilDate ,
39- getIncomingPoints ,
40- getPointsAddress ,
41- getTotalPoints ,
42- type IncomingPoints ,
4340 recordBackupPointEvent ,
4441 recordNotificationPointEvent ,
4542} from '@/utils/points' ;
4643
4744const Points : React . FC = ( ) => {
48- const [ selfPoints , setSelfPoints ] = useState ( 0 ) ;
4945 const { bottom } = useSafeAreaInsets ( ) ;
5046 const navigation =
5147 useNavigation < NativeStackNavigationProp < RootStackParamList > > ( ) ;
5248 const [ isNovaSubscribed , setIsNovaSubscribed ] = useState ( false ) ;
5349 const [ isEnabling , setIsEnabling ] = useState ( false ) ;
54- const [ incomingPoints , setIncomingPoints ] = useState < IncomingPoints | null > (
55- null ,
56- ) ;
50+ const incomingPoints = useIncomingPoints ( ) ;
5751 const loadEvents = usePointEventStore ( state => state . loadEvents ) ;
5852 const { hasCompletedBackupForPoints, setBackupForPointsCompleted } =
5953 useSettingStore ( ) ;
@@ -85,14 +79,7 @@ const Points: React.FC = () => {
8579 loadEvents ( ) ;
8680 } , [ loadEvents ] ) ;
8781
88- useEffect ( ( ) => {
89- const fetchPoints = async ( ) => {
90- const address = await getPointsAddress ( ) ;
91- const points = await getTotalPoints ( address ) ;
92- setSelfPoints ( points ) ;
93- } ;
94- fetchPoints ( ) ;
95- } , [ ] ) ;
82+ const points = usePoints ( ) ;
9683
9784 useEffect ( ( ) => {
9885 const checkSubscription = async ( ) => {
@@ -102,14 +89,6 @@ const Points: React.FC = () => {
10289 checkSubscription ( ) ;
10390 } , [ ] ) ;
10491
105- useEffect ( ( ) => {
106- const fetchIncomingPoints = async ( ) => {
107- const incoming = await getIncomingPoints ( ) ;
108- setIncomingPoints ( incoming ) ;
109- } ;
110- fetchIncomingPoints ( ) ;
111- } , [ ] ) ;
112-
11392 const handleContentLayout = ( ) => {
11493 if ( ! isContentReady ) {
11594 setIsContentReady ( true ) ;
@@ -211,15 +190,12 @@ const Points: React.FC = () => {
211190
212191 setIsBackingUp ( true ) ;
213192 try {
193+ // this will add event to store and the new event will then trigger useIncomingPoints hook to refetch incoming points
214194 const response = await recordBackupPointEvent ( ) ;
215195
216196 if ( response . success ) {
217197 setBackupForPointsCompleted ( ) ;
218198
219- const address = await getPointsAddress ( ) ;
220- const points = await getTotalPoints ( address ) ;
221- setSelfPoints ( points ) ;
222-
223199 if ( listRefreshRef . current ) {
224200 await listRefreshRef . current ( ) ;
225201 }
@@ -296,22 +272,14 @@ const Points: React.FC = () => {
296272 < XStack gap = { 4 } alignItems = "center" >
297273 < Text
298274 color = { black }
275+ textAlign = "center"
299276 fontFamily = "DIN OT"
300277 fontWeight = "500"
301278 fontSize = { 32 }
302279 lineHeight = { 32 }
303280 letterSpacing = { - 1 }
304281 >
305- { `${ selfPoints } Self ` }
306- </ Text >
307- < Text
308- fontFamily = "DIN OT"
309- fontWeight = "500"
310- fontSize = { 32 }
311- lineHeight = { 32 }
312- letterSpacing = { - 1 }
313- >
314- points
282+ { `${ points } Self points` }
315283 </ Text >
316284 </ XStack >
317285 < Text
0 commit comments