@@ -16,24 +16,24 @@ interface DopplerPriceListResponse {
16
16
}
17
17
18
18
interface PriceCache {
19
- timestamp : number ;
19
+ lastUpdated : number ;
20
20
prices : Record < string , number > ;
21
21
dopplerPrices : Record < string , Record < number , number > > ;
22
22
}
23
23
24
24
class PriceFetcher {
25
- async fetch ( market_hash_name : string , paintIndex ?: number ) : Promise < number > {
25
+ async fetch ( marketHashName : string , paintIndex ?: number ) : Promise < number > {
26
26
const { prices, dopplerPrices} = await this . getValidPrices ( ) ;
27
27
28
28
// If it's a Doppler and we have a paint index, use the Doppler price
29
29
if ( paintIndex !== undefined ) {
30
- const dopplerPrice = dopplerPrices [ market_hash_name ] ?. [ paintIndex ] ;
30
+ const dopplerPrice = dopplerPrices [ marketHashName ] ?. [ paintIndex ] ;
31
31
if ( dopplerPrice ) {
32
32
return dopplerPrice ;
33
33
}
34
34
}
35
35
36
- return prices [ market_hash_name ] || 0 ;
36
+ return prices [ marketHashName ] || 0 ;
37
37
}
38
38
39
39
private async getValidPrices ( ) : Promise < {
@@ -44,7 +44,7 @@ class PriceFetcher {
44
44
45
45
// Try loading from storage first
46
46
const storedCache = await gStore . getWithStorage < PriceCache > ( chrome . storage . local , PRICE_CACHE . key ) ;
47
- if ( storedCache && now - storedCache . timestamp < DEFAULT_CACHE_DURATION ) {
47
+ if ( storedCache && now - storedCache . lastUpdated < DEFAULT_CACHE_DURATION ) {
48
48
return {
49
49
prices : storedCache . prices ,
50
50
dopplerPrices : storedCache . dopplerPrices || { } ,
@@ -89,17 +89,22 @@ class PriceFetcher {
89
89
}
90
90
91
91
await gStore . setWithStorage ( chrome . storage . local , PRICE_CACHE . key , {
92
- timestamp : now ,
92
+ lastUpdated : now ,
93
93
prices,
94
94
dopplerPrices,
95
95
} ) ;
96
96
97
97
return { prices, dopplerPrices} ;
98
98
} catch ( error ) {
99
- // On error, return existing cache regardless of age, or empty objects if no cache exists
99
+ // If we have no stored cache, bubble up the error
100
+ if ( ! storedCache ) {
101
+ throw new Error ( 'Failed to fetch prices and no cached data available' ) ;
102
+ }
103
+
104
+ // On error with existing cache, return existing cache regardless of age
100
105
return {
101
- prices : storedCache ? .prices || { } ,
102
- dopplerPrices : storedCache ? .dopplerPrices || { } ,
106
+ prices : storedCache . prices || { } ,
107
+ dopplerPrices : storedCache . dopplerPrices || { } ,
103
108
} ;
104
109
}
105
110
}
0 commit comments