File tree 2 files changed +48
-1
lines changed
2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 7
7
GasPriceValue ,
8
8
FeeMarketEIP1559Values ,
9
9
} from './transaction/TransactionController' ;
10
+ import { NetworksChainId } from './network/NetworkController' ;
10
11
11
12
const VALID = '4e1fF7229BDdAf0A73DF183a88d9c3a04cc975e0' ;
12
13
const SOME_API = 'https://someapi.com' ;
@@ -1267,3 +1268,27 @@ describe('isValidJson', () => {
1267
1268
expect ( util . isValidJson ( { foo : 'bar' , test : { num : 5 } } ) ) . toBe ( true ) ;
1268
1269
} ) ;
1269
1270
} ) ;
1271
+
1272
+ describe ( 'isTokenDetectionEnabledForNetwork' , ( ) => {
1273
+ it ( 'returns true for Mainnet' , ( ) => {
1274
+ expect (
1275
+ util . isTokenDetectionEnabledForNetwork (
1276
+ util . SupportedTokenDetectionNetworks . mainnet ,
1277
+ ) ,
1278
+ ) . toBe ( true ) ;
1279
+ } ) ;
1280
+
1281
+ it ( 'returns true for custom network such as BSC' , ( ) => {
1282
+ expect (
1283
+ util . isTokenDetectionEnabledForNetwork (
1284
+ util . SupportedTokenDetectionNetworks . bsc ,
1285
+ ) ,
1286
+ ) . toBe ( true ) ;
1287
+ } ) ;
1288
+
1289
+ it ( 'returns false for testnets such as Ropsten' , ( ) => {
1290
+ expect (
1291
+ util . isTokenDetectionEnabledForNetwork ( NetworksChainId . ropsten ) ,
1292
+ ) . toBe ( false ) ;
1293
+ } ) ;
1294
+ } ) ;
Original file line number Diff line number Diff line change @@ -324,7 +324,7 @@ export async function safelyExecute(
324
324
) {
325
325
try {
326
326
return await operation ( ) ;
327
- } catch ( error ) {
327
+ } catch ( error : any ) {
328
328
/* istanbul ignore next */
329
329
if ( logError ) {
330
330
console . error ( error ) ;
@@ -931,3 +931,25 @@ export function isValidJson(value: unknown): value is Json {
931
931
return false ;
932
932
}
933
933
}
934
+
935
+ /**
936
+ * Networks where token detection is supported - Values are in decimal format
937
+ */
938
+ export enum SupportedTokenDetectionNetworks {
939
+ mainnet = '1' ,
940
+ bsc = '56' ,
941
+ polygon = '137' ,
942
+ avax = '43114' ,
943
+ }
944
+
945
+ /**
946
+ * Check if token detection is enabled for certain networks.
947
+ *
948
+ * @param chainId - ChainID of network
949
+ * @returns Whether the current network supports token detection
950
+ */
951
+ export function isTokenDetectionEnabledForNetwork ( chainId : string ) : boolean {
952
+ return Object . values < string > ( SupportedTokenDetectionNetworks ) . includes (
953
+ chainId ,
954
+ ) ;
955
+ }
You can’t perform that action at this time.
0 commit comments