You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lntop/ui/models/models.go

79 lines
1.5 KiB
Go

5 years ago
package models
5 years ago
import (
"context"
"github.com/edouardparis/lntop/app"
"github.com/edouardparis/lntop/network/models"
)
5 years ago
type Models struct {
5 years ago
App *app.App
Info *Info
Channels *Channels
WalletBalance *WalletBalance
ChannelsBalance *ChannelsBalance
5 years ago
}
func New(app *app.App) *Models {
5 years ago
return &Models{
5 years ago
App: app,
Info: &Info{},
Channels: &Channels{},
WalletBalance: &WalletBalance{},
ChannelsBalance: &ChannelsBalance{},
5 years ago
}
}
5 years ago
type Info struct {
*models.Info
}
5 years ago
func (m *Models) RefreshInfo(ctx context.Context) error {
info, err := m.App.Network.Info(ctx)
if err != nil {
return err
}
*m.Info = Info{info}
return nil
}
5 years ago
type Channels struct {
Items []*models.Channel
}
func (m *Models) RefreshChannels(ctx context.Context) error {
channels, err := m.App.Network.ListChannels(ctx)
if err != nil {
return err
}
*m.Channels = Channels{channels}
return nil
}
5 years ago
type WalletBalance struct {
*models.WalletBalance
5 years ago
}
5 years ago
func (m *Models) RefreshWalletBalance(ctx context.Context) error {
balance, err := m.App.Network.GetWalletBalance(ctx)
if err != nil {
return err
}
*m.WalletBalance = WalletBalance{balance}
return nil
}
type ChannelsBalance struct {
*models.ChannelsBalance
}
func (m *Models) RefreshChannelsBalance(ctx context.Context) error {
balance, err := m.App.Network.GetChannelsBalance(ctx)
if err != nil {
return err
}
*m.ChannelsBalance = ChannelsBalance{balance}
return nil
}