@@ -4,6 +4,7 @@ import cache from 'memory-cache';
44import { BigNumber } from 'ethers' ;
55import { fetchRetry } from '../utils' ;
66import { NETWORK_LIST } from '../constants' ;
7+ import * as Sentry from '@sentry/react' ;
78export interface UserOp {
89 id : string | null ;
910 transactionHash : string | null ;
@@ -444,29 +445,36 @@ export const getTopPaymasters = async (
444445
445446export const getTopBundlers = async ( selectedNetwork : string , pageSize : number , pageNo : number , toast : any ) : Promise < Bundler [ ] > => {
446447 if ( ! performApiCall ( selectedNetwork ) ) return [ ] as Bundler [ ] ;
447- const response = await fetch (
448- API_URL +
449- '/v0/getTopBundlers?network=' +
450- selectedNetwork +
451- '&first=' +
452- pageSize +
453- '&skip=' +
454- ( pageNo * pageSize >= 0 ? pageNo * pageSize : 0 ) ,
455- {
456- headers : { 'x-api-key' : 'gFQghtJC6F734nPaUYK8M3ggf9TOpojkbNTH9gR5' } ,
457- } ,
458- ) ;
459- if ( response . status != 200 ) {
460- showToast ( toast , 'Error fetching data' ) ;
461- }
462- const data = await response . json ( ) ;
463- if ( 'bundlers' in data ) {
464- if ( data . bundlers . length == 0 ) {
465- showToast ( toast , 'No data found' ) ;
448+ try {
449+ const response = await fetch (
450+ API_URL +
451+ '/v0/getTopBundlers?network=' +
452+ selectedNetwork +
453+ '&first=' +
454+ pageSize +
455+ '&skip=' +
456+ ( pageNo * pageSize >= 0 ? pageNo * pageSize : 0 ) ,
457+ {
458+ headers : { 'x-api-key' : 'gFQghtJC6F734nPaUYK8M3ggf9TOpojkbNTH9gR5' } ,
459+ } ,
460+ ) ;
461+ if ( response . status != 200 ) {
462+ showToast ( toast , 'Error fetching data' ) ;
466463 }
467- return data . bundlers as Bundler [ ] ;
464+ const data = await response . json ( ) ;
465+ if ( 'bundlers' in data ) {
466+ if ( data . bundlers . length == 0 ) {
467+ showToast ( toast , 'No data found' ) ;
468+ }
469+ return data . bundlers as Bundler [ ] ;
470+ }
471+ return [ ] as Bundler [ ] ;
472+ }
473+ catch ( error ) {
474+ showToast ( toast , 'An unexpected error occurred' ) ;
475+ console . error ( 'Error fetching top bundlers:' , error ) ;
476+ return [ ] as Bundler [ ] ; // Return empty array in case of a network error
468477 }
469- return [ ] as Bundler [ ] ;
470478} ;
471479
472480export const getTopFactories = async ( selectedNetwork : string , pageSize : number , pageNo : number , toast : any ) : Promise < FactoryDetails [ ] > => {
@@ -523,31 +531,45 @@ export const getLatestUserOps = async (selectedNetwork: string, pageSize: number
523531 return [ ] as UserOp [ ] ;
524532} ;
525533
526- export const getLatestBundles = async ( selectedNetwork : string , pageSize : number , pageNo : number , toast : any ) : Promise < Bundle [ ] > => {
534+ export const getLatestBundles = async (
535+ selectedNetwork : string ,
536+ pageSize : number ,
537+ pageNo : number ,
538+ toast : any ,
539+ ) : Promise < Bundle [ ] > => {
527540 if ( ! performApiCall ( selectedNetwork ) ) return [ ] as Bundle [ ] ;
528- const response = await fetch (
529- API_URL +
530- '/v0/getLatestBundles?network=' +
531- selectedNetwork +
532- '&first=' +
533- pageSize +
534- '&skip=' +
535- ( pageNo * pageSize >= 0 ? pageNo * pageSize : 0 ) ,
536- {
537- headers : { 'x-api-key' : 'gFQghtJC6F734nPaUYK8M3ggf9TOpojkbNTH9gR5' } ,
538- } ,
539- ) ;
540- if ( response . status != 200 ) {
541- showToast ( toast , 'Error fetching data' ) ;
542- }
543- const data = await response . json ( ) ;
544- if ( 'bundles' in data ) {
545- if ( data . bundles . length == 0 ) {
541+
542+ try {
543+ const response = await fetch (
544+ `${ API_URL } /v0/getLatestBundles?network=${ selectedNetwork } &first=${ pageSize } &skip=${
545+ pageNo * pageSize >= 0 ? pageNo * pageSize : 0
546+ } `,
547+ {
548+ headers : { 'x-api-key' : 'gFQghtJC6F734nPaUYK8M3ggf9TOpojkbNTH9gR5' } ,
549+ } ,
550+ ) ;
551+
552+ if ( response . status !== 200 ) {
546553 showToast ( toast , 'Error fetching data' ) ;
554+ return [ ] as Bundle [ ] ; // Return an empty array if the response status is not 200
555+ }
556+
557+ const data = await response . json ( ) ;
558+
559+ if ( data . bundles && data . bundles . length === 0 ) {
560+ showToast ( toast , 'No bundles found' ) ;
547561 }
562+
548563 return data . bundles as Bundle [ ] ;
564+ } catch ( error ) {
565+ if ( error instanceof TypeError && error . message === 'Failed to fetch' ) {
566+ showToast ( toast , 'Network error: Unable to fetch data' ) ;
567+ } else {
568+ showToast ( toast , 'An unexpected error occurred' ) ;
569+ }
570+ console . error ( 'Error fetching latest bundles:' , error ) ;
571+ return [ ] as Bundle [ ] ; // Return an empty array in case of a network error
549572 }
550- return [ ] as Bundle [ ] ;
551573} ;
552574
553575export const getDailyMetrics = async ( selectedNetwork : string , noOfDays : number , toast : any ) : Promise < DailyMetric [ ] > => {
@@ -1007,32 +1029,39 @@ export const getBundlerDetails = async (
10071029 toast : any ,
10081030) : Promise < Bundle > => {
10091031 if ( ! performApiCall ( selectedNetwork ) ) return { } as Bundle ;
1010- const response = await fetch (
1011- API_URL +
1012- '/v0/getBundlerActivity?address=' +
1013- userOpHash +
1014- '&network=' +
1015- selectedNetwork +
1016- '&first=' +
1017- pageSize +
1018- '&skip=' +
1019- ( pageNo * pageSize >= 0 ? pageNo * pageSize : 0 ) ,
1020- {
1021- headers : { 'x-api-key' : 'gFQghtJC6F734nPaUYK8M3ggf9TOpojkbNTH9gR5' } ,
1022- } ,
1023- ) ;
1024- // if (response == null) return {} as Bundle;
1025- if ( response . status != 200 ) {
1026- showToast ( toast , 'Error fetching data' ) ;
1027- }
1028- const data = await response . json ( ) ;
1029- if ( 'bundlerDetails' in data ) {
1030- if ( Object . keys ( data . bundlerDetails ) . length == 0 ) {
1032+ try {
1033+ const response = await fetch (
1034+ API_URL +
1035+ '/v0/getBundlerActivity?address=' +
1036+ userOpHash +
1037+ '&network=' +
1038+ selectedNetwork +
1039+ '&first=' +
1040+ pageSize +
1041+ '&skip=' +
1042+ ( pageNo * pageSize >= 0 ? pageNo * pageSize : 0 ) ,
1043+ {
1044+ headers : { 'x-api-key' : 'gFQghtJC6F734nPaUYK8M3ggf9TOpojkbNTH9gR5' } ,
1045+ } ,
1046+ ) ;
1047+ // if (response == null) return {} as Bundle;
1048+ if ( response . status != 200 ) {
10311049 showToast ( toast , 'Error fetching data' ) ;
10321050 }
1033- return data . bundlerDetails as Bundle ;
1051+ const data = await response . json ( ) ;
1052+ if ( 'bundlerDetails' in data ) {
1053+ if ( Object . keys ( data . bundlerDetails ) . length == 0 ) {
1054+ showToast ( toast , 'Error fetching data' ) ;
1055+ }
1056+ return data . bundlerDetails as Bundle ;
1057+ }
1058+ return { } as Bundle ;
1059+ }
1060+ catch ( error ) {
1061+ showToast ( toast , 'An unexpected error occurred' ) ;
1062+ console . error ( 'Error fetching bundler details:' , error ) ;
1063+ return { } as Bundle ; // Return an empty object in case of a network error
10341064 }
1035- return { } as Bundle ;
10361065} ;
10371066
10381067export const fetchAPIKeyList = async ( Authorization : string , sub : string ) => {
@@ -1075,13 +1104,20 @@ export const resolveBNSAddress = async (address: String, network: string): Promi
10751104 let name = '' ;
10761105
10771106 if ( address && address . length > 2 && address . slice ( 0 , 2 ) == '0x' && address . length == 42 ) {
1107+ try {
10781108 const BnsResponse = await axios . get ( 'https://resolver-api.basename.app/v1/addresses/' + address . toString ( ) , {
10791109 headers : {
10801110 'Access-Control-Allow-Origin' : '*' ,
10811111 'Content-Type' : 'application/json' ,
10821112 } ,
10831113 } ) ;
10841114 name = BnsResponse ?. data ?. name ? BnsResponse . data . name : '' ;
1115+ }
1116+ catch ( error ) {
1117+ // console.error('Error resolving BNS address:',error);
1118+ Sentry . captureException ( error ) ; // Report error to Sentry
1119+ name = '' ; // or return a default value if needed
1120+ }
10851121 }
10861122 return name ;
10871123} ;
0 commit comments