@@ -557,10 +557,14 @@ export class MainController extends EventEmitter implements IMainController {
557557
558558 if ( selectedAccountAddr ) {
559559 const FIVE_MINUTES = 1000 * 60 * 5
560+ const ONE_HOUR = 1000 * 60 * 60
560561 this . domains . batchReverseLookup ( this . accounts . accounts . map ( ( a ) => a . addr ) )
561562
562563 if ( ! ( this . activity . broadcastedButNotConfirmed [ selectedAccountAddr ] || [ ] ) . length ) {
563- this . updateSelectedAccountPortfolio ( { maxDataAgeMs : FIVE_MINUTES } )
564+ this . updateSelectedAccountPortfolio ( {
565+ maxDataAgeMs : FIVE_MINUTES ,
566+ maxDataAgeMsUnused : ONE_HOUR
567+ } )
564568 this . defiPositions . updatePositions ( { maxDataAgeMs : FIVE_MINUTES } )
565569 }
566570
@@ -650,7 +654,8 @@ export class MainController extends EventEmitter implements IMainController {
650654 // will block the UI until these are resolved.
651655 // eslint-disable-next-line @typescript-eslint/no-floating-promises
652656 this . reloadSelectedAccount ( {
653- maxDataAgeMs : 5 * 60 * 1000
657+ maxDataAgeMs : 5 * 60 * 1000 ,
658+ maxDataAgeMsUnused : 60 * 60 * 1000
654659 } )
655660 }
656661
@@ -1357,9 +1362,10 @@ export class MainController extends EventEmitter implements IMainController {
13571362 async reloadSelectedAccount ( options ?: {
13581363 chainIds ?: bigint [ ]
13591364 maxDataAgeMs ?: number
1365+ maxDataAgeMsUnused ?: number
13601366 isManualReload ?: boolean
13611367 } ) {
1362- const { chainIds, isManualReload = false , maxDataAgeMs } = options || { }
1368+ const { chainIds, isManualReload = false , maxDataAgeMsUnused , maxDataAgeMs } = options || { }
13631369 const networksToUpdate = chainIds
13641370 ? this . networks . networks . filter ( ( n ) => chainIds . includes ( n . chainId ) )
13651371 : undefined
@@ -1385,6 +1391,7 @@ export class MainController extends EventEmitter implements IMainController {
13851391 this . updateSelectedAccountPortfolio ( {
13861392 networks : networksToUpdate ,
13871393 isManualUpdate : isManualReload ,
1394+ maxDataAgeMsUnused,
13881395 maxDataAgeMs
13891396 } ) ,
13901397 this . defiPositions . updatePositions ( { chainIds, maxDataAgeMs, forceUpdate : isManualReload } )
@@ -1401,15 +1408,15 @@ export class MainController extends EventEmitter implements IMainController {
14011408 // and not the selected account portfolio the flag isOffline
14021409 // and the errors of the selected account portfolio should
14031410 // come in the same tick. Otherwise the UI may flash the wrong error.
1404- const latestState = this . portfolio . getLatestPortfolioState ( accountAddr )
1405- const latestStateKeys = Object . keys ( latestState )
1406- const isAllLoaded = latestStateKeys . every ( ( chainId ) => {
1407- return isNetworkReady ( latestState [ chainId ] ) && ! latestState [ chainId ] ?. isLoading
1411+ const portfolioState = this . portfolio . getAccountPortfolioState ( accountAddr )
1412+ const portfolioStateKeys = Object . keys ( portfolioState )
1413+ const isAllLoaded = portfolioStateKeys . every ( ( chainId ) => {
1414+ return isNetworkReady ( portfolioState [ chainId ] ) && ! portfolioState [ chainId ] ?. isLoading
14081415 } )
14091416
14101417 // Set isOffline back to false if the portfolio is loading.
14111418 // This is done to prevent the UI from flashing the offline error
1412- if ( ! latestStateKeys . length || ! isAllLoaded ) {
1419+ if ( ! portfolioStateKeys . length || ! isAllLoaded ) {
14131420 // Skip unnecessary updates
14141421 if ( ! this . isOffline ) return
14151422
@@ -1418,8 +1425,8 @@ export class MainController extends EventEmitter implements IMainController {
14181425 return
14191426 }
14201427
1421- const allPortfolioNetworksHaveErrors = latestStateKeys . every ( ( chainId ) => {
1422- const state = latestState [ chainId ]
1428+ const allPortfolioNetworksHaveErrors = portfolioStateKeys . every ( ( chainId ) => {
1429+ const state = portfolioState [ chainId ]
14231430
14241431 return ! ! state ?. criticalError
14251432 } )
@@ -1444,8 +1451,9 @@ export class MainController extends EventEmitter implements IMainController {
14441451 networks ?: Network [ ]
14451452 isManualUpdate ?: boolean
14461453 maxDataAgeMs ?: number
1454+ maxDataAgeMsUnused ?: number
14471455 } ) {
1448- const { networks, maxDataAgeMs, isManualUpdate } = opts || { }
1456+ const { networks, maxDataAgeMs, maxDataAgeMsUnused , isManualUpdate } = opts || { }
14491457
14501458 await this . initialLoadPromise
14511459 if ( ! this . selectedAccount . account ) return
@@ -1467,7 +1475,7 @@ export class MainController extends EventEmitter implements IMainController {
14671475 states : await this . accounts . getOrFetchAccountStates ( this . selectedAccount . account . addr )
14681476 }
14691477 : undefined ,
1470- { maxDataAgeMs, isManualUpdate }
1478+ { maxDataAgeMs, maxDataAgeMsUnused , isManualUpdate }
14711479 )
14721480 this . #updateIsOffline( )
14731481 }
0 commit comments