From dba437801dec5596eaa82706d1cf6d6bbfedf30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Vi=C3=A9not?= Date: Thu, 23 Nov 2023 16:32:51 +0100 Subject: [PATCH] 00749 wrong hbar price and market cap when switching from previewnet (#767) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simon ViƩnot --- .../dashboard/HbarMarketDashboard.vue | 19 ++++++++--------- .../{HbarPriceCache.ts => HbarPriceLoader.ts} | 6 ++---- ...HbarSupplyCache.ts => HbarSupplyLoader.ts} | 2 +- src/components/dashboard/MarketDataCache.ts | 21 +++++++++++++------ src/utils/cache/CacheUtils.ts | 2 ++ 5 files changed, 29 insertions(+), 21 deletions(-) rename src/components/dashboard/{HbarPriceCache.ts => HbarPriceLoader.ts} (86%) rename src/components/dashboard/{HbarSupplyCache.ts => HbarSupplyLoader.ts} (96%) diff --git a/src/components/dashboard/HbarMarketDashboard.vue b/src/components/dashboard/HbarMarketDashboard.vue index 596237115..ddc839966 100644 --- a/src/components/dashboard/HbarMarketDashboard.vue +++ b/src/components/dashboard/HbarMarketDashboard.vue @@ -110,9 +110,8 @@ export default defineComponent({ const hbarTotalLabel = 'HBAR TOTAL' // marketDataCache - const marketDataCache = new MarketDataCache() - onMounted(() => marketDataCache.mount()) - onBeforeUnmount(() => marketDataCache.unmount()) + onMounted(() => MarketDataCache.instance.mount()) + onBeforeUnmount(() => MarketDataCache.instance.unmount()) return { isMainNetwork, @@ -123,13 +122,13 @@ export default defineComponent({ hbarMarketCapLabel, hbarReleasedLabel, hbarTotalLabel, - marketDataCache, // For testing purpose - hbarReleased: marketDataCache.hbarReleased, - hbarTotal: marketDataCache.hbarTotal, - hbarPrice: marketDataCache.hbarPrice, - hbarPriceVariation: marketDataCache.hbarPriceVariation, - hbarMarketCap: marketDataCache.hbarMarketCap, - hbarMarketCapVariation: marketDataCache.hbarMarketCapVariation, + marketDataCache: MarketDataCache.instance, // For testing purpose + hbarReleased: MarketDataCache.instance.hbarReleased, + hbarTotal: MarketDataCache.instance.hbarTotal, + hbarPrice: MarketDataCache.instance.hbarPrice, + hbarPriceVariation: MarketDataCache.instance.hbarPriceVariation, + hbarMarketCap: MarketDataCache.instance.hbarMarketCap, + hbarMarketCapVariation: MarketDataCache.instance.hbarMarketCapVariation, } }, }); diff --git a/src/components/dashboard/HbarPriceCache.ts b/src/components/dashboard/HbarPriceLoader.ts similarity index 86% rename from src/components/dashboard/HbarPriceCache.ts rename to src/components/dashboard/HbarPriceLoader.ts index 7e415cec2..d12aef6de 100644 --- a/src/components/dashboard/HbarPriceCache.ts +++ b/src/components/dashboard/HbarPriceLoader.ts @@ -23,7 +23,7 @@ import axios, {AxiosResponse} from "axios"; import {computed} from "vue"; import {NetworkExchangeRateSetResponse} from "@/schemas/HederaSchemas"; -export class HbarPriceCache extends AutoRefreshLoader { +export class HbarPriceLoader extends AutoRefreshLoader { // // Public @@ -52,9 +52,7 @@ export class HbarPriceCache extends AutoRefreshLoader("api/v1/network/exchangerate", {params: params}) diff --git a/src/components/dashboard/HbarSupplyCache.ts b/src/components/dashboard/HbarSupplyLoader.ts similarity index 96% rename from src/components/dashboard/HbarSupplyCache.ts rename to src/components/dashboard/HbarSupplyLoader.ts index 2ded492f2..c7ab5b243 100644 --- a/src/components/dashboard/HbarSupplyCache.ts +++ b/src/components/dashboard/HbarSupplyLoader.ts @@ -23,7 +23,7 @@ import axios, {AxiosResponse} from "axios"; import {computed} from "vue"; import {NetworkSupplyResponse} from "@/schemas/HederaSchemas"; -export class HbarSupplyCache extends AutoRefreshLoader { +export class HbarSupplyLoader extends AutoRefreshLoader { // // Public diff --git a/src/components/dashboard/MarketDataCache.ts b/src/components/dashboard/MarketDataCache.ts index 0668d384c..d605e3470 100644 --- a/src/components/dashboard/MarketDataCache.ts +++ b/src/components/dashboard/MarketDataCache.ts @@ -19,18 +19,20 @@ */ import {computed} from "vue"; -import {HbarPriceCache} from "@/components/dashboard/HbarPriceCache"; -import {HbarSupplyCache} from "@/components/dashboard/HbarSupplyCache"; +import {HbarPriceLoader} from "@/components/dashboard/HbarPriceLoader"; +import {HbarSupplyLoader} from "@/components/dashboard/HbarSupplyLoader"; export class MarketDataCache { // // Public // - public readonly hbarPriceCache = new HbarPriceCache() - public readonly hbarPrice24hCache = new HbarPriceCache(86400) - public readonly hbarSupplyCache = new HbarSupplyCache() - public readonly hbarSupply24hCache = new HbarSupplyCache(86400) + public static readonly instance = new MarketDataCache() + + public readonly hbarPriceCache = new HbarPriceLoader() + public readonly hbarPrice24hCache = new HbarPriceLoader(86400) + public readonly hbarSupplyCache = new HbarSupplyLoader() + public readonly hbarSupply24hCache = new HbarSupplyLoader(86400) public readonly hbarPrice = computed(() => { const currentPrice = this.hbarPriceCache.hbarPrice.value @@ -91,4 +93,11 @@ export class MarketDataCache { this.hbarSupplyCache.mounted.value = false this.hbarSupply24hCache.mounted.value = false } + + public clear(): void { + this.hbarPriceCache.requestLoad() + this.hbarPrice24hCache.requestLoad() + this.hbarSupplyCache.requestLoad() + this.hbarSupply24hCache.requestLoad() + } } diff --git a/src/utils/cache/CacheUtils.ts b/src/utils/cache/CacheUtils.ts index 8ebfef6d6..f115b9722 100644 --- a/src/utils/cache/CacheUtils.ts +++ b/src/utils/cache/CacheUtils.ts @@ -45,6 +45,7 @@ import {ContractResultByTransactionIdCache} from "@/utils/cache/ContractResultBy import {ContractResultByTsCache} from "@/utils/cache/ContractResultByTsCache"; import {SourcifyCache} from "@/utils/cache/SourcifyCache"; import {TokenAssociationCache} from "@/utils/cache/TokenAssociationCache"; +import {MarketDataCache} from "@/components/dashboard/MarketDataCache"; export class CacheUtils { @@ -62,6 +63,7 @@ export class CacheUtils { ContractResultByHashCache.instance.clear() ContractResultByTransactionIdCache.instance.clear() ContractResultByTsCache.instance.clear() + MarketDataCache.instance.clear() HbarPriceCache.instance.clear() // IPFSCache.instance => no clear: we preserve it because IPFS content is valid for all networks NetworkCache.instance.clear()