Skip to content

Commit

Permalink
00749 wrong hbar price and market cap when switching from previewnet (#…
Browse files Browse the repository at this point in the history
…767)

Signed-off-by: Simon Viénot <[email protected]>
  • Loading branch information
svienot authored Nov 23, 2023
1 parent ef3c4a1 commit dba4378
Showing 5 changed files with 29 additions and 21 deletions.
19 changes: 9 additions & 10 deletions src/components/dashboard/HbarMarketDashboard.vue
Original file line number Diff line number Diff line change
@@ -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,
}
},
});
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ import axios, {AxiosResponse} from "axios";
import {computed} from "vue";
import {NetworkExchangeRateSetResponse} from "@/schemas/HederaSchemas";

export class HbarPriceCache extends AutoRefreshLoader<NetworkExchangeRateSetResponse> {
export class HbarPriceLoader extends AutoRefreshLoader<NetworkExchangeRateSetResponse> {

//
// Public
@@ -52,9 +52,7 @@ export class HbarPriceCache extends AutoRefreshLoader<NetworkExchangeRateSetResp
timestamp: string
}
if (this.deltaSeconds) {
const now = new Date()
const target = new Date(now.getTime() - this.deltaSeconds * 1000)
params.timestamp = (target.getTime() / 1000).toString()
params.timestamp = (new Date().getTime() / 1000 - this.deltaSeconds).toString()
}

return axios.get<NetworkExchangeRateSetResponse>("api/v1/network/exchangerate", {params: params})
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ import axios, {AxiosResponse} from "axios";
import {computed} from "vue";
import {NetworkSupplyResponse} from "@/schemas/HederaSchemas";

export class HbarSupplyCache extends AutoRefreshLoader<NetworkSupplyResponse> {
export class HbarSupplyLoader extends AutoRefreshLoader<NetworkSupplyResponse> {

//
// Public
21 changes: 15 additions & 6 deletions src/components/dashboard/MarketDataCache.ts
Original file line number Diff line number Diff line change
@@ -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()
}
}
2 changes: 2 additions & 0 deletions src/utils/cache/CacheUtils.ts
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit dba4378

Please sign in to comment.