Skip to content

Commit

Permalink
various small fixes for validator details page
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Dec 2, 2024
1 parent 9317d19 commit 88297d9
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 66 deletions.
7 changes: 0 additions & 7 deletions handlers/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,9 @@ func buildValidatorPageData(validatorIndex uint64, tabView string) (*models.Vali
for _, elWithdrawal := range dbElWithdrawals {
elWithdrawalData := &models.ValidatorPageDataWithdrawal{
SourceAddr: elWithdrawal.SourceAddress(),
PublicKey: elWithdrawal.ValidatorPubkey(),
Amount: elWithdrawal.Amount(),
}

if validatorIndex := elWithdrawal.ValidatorIndex(); validatorIndex != nil {
elWithdrawalData.ValidatorValid = true
elWithdrawalData.ValidatorIndex = *validatorIndex
elWithdrawalData.ValidatorName = services.GlobalBeaconService.GetValidatorName(*validatorIndex)
}

if request := elWithdrawal.Request; request != nil {
elWithdrawalData.IsIncluded = true
elWithdrawalData.SlotNumber = request.SlotNumber
Expand Down
6 changes: 3 additions & 3 deletions templates/validator/consolidationRequests.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
<td data-timer="{{ $request.Time.Unix }}"><span data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="{{ $request.Time }}">{{ formatRecentTimeShort $request.Time }}</span></td>
<td>
<div class="d-flex">
<span class="flex-grow-1 text-truncate" style="max-width: 400px;">{{ ethAddressLink $request.SourceAddr }}</span>
<span class="flex-grow-1 text-truncate" style="width: 150px;">{{ ethAddressLink $request.SourceAddr }}</span>
<div>
<i class="fa fa-copy text-muted ml-2 p-1" role="button" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ formatEthAddress $request.SourceAddr }}"></i>
</div>
</div>
</td>
<td>
{{- if $request.SourceValidatorValid }}
{{ formatValidator $request.SourceValidatorIndex $request.SourceValidatorName }}
{{ formatValidatorWithIndex $request.SourceValidatorIndex $request.SourceValidatorName }}
{{- else }}
<div class="d-flex">
<span class="flex-grow-1 text-truncate" style="max-width: 150px;" data-bs-toggle="tooltip" title="pubkey not in validator set">0x{{ printf "%x" $request.SourcePublicKey }}</span>
Expand All @@ -49,7 +49,7 @@
</td>
<td>
{{- if $request.TargetValidatorValid }}
{{ formatValidator $request.TargetValidatorIndex $request.TargetValidatorName }}
{{ formatValidatorWithIndex $request.TargetValidatorIndex $request.TargetValidatorName }}
{{- else }}
<div class="d-flex">
<span class="flex-grow-1 text-truncate" style="max-width: 150px;" data-bs-toggle="tooltip" title="pubkey not in validator set">0x{{ printf "%x" $request.TargetPublicKey }}</span>
Expand Down
4 changes: 2 additions & 2 deletions templates/validator/validator.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ define "page" }}
<div class="container mt-2">
<div class="d-md-flex py-2 justify-content-md-between">
<h1 class="h4 mb-1 mb-md-0"><i class="fas fa-table mx-2"></i> Validator {{ formatValidatorWithIndex .Index .Name }}</h1>
<h1 class="h4 mb-1 mb-md-0"><i class="fas fa-table mx-2"></i> Validator {{ formatValidatorNameWithIndex .Index .Name }}</h1>
<nav aria-label="breadcrumb">
<ol class="breadcrumb font-size-1 mb-0" style="padding:0; background-color:transparent;">
<li class="breadcrumb-item"><a href="/" title="Home">Home</a></li>
Expand Down Expand Up @@ -107,7 +107,7 @@ <h1 class="h4 mb-1 mb-md-0"><i class="fas fa-table mx-2"></i> Validator {{ forma
<div class="row border-bottom p-2 mx-0">
<div class="col-md-2"><span data-bs-toggle="tooltip" data-bs-placement="top" title="Represents the index for this validator in the beacon chain">Index:</span></div>
<div class="col-md-10">
{{ formatValidatorWithIndex .Index .Name }}
{{ formatValidatorNameWithIndex .Index .Name }}
<i class="fa fa-copy text-muted p-1" role="button" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ .Index }}"></i>
</div>
</div>
Expand Down
19 changes: 3 additions & 16 deletions templates/validator/withdrawalRequests.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<th>Time</th>
<th><span class="d-none d-lg-inline">Source </span>Address</th>
<th><span class="d-none d-lg-inline">Request </span>Type</th>
<th>Validator</th>
<th>Amount</th>
<th>Transaction</th>
<th><span class="d-none d-lg-inline">Incl. </span>Status</th>
Expand All @@ -29,7 +28,7 @@
<td data-timer="{{ $request.Time.Unix }}"><span data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="{{ $request.Time }}">{{ formatRecentTimeShort $request.Time }}</span></td>
<td>
<div class="d-flex">
<span class="flex-grow-1 text-truncate" style="max-width: 400px;">{{ ethAddressLink $request.SourceAddr }}</span>
<span class="flex-grow-1 text-truncate" style="width: 150px;">{{ ethAddressLink $request.SourceAddr }}</span>
<div>
<i class="fa fa-copy text-muted ml-2 p-1" role="button" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="{{ formatEthAddress $request.SourceAddr }}"></i>
</div>
Expand All @@ -42,23 +41,11 @@
Withdrawal
{{- end }}
</td>
<td>
{{- if $request.ValidatorValid }}
{{ formatValidator $request.ValidatorIndex $request.ValidatorName }}
{{- else }}
<div class="d-flex">
<span class="flex-grow-1 text-truncate" style="max-width: 150px;" data-bs-toggle="tooltip" title="pubkey not in validator set">0x{{ printf "%x" $request.PublicKey }}</span>
<div>
<i class="fa fa-copy text-muted ml-2 p-1" role="button" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="0x{{ printf "%x" $request.PublicKey }}"></i>
</div>
</div>
{{- end }}
</td>
<td>{{ formatEthFromGwei $request.Amount }}</td>
<td>
{{- if $request.LinkedTransaction }}
<div class="d-flex">
<span class="flex-grow-1 text-truncate" style="max-width: 150px;">{{ ethTransactionLink $request.TransactionHash 0 }}</span>
<span class="flex-grow-1 text-truncate" style="width: 150px;">{{ ethTransactionLink $request.TransactionHash 0 }}</span>
<div>
<i class="fa fa-copy text-muted ml-2 p-1" role="button" data-bs-toggle="tooltip" title="Copy to clipboard" data-clipboard-text="0x{{ printf "%x" $request.TransactionHash }}"></i>
</div>
Expand Down Expand Up @@ -88,7 +75,7 @@
</tr>
{{ end }}
<tr>
<td colspan="8" class="text-center">
<td colspan="7" class="text-center">
{{ if gt .AdditionalWithdrawalRequestCount 0 }}
<a class="text-white" href="/validators/withdrawal_requests?f&f.pubkey=0x{{ printf "%x" .PublicKey }}">View {{ .AdditionalWithdrawalRequestCount }} more withdrawal requests</a>
{{ end }}
Expand Down
2 changes: 1 addition & 1 deletion templates/validator_slots/slots.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ define "page" }}
<div class="container mt-2">
<div class="d-md-flex py-2 justify-content-md-between">
<h1 class="h4 mb-1 mb-md-0"><i class="fas fa-cube mx-2"></i> Validator {{ formatValidatorWithIndex .Index .Name }}: Slots</h1>
<h1 class="h4 mb-1 mb-md-0"><i class="fas fa-cube mx-2"></i> Validator {{ formatValidatorNameWithIndex .Index .Name }}: Slots</h1>
<nav aria-label="breadcrumb">
<ol class="breadcrumb font-size-1 mb-0" style="padding:0; background-color:transparent;">
<li class="breadcrumb-item"><a href="/" title="Home">Home</a></li>
Expand Down
2 changes: 1 addition & 1 deletion templates/validators/validators.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ <h1 class="h4 mb-1 mb-md-0"><i class="fas fa-table mx-2"></i> Validators Overvie
<tbody>
{{ range $i, $validator := .Validators }}
<tr>
<td><a href="/validator/{{ $validator.Index }}">{{ formatValidatorWithIndex $validator.Index $validator.Name }}</a></td>
<td><a href="/validator/{{ $validator.Index }}">{{ formatValidatorNameWithIndex $validator.Index $validator.Name }}</a></td>
<td><a href="/validator/0x{{ printf "%x" $validator.PublicKey }}" class="text-truncate d-inline-block" style="max-width: 200px">0x{{ printf "%x" $validator.PublicKey }}</a></td>
<td>{{ formatEthFromGwei $validator.Balance }} ({{ formatEthAddCommasFromGwei $validator.EffectiveBalance }} ETH)</td>
<td>
Expand Down
4 changes: 0 additions & 4 deletions types/models/debug_cache.go

This file was deleted.

4 changes: 0 additions & 4 deletions types/models/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ type ValidatorPageDataWithdrawal struct {
TxStatus uint64 `json:"tx_status"`
SourceAddr []byte `json:"source_addr"`
Amount uint64 `json:"amount"`
ValidatorValid bool `json:"vvalid"`
ValidatorIndex uint64 `json:"vindex"`
ValidatorName string `json:"vname"`
PublicKey []byte `json:"pubkey"`
LinkedTransaction bool `json:"linked_tx"`
TransactionHash []byte `json:"tx_hash"`

Expand Down
20 changes: 15 additions & 5 deletions utils/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,23 +330,33 @@ func FormatEthAddress(address []byte) template.HTML {
}

func FormatValidator(index uint64, name string) template.HTML {
return formatValidator(index, name, "fa-male mr-2")
return formatValidator(index, name, "fa-male mr-2", false)
}

func FormatValidatorWithIndex(index uint64, name string) template.HTML {
return formatValidator(index, name, "fa-male mr-2", true)
}

func FormatSlashedValidator(index uint64, name string) template.HTML {
return formatValidator(index, name, "fa-user-slash mr-2 text-danger")
return formatValidator(index, name, "fa-user-slash mr-2 text-danger", true)
}

func formatValidator(index uint64, name string, icon string) template.HTML {
func formatValidator(index uint64, name string, icon string, withIndex bool) template.HTML {
if index == math.MaxInt64 {
return template.HTML(fmt.Sprintf("<span class=\"validator-label validator-index\"><i class=\"fas %v\"></i> unknown</span>", icon))
} else if name != "" {
return template.HTML(fmt.Sprintf("<span class=\"validator-label validator-name\" data-bs-toggle=\"tooltip\" data-bs-placement=\"top\" data-bs-title=\"%v\"><i class=\"fas %v\"></i> <a href=\"/validator/%v\">%v</a></span>", index, icon, index, html.EscapeString(name)))
var nameLabel string
if withIndex {
nameLabel = fmt.Sprintf("%v (%v)", html.EscapeString(name), index)
} else {
nameLabel = html.EscapeString(name)
}
return template.HTML(fmt.Sprintf("<span class=\"validator-label validator-name\" data-bs-toggle=\"tooltip\" data-bs-placement=\"top\" data-bs-title=\"%v\"><i class=\"fas %v\"></i> <a href=\"/validator/%v\">%v</a></span>", index, icon, index, nameLabel))
}
return template.HTML(fmt.Sprintf("<span class=\"validator-label validator-index\"><i class=\"fas %v\"></i> <a href=\"/validator/%v\">%v</a></span>", icon, index, index))
}

func FormatValidatorWithIndex(index uint64, name string) template.HTML {
func FormatValidatorNameWithIndex(index uint64, name string) template.HTML {
if name != "" {
return template.HTML(fmt.Sprintf("<span class=\"validator-label validator-name\">%v (%v)</span>", html.EscapeString(name), index))
}
Expand Down
47 changes: 24 additions & 23 deletions utils/templateFucs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,30 @@ func GetTemplateFuncs() template.FuncMap {
"round": func(i float64, n int) float64 {
return math.Round(i*math.Pow10(n)) / math.Pow10(n)
},
"percent": func(i float64) float64 { return i * 100 },
"contains": strings.Contains,
"formatAddCommas": FormatAddCommas,
"formatFloat": FormatFloat,
"formatBitlist": FormatBitlist,
"formatBitvectorValidators": formatBitvectorValidators,
"formatParticipation": FormatParticipation,
"formatEthFromGwei": FormatETHFromGwei,
"formatEthFromGweiShort": FormatETHFromGweiShort,
"formatFullEthFromGwei": FormatFullETHFromGwei,
"formatEthAddCommasFromGwei": FormatETHAddCommasFromGwei,
"formatAmount": FormatAmount,
"ethBlockLink": FormatEthBlockLink,
"ethBlockHashLink": FormatEthBlockHashLink,
"ethAddressLink": FormatEthAddressLink,
"ethTransactionLink": FormatEthTransactionLink,
"formatEthAddress": FormatEthAddress,
"formatValidator": FormatValidator,
"formatValidatorWithIndex": FormatValidatorWithIndex,
"formatSlashedValidator": FormatSlashedValidator,
"formatWithdawalCredentials": FormatWithdawalCredentials,
"formatRecentTimeShort": FormatRecentTimeShort,
"formatGraffiti": FormatGraffiti,
"percent": func(i float64) float64 { return i * 100 },
"contains": strings.Contains,
"formatAddCommas": FormatAddCommas,
"formatFloat": FormatFloat,
"formatBitlist": FormatBitlist,
"formatBitvectorValidators": formatBitvectorValidators,
"formatParticipation": FormatParticipation,
"formatEthFromGwei": FormatETHFromGwei,
"formatEthFromGweiShort": FormatETHFromGweiShort,
"formatFullEthFromGwei": FormatFullETHFromGwei,
"formatEthAddCommasFromGwei": FormatETHAddCommasFromGwei,
"formatAmount": FormatAmount,
"ethBlockLink": FormatEthBlockLink,
"ethBlockHashLink": FormatEthBlockHashLink,
"ethAddressLink": FormatEthAddressLink,
"ethTransactionLink": FormatEthTransactionLink,
"formatEthAddress": FormatEthAddress,
"formatValidator": FormatValidator,
"formatValidatorWithIndex": FormatValidatorWithIndex,
"formatValidatorNameWithIndex": FormatValidatorNameWithIndex,
"formatSlashedValidator": FormatSlashedValidator,
"formatWithdawalCredentials": FormatWithdawalCredentials,
"formatRecentTimeShort": FormatRecentTimeShort,
"formatGraffiti": FormatGraffiti,
}

for k, v := range customFuncs {
Expand Down

0 comments on commit 88297d9

Please sign in to comment.