1- import React , { useCallback } from "react" ;
1+ import React , { useCallback , useMemo } from "react" ;
22import { useTranslation } from "react-i18next" ;
33import { Pressable } from "react-native" ;
44import { useSafeAreaInsets } from "react-native-safe-area-context" ;
@@ -39,15 +39,29 @@ export default function Pay() {
3939 const { address } = useAccount ( ) ;
4040 const insets = useSafeAreaInsets ( ) ;
4141 const router = useRouter ( ) ;
42- const { market : exaUSDC } = useAsset ( marketUSDCAddress ) ;
42+ const { market : exaUSDC , timestamp } = useAsset ( marketUSDCAddress ) ;
4343 const { success, output : repayMaturity } = safeParse (
4444 pipe ( string ( ) , nonEmpty ( "no maturity" ) ) ,
4545 useLocalSearchParams ( ) . maturity ,
4646 ) ;
4747
48- const timestamp = Math . floor ( Date . now ( ) / 1000 ) ;
49- const nextMaturity = timestamp - ( timestamp % MATURITY_INTERVAL ) + MATURITY_INTERVAL ;
50- const borrowMaturity = Number ( repayMaturity ) < timestamp ? nextMaturity : Number ( repayMaturity ) + MATURITY_INTERVAL ;
48+ const now = Number ( timestamp ) ;
49+ const nextMaturity = now - ( now % MATURITY_INTERVAL ) + MATURITY_INTERVAL ;
50+ const borrowMaturity = Number ( repayMaturity ) < now ? nextMaturity : Number ( repayMaturity ) + MATURITY_INTERVAL ;
51+ const repayLabel = useMemo (
52+ ( ) =>
53+ new Date ( Number ( repayMaturity ) * 1000 ) . toLocaleDateString ( language , {
54+ year : "numeric" ,
55+ month : "short" ,
56+ day : "numeric" ,
57+ } ) ,
58+ [ repayMaturity , language ] ,
59+ ) ;
60+ const borrowLabel = useMemo (
61+ ( ) =>
62+ new Date ( borrowMaturity * 1000 ) . toLocaleDateString ( language , { year : "numeric" , month : "short" , day : "numeric" } ) ,
63+ [ borrowMaturity , language ] ,
64+ ) ;
5165 const borrow = exaUSDC ?. fixedBorrowPositions . find ( ( b ) => b . maturity === BigInt ( success ? repayMaturity : 0 ) ) ;
5266 const rolloverMaturityBorrow = exaUSDC ?. fixedBorrowPositions . find ( ( b ) => b . maturity === BigInt ( borrowMaturity ) ) ;
5367
@@ -99,13 +113,7 @@ export default function Pay() {
99113 { t ( "Debt to rollover" ) }
100114 </ Text >
101115 < Text secondary footnote textAlign = "left" >
102- { t ( "due {{date}}" , {
103- date : new Date ( Number ( repayMaturity ) * 1000 ) . toLocaleDateString ( language , {
104- year : "numeric" ,
105- month : "short" ,
106- day : "numeric" ,
107- } ) ,
108- } ) }
116+ { t ( "due {{date}}" , { date : repayLabel } ) }
109117 </ Text >
110118 </ YStack >
111119 < Text primary title3 textAlign = "right" >
@@ -127,7 +135,7 @@ export default function Pay() {
127135 rate : (
128136 Number (
129137 ( ( borrowPreview . assets - borrow . previewValue ) * WAD * 31_536_000n ) /
130- ( borrow . previewValue * ( borrowPreview . maturity - BigInt ( timestamp ) ) ) ,
138+ ( borrow . previewValue * ( borrowPreview . maturity - timestamp ) ) ,
131139 ) /
132140 1e18 /
133141 100
@@ -156,13 +164,7 @@ export default function Pay() {
156164 { t ( "Current debt" ) }
157165 </ Text >
158166 < Text secondary footnote textAlign = "left" >
159- { t ( "due {{date}}" , {
160- date : new Date ( borrowMaturity * 1000 ) . toLocaleDateString ( language , {
161- year : "numeric" ,
162- month : "short" ,
163- day : "numeric" ,
164- } ) ,
165- } ) }
167+ { t ( "due {{date}}" , { date : borrowLabel } ) }
166168 </ Text >
167169 </ YStack >
168170 < Text primary title3 textAlign = "right" >
@@ -180,11 +182,7 @@ export default function Pay() {
180182 { t ( "Total after rollover" ) }
181183 </ Text >
182184 < Text secondary footnote textAlign = "left" >
183- { new Date ( borrowMaturity * 1000 ) . toLocaleDateString ( language , {
184- year : "numeric" ,
185- month : "short" ,
186- day : "numeric" ,
187- } ) }
185+ { borrowLabel }
188186 </ Text >
189187 </ YStack >
190188 < Text title color = "$uiBrandSecondary" textAlign = "right" >
0 commit comments