@@ -162,25 +162,32 @@ export default function UsernameProfileSectionHeatmap() {
162162 } ;
163163 } ;
164164
165+ type EtherscanApiResponse = {
166+ status : '1' | '0' ;
167+ message : string ;
168+ result : unknown ;
169+ } ;
170+
165171 const fetchTransactions = useCallback (
166172 async ( apiUrl : string , retryCount = 3 ) : Promise < Transaction [ ] > => {
167173 try {
168174 const response = await fetch ( apiUrl ) ;
169- const json = ( await response . json ( ) ) as {
170- data : { result : Transaction [ ] ; status : '1' | '0' ; message : string } ;
171- } ;
175+ const json = ( await response . json ( ) ) as { data : EtherscanApiResponse } ;
176+ const data = json . data ;
177+
178+ if ( data . status === '1' && Array . isArray ( data . result ) ) {
179+ return data . result as Transaction [ ] ;
180+ }
172181
173- if ( json . data ?. status === '1' && Array . isArray ( json . data . result ) ) {
174- return json . data . result ;
175- } else if ( json . data ?. status === '0' && json . data . message === 'No transactions found' ) {
182+ if ( data . status === '0' && data . message === 'No transactions found' ) {
176183 return [ ] ; // Return an empty array for no transactions
177- } else if ( json . data ? .status === '0' && json . data . message === 'Exception' ) {
184+ } else if ( data . status === '0' && data . message === 'Exception' ) {
178185 if ( retryCount > 0 ) {
179186 console . log ( `API returned an exception. Retrying... (${ retryCount } attempts left)` ) ;
180187 await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
181188 return await fetchTransactions ( apiUrl , retryCount - 1 ) ;
182189 } else {
183- throw new Error ( `API Error: ${ json . data . message } ` ) ;
190+ throw new Error ( `API Error: ${ data . message } ` ) ;
184191 }
185192 } else {
186193 console . error ( 'Unexpected API response structure:' , json ) ;
@@ -444,6 +451,7 @@ export default function UsernameProfileSectionHeatmap() {
444451 style = { { direction : 'rtl' } }
445452 className = "w-full max-w-full overflow-x-auto overflow-y-hidden whitespace-nowrap"
446453 >
454+ { /* @ts -expect-error react-calendar-heatmap has incompatible JSX types in our setup; runtime is fine */ }
447455 < CalendarHeatmap
448456 startDate = { new Date ( new Date ( ) . setFullYear ( new Date ( ) . getFullYear ( ) - 1 ) ) }
449457 endDate = { new Date ( ) }
0 commit comments