mirror of
https://github.com/Retropex/custom-ocean.xyz-dashboard.git
synced 2025-05-12 19:20:45 +02:00
Refactor pool fee calculation to use last block earnings
Updated `calculatePoolFeeInSats` to accept `lastBlockEarnings` instead of `estimatedEarningsPerDay`. Added debugging logs for pool fee percentage and last block earnings. Modified `updateUI` to check for `last_block_earnings` and parse its value accordingly.
This commit is contained in:
parent
b253e5aa7c
commit
57d8a9ab45
@ -1515,16 +1515,19 @@ function updateChartWithNormalizedData(chart, data) {
|
||||
}
|
||||
}
|
||||
|
||||
// Add a new helper function to calculate pool fees in SATS
|
||||
function calculatePoolFeeInSats(poolFeePercentage, estimatedEarningsPerDay) {
|
||||
// Modify the pool fee calculation to use actual last block earnings
|
||||
function calculatePoolFeeInSats(poolFeePercentage, lastBlockEarnings) {
|
||||
if (poolFeePercentage === undefined || poolFeePercentage === null ||
|
||||
estimatedEarningsPerDay === undefined || estimatedEarningsPerDay === null) {
|
||||
lastBlockEarnings === undefined || lastBlockEarnings === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Calculate how many SATS are taken as fees daily
|
||||
// Log the raw values for debugging
|
||||
console.log("Pool Fee %:", poolFeePercentage, "Last Block Earnings:", lastBlockEarnings);
|
||||
|
||||
// Calculate how many SATS were taken as fees from the last block
|
||||
// Pool fee is a percentage, so we divide by 100 to get the actual rate
|
||||
const feeAmount = (poolFeePercentage / 100) * estimatedEarningsPerDay;
|
||||
const feeAmount = (poolFeePercentage / 100) * lastBlockEarnings;
|
||||
|
||||
// Return as a negative number since it represents a cost
|
||||
return -Math.round(feeAmount);
|
||||
@ -1753,10 +1756,13 @@ function updateUI() {
|
||||
}
|
||||
|
||||
// Update pool fees in SATS (as negative value)
|
||||
if (data.pool_fees_percentage !== undefined && data.estimated_earnings_per_day_sats !== undefined) {
|
||||
if (data.pool_fees_percentage !== undefined && data.last_block_earnings !== undefined) {
|
||||
// Parse the last_block_earnings (removing any "+" prefix if present)
|
||||
const lastBlockEarnings = parseFloat(data.last_block_earnings.toString().replace(/^\+/, ''));
|
||||
|
||||
const poolFeeSats = calculatePoolFeeInSats(
|
||||
parseFloat(data.pool_fees_percentage),
|
||||
parseFloat(data.estimated_earnings_per_day_sats)
|
||||
lastBlockEarnings
|
||||
);
|
||||
|
||||
// Find the pool_fees_percentage element
|
||||
|
Loading…
Reference in New Issue
Block a user