This commit is contained in:
parent
c28fc0167a
commit
e5642940f2
@ -6,6 +6,7 @@ import (
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/gchaincl/mempool/client"
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
@ -18,6 +19,7 @@ type FeeDistribution struct {
|
||||
isProjected bool
|
||||
cancelFn context.CancelFunc
|
||||
fees client.Fees
|
||||
title string
|
||||
}
|
||||
|
||||
func NewFeeDistribution(g *gocui.Gui) *FeeDistribution {
|
||||
@ -84,7 +86,7 @@ func (fd *FeeDistribution) Layout(g *gocui.Gui) error {
|
||||
return err
|
||||
}
|
||||
|
||||
v.Title = "Fee distribution ('esc' to close)"
|
||||
v.Title = "Fee distribution" + fd.title + "('esc' to close)"
|
||||
g.SetCurrentView(name)
|
||||
g.SetViewOnTop(name)
|
||||
g.SetKeybinding(name, gocui.KeyEsc, gocui.ModNone, fd.close)
|
||||
@ -97,22 +99,17 @@ func (fd *FeeDistribution) Layout(g *gocui.Gui) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
min, max := 99999, 0
|
||||
for _, f := range fd.fees {
|
||||
fee := int(f.FPV)
|
||||
if fee < min {
|
||||
min = fee
|
||||
}
|
||||
if fee > max {
|
||||
max = fee
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(v, "Fee span: %d - %d sat/vByte\n", min, max)
|
||||
|
||||
fmt.Fprintf(v, "Tx count: %d transactions\n", len(fd.fees))
|
||||
|
||||
sort.Sort(fd.fees)
|
||||
fmt.Fprintf(v, "Median: ~%d sat/vBytes", int(fd.fees[len(fd.fees)/2].FPV))
|
||||
txs := len(fd.fees)
|
||||
min, max := fd.fees[0].FPV, fd.fees[txs-1].FPV
|
||||
|
||||
var (
|
||||
white = color.New(color.FgWhite).SprintfFunc()
|
||||
yellow = color.New(color.FgYellow).SprintfFunc()
|
||||
)
|
||||
fmt.Fprintf(v, white("Fee span:")+" %d - %d "+yellow("sat/vByte\n"), ceil(min), ceil(max))
|
||||
fmt.Fprintf(v, white("Tx count:")+" %d "+white("transactions\n"), txs)
|
||||
fmt.Fprintf(v, white("Median: ")+" ~%d "+yellow("sat/vBytes\n"), ceil(fd.fees[txs/2].FPV))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
27
ui/ui.go
27
ui/ui.go
@ -2,7 +2,6 @@ package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -275,32 +274,6 @@ func (ui *UI) info(g *gocui.Gui, x, y int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ceil(f float64) int {
|
||||
return int(
|
||||
math.Ceil(f),
|
||||
)
|
||||
}
|
||||
|
||||
func fmtSeconds(s int64) string {
|
||||
if s < 60 {
|
||||
return "< 1 minute"
|
||||
} else if s < 120 {
|
||||
return fmt.Sprintf("1 minute")
|
||||
} else if s < 3600 {
|
||||
return fmt.Sprintf("%d minutes", s/60)
|
||||
}
|
||||
return fmt.Sprintf("%d hours", s/3600)
|
||||
}
|
||||
|
||||
func fmtSize(s int) string {
|
||||
if s < 1024*1024 {
|
||||
m := float64(s) / 1000.0
|
||||
return fmt.Sprintf("%dkB", ceil(m))
|
||||
}
|
||||
m := float64(s) / (1000.0 * 1000.0)
|
||||
return fmt.Sprintf("%dMB", ceil(m))
|
||||
}
|
||||
|
||||
func (ui *UI) onBlockClick(g *gocui.Gui, v *gocui.View) error {
|
||||
name := v.Name()
|
||||
if strings.HasPrefix(name, "projected-block-") {
|
||||
|
||||
32
ui/util.go
Normal file
32
ui/util.go
Normal file
@ -0,0 +1,32 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func ceil(f float64) int {
|
||||
return int(
|
||||
math.Ceil(f),
|
||||
)
|
||||
}
|
||||
|
||||
func fmtSeconds(s int64) string {
|
||||
if s < 60 {
|
||||
return "< 1 minute"
|
||||
} else if s < 120 {
|
||||
return fmt.Sprintf("1 minute")
|
||||
} else if s < 3600 {
|
||||
return fmt.Sprintf("%d minutes", s/60)
|
||||
}
|
||||
return fmt.Sprintf("%d hours", s/3600)
|
||||
}
|
||||
|
||||
func fmtSize(s int) string {
|
||||
if s < 1024*1024 {
|
||||
m := float64(s) / 1000.0
|
||||
return fmt.Sprintf("%dkB", ceil(m))
|
||||
}
|
||||
m := float64(s) / (1000.0 * 1000.0)
|
||||
return fmt.Sprintf("%dMB", ceil(m))
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user