From 42d9cfa8d48bc6fda3b44ffabf53979de5112690 Mon Sep 17 00:00:00 2001 From: Wojciech Basiura Date: Wed, 9 Oct 2024 13:55:16 +0200 Subject: [PATCH] L1-287: Update inflation help informations --- src/contexts/Api/defaults.ts | 1 + src/contexts/Api/index.tsx | 1 + src/contexts/Api/types.ts | 1 + src/contexts/Network/defaults.ts | 2 ++ src/contexts/Network/index.tsx | 4 +++- src/contexts/Network/types.ts | 1 + src/library/Hooks/useFillVariables/index.tsx | 19 +++++++++++++++++-- src/locale/cn/help.json | 4 ++-- src/locale/en/help.json | 4 ++-- 9 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/contexts/Api/defaults.ts b/src/contexts/Api/defaults.ts index 3b7762fe60..6aefd3fa29 100644 --- a/src/contexts/Api/defaults.ts +++ b/src/contexts/Api/defaults.ts @@ -38,6 +38,7 @@ if (!isValidConfiguredNetworkName(cachedNetworkName)) { } export const consts: APIConstants = { + chainDecimals: 12, bondDuration: new BigNumber(0), maxNominations: new BigNumber(0), sessionsPerEra: new BigNumber(0), diff --git a/src/contexts/Api/index.tsx b/src/contexts/Api/index.tsx index b762208084..4189638bae 100644 --- a/src/contexts/Api/index.tsx +++ b/src/contexts/Api/index.tsx @@ -275,6 +275,7 @@ export const APIProvider = ({ children }: { children: React.ReactNode }) => { const expectedEraTime = FallbackExpectedEraTime; setConsts({ + chainDecimals: newApi.registry.chainDecimals[0], bondDuration, maxNominations, sessionsPerEra, diff --git a/src/contexts/Api/types.ts b/src/contexts/Api/types.ts index 7bbd76f475..846901b3c4 100644 --- a/src/contexts/Api/types.ts +++ b/src/contexts/Api/types.ts @@ -13,6 +13,7 @@ export interface NetworkState { meta: Network; } export interface APIConstants { + chainDecimals: number; bondDuration: BigNumber; maxNominations: BigNumber; sessionsPerEra: BigNumber; diff --git a/src/contexts/Network/defaults.ts b/src/contexts/Network/defaults.ts index 02af14f760..253d7971e1 100644 --- a/src/contexts/Network/defaults.ts +++ b/src/contexts/Network/defaults.ts @@ -12,7 +12,9 @@ export const activeEra: ActiveEra = { index: new BigNumber(0), start: new BigNumber(0), }; + export const metrics: NetworkMetrics = { + azeroCap: new BigNumber(0), totalIssuance: new BigNumber(0), auctionCounter: new BigNumber(0), earliestStoredSession: new BigNumber(0), diff --git a/src/contexts/Network/index.tsx b/src/contexts/Network/index.tsx index 56875ef581..d3da8689d1 100644 --- a/src/contexts/Network/index.tsx +++ b/src/contexts/Network/index.tsx @@ -40,12 +40,14 @@ export const NetworkMetricsProvider = ({ const subscribeToMetrics = async () => { const unsub = await api.queryMulti( [ + api.query.aleph.azeroCap, api.query.balances.totalIssuance, api.query.staking.minimumActiveStake, ], - ([totalIssuance, minimumActiveStake]: AnyApi) => { + ([azeroCap, totalIssuance, minimumActiveStake]: AnyApi) => { setStateWithRef( { + azeroCap: new BigNumber(azeroCap.toString()), totalIssuance: new BigNumber(totalIssuance.toString()), auctionCounter: metrics.auctionCounter, earliestStoredSession: metrics.earliestStoredSession, diff --git a/src/contexts/Network/types.ts b/src/contexts/Network/types.ts index b3c5dd7e4b..fd7569a770 100644 --- a/src/contexts/Network/types.ts +++ b/src/contexts/Network/types.ts @@ -9,6 +9,7 @@ export interface NetworkMetricsContextInterface { } export interface NetworkMetrics { + azeroCap: BigNumber; totalIssuance: BigNumber; auctionCounter: BigNumber; earliestStoredSession: BigNumber; diff --git a/src/library/Hooks/useFillVariables/index.tsx b/src/library/Hooks/useFillVariables/index.tsx index 4491cb4d03..7f8dabde6f 100644 --- a/src/library/Hooks/useFillVariables/index.tsx +++ b/src/library/Hooks/useFillVariables/index.tsx @@ -5,7 +5,12 @@ import { capitalizeFirstLetter, planckToUnit } from '@polkadot-cloud/utils'; import { useApi } from 'contexts/Api'; import { useNetworkMetrics } from 'contexts/Network'; import { usePoolsConfig } from 'contexts/Pools/PoolsConfig'; -import type { AnyJson } from 'types'; +import type { AnyJson, NetworkName } from 'types'; + +const networkToFirstYearInflation: Partial> = { + 'Aleph Zero': '27M', + 'Aleph Zero Testnet': '1000M', +}; export const useFillVariables = () => { const { network, consts } = useApi(); @@ -17,7 +22,7 @@ export const useFillVariables = () => { } = consts; const { minJoinBond, minCreateBond } = stats; const { metrics } = useNetworkMetrics(); - const { minimumActiveStake } = metrics; + const { azeroCap, minimumActiveStake } = metrics; const fillVariables = (d: AnyJson, keys: string[]) => { const fields: AnyJson = Object.entries(d).filter(([k]: any) => @@ -26,6 +31,16 @@ export const useFillVariables = () => { const transformed = Object.entries(fields).map( ([, [key, val]]: AnyJson) => { const varsToValues = [ + [ + '{AZERO_CAP}', + azeroCap + .shiftedBy(-(consts.chainDecimals + 6)) + .toFormat({ suffix: 'M' }), + ], + [ + '{INFLATION_FIRST_YEAR}', + networkToFirstYearInflation[network.name] ?? '-M', + ], ['{NETWORK_UNIT}', network.unit], ['{NETWORK_NAME}', capitalizeFirstLetter(network.name)], [ diff --git a/src/locale/cn/help.json b/src/locale/cn/help.json index 95db0f4409..14501e626b 100644 --- a/src/locale/cn/help.json +++ b/src/locale/cn/help.json @@ -114,8 +114,8 @@ "inflation": [ "้€š่ดง่†จ่ƒ€", [ - "{NETWORK_UNIT} is inflationary. Inflation is exponentially decreasing, starting at 27M {NETWORK_UNIT} emission in the first year.", - "The max supply is 520M {NETWORK_UNIT}." + "{NETWORK_UNIT} is inflationary. Inflation is exponentially decreasing, starting at {INFLATION_FIRST_YEAR} {NETWORK_UNIT} emission in the first year.", + "The max supply is {AZERO_CAP} {NETWORK_UNIT}." ] ], "lastEraPayout": [ diff --git a/src/locale/en/help.json b/src/locale/en/help.json index 2731497550..39d230d5bb 100644 --- a/src/locale/en/help.json +++ b/src/locale/en/help.json @@ -108,8 +108,8 @@ "inflation": [ "Inflation", [ - "{NETWORK_UNIT} is inflationary. Inflation is exponentially decreasing, starting at 27M {NETWORK_UNIT} emission in the first year.", - "The max supply is 520M {NETWORK_UNIT}." + "{NETWORK_UNIT} is inflationary. Inflation is exponentially decreasing, starting at {INFLATION_FIRST_YEAR} {NETWORK_UNIT} emission in the first year.", + "The max supply is {AZERO_CAP} {NETWORK_UNIT}." ] ], "lastEraPayout": [