-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Flexible network selector in the mana calculator * feat: Improved user flow for the Mana calculator * typo * chore: Refactor the Mana Calculator * ✨ * clean up * clean up * feat: Add user total holding input * feat: Mana accumulation graph * feat: Block issuance rate graph * clean up * network params * clean up * clean up * fmt * prettify * typo * fix * fix * fix * improve graph * tweak * enhancement * Update src/components/ManaCalculator/hooks/useManaState.ts Co-authored-by: Dr-Electron <[email protected]> * Update src/components/ManaCalculator/hooks/useManaState.ts Co-authored-by: Dr-Electron <[email protected]> * fmt * clean up * fmt * feat: UI Polish * ui polish * feat: Display units in Mana Calculator * Add humanizer config * clean up styles * Update src/components/ManaCalculator/components/AdvancedSettingsValidator.tsx Co-authored-by: Dr-Electron <[email protected]> * fixes * clean up * more units * more decimals * smarter rounding --------- Co-authored-by: Begoña Alvarez <[email protected]> Co-authored-by: Dr-Electron <[email protected]>
- Loading branch information
1 parent
e73ce44
commit b7d163f
Showing
14 changed files
with
136 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './useManaState'; | ||
export * from './useResults'; | ||
export * from './useResultsPerEpoch'; | ||
export * from './useResultsWithUnit'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { EpochReward } from '../types/epoch-reward.type'; | ||
|
||
export enum Unit { | ||
default = 'default', | ||
K = 'K', | ||
M = 'M', | ||
G = 'G', | ||
T = 'T', | ||
P = 'P', | ||
} | ||
|
||
const UNIT_MAP: { [unit in Unit]: { val: number; dp: number } } = { | ||
default: { val: 1, dp: 0 }, | ||
K: { val: 1000, dp: 3 }, | ||
M: { val: 1000000, dp: 6 }, | ||
G: { val: 1000000000, dp: 9 }, | ||
T: { val: 1000000000000, dp: 12 }, | ||
P: { val: 1000000000000000, dp: 15 }, | ||
}; | ||
|
||
const getUnit = (value: number): Unit => { | ||
let bestUnits: Unit = Unit.default; | ||
if (!value || value === 0) { | ||
return Unit.M; | ||
} | ||
const checkLength = Math.abs(value).toString().length; | ||
|
||
if (checkLength > UNIT_MAP.M.dp) { | ||
bestUnits = Unit.M; | ||
} else if (checkLength > UNIT_MAP.K.dp) { | ||
bestUnits = Unit.K; | ||
} else if (checkLength > UNIT_MAP.G.dp) { | ||
bestUnits = Unit.G; | ||
} else if (checkLength > UNIT_MAP.M.dp) { | ||
bestUnits = Unit.M; | ||
} else if (checkLength > UNIT_MAP.K.dp) { | ||
bestUnits = Unit.K; | ||
} | ||
|
||
return bestUnits; | ||
}; | ||
|
||
interface UseResultsWithUnit { | ||
data: EpochReward[]; | ||
manaUnit: Unit; | ||
blocksUnit: Unit; | ||
} | ||
|
||
export function getSizeOfUnit(unit: Unit): number { | ||
return UNIT_MAP[unit].val; | ||
} | ||
|
||
export function useResultsWithUnit(results: EpochReward[]): UseResultsWithUnit { | ||
const averageMana = | ||
results.reduce((acc, reward) => acc + reward.mana, 0) / results.length; | ||
const averageBlocks = | ||
results.reduce((acc, reward) => acc + reward.totalTps, 0) / results.length; | ||
|
||
const manaUnit = getUnit(averageMana); | ||
const blocksUnit = getUnit(averageBlocks); | ||
|
||
const manaSize = getSizeOfUnit(manaUnit); | ||
const blocksSize = getSizeOfUnit(blocksUnit); | ||
|
||
const data = results.map<EpochReward>((reward) => { | ||
return { | ||
...reward, | ||
mana: reward.mana / manaSize, | ||
totalTps: reward.totalTps / blocksSize, | ||
}; | ||
}); | ||
|
||
return { | ||
data, | ||
manaUnit, | ||
blocksUnit, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export interface EpochReward { | ||
epoch: number; | ||
mana: number; | ||
totalTps: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters