[codex] Compute mining calculator average multiplier#7763
Conversation
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
jaxint
left a comment
There was a problem hiding this comment.
PR Review
Thank you for this contribution! Here's my review:
Summary
This PR improves the wallet tracker and mining calculator functionality.
Code Quality
- ✅ Clean implementation of number formatting
- ✅ Proper decimal precision handling
- ✅ Good use of existing utility functions
Observations
✅ Calculator logic updated in mining-calculator/index.html - useful metric
Testing
The changes appear to be focused on display/UX improvements. Consider:
- Adding unit tests for formatting functions
- Testing edge cases with very large/small numbers
Verdict
APPROVE ✅ - Changes are beneficial and low-risk.
Review by @jaxint | Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG
jujujuda
left a comment
There was a problem hiding this comment.
Review: LGTM ✅
Replace hardcoded average multiplier with computed value from . Weighted average is correct: . Graceful fallback to 1.0 when network is empty.
Recommendation: APPROVE.
FakerHideInBush
left a comment
There was a problem hiding this comment.
Two concerns before merging:
1. calculateDefaultAverageMultiplier() is called twice on every render cycle but always returns the same value — it should be a module-level constant
The function reads DEFAULT_NETWORK, which is a static constant that never changes at runtime. Calling Array.reduce on it twice per page interaction (once at line ~582 for the preset-miner estimate and once at line ~631 for the network-size table) is redundant work.
Replace with a single computation at module scope:
const DEFAULT_AVG_MULTIPLIER = (() => {
const totalWeight = DEFAULT_NETWORK.reduce(
(sum, item) => sum + item.multiplier * item.count, 0);
const totalMiners = DEFAULT_NETWORK.reduce(
(sum, item) => sum + item.count, 0);
return totalMiners > 0 ? totalWeight / totalMiners : 1.0;
})();This also makes the value visible to anyone reading the file without needing to trace through a function call.
2. The totalWeight variable name inside calculateDefaultAverageMultiplier() shadows the totalWeight used immediately after the call — different concepts, same name
Inside the function, totalWeight means:
the sum of (multiplier × count) across all hardware tiers in DEFAULT_NETWORK
Immediately after the call, at the call site, totalWeight means:
the estimated total network hashrate weight:
presetMiners × avgMultiplier + userMultiplier
These are semantically different quantities with the same identifier. A maintainer reading the two blocks in sequence could easily confuse them, especially since the outer totalWeight formula references avgMultiplier (the return value of the function) but has the same name as the inner intermediate variable.
Please rename the internal variable — e.g. weightedMultiplierSum inside the function — to make the distinction clear:
const weightedMultiplierSum = DEFAULT_NETWORK.reduce(
(sum, item) => sum + item.multiplier * item.count, 0);
const totalMiners = DEFAULT_NETWORK.reduce(
(sum, item) => sum + item.count, 0);
return totalMiners > 0 ? weightedMultiplierSum / totalMiners : 1.0;3e8baa9 to
1d55547
Compare
Summary
Why
The calculator had two paths using const avgMultiplier = 1.5, so estimates could drift when DEFAULT_NETWORK changes. With the current DEFAULT_NETWORK, the derived value is 19.9 / 12 = 1.6583 instead of the hardcoded 1.5.
Fixes #7728.
Validation