Misc small improvements.
All checks were successful
Build & Test / Main (push) Successful in 1m0s

This commit is contained in:
Sam Fredrickson 2024-03-29 18:40:33 -07:00
parent 9e6abb1112
commit 4d5dcc46d2
2 changed files with 19 additions and 20 deletions

View File

@ -46,26 +46,25 @@ type Asset struct {
RelativeBases []moon.RelativeBase `koanf:"relativeBases"` RelativeBases []moon.RelativeBase `koanf:"relativeBases"`
} }
func (r Root) ForAsset(asset coindesk.Asset) (data Asset) { func (r Root) ForAsset(a coindesk.Asset) (cfg Asset) {
data, ok := r.Assets[asset] cfg = merge(r.Assets[a], r.Defaults)
if !ok { cfg.Asset = a
data = r.Defaults
}
if data.Asset == "" {
data.Asset = asset
}
if data.Goals == nil || len(data.Goals) == 0 {
data.Goals = r.Defaults.Goals
}
if data.ConstantBases == nil || len(data.ConstantBases) == 0 {
data.ConstantBases = r.Defaults.ConstantBases
}
if data.RelativeBases == nil || len(data.RelativeBases) == 0 {
data.RelativeBases = r.Defaults.RelativeBases
}
return return
} }
func merge(dst, src Asset) Asset {
if len(dst.Goals) == 0 {
dst.Goals = src.Goals
}
if len(dst.ConstantBases) == 0 {
dst.ConstantBases = src.ConstantBases
}
if len(dst.RelativeBases) == 0 {
dst.RelativeBases = src.RelativeBases
}
return dst
}
// GetBases returns the concatenation of the constant and relative bases, sorted // GetBases returns the concatenation of the constant and relative bases, sorted
// from most recent to least recent in time. // from most recent to least recent in time.
func GetBases(d *Asset) (bases []moon.Base) { func GetBases(d *Asset) (bases []moon.Base) {

View File

@ -148,9 +148,9 @@ type update struct {
type stopIndicator struct{} type stopIndicator struct{}
func (m Model) refresh() tea.Msg { func (m Model) refresh() tea.Msg {
ctx, cancel := context.WithDeadline( ctx, cancel := context.WithTimeout(
context.Background(), context.Background(),
time.Now().Add(refreshDeadline)) refreshTimeout)
defer cancel() defer cancel()
err := m.math.Refresh(ctx) err := m.math.Refresh(ctx)
if err != nil { if err != nil {
@ -183,7 +183,7 @@ func (m Model) stopIndicator() tea.Cmd {
} }
var refreshInterval = time.Second * 30 var refreshInterval = time.Second * 30
var refreshDeadline = time.Second * 15 var refreshTimeout = time.Second * 15
var stopIndicatorDelay = time.Millisecond * 500 var stopIndicatorDelay = time.Millisecond * 500
func refillProperties(m *Model) { func refillProperties(m *Model) {