Skip to content

Commit

Permalink
L1-287: Update inflation help informations
Browse files Browse the repository at this point in the history
  • Loading branch information
youPickItUp committed Oct 9, 2024
1 parent 4b4d5a5 commit 72e15d5
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/contexts/Api/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/contexts/Api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export const APIProvider = ({ children }: { children: React.ReactNode }) => {
const expectedEraTime = FallbackExpectedEraTime;

setConsts({
chainDecimals: newApi.registry.chainDecimals[0],
bondDuration,
maxNominations,
sessionsPerEra,
Expand Down
1 change: 1 addition & 0 deletions src/contexts/Api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface NetworkState {
meta: Network;
}
export interface APIConstants {
chainDecimals: number;
bondDuration: BigNumber;
maxNominations: BigNumber;
sessionsPerEra: BigNumber;
Expand Down
2 changes: 2 additions & 0 deletions src/contexts/Network/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion src/contexts/Network/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/contexts/Network/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface NetworkMetricsContextInterface {
}

export interface NetworkMetrics {
azeroCap: BigNumber;
totalIssuance: BigNumber;
auctionCounter: BigNumber;
earliestStoredSession: BigNumber;
Expand Down
19 changes: 17 additions & 2 deletions src/library/Hooks/useFillVariables/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = new Map<NetworkName, string>([
['Aleph Zero', '27M'],
['Aleph Zero Testnet', '1000M'],
]);

export const useFillVariables = () => {
const { network, consts } = useApi();
Expand All @@ -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) =>
Expand All @@ -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.get(network.name) ?? '-M',
],
['{NETWORK_UNIT}', network.unit],
['{NETWORK_NAME}', capitalizeFirstLetter(network.name)],
[
Expand Down
4 changes: 2 additions & 2 deletions src/locale/cn/help.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
4 changes: 2 additions & 2 deletions src/locale/en/help.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit 72e15d5

Please sign in to comment.