chore: update project changes
This commit is contained in:
@@ -13,10 +13,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
recentJournalLimit = 12
|
||||
transactionPageSize = 20
|
||||
topAssetLimit = 5
|
||||
topHoldersPerAsset = 5
|
||||
recentJournalLimit = 12
|
||||
recentSettlementLimit = 12
|
||||
transactionPageSize = 20
|
||||
topAssetLimit = 5
|
||||
topHoldersPerAsset = 5
|
||||
)
|
||||
|
||||
type Stats struct {
|
||||
@@ -26,6 +27,25 @@ type Stats struct {
|
||||
LastRecordedAt time.Time
|
||||
}
|
||||
|
||||
type SettlementStats struct {
|
||||
Pending int64
|
||||
Retryable int64
|
||||
Confirmed int64
|
||||
ManualReview int64
|
||||
}
|
||||
|
||||
type Settlement struct {
|
||||
ID string
|
||||
SourceService string
|
||||
SourceTransactionID string
|
||||
Status ledger.SettlementStatus
|
||||
Network string
|
||||
TransactionHash string
|
||||
Attempts int
|
||||
LastError string
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type Holder struct {
|
||||
Rank int64
|
||||
OwnerType string
|
||||
@@ -47,6 +67,7 @@ type Repository interface {
|
||||
GetByID(context.Context, string) (ledger.Journal, error)
|
||||
Balance(context.Context, ledger.AccountReference, time.Time) (ledger.Amount, error)
|
||||
TopHolders(context.Context, int, int) ([]Holder, error)
|
||||
SettlementDashboard(context.Context, int) (SettlementStats, []Settlement, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
@@ -54,8 +75,10 @@ type Service struct {
|
||||
}
|
||||
|
||||
type Dashboard struct {
|
||||
Stats Stats
|
||||
Journals []ledger.Journal
|
||||
Stats Stats
|
||||
Journals []ledger.Journal
|
||||
SettlementStats SettlementStats
|
||||
Settlements []Settlement
|
||||
}
|
||||
|
||||
type Assets struct {
|
||||
@@ -100,7 +123,11 @@ func (s *Service) Dashboard(ctx context.Context) (Dashboard, error) {
|
||||
if err != nil {
|
||||
return Dashboard{}, fmt.Errorf("read recent journals: %w", err)
|
||||
}
|
||||
return Dashboard{Stats: stats, Journals: journals}, nil
|
||||
settlementStats, settlements, err := s.repository.SettlementDashboard(ctx, recentSettlementLimit)
|
||||
if err != nil {
|
||||
return Dashboard{}, fmt.Errorf("read settlement dashboard: %w", err)
|
||||
}
|
||||
return Dashboard{Stats: stats, Journals: journals, SettlementStats: settlementStats, Settlements: settlements}, nil
|
||||
}
|
||||
|
||||
func (s *Service) Assets(ctx context.Context) (Assets, error) {
|
||||
|
||||
@@ -10,14 +10,16 @@ import (
|
||||
)
|
||||
|
||||
type repositoryStub struct {
|
||||
stats Stats
|
||||
journals []ledger.Journal
|
||||
transactions []ledger.Journal
|
||||
journal ledger.Journal
|
||||
journalErr error
|
||||
holders []Holder
|
||||
balance ledger.Amount
|
||||
lastFilter *ledger.JournalFilter
|
||||
stats Stats
|
||||
journals []ledger.Journal
|
||||
transactions []ledger.Journal
|
||||
journal ledger.Journal
|
||||
journalErr error
|
||||
holders []Holder
|
||||
balance ledger.Amount
|
||||
settlementStats SettlementStats
|
||||
settlements []Settlement
|
||||
lastFilter *ledger.JournalFilter
|
||||
}
|
||||
|
||||
func (r repositoryStub) Stats(context.Context) (Stats, error) { return r.stats, nil }
|
||||
@@ -39,6 +41,23 @@ func (r repositoryStub) Balance(context.Context, ledger.AccountReference, time.T
|
||||
func (r repositoryStub) TopHolders(context.Context, int, int) ([]Holder, error) {
|
||||
return r.holders, nil
|
||||
}
|
||||
func (r repositoryStub) SettlementDashboard(context.Context, int) (SettlementStats, []Settlement, error) {
|
||||
return r.settlementStats, r.settlements, nil
|
||||
}
|
||||
|
||||
func TestDashboardIncludesBlockchainSettlements(t *testing.T) {
|
||||
service := NewService(repositoryStub{
|
||||
settlementStats: SettlementStats{Confirmed: 7, Pending: 2},
|
||||
settlements: []Settlement{{ID: "settlement-1", Status: ledger.SettlementConfirmed, TransactionHash: "chain-hash"}},
|
||||
})
|
||||
result, err := service.Dashboard(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.SettlementStats.Confirmed != 7 || len(result.Settlements) != 1 || result.Settlements[0].TransactionHash != "chain-hash" {
|
||||
t.Fatalf("unexpected settlement dashboard: %+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssetsIncludesTopHolders(t *testing.T) {
|
||||
balance, err := ledger.ParseAmount("125.5")
|
||||
|
||||
Reference in New Issue
Block a user