Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BIDS-2619) fix vali history tooltip #2676

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion handlers/mempoolView.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func toTableDataRow(tx *types.RawMempoolTransaction) []interface{} {
utils.FormatAddressAll(tx.From.Bytes(), "", false, "address", "", int(12), int(12), true),
_isContractCreation(tx.To),
utils.FormatAmount((*big.Int)(tx.Value), utils.Config.Frontend.ElCurrency, 5),
utils.FormatAddCommasFormated(float64(tx.Gas.ToInt().Int64()), 0),
utils.FormatAddCommasFormatted(float64(tx.Gas.ToInt().Int64()), 0),
utils.FormatAmountFormatted(tx.GasPrice.ToInt(), "GWei", 5, 0, true, true, false),
tx.Nonce.ToInt(),
}
Expand Down
12 changes: 6 additions & 6 deletions handlers/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1592,8 +1592,8 @@ func ValidatorHistory(w http.ResponseWriter, r *http.Request) {
maxPages := 10

vars := mux.Vars(r)
index, err := strconv.ParseUint(vars["index"], 10, 64)
if err != nil || index > math.MaxInt32 { // index in postgres is limited to int
index, err := strconv.ParseUint(vars["index"], 10, 31)
if err != nil {
logger.Warnf("error parsing validator index: %v", err)
http.Error(w, "Error: Invalid parameter validator index.", http.StatusBadRequest)
return
Expand Down Expand Up @@ -1709,7 +1709,7 @@ func ValidatorHistory(w http.ResponseWriter, r *http.Request) {
} else if len(tableData) >= pageLength {
continue
}
tableData = append(tableData, icomeToTableData(i, incomeDetails[index][i], withdrawalMap[i], currency))
tableData = append(tableData, incomeToTableData(i, incomeDetails[index][i], withdrawalMap[i], currency))
}
}

Expand Down Expand Up @@ -1750,7 +1750,7 @@ func ValidatorHistory(w http.ResponseWriter, r *http.Request) {
}
continue
}
tableData = append(tableData, icomeToTableData(epoch, incomeDetails[index][epoch], withdrawalMap[epoch], currency))
tableData = append(tableData, incomeToTableData(epoch, incomeDetails[index][epoch], withdrawalMap[epoch], currency))

}
}
Expand Down Expand Up @@ -1821,7 +1821,7 @@ func getWithdrawalAndIncome(index uint64, startEpoch uint64, endEpoch uint64) (m
return withdrawalMap, incomeDetails, err
}

func icomeToTableData(epoch uint64, income *itypes.ValidatorEpochIncome, withdrawal *types.ValidatorWithdrawal, currency string) []interface{} {
func incomeToTableData(epoch uint64, income *itypes.ValidatorEpochIncome, withdrawal *types.ValidatorWithdrawal, currency string) []interface{} {
events := template.HTML("")
if income.AttestationSourcePenalty > 0 && income.AttestationTargetPenalty > 0 {
events += utils.FormatAttestationStatusShort(2)
Expand All @@ -1845,7 +1845,7 @@ func icomeToTableData(epoch uint64, income *itypes.ValidatorEpochIncome, withdra
rewards := income.TotalClRewards()
return []interface{}{
utils.FormatEpoch(epoch),
utils.FormatBalanceChangeFormated(&rewards, currency, income),
utils.FormatBalanceChangeFormatted(&rewards, currency, income),
template.HTML(""),
template.HTML(events),
}
Expand Down
54 changes: 27 additions & 27 deletions utils/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ func FormatAttestationStatus(status uint64) template.HTML {
// FormatAttestationStatusShort will return a user-friendly attestation for an attestation status number
func FormatAttestationStatusShort(status uint64) template.HTML {
if status == 0 {
return `<span title="Scheduled" data-toggle="tooltip" class="mx-1 badge badge-pill bg-light text-dark" style="font-size: 12px; font-weight: 500;">Sche.</span>`
return `<span title="Scheduled Attestation" data-toggle="tooltip" class="mx-1 badge badge-pill bg-light text-dark" style="font-size: 12px; font-weight: 500;">Sche.</span>`
Eisei24 marked this conversation as resolved.
Show resolved Hide resolved
} else if status == 1 {
return `<span title="Attested" data-toggle="tooltip" class="mx-1 badge badge-pill bg-success text-white" style="font-size: 12px; font-weight: 500;">Att.</span>`
} else if status == 2 {
return `<span title="Missed" data-toggle="tooltip" class="mx-1 badge badge-pill bg-warning text-white" style="font-size: 12px; font-weight: 500;">Miss.</span>`
return `<span title="Missed Attestation" data-toggle="tooltip" class="mx-1 badge badge-pill bg-warning text-white" style="font-size: 12px; font-weight: 500;">Miss.</span>`
} else if status == 3 {
return `<span title="Missed (Orphaned)" data-toggle="tooltip" class="mx-1 badge badge-pill bg-warning text-white" style="font-size: 12px; font-weight: 500;">Orph.</span>`
return `<span title="Missed Attestation (Orphaned)" data-toggle="tooltip" class="mx-1 badge badge-pill bg-warning text-white" style="font-size: 12px; font-weight: 500;">Orph.</span>`
} else if status == 4 {
return `<span title="Inactivity Leak" data-toggle="tooltip" class="mx-1 badge badge-pill bg-danger text-white" style="font-size: 12px; font-weight: 500;">Leak</span>`
} else if status == 5 {
Expand Down Expand Up @@ -257,7 +257,7 @@ func IfToDec(valIf interface{}) decimal.Decimal {
return val
}

func FormatBalanceChangeFormated(balance *int64, currencyName string, details *itypes.ValidatorEpochIncome) template.HTML {
func FormatBalanceChangeFormatted(balance *int64, currencyName string, details *itypes.ValidatorEpochIncome) template.HTML {
currencySymbol := "GWei"
currencyFunc := ClToCurrencyGwei
if currencyName != Config.Frontend.MainCurrency {
Expand All @@ -273,49 +273,49 @@ func FormatBalanceChangeFormated(balance *int64, currencyName string, details *i

income := ""
if details != nil {
income += fmt.Sprintf("Att. Source: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.AttestationSourceReward-details.AttestationSourcePenalty, currencyName).InexactFloat64(), maxDigits), currencySymbol)
income += fmt.Sprintf("Att. Target: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.AttestationTargetReward-details.AttestationTargetPenalty, currencyName).InexactFloat64(), maxDigits), currencySymbol)
income += fmt.Sprintf("Att. Head Vote: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.AttestationHeadReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
income += fmt.Sprintf("Att. Source: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(IfToDec(details.AttestationSourceReward).Sub(IfToDec(details.AttestationSourcePenalty)), currencyName).InexactFloat64(), maxDigits), currencySymbol)
income += fmt.Sprintf("Att. Target: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(IfToDec(details.AttestationTargetReward).Sub(IfToDec(details.AttestationTargetPenalty)), currencyName).InexactFloat64(), maxDigits), currencySymbol)
Comment on lines +276 to +277
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the relevant part for the BIDS (=preventing int underflow)

income += fmt.Sprintf("Att. Head Vote: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(details.AttestationHeadReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)

if details.FinalityDelayPenalty > 0 {
income += fmt.Sprintf("Finality Delay Penalty: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.FinalityDelayPenalty, currencyName).InexactFloat64()*-1, maxDigits), currencySymbol)
income += fmt.Sprintf("Finality Delay Penalty: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(details.FinalityDelayPenalty, currencyName).InexactFloat64()*-1, maxDigits), currencySymbol)
}

if details.ProposerSlashingInclusionReward > 0 {
income += fmt.Sprintf("Proposer Slashing Inc. Reward: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.ProposerSlashingInclusionReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
income += fmt.Sprintf("Proposer Slashing Inc. Reward: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(details.ProposerSlashingInclusionReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
}

if details.ProposerAttestationInclusionReward > 0 {
income += fmt.Sprintf("Proposer Att. Inc. Reward: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.ProposerAttestationInclusionReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
income += fmt.Sprintf("Proposer Att. Inc. Reward: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(details.ProposerAttestationInclusionReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
}

if details.ProposerSyncInclusionReward > 0 {
income += fmt.Sprintf("Proposer Sync Inc. Reward: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.ProposerSyncInclusionReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
income += fmt.Sprintf("Proposer Sync Inc. Reward: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(details.ProposerSyncInclusionReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
}

if details.SyncCommitteeReward > 0 {
income += fmt.Sprintf("Sync Comm. Reward: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.SyncCommitteeReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
income += fmt.Sprintf("Sync Comm. Reward: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(details.SyncCommitteeReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
}

if details.SyncCommitteePenalty > 0 {
income += fmt.Sprintf("Sync Comm. Penalty: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.SyncCommitteePenalty, currencyName).InexactFloat64()*-1, maxDigits), currencySymbol)
income += fmt.Sprintf("Sync Comm. Penalty: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(details.SyncCommitteePenalty, currencyName).InexactFloat64()*-1, maxDigits), currencySymbol)
}

if details.SlashingReward > 0 {
income += fmt.Sprintf("Slashing Reward: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.SlashingReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
income += fmt.Sprintf("Slashing Reward: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(details.SlashingReward, currencyName).InexactFloat64(), maxDigits), currencySymbol)
}

if details.SlashingPenalty > 0 {
income += fmt.Sprintf("Slashing Penalty: %s %s<br/>", FormatAddCommasFormated(currencyFunc(details.SlashingPenalty, currencyName).InexactFloat64()*-1, maxDigits), currencySymbol)
income += fmt.Sprintf("Slashing Penalty: %s %s<br/>", FormatAddCommasFormatted(currencyFunc(details.SlashingPenalty, currencyName).InexactFloat64()*-1, maxDigits), currencySymbol)
}

income += fmt.Sprintf("Total: %s %s", FormatAddCommasFormated(currencyFunc(details.TotalClRewards(), currencyName).InexactFloat64(), maxDigits), currencySymbol)
income += fmt.Sprintf("Total: %s %s", FormatAddCommasFormatted(currencyFunc(details.TotalClRewards(), currencyName).InexactFloat64(), maxDigits), currencySymbol)
}

if *balance < 0 {
return template.HTML(fmt.Sprintf("<span title='%s' data-html=\"true\" data-toggle=\"tooltip\" class=\"text-danger float-right\">%s %s</span>", income, FormatAddCommasFormated(currencyFunc(*balance, currencyName).InexactFloat64(), maxDigits), currencySymbol))
return template.HTML(fmt.Sprintf("<span title='%s' data-html=\"true\" data-toggle=\"tooltip\" class=\"text-danger float-right\">%s %s</span>", income, FormatAddCommasFormatted(currencyFunc(*balance, currencyName).InexactFloat64(), maxDigits), currencySymbol))
}
return template.HTML(fmt.Sprintf("<span title='%s' data-html=\"true\" data-toggle=\"tooltip\" class=\"text-success float-right\">+%s %s</span>", income, FormatAddCommasFormated(currencyFunc(*balance, currencyName).InexactFloat64(), maxDigits), currencySymbol))
return template.HTML(fmt.Sprintf("<span title='%s' data-html=\"true\" data-toggle=\"tooltip\" class=\"text-success float-right\">+%s %s</span>", income, FormatAddCommasFormatted(currencyFunc(*balance, currencyName).InexactFloat64(), maxDigits), currencySymbol))
}

// FormatBalanceChange will return a string for a balance change
Expand All @@ -325,9 +325,9 @@ func FormatBalanceChange(balance *int64, currency string) template.HTML {
return template.HTML("<span> 0 " + currency + "</span>")
}
if *balance < 0 {
return template.HTML(fmt.Sprintf("<span class=\"text-danger float-right\">%s GWei</span>", FormatAddCommasFormated(ClToCurrencyGwei(*balance, currency).InexactFloat64(), 0)))
return template.HTML(fmt.Sprintf("<span class=\"text-danger float-right\">%s GWei</span>", FormatAddCommasFormatted(ClToCurrencyGwei(*balance, currency).InexactFloat64(), 0)))
}
return template.HTML(fmt.Sprintf("<span class=\"text-success float-right\">+%s GWei</span>", FormatAddCommasFormated(ClToCurrencyGwei(*balance, currency).InexactFloat64(), 0)))
return template.HTML(fmt.Sprintf("<span class=\"text-success float-right\">+%s GWei</span>", FormatAddCommasFormatted(ClToCurrencyGwei(*balance, currency).InexactFloat64(), 0)))
}
if balance == nil {
return template.HTML("<span> 0 " + currency + "</span>")
Expand Down Expand Up @@ -384,7 +384,7 @@ func FormatFloatWithDigitsString(num float64, min, max int) string {
return b[0] + "." + b[1][:idx+min]
}

func FormatAddCommasFormated(num float64, precision uint) template.HTML {
func FormatAddCommasFormatted(num float64, precision uint) template.HTML {
p := message.NewPrinter(language.English)
s := p.Sprintf(fmt.Sprintf("%%.%vf", precision), num)
if precision > 0 {
Expand All @@ -394,7 +394,7 @@ func FormatAddCommasFormated(num float64, precision uint) template.HTML {
}

func FormatBigNumberAddCommasFormated(val hexutil.Big, precision uint) template.HTML {
return FormatAddCommasFormated(float64(val.ToInt().Int64()), 0)
return FormatAddCommasFormatted(float64(val.ToInt().Int64()), 0)
}

func FormatAddCommas(n uint64) template.HTML {
Expand Down Expand Up @@ -468,15 +468,15 @@ func FormatBlockStatus(status, slot uint64) template.HTML {
func FormatBlockStatusShort(status, slot uint64) template.HTML {
// genesis <span class="badge text-dark" style="background: rgba(179, 159, 70, 0.8) none repeat scroll 0% 0%;">Genesis</span>
if status == 0 && SlotToTime(slot).Before(time.Now().Add(time.Minute*-1)) {
return `<span title="Scheduled" data-toggle="tooltip" class="mx-1 badge badge-pill bg-light text-dark" style="font-size: 12px; font-weight: 500;">Miss.</span>`
return `<span title="Scheduled Block" data-toggle="tooltip" class="mx-1 badge badge-pill bg-light text-dark" style="font-size: 12px; font-weight: 500;">Miss.</span>`
} else if status == 0 {
return `<span title="Scheduled" data-toggle="tooltip" class="mx-1 badge badge-pill bg-light text-dark" style="font-size: 12px; font-weight: 500;">Sche.</span>`
return `<span title="Scheduled Block" data-toggle="tooltip" class="mx-1 badge badge-pill bg-light text-dark" style="font-size: 12px; font-weight: 500;">Sche.</span>`
} else if status == 1 {
return `<span title="Proposed" data-toggle="tooltip" class="mx-1 badge badge-pill bg-success text-white" style="font-size: 12px; font-weight: 500;">Prop.</span>`
return `<span title="Proposed Block" data-toggle="tooltip" class="mx-1 badge badge-pill bg-success text-white" style="font-size: 12px; font-weight: 500;">Prop.</span>`
} else if status == 2 {
return `<span title="Missed" data-toggle="tooltip" class="mx-1 badge badge-pill bg-warning text-white" style="font-size: 12px; font-weight: 500;">Miss.</span>`
return `<span title="Missed Block" data-toggle="tooltip" class="mx-1 badge badge-pill bg-warning text-white" style="font-size: 12px; font-weight: 500;">Miss.</span>`
} else if status == 3 {
return `<span title="Missed (Orphaned)" data-toggle="tooltip" class="mx-1 badge badge-pill bg-secondary text-white" style="font-size: 12px; font-weight: 500;">Orph.</span>`
return `<span title="Missed Block (Orphaned)" data-toggle="tooltip" class="mx-1 badge badge-pill bg-secondary text-white" style="font-size: 12px; font-weight: 500;">Orph.</span>`
} else {
return "Unknown"
}
Expand Down
Loading