From 8edd2b5802f91ec5307ff3cace74a8072259af51 Mon Sep 17 00:00:00 2001 From: natsoni Date: Tue, 19 Mar 2024 11:58:50 +0900 Subject: [PATCH] Fix fiat price displayed on test networks --- frontend/src/app/services/price.service.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/services/price.service.ts b/frontend/src/app/services/price.service.ts index 7a2f42c95..a27c65df8 100644 --- a/frontend/src/app/services/price.service.ts +++ b/frontend/src/app/services/price.service.ts @@ -101,6 +101,10 @@ export class PriceService { lastQueriedCurrency: string; lastQueriedHistoricalCurrency: string; + network: string; + networkChangedSinceLastQuery = false; + networkChangedSinceLastSingleQuery = false; + historicalPrice: ConversionDict = { prices: null, exchangeRates: null, @@ -110,6 +114,13 @@ export class PriceService { private apiService: ApiService, private stateService: StateService ) { + this.stateService.networkChanged$.subscribe((network: string) => { + if (this.network !== network) { + this.network = network; + this.networkChangedSinceLastQuery = true; + this.networkChangedSinceLastSingleQuery = true; + } + }); } getEmptyPrice(): Price { @@ -144,10 +155,11 @@ export class PriceService { * query a different timestamp than the last one */ if (singlePrice) { - if (!this.singlePriceObservable$ || (this.singlePriceObservable$ && (blockTimestamp !== this.lastQueriedTimestamp || currency !== this.lastQueriedCurrency))) { + if (!this.singlePriceObservable$ || (this.singlePriceObservable$ && (blockTimestamp !== this.lastQueriedTimestamp || currency !== this.lastQueriedCurrency || this.networkChangedSinceLastSingleQuery))) { this.singlePriceObservable$ = this.apiService.getHistoricalPrice$(blockTimestamp, currency).pipe(shareReplay()); this.lastQueriedTimestamp = blockTimestamp; this.lastQueriedCurrency = currency; + this.networkChangedSinceLastSingleQuery = false; } return this.singlePriceObservable$.pipe( @@ -180,10 +192,11 @@ export class PriceService { * Query all price history only once. The observable is invalidated after 1 hour */ else { - if (!this.priceObservable$ || (this.priceObservable$ && (now - this.lastPriceHistoryUpdate > 3600 || currency !== this.lastQueriedHistoricalCurrency))) { + if (!this.priceObservable$ || (this.priceObservable$ && (now - this.lastPriceHistoryUpdate > 3600 || currency !== this.lastQueriedHistoricalCurrency || this.networkChangedSinceLastQuery))) { this.priceObservable$ = this.apiService.getHistoricalPrice$(undefined, currency).pipe(shareReplay()); this.lastPriceHistoryUpdate = new Date().getTime() / 1000; this.lastQueriedHistoricalCurrency = currency; + this.networkChangedSinceLastQuery = false; } return this.priceObservable$.pipe(