@@ -377,65 +377,74 @@ export const getBalance = (
377377 ) [ 0 ] ;
378378
379379 if ( token ) {
380- const balanceInProgress = account ?. tokens [ chainId ] [ token ] ?. balance ?. inProgress ;
381- const balanceTimestamp = account ?. tokens [ chainId ] [ token ] ?. balance ?. timestamp || 0 ;
382-
383- if ( force || ( ! balanceInProgress && balanceTimestamp + 10 * 3600 < Date . now ( ) ) ) {
384- const data = {
385- walletId : wallet . id ,
386- address,
387- token,
388- blockchain,
389- chainId
390- } ;
391-
392- dispatch ( {
393- type : ACCOUNT_GET_BALANCE ,
394- data,
395- inProgress : true
396- } ) ;
397- try {
398- const tokenConfig = getTokenConfig ( account . blockchain , token ) ;
399- const client = getBlockchain ( blockchain ) . getClient ( chainId ) ;
400-
401- let balance ;
402- switch ( tokenConfig . type ) {
403- case TokenType . NATIVE : {
404- balance = await client . getBalance ( address ) ;
405- break ;
406- }
407- default :
408- if ( client . tokens [ tokenConfig . type ] ) {
409- balance = await client . tokens [ tokenConfig . type ] . getBalance (
410- tokenConfig . contractAddress ,
411- address
412- ) ;
413- } else {
414- throw new Error (
415- `Token Type (${ tokenConfig . type } ) not handled for blockchain ${ blockchain } .`
416- ) ;
417- }
418- }
380+ const isTokenActive = account ?. tokens [ chainId ] [ token ] ?. active === true ;
381+
382+ // get balance only for active tokens
383+ if ( isTokenActive ) {
384+ const balanceInProgress = account ?. tokens [ chainId ] [ token ] ?. balance ?. inProgress ;
385+ const balanceTimestamp = account ?. tokens [ chainId ] [ token ] ?. balance ?. timestamp || 0 ;
386+
387+ if ( force || ( ! balanceInProgress && balanceTimestamp + 10 * 3600 < Date . now ( ) ) ) {
388+ const data = {
389+ walletId : wallet . id ,
390+ address,
391+ token,
392+ blockchain,
393+ chainId
394+ } ;
419395
420- dispatch ( {
421- type : ACCOUNT_GET_BALANCE ,
422- data : {
423- ...data ,
424- balance
425- }
426- } ) ;
427- } catch ( error ) {
428396 dispatch ( {
429397 type : ACCOUNT_GET_BALANCE ,
430398 data,
431- error
399+ inProgress : true
432400 } ) ;
401+ try {
402+ const tokenConfig = getTokenConfig ( account . blockchain , token ) ;
403+ const client = getBlockchain ( blockchain ) . getClient ( chainId ) ;
404+
405+ let balance ;
406+ switch ( tokenConfig . type ) {
407+ case TokenType . NATIVE : {
408+ balance = await client . getBalance ( address ) ;
409+ break ;
410+ }
411+ default :
412+ if ( client . tokens [ tokenConfig . type ] ) {
413+ balance = await client . tokens [ tokenConfig . type ] . getBalance (
414+ tokenConfig . contractAddress ,
415+ address
416+ ) ;
417+ } else {
418+ throw new Error (
419+ `Token Type (${ tokenConfig . type } ) not handled for blockchain ${ blockchain } .`
420+ ) ;
421+ }
422+ }
423+
424+ dispatch ( {
425+ type : ACCOUNT_GET_BALANCE ,
426+ data : {
427+ ...data ,
428+ balance
429+ }
430+ } ) ;
431+ } catch ( error ) {
432+ dispatch ( {
433+ type : ACCOUNT_GET_BALANCE ,
434+ data,
435+ error
436+ } ) ;
437+ }
433438 }
434439 }
435440 } else {
436441 // call get balance for all tokens
437442 Object . keys ( account . tokens [ chainId ] || { } ) . map ( tokenSymbol => {
438- getBalance ( blockchain , address , tokenSymbol , force ) ( dispatch , getState ) ;
443+ const isTokenActive = account ?. tokens [ chainId ] [ tokenSymbol ] ?. active === true ;
444+ if ( isTokenActive ) {
445+ // get balance only for active tokens
446+ getBalance ( blockchain , address , tokenSymbol , force ) ( dispatch , getState ) ;
447+ }
439448 } ) ;
440449 }
441450} ;
0 commit comments