diff --git a/core/common/services.go b/core/common/services.go index efdfd48..e89fc6c 100644 --- a/core/common/services.go +++ b/core/common/services.go @@ -15,6 +15,11 @@ import ( type ApplicationServices *map[string]base.AmiServiceInfo +type AplicationServicesStatus struct { + Applications map[string]ApplicationServices `json:"applications,omitempty"` + Timestamp int64 `json:"timestamp,omitempty"` // last update +} + type ServicesStatusUpdate struct { Application string Status ApplicationServices diff --git a/core/providers/tezbake/main.go b/core/providers/tezbake/main.go index fe1b824..5bd960a 100644 --- a/core/providers/tezbake/main.go +++ b/core/providers/tezbake/main.go @@ -3,6 +3,7 @@ package tezbake import ( "context" "maps" + "time" "github.com/gofiber/fiber/v2" "github.com/tez-capital/tezpeak/configuration" @@ -10,17 +11,20 @@ import ( ) type Status struct { - Rights RightsStatus `json:"rights,omitempty"` - Services map[string]common.ApplicationServices `json:"services,omitempty"` - Bakers BakersStatus `json:"bakers,omitempty"` - Ledgers LedgerStatus `json:"ledgers,omitempty"` + Rights RightsStatus `json:"rights,omitempty"` + Services common.AplicationServicesStatus `json:"services,omitempty"` + Bakers BakersStatus `json:"bakers,omitempty"` + Ledgers LedgerStatus `json:"ledgers,omitempty"` } func (status *Status) Clone() *Status { return &Status{ // no need to clone RightsStatus status.Rights, - maps.Clone(status.Services), + common.AplicationServicesStatus{ + Applications: maps.Clone(status.Services.Applications), + Timestamp: status.Services.Timestamp, + }, status.Bakers, // no need to clone BakersStatus status.Ledgers, // no need to clone LedgerStatus } @@ -32,7 +36,10 @@ func GetEmptyStatus() *Status { Level: 0, Rights: []*BlockRights{}, }, - Services: make(map[string]common.ApplicationServices), + Services: common.AplicationServicesStatus{ + Applications: make(map[string]common.ApplicationServices), + Timestamp: time.Now().Unix(), + }, Bakers: BakersStatus{ Level: 0, Bakers: map[string]*BakerStakingStatus{}, @@ -73,7 +80,8 @@ func SetupModule(ctx context.Context, configuration *configuration.TezbakeModule switch statusUpdate := statusUpdate.(type) { case *common.ServicesStatusUpdate: application := statusUpdate.Application - tezbakeStatus.Services[application] = statusUpdate.Status + tezbakeStatus.Services.Applications[application] = statusUpdate.Status + tezbakeStatus.Services.Timestamp = time.Now().Unix() case *RightsStatusUpdate: tezbakeStatus.Rights = statusUpdate.RightsStatus case *BakersStatusUpdate: diff --git a/core/providers/tezpay/main.go b/core/providers/tezpay/main.go index 898b9cd..7152fbb 100644 --- a/core/providers/tezpay/main.go +++ b/core/providers/tezpay/main.go @@ -2,6 +2,7 @@ package tezpay import ( "context" + "time" "github.com/gofiber/fiber/v2" "github.com/tez-capital/tezpeak/configuration" @@ -10,14 +11,17 @@ import ( ) type Status struct { - Services map[string]common.ApplicationServices `json:"services,omitempty"` - Wallet WalletStatus `json:"wallet,omitempty"` + Services common.AplicationServicesStatus `json:"services,omitempty"` + Wallet WalletStatus `json:"wallet,omitempty"` } func (status *Status) Clone() *Status { return &Status{ - Services: maps.Clone(status.Services), - Wallet: status.Wallet, + Services: common.AplicationServicesStatus{ + Applications: maps.Clone(status.Services.Applications), + Timestamp: status.Services.Timestamp, + }, + Wallet: status.Wallet, } } @@ -35,7 +39,10 @@ func (statusUpdate *StatusUpdate) GetData() any { func GetEmptyStatus() *Status { return &Status{ - Services: make(map[string]common.ApplicationServices), + Services: common.AplicationServicesStatus{ + Applications: make(map[string]common.ApplicationServices), + Timestamp: time.Now().Unix(), + }, } } @@ -57,7 +64,8 @@ func SetupModule(ctx context.Context, configuration *configuration.TezpayModuleC switch statusUpdate := statusUpdate.(type) { case *common.ServicesStatusUpdate: application := statusUpdate.Application - tezpayStatus.Services[application] = statusUpdate.Status + tezpayStatus.Services.Applications[application] = statusUpdate.Status + tezpayStatus.Services.Timestamp = time.Now().Unix() case *WalletBalanceUpdate: tezpayStatus.Wallet = statusUpdate.Status } diff --git a/web/src/components/app/PayoutsCard.svelte b/web/src/components/app/PayoutsCard.svelte index 1073666..7b33b11 100644 --- a/web/src/components/app/PayoutsCard.svelte +++ b/web/src/components/app/PayoutsCard.svelte @@ -10,6 +10,7 @@ goto('/tezpay'); } + $: hasTezpayStatus = !!$services.applications?.tezpay?.['tezpay']; $: isTezpayRunning = $services.applications?.tezpay?.['tezpay']?.status === 'running'; @@ -24,7 +25,9 @@
Automatic Payouts:
- {#if isTezpayRunning} + {#if !hasTezpayStatus} +
UNKNOWN
+ {:else if isTezpayRunning}
ACTIVE
{:else}
INACTIVE