Skip to content

Commit

Permalink
Add time to issue default block (#1323)
Browse files Browse the repository at this point in the history
* Add time to accumulate

* Change var names

* Use import

* chore: rename vars

* chore: rename vars

---------

Co-authored-by: Begoña Alvarez <[email protected]>
  • Loading branch information
Dr-Electron and begonaalvarezd authored Nov 7, 2023
1 parent 2003952 commit f2182f2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"flickity-fade": "^2.0.0",
"globby": "^13.1.4",
"hast-util-is-element": "1.1.0",
"humanize-duration": "^3.30.0",
"plugin-image-zoom": "flexanalytics/plugin-image-zoom",
"raw-loader": "^4.0.2",
"react": "18.2.0",
Expand Down
30 changes: 27 additions & 3 deletions src/components/ManaCalculator/components/OutputForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import React from 'react';
import { useManaState, useResults } from '../hooks';
import { fromMicro } from '../utils';
import humanizeDuration from 'humanize-duration';

export function OutputForm() {
const { state } = useManaState();
const { manaGenerated, passiveRewards, totalTPS } = useResults(state);
const {
generatedRewards,
passiveRewards,
totalTPS,
msToTransaction,
passiveMsToTransaction,
} = useResults(state);

return (
<div className='table'>
<div className='row '>
Expand All @@ -15,13 +23,29 @@ export function OutputForm() {
</div>
<div className='row '>
<div className='col col--6'>Mana rewards</div>
<div className='col col--6 align-right'>{fromMicro(manaGenerated)}</div>
<div className='col col--6 align-right'>{fromMicro(generatedRewards)}</div>
</div>

<div className='row '>
<div className='col col--6'>Total TPS granted with</div>
<div className='col col--6 align-right'>{totalTPS}</div>
</div>
<div className='row '>
<div className='col col--6'>
Time it takes to accumulate enough mana for a standard transaction...
</div>
</div>
<div className='row '>
<div className='col col--6'>...as a delegator/validator</div>
<div className='col col--6 align-right'>
{humanizeDuration(msToTransaction * 1000)}
</div>
</div>
<div className='row '>
<div className='col col--6'>...as a holder</div>
<div className='col col--6 align-right'>
{humanizeDuration(passiveMsToTransaction * 1000)}
</div>
</div>
</div>
);
}
31 changes: 18 additions & 13 deletions src/components/ManaCalculator/hooks/useResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ export function useResults(state: ManaCalculatorProps) {
state.finalEpoch,
);

const additionalTPS = calculateTPS(passiveRewards, state.congestion);
const passiveTPS = calculateTPS(passiveRewards, state.congestion);

const validatorParameters =
state.userType === UserType.VALIDATOR
? ({
performanceFactor: state.validator.performanceFactor,
fixedCost: state.validator.fixedCost,
shareOfYourStakeLocked: state.validator.shareOfYourStakeLocked,
attractedNewDelegatedStake:
state.validator.attractedNewDelegatedStake,
attractedDelegatedStakeFromOtherPools:
state.validator.attractedDelegatedStakeFromOtherPools,
} as ValidatorParameters)
performanceFactor: state.validator.performanceFactor,
fixedCost: state.validator.fixedCost,
shareOfYourStakeLocked: state.validator.shareOfYourStakeLocked,
attractedNewDelegatedStake:
state.validator.attractedNewDelegatedStake,
attractedDelegatedStakeFromOtherPools:
state.validator.attractedDelegatedStakeFromOtherPools,
} as ValidatorParameters)
: null;

const manaGenerated = calculateManaRewards(
const generatedRewards = calculateManaRewards(
state.stakedOrDelegatedTokens,
state.delegator.validator,
validatorParameters,
Expand All @@ -39,12 +39,17 @@ export function useResults(state: ManaCalculatorProps) {
state.network,
);

const grantedTPS = calculateTPS(manaGenerated, state.congestion);
const totalTPS = grantedTPS + additionalTPS;
const generatedTPS = calculateTPS(generatedRewards, state.congestion);
const totalTPS = generatedTPS + passiveTPS;

const msToTransaction = (1 / totalTPS) * 1_000;
const passiveMsToTransaction = (1 / passiveTPS) * 1_000;

return {
manaGenerated,
generatedRewards,
passiveRewards,
totalTPS,
msToTransaction,
passiveMsToTransaction,
};
}
6 changes: 3 additions & 3 deletions src/components/ManaCalculator/hooks/useResultsPerEpoch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function useResultsPerEpoch(state: ManaCalculatorProps): EpochReward[] {
const results = [];

for (let i = state.initialEpoch; i <= state.finalEpoch; i++) {
const manaGenerated = calculateManaRewards(
const generatedRewards = calculateManaRewards(
state.stakedOrDelegatedTokens,
state.delegator.validator,
validatorParameters,
Expand All @@ -44,13 +44,13 @@ export function useResultsPerEpoch(state: ManaCalculatorProps): EpochReward[] {
i,
);

const mana = manaGenerated + passiveRewards;
const mana = generatedRewards + passiveRewards;

const tpsFromPassiveRewards = calculateTPS(
passiveRewards,
state.congestion,
);
const tpsFromGeneratedMana = calculateTPS(manaGenerated, state.congestion);
const tpsFromGeneratedMana = calculateTPS(generatedRewards, state.congestion);
const totalTps = tpsFromPassiveRewards + tpsFromGeneratedMana;

results.push({
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2835,6 +2835,7 @@ __metadata:
flickity-fade: ^2.0.0
globby: ^13.1.4
hast-util-is-element: 1.1.0
humanize-duration: ^3.30.0
plugin-image-zoom: flexanalytics/plugin-image-zoom
prettier: ^2.8.8
raw-loader: ^4.0.2
Expand Down Expand Up @@ -10752,6 +10753,13 @@ __metadata:
languageName: node
linkType: hard

"humanize-duration@npm:^3.30.0":
version: 3.30.0
resolution: "humanize-duration@npm:3.30.0"
checksum: 6eaf888219801d47d42cfb03523e736367c260e3f32cddb4e30c30f49500e08e7cdfd413f02a5ed24943ef382b3e89c8a11e6eda3a432846385903a9f49e576a
languageName: node
linkType: hard

"humanize-ms@npm:^1.2.1":
version: 1.2.1
resolution: "humanize-ms@npm:1.2.1"
Expand Down

0 comments on commit f2182f2

Please sign in to comment.