@@ -14,23 +14,35 @@ const normalizeUpgrade = (upgrade: UpgradeInfo): UpgradeInfo => ({
1414 timestampMs : upgrade . timestampMs ,
1515} )
1616
17- export const persistSpecUpgradeCache = ( cache : Map < string , UpgradeInfo > , networkStorageKeys : Map < NetworkId , string > ) => {
17+ export const persistSpecUpgradeCache = (
18+ cache : Map < string , UpgradeInfo > ,
19+ networkStorageKeys : Map < NetworkId , string > ,
20+ currentSpecVersions ?: Map < NetworkId , number > ,
21+ ) => {
1822 if ( typeof window === 'undefined' || ! window . localStorage ) {
1923 return
2024 }
2125
2226 try {
2327 const groupedByNetwork = new Map < NetworkId , Array < [ number , UpgradeInfo ] > > ( )
28+ const staleCacheKeys : string [ ] = [ ]
2429
2530 for ( const [ cacheKey , upgradeInfo ] of cache . entries ( ) ) {
2631 const separatorIndex = cacheKey . indexOf ( ':' )
2732 if ( separatorIndex === - 1 ) {
33+ staleCacheKeys . push ( cacheKey )
2834 continue
2935 }
3036 const networkId = cacheKey . slice ( 0 , separatorIndex ) as NetworkId
3137 const specVersionValue = cacheKey . slice ( separatorIndex + 1 )
3238 const specVersion = parseSpecVersion ( specVersionValue )
3339 if ( specVersion == null ) {
40+ staleCacheKeys . push ( cacheKey )
41+ continue
42+ }
43+ const currentSpecVersion = currentSpecVersions ?. get ( networkId )
44+ if ( currentSpecVersion != null && specVersion !== currentSpecVersion ) {
45+ staleCacheKeys . push ( cacheKey )
3446 continue
3547 }
3648 const entriesForNetwork = groupedByNetwork . get ( networkId )
@@ -42,6 +54,10 @@ export const persistSpecUpgradeCache = (cache: Map<string, UpgradeInfo>, network
4254 }
4355 }
4456
57+ for ( const cacheKey of staleCacheKeys ) {
58+ cache . delete ( cacheKey )
59+ }
60+
4561 const persistedKeys = new Set < string > ( )
4662
4763 for ( const [ networkId , entries ] of groupedByNetwork ) {
0 commit comments