Skip to content

Commit

Permalink
Merge pull request #1774 from gobitfly/BIDS-1508/ColorcodeWithdrawalC…
Browse files Browse the repository at this point in the history
…reds

(BIDS-1508) Colorcode withdrawal credentials
  • Loading branch information
recy21 authored Feb 2, 2023
2 parents a9fa091 + 5335ffd commit 524b86f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion handlers/eth2Deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func Eth2DepositsData(w http.ResponseWriter, r *http.Request) {
utils.FormatBlockSlot(d.BlockSlot),
utils.FormatPublicKey(d.Publickey),
utils.FormatDepositAmount(d.Amount, currency),
utils.FormatHash(d.Withdrawalcredentials),
utils.FormatWithdawalCredentials(d.Withdrawalcredentials, false),
utils.FormatHash(d.Signature),
utils.FormatHash(d.Withdrawalcredentials, false),
utils.FormatHash(d.Signature, false),
Expand Down
15 changes: 13 additions & 2 deletions utils/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,19 +508,30 @@ func FormatHash(hash []byte, trunc_opt ...bool) template.HTML {
return template.HTML(fmt.Sprintf("<span class=\"text-monospace\">%#x</span>", hash))
}

func formatWithdrawalHash(hash []byte) template.HTML {
var colorClass string
if hash[0] == 0x01 {
colorClass = "text-success"
} else {
colorClass = "text-warning"
}

return template.HTML(fmt.Sprintf("<span class=\"text-monospace %s\">%#x</span><span class=\"text-monospace\">%x…%x</span>", colorClass, hash[:1], hash[1:2], hash[len(hash)-2:]))
}

func FormatWithdawalCredentials(hash []byte, addCopyButton bool) template.HTML {
if len(hash) != 32 {
return "INVALID CREDENTIALS"
}

if hash[0] == 0x01 {
text := fmt.Sprintf("<a href=\"/address/0x%x\">%s</a>", hash[12:], FormatHash(hash))
text := fmt.Sprintf("<a href=\"/address/0x%x\">%s</a>", hash[12:], formatWithdrawalHash(hash))
if addCopyButton {
text += fmt.Sprintf("<i class=\"fa fa-copy text-muted p-1\" role=\"button\" data-toggle=\"tooltip\" title=\"Copy to clipboard\" data-clipboard-text=\"%#x\"></i>", hash)
}
return template.HTML(text)
} else {
return FormatHash(hash)
return formatWithdrawalHash(hash)
}
}

Expand Down

0 comments on commit 524b86f

Please sign in to comment.